/** * Ensures that the user page is available after installation. */ public function testInstaller() { // Do assertions from parent. parent::testInstaller(); // Do assertions specific to test. $this->assertEqual(drupal_realpath($this->sync_dir), config_get_config_directory(CONFIG_SYNC_DIRECTORY), 'The sync directory has been updated during the installation.'); $this->assertEqual(USER_REGISTER_ADMINISTRATORS_ONLY, \Drupal::config('user.settings')->get('register'), 'Ensure standard_install() does not overwrite user.settings::register.'); $this->assertEqual([], \Drupal::entityDefinitionUpdateManager()->getChangeSummary(), 'There are no entity or field definition updates.'); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $directory = $input->getOption('directory'); $tar = $input->getOption('tar'); $removeUuid = $input->getOption('remove-uuid'); if (!$directory) { $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); } if ($tar) { if (!is_dir($directory)) { mkdir($directory, 0777, true); } $dateTime = new \DateTime(); $archiveFile = sprintf('%s/config-%s.tar.gz', $directory, $dateTime->format('Y-m-d-H-i-s')); $archiveTar = new ArchiveTar($archiveFile, 'gz'); } try { // Get raw configuration data without overrides. foreach ($this->configManager->getConfigFactory()->listAll() as $name) { $configData = $this->configManager->getConfigFactory()->get($name)->getRawData(); $configName = sprintf('%s.yml', $name); // The _core is site-specific, so don't export it. unset($configData['_core']); if ($removeUuid) { unset($configData['uuid']); } $ymlData = Yaml::encode($configData); if ($tar) { $archiveTar->addString($configName, $ymlData); continue; } $configFileName = sprintf('%s/%s', $directory, $configName); $fileSystem = new Filesystem(); try { $fileSystem->mkdir($directory); } catch (IOExceptionInterface $e) { $io->error(sprintf($this->trans('commands.config.export.messages.error'), $e->getPath())); } file_put_contents($configFileName, $ymlData); } } catch (\Exception $e) { $io->error($e->getMessage()); } $io->info(sprintf($this->trans('commands.config.export.messages.directory'), $directory)); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $directory = $input->getOption('directory'); if ($directory) { $configSyncDir = $directory; } else { $configSyncDir = config_get_config_directory(CONFIG_SYNC_DIRECTORY); } $source_storage = new FileStorage($configSyncDir); $storage_comparer = new StorageComparer($source_storage, $this->configStorage, $this->configManager); if (!$storage_comparer->createChangelist()->hasChanges()) { $io->success($this->trans('commands.config.import.messages.nothing-to-do')); } if ($this->configImport($io, $storage_comparer)) { $io->success($this->trans('commands.config.import.messages.imported')); } }
/** * Tests creating a content type during config import. */ public function testImportCreate() { $node_type_id = 'import'; $node_type_config_name = "node.type.{$node_type_id}"; // Simulate config data to import. $active = $this->container->get('config.storage'); $sync = $this->container->get('config.storage.sync'); $this->copyConfig($active, $sync); // Manually add new node type. $src_dir = __DIR__ . '/../../../modules/node_test_config/sync'; $target_dir = config_get_config_directory(CONFIG_SYNC_DIRECTORY); $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$node_type_config_name}.yml", "{$target_dir}/{$node_type_config_name}.yml")); // Import the content of the sync directory. $this->configImporter()->import(); // Check that the content type was created. $node_type = NodeType::load($node_type_id); $this->assertTrue($node_type, 'Import node type from sync was created.'); $this->assertFalse(FieldConfig::loadByName('node', $node_type_id, 'body')); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { if ($path = $form_state->getValue('import_tarball')) { $this->configStorage->deleteAll(); try { $archiver = new ArchiveTar($path, 'gz'); $files = array(); foreach ($archiver->listContent() as $file) { $files[] = $file['filename']; } $archiver->extractList($files, config_get_config_directory(CONFIG_STAGING_DIRECTORY)); drupal_set_message($this->t('Your configuration files were successfully uploaded, ready for import.')); $form_state->setRedirect('config.sync'); } catch (\Exception $e) { drupal_set_message($this->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', array('@message' => $e->getMessage())), 'error'); } drupal_unlink($path); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $config_file = $input->getArgument('config-file'); $copy_only = $input->getOption('copy-only'); try { $files = array(); $archiver = new ArchiveTar($config_file, 'gz'); $output->writeln($this->trans('commands.config.import.messages.config_files_imported')); foreach ($archiver->listContent() as $file) { $pathinfo = pathinfo($file['filename']); $files[$pathinfo['filename']] = $file['filename']; $output->writeln('[-] <info>' . $file['filename'] . '</info>'); } $config_staging_dir = config_get_config_directory(CONFIG_SYNC_DIRECTORY); try { $archiver->extract($config_staging_dir . '/'); } catch (\Exception $e) { $output->writeln('[+] <error>' . $e->getMessage() . '</error>'); return; } if ($copy_only) { $output->writeln(sprintf($this->trans('commands.config.import.messages.copied'), CONFIG_SYNC_DIRECTORY)); } else { foreach ($files as $cofig_name => $filename) { $config = $this->getConfigFactory()->getEditable($cofig_name); $parser = new Parser(); $config_value = $parser->parse(file_get_contents($config_staging_dir . '/' . $filename)); $config->setData($config_value); try { $config->save(); } catch (\Exception $e) { $output->writeln('[+] <error>' . $e->getMessage() . '</error>'); return; } } $output->writeln(sprintf($this->trans('commands.config.import.messages.imported'), CONFIG_SYNC_DIRECTORY)); } } catch (\Exception $e) { $output->writeln('[+] <error>' . $e->getMessage() . '</error>'); return; } }
/** * Tests importing configuration. */ function testImport() { // Verify access to the config upload form. $this->drupalGet('admin/config/development/configuration/full/import'); $this->assertResponse(200); // Attempt to upload a non-tar file. $text_file = current($this->drupalGetTestFiles('text')); $edit = array('files[import_tarball]' => drupal_realpath($text_file->uri)); $this->drupalPostForm('admin/config/development/configuration/full/import', $edit, t('Upload')); $this->assertText(t('Could not extract the contents of the tar file')); // Make the sync directory read-only. $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); \Drupal::service('file_system')->chmod($directory, 0555); $this->drupalGet('admin/config/development/configuration/full/import'); $this->assertRaw(t('The directory %directory is not writable.', ['%directory' => $directory])); // Ensure submit button for \Drupal\config\Form\ConfigImportForm is // disabled. $submit_is_disabled = $this->cssSelect('form.config-import-form input[type="submit"]:disabled'); $this->assertTrue(count($submit_is_disabled) === 1, 'The submit button is disabled.'); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $configFile = $input->getOption('file'); $removeFiles = $input->getOption('remove-files'); $configSyncDir = config_get_config_directory(CONFIG_SYNC_DIRECTORY); if ($configFile) { $archiveTar = new ArchiveTar($configFile, 'gz'); $io->simple($this->trans('commands.config.import.messages.config_files_imported')); foreach ($archiveTar->listContent() as $file) { $io->info('[-] ' . $file['filename']); } try { $archiveTar->extract($configSyncDir . '/'); } catch (\Exception $e) { $io->error($e->getMessage()); return; } } $finder = new Finder(); $finder->in($configSyncDir); $finder->name("*.yml"); foreach ($finder as $configFile) { $configName = $configFile->getBasename('.yml'); $configFilePath = sprintf('%s/%s', $configSyncDir, $configFile->getBasename()); $config = $this->getConfigFactory()->getEditable($configName); $parser = new Parser(); $configData = $parser->parse(file_get_contents($configFilePath)); $config->setData($configData); if ($removeFiles) { file_unmanaged_delete($configFilePath); } try { $config->save(); } catch (\Exception $e) { $io->error($e->getMessage()); return; } } $io->success(sprintf($this->trans('commands.config.import.messages.imported'), CONFIG_SYNC_DIRECTORY)); }
/** * Tests creating field storages and fields during config import. */ function testImportCreate() { // A field storage with one single field. $field_name = 'field_test_import_sync'; $field_storage_id = "entity_test.{$field_name}"; $field_id = "entity_test.entity_test.{$field_name}"; $field_storage_config_name = "field.storage.{$field_storage_id}"; $field_config_name = "field.field.{$field_id}"; // A field storage with two fields. $field_name_2 = 'field_test_import_sync_2'; $field_storage_id_2 = "entity_test.{$field_name_2}"; $field_id_2a = "entity_test.test_bundle.{$field_name_2}"; $field_id_2b = "entity_test.test_bundle_2.{$field_name_2}"; $field_storage_config_name_2 = "field.storage.{$field_storage_id_2}"; $field_config_name_2a = "field.field.{$field_id_2a}"; $field_config_name_2b = "field.field.{$field_id_2b}"; $active = $this->container->get('config.storage'); $sync = $this->container->get('config.storage.sync'); $this->copyConfig($active, $sync); // Add the new files to the sync directory. $src_dir = __DIR__ . '/../../modules/field_test_config/sync'; $target_dir = config_get_config_directory(CONFIG_SYNC_DIRECTORY); $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_storage_config_name}.yml", "{$target_dir}/{$field_storage_config_name}.yml")); $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_config_name}.yml", "{$target_dir}/{$field_config_name}.yml")); $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_storage_config_name_2}.yml", "{$target_dir}/{$field_storage_config_name_2}.yml")); $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_config_name_2a}.yml", "{$target_dir}/{$field_config_name_2a}.yml")); $this->assertTrue(file_unmanaged_copy("{$src_dir}/{$field_config_name_2b}.yml", "{$target_dir}/{$field_config_name_2b}.yml")); // Import the content of the sync directory. $this->configImporter()->import(); // Check that the field and storage were created. $field_storage = FieldStorageConfig::load($field_storage_id); $this->assertTrue($field_storage, 'Test import storage field from sync exists'); $field = FieldConfig::load($field_id); $this->assertTrue($field, 'Test import field from sync exists'); $field_storage = FieldStorageConfig::load($field_storage_id_2); $this->assertTrue($field_storage, 'Test import storage field 2 from sync exists'); $field = FieldConfig::load($field_id_2a); $this->assertTrue($field, 'Test import field 2a from sync exists'); $field = FieldConfig::load($field_id_2b); $this->assertTrue($field, 'Test import field 2b from sync exists'); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $messageHelper = $this->getMessageHelper(); $directory = $input->getOption('directory'); $tar = $input->getOption('tar'); $archiveTar = new ArchiveTar(); if (!$directory) { $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); } if ($tar) { if (!is_dir($directory)) { mkdir($directory, 0777, true); } $dateTime = new \DateTime(); $archiveFile = sprintf('%s/config-%s.tar.gz', $directory, $dateTime->format('Y-m-d-H-i-s')); $archiveTar = new ArchiveTar($archiveFile, 'gz'); } try { $configManager = $this->getConfigManager(); // Get raw configuration data without overrides. foreach ($configManager->getConfigFactory()->listAll() as $name) { $configData = $configManager->getConfigFactory()->get($name)->getRawData(); $configName = sprintf('%s.yml', $name); $ymlData = Yaml::encode($configData); if ($tar) { $archiveTar->addString($configName, $ymlData); continue; } $configFileName = sprintf('%s/%s', $directory, $configName); file_put_contents($configFileName, $ymlData); } } catch (\Exception $e) { $output->writeln('[+] <error>' . $e->getMessage() . '</error>'); return; } $messageHelper->addSuccessMessage(sprintf($this->trans('commands.config.export.messages.directory'))); $messageHelper->addSuccessMessage($directory); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $archiveFile = $input->getOption('file'); $directory = $input->getOption('directory'); $removeFiles = $input->getOption('remove-files'); if ($directory) { $configSyncDir = $directory; } else { $configSyncDir = config_get_config_directory(CONFIG_SYNC_DIRECTORY); } // Determine $source_storage in partial and non-partial cases. $active_storage = \Drupal::service('config.storage'); $source_storage = new FileStorage($configSyncDir); /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */ $config_manager = \Drupal::service('config.manager'); $storage_comparer = new StorageComparer($source_storage, $active_storage, $config_manager); if (!$storage_comparer->createChangelist()->hasChanges()) { $io->success($this->trans('commands.config.import.messages.nothing-to-do')); } if ($this->configImport($io, $storage_comparer)) { $io->success($this->trans('commands.config.import.messages.imported')); } }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $directory = $input->getOption('directory'); $module = $input->getOption('module'); $configName = $input->getArgument('config-name'); $optionalConfig = $input->getOption('optional-config'); $config = $this->getConfiguration($configName); if ($config) { if (!$directory) { $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); } $this->configExport[$configName] = array('data' => $config, 'optional' => $optionalConfig); if ($input->getOption('include-dependencies')) { // Include config dependencies in export files if ($dependencies = $this->fetchDependencies($config, 'config')) { $this->resolveDependencies($dependencies, $optionalConfig); } } } else { $io->error($this->trans('commands.config.export.single.messages.config-not-found')); } if (!$module) { if (!$directory) { $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); } $this->exportConfig($directory, $io, $this->trans('commands.config.export.single.messages.config_exported')); } else { $this->exportConfigToModule($module, $io, $this->trans('commands.config.export.single.messages.config_exported')); } }
/** * Prepares the current environment for running the test. * * Backups various current environment variables and resets them, so they do * not interfere with the Backdrop site installation in which tests are executed * and can be restored in tearDown(). * * Also sets up new resources for the testing environment, such as the public * filesystem and configuration directories. * * @see BackdropWebTestCase::setUp() * @see BackdropWebTestCase::tearDown() */ protected function prepareEnvironment() { global $user, $language, $settings, $config_directories; // Store necessary current values before switching to prefixed database. $this->originalLanguage = $language; $this->originalLanguageDefault = config_get('system.core', 'language_default'); $this->originalConfigDirectories = $config_directories; $this->originalFileDirectory = config_get('system.core', 'file_public_path', 'files'); $this->originalProfile = backdrop_get_profile(); $this->originalCleanUrl = config_get('system.core', 'clean_url'); $this->originalUser = $user; $this->originalSettings = $settings; // Set to English to prevent exceptions from utf8_truncate() from t() // during install if the current language is not 'en'. // The following array/object conversion is copied from language_default(). $language = (object) array('langcode' => 'en', 'name' => 'English', 'direction' => 0, 'enabled' => 1, 'weight' => 0); // Save and clean the shutdown callbacks array because it is static cached // and will be changed by the test run. Otherwise it will contain callbacks // from both environments and the testing environment will try to call the // handlers defined by the original one. $callbacks =& backdrop_register_shutdown_function(); $this->originalShutdownCallbacks = $callbacks; $callbacks = array(); // Create test directory ahead of installation so fatal errors and debug // information can be logged during installation process. // Use temporary files directory with the same prefix as the database. $this->public_files_directory = $this->originalFileDirectory . '/simpletest/' . substr($this->databasePrefix, 10); $this->private_files_directory = $this->public_files_directory . '/private'; $this->temp_files_directory = $this->private_files_directory . '/temp'; // Create the directories. file_prepare_directory($this->public_files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); file_prepare_directory($this->private_files_directory, FILE_CREATE_DIRECTORY); file_prepare_directory($this->temp_files_directory, FILE_CREATE_DIRECTORY); $this->generatedTestFiles = FALSE; // Set the new config directories. During test execution, these values are // manually set directly in config_get_config_directory(). $config_base_path = 'files/simpletest/' . substr($this->databasePrefix, 10) . '/config_'; $config_directories['active'] = $config_base_path . 'active'; $config_directories['staging'] = $config_base_path . 'staging'; $active_directory = config_get_config_directory('active'); $staging_directory = config_get_config_directory('staging'); file_prepare_directory($active_directory, FILE_CREATE_DIRECTORY); file_prepare_directory($staging_directory, FILE_CREATE_DIRECTORY); // Log fatal errors. ini_set('log_errors', 1); ini_set('error_log', $this->public_files_directory . '/error.log'); // Set the test information for use in other parts of Backdrop. $test_info =& $GLOBALS['backdrop_test_info']; $test_info['test_run_id'] = $this->databasePrefix; $test_info['in_child_site'] = FALSE; // Disable Drupal compatibility for test runs. $settings['backdrop_drupal_compatibility'] = FALSE; // Indicate the environment was set up correctly. $this->setupEnvironment = TRUE; }
/** * Tests config_get_config_directory(). */ public function testConfigGetConfigDirectory() { $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); $this->assertEqual($this->configDirectories[CONFIG_SYNC_DIRECTORY], $directory); $message = 'Calling config_get_config_directory() with CONFIG_ACTIVE_DIRECTORY results in an exception.'; try { config_get_config_directory(CONFIG_ACTIVE_DIRECTORY); $this->fail($message); } catch (\Exception $e) { $this->pass($message); } }
protected function getConfigurationData() { try { $active = config_get_config_directory('active'); $staging = config_get_config_directory('staging'); } catch (\Exception $e) { $active = ''; $staging = ''; } return ['configuration' => [$this->trans('commands.site.status.messages.active') => $active, $this->trans('commands.site.status.messages.staging') => $staging]]; }
/** * BC: Automatically resolve former KernelTestBase class properties. * * Test authors should follow the provided instructions and adjust their tests * accordingly. * * @deprecated in Drupal 8.0.x, will be removed before Drupal 8.2.0. */ public function __get($name) { if (in_array($name, array('public_files_directory', 'private_files_directory', 'temp_files_directory', 'translation_files_directory'))) { // @comment it in again. trigger_error(sprintf("KernelTestBase::\$%s no longer exists. Use the regular API method to retrieve it instead (e.g., Settings).", $name), E_USER_DEPRECATED); switch ($name) { case 'public_files_directory': return Settings::get('file_public_path', \Drupal::service('site.path') . '/files'); case 'private_files_directory': return $this->container->get('config.factory')->get('system.file')->get('path.private'); case 'temp_files_directory': return file_directory_temp(); case 'translation_files_directory': return Settings::get('file_public_path', \Drupal::service('site.path') . '/translations'); } } if ($name === 'configDirectories') { trigger_error(sprintf("KernelTestBase::\$%s no longer exists. Use config_get_config_directory() directly instead.", $name), E_USER_DEPRECATED); return array(CONFIG_SYNC_DIRECTORY => config_get_config_directory(CONFIG_SYNC_DIRECTORY)); } $denied = array('testId', 'timeLimit', 'results', 'assertions', 'skipClasses', 'verbose', 'verboseId', 'verboseClassName', 'verboseDirectory', 'verboseDirectoryUrl', 'dieOnFail', 'kernel', 'generatedTestFiles', 'keyValueFactory'); if (in_array($name, $denied) || strpos($name, 'original') === 0) { throw new \RuntimeException(sprintf('TestBase::$%s property no longer exists', $name)); } }
/** * Returns a File-based configuration storage implementation. * * If there is no active configuration directory calling this method will * result in an error. * * @return \Drupal\Core\Config\FileStorage * * @deprecated in Drupal 8.0.x and will be removed before 9.0.0. Drupal core * no longer creates an active directory. * * @throws \Exception */ public static function getFileStorage() { return new FileStorage(config_get_config_directory(CONFIG_ACTIVE_DIRECTORY)); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { global $config_directories, $install_state; $sync_directory = $form_state->getValue('sync_directory'); if ($sync_directory != config_get_config_directory(CONFIG_SYNC_DIRECTORY)) { $settings['config_directories'][CONFIG_SYNC_DIRECTORY] = (object) array('value' => $sync_directory, 'required' => TRUE); drupal_rewrite_settings($settings); $config_directories[CONFIG_SYNC_DIRECTORY] = $sync_directory; } if ($path = $form_state->getValue('import_tarball')) { // Ensure that we have an empty directory if we're going. $sync = new FileStorage($sync_directory); $sync->deleteAll(); try { $archiver = new ArchiveTar($path, 'gz'); $files = array(); foreach ($archiver->listContent() as $file) { $files[] = $file['filename']; } $archiver->extractList($files, config_get_config_directory(CONFIG_SYNC_DIRECTORY)); drupal_set_message($this->t('Your configuration files were successfully uploaded, ready for import.')); } catch (\Exception $e) { drupal_set_message($this->t('Could not extract the contents of the tar file. The error message is <em>@message</em>', array('@message' => $e->getMessage())), 'error'); } drupal_unlink($path); } // Change the langcode to the site default langcode provided by the // configuration. $config_storage = new FileStorage(config_get_config_directory(CONFIG_SYNC_DIRECTORY)); $install_state['parameters']['langcode'] = $config_storage->read('system.site')['langcode']; }
protected function getConfigurationData() { return ['configuration' => [$this->trans('commands.site.status.messages.active') => config_get_config_directory(active), $this->trans('commands.site.status.messages.staging') => config_get_config_directory(staging)]]; }
/** * Returns a FileStorage object working with the sync config directory. * * @return \Drupal\Core\Config\FileStorage FileStorage */ static function getSync() { return new FileStorage(config_get_config_directory(CONFIG_SYNC_DIRECTORY)); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $directory = $input->getOption('directory'); if (!$directory) { $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); } if (!is_dir($directory)) { mkdir($directory, 0777, true); } $configName = $input->getArgument('config-name'); $configExportFile = $directory . '/' . $configName . '.yml'; file_unmanaged_delete($configExportFile); $config = $this->getConfigFactory()->getEditable($configName); if ($config) { $yaml = Yaml::encode($config->getRawData()); // Save release file file_put_contents($configExportFile, $yaml); $output->writeln('[+] <info>' . sprintf($this->trans('commands.config.export.single.messages.export'), $configExportFile) . '</info>'); } else { $output->writeln('[+] <error>' . $this->trans('commands.config.export.single.messages.config-not-found') . '</error>'); } }
/** * Returns a FileStorage object working with the staging config directory. * * @return \Drupal\Core\Config\FileStorage FileStorage */ static function getStaging() { return new FileStorage(config_get_config_directory(CONFIG_STAGING_DIRECTORY)); }
/** * Tests serialization of configuration to file. */ function testSerialization() { $name = $this->randomMachineName(10) . '.' . $this->randomMachineName(10); $config_data = array('numeric keys' => array('i', 'n', 'd', 'e', 'x', 'e', 'd'), 'nested keys' => array('HTML' => '<strong> <bold> <em> <blockquote>', 'UTF-8' => 'FrançAIS is ÜBER-åwesome', 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ' => 'αβγδεζηθικλμνξοσὠ'), 'invalid xml' => '</title><script type="text/javascript">alert("Title XSS!");</script> & < > " \' '); // Encode and write, and reload and decode the configuration data. $filestorage = new FileStorage(config_get_config_directory(CONFIG_SYNC_DIRECTORY)); $filestorage->write($name, $config_data); $config_parsed = $filestorage->read($name); $key = 'numeric keys'; $this->assertIdentical($config_data[$key], $config_parsed[$key]); $key = 'nested keys'; $this->assertIdentical($config_data[$key], $config_parsed[$key]); $key = 'HTML'; $this->assertIdentical($config_data['nested keys'][$key], $config_parsed['nested keys'][$key]); $key = 'UTF-8'; $this->assertIdentical($config_data['nested keys'][$key], $config_parsed['nested keys'][$key]); $key = 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΣὨ'; $this->assertIdentical($config_data['nested keys'][$key], $config_parsed['nested keys'][$key]); $key = 'invalid xml'; $this->assertIdentical($config_data[$key], $config_parsed[$key]); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); $directory = $input->getOption('directory'); if (!$directory) { $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); } if (!is_dir($directory)) { mkdir($directory, 0777, true); } $configName = $input->getArgument('config-name'); $configNames = [$configName]; if ($input->getOption('include-dependencies')) { $configNames += $this->getConfigDependencies($configName); } foreach ($configNames as $configName) { $config = $this->getConfigFactory()->getEditable($configName); $configExportFile = $directory . '/' . $configName . '.yml'; file_unmanaged_delete($configExportFile); if ($config) { $yaml = Yaml::encode($config->getRawData()); // Save configuration file. file_put_contents($configExportFile, $yaml); $io->info(sprintf($this->trans('commands.config.export.single.messages.export'), $configExportFile)); } else { $io->error($this->trans('commands.config.export.single.messages.config-not-found')); } } }
/** * Tests config_requirements(). */ public function testConfigModuleRequirements() { $this->drupalLogin($this->adminUser); $this->drupalPostForm('admin/modules', array('modules[Core][config][enable]' => TRUE), t('Install')); $directory = config_get_config_directory(CONFIG_SYNC_DIRECTORY); file_unmanaged_delete_recursive($directory); $this->drupalGet('/admin/reports/status'); $this->assertRaw(t('The directory %directory does not exist.', array('%directory' => $directory))); file_prepare_directory($directory, FILE_CREATE_DIRECTORY); \Drupal::service('file_system')->chmod($directory, 0555); $this->drupalGet('/admin/reports/status'); $this->assertRaw(t('The directory %directory is not writable.', ['%directory' => $directory])); }
/** * Provides an overview of the Backdrop database update. * * This page provides cautionary suggestions that should happen before * proceeding with the update to ensure data integrity. * * @return * Rendered HTML form. */ function update_info_page() { global $databases; // Change query-strings on css/js files to enforce reload for all users. _backdrop_flush_css_js(); // Flush the cache of all data for the update status module. if (db_table_exists('cache_update')) { cache('update')->flush(); } // Get database name $db_name = $databases['default']['default']['database']; // Get the config path $config_dir = config_get_config_directory('active'); update_task_list('info'); backdrop_set_title('Backdrop database update'); $token = backdrop_get_token('update'); $output = '<p>Use this utility to update your database whenever you install a new version of Backdrop CMS and/or one of the site\'s modules.</p><p>For more detailed information, see the <a href="http://backdropcms.org/guide/upgrade">upgrading handbook</a>. If you are unsure of what these terms mean you should probably contact your hosting provider.</p>'; $output .= "<ol>\n"; $output .= "<li><strong>Make any necessary backups.</strong> This update utility will alter your database and config files. In case of an emergency you may need to revert to a recent backup; make sure you have one.\n"; $output .= "<ul>\n"; $output .= "<li><strong>Database:</strong> Back up a dump of the '" . $db_name . "' database.</li>\n"; $output .= "<li><strong>Config files:</strong> Back up the entire '" . $config_dir . "' directory.</li>\n"; $output .= "</ul>\n"; $output .= '<li>Put your site into <a href="' . base_path() . '?q=admin/config/development/maintenance">maintenance mode</a> (optional but recommended).</li>' . "\n"; $output .= "<li>Install your new files into the appropriate location, as described in the handbook.</li>\n"; $output .= "</ol>\n"; $output .= "<p>When you have performed the above steps you may proceed.</p>\n"; $form_action = check_url(backdrop_current_script_url(array('op' => 'selection', 'token' => $token))); $output .= '<form method="post" action="' . $form_action . '"><p><input type="submit" value="Continue" class="form-submit" /></p></form>'; $output .= "\n"; return $output; }