copyConfig example

->save();

    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()
      ->addState('test1', 'Test one')
      ->addState('test2', 'Test two')
      ->addState('test3', 'Test three')
      ->addEntityTypeAndBundle('node', 'example');
    $workflow->save();
    $this->workflow = $workflow;

    $this->copyConfig($this->container->get('config.storage')$this->container->get('config.storage.sync'));
  }

  /** * Tests deleting a state via config import. */
  public function testDeletingStateViaConfiguration() {
    $config_sync = \Drupal::service('config.storage.sync');

    // Alter the workflow data.     $config_data = $this->config('workflows.workflow.editorial')->get();
    unset($config_data['type_settings']['states']['test1']);
    

  protected static $modules = ['system', 'language'];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->installConfig(['system']);
    $this->copyConfig($this->container->get('config.storage')$this->container->get('config.storage.sync'));

    // Set up the ConfigImporter object for testing.     $storage_comparer = new StorageComparer(
      $this->container->get('config.storage.sync'),
      $this->container->get('config.storage')
    );
    $this->configImporter = new ConfigImporter(
      $storage_comparer->createChangelist(),
      $this->container->get('event_dispatcher'),
      $this->container->get('config.manager'),
      $this->container->get('lock'),
      
    $this->drupalGet('node/' . $nid);
    $this->assertSession()->responseContains(\Drupal::service('file_url_generator')->transformRelative($style->buildUrl($original_uri)));

    // Copy config to sync, and delete the image style.     $sync = $this->container->get('config.storage.sync');
    $active = $this->container->get('config.storage');
    // Remove the image field from the display, to avoid a dependency error     // during import.     EntityViewDisplay::load('node.article.default')
      ->removeComponent($field_name)
      ->save();
    $this->copyConfig($active$sync);
    $sync->delete('image.style.' . $style_name);
    $this->configImporter()->import();

    $this->assertNull(ImageStyle::load($style_name), 'Style deleted after config import.');
    $this->assertEquals(0, $this->getImageCount($style), 'Image style was flushed after being deleted by config import.');
  }

  /** * Tests access for the image style listing. */
  public function testImageStyleAccess() {
    
$this->submitForm([], 'Update translations');

    // Check if configuration translations have been imported.     $override = \Drupal::languageManager()->getLanguageConfigOverride('af', 'system.maintenance');
    // cSpell:disable-next-line     $this->assertEquals('Ons is tans besig met onderhoud op @site. Wees asseblief geduldig, ons sal binnekort weer terug wees.', $override->get('message'));

    // Ensure that \Drupal\locale\LocaleConfigSubscriber::onConfigSave() works     // as expected during a configuration install that installs locale.     /** @var \Drupal\Core\Config\FileStorage $sync */
    $sync = $this->container->get('config.storage.sync');
    $this->copyConfig($this->container->get('config.storage')$sync);

    // Add our own translation to the config that will be imported.     $af_sync = $sync->createCollection('language.af');
    $data = $af_sync->read('system.maintenance');
    $data['message'] = 'Test af message';
    $af_sync->write('system.maintenance', $data);

    // Uninstall locale module.     $this->container->get('module_installer')->uninstall(['locale_test_translate']);
    $this->container->get('module_installer')->uninstall(['locale']);
    $this->resetAll();

    


  /** * Tests config imports that install and uninstall a theme with dependencies. */
  public function testConfigImportWithThemeWithModuleDependencies() {
    $this->container->get('module_installer')->install(['test_module_required_by_theme', 'test_another_module_required_by_theme']);
    $this->container->get('theme_installer')->install(['test_theme_depending_on_modules']);
    $this->assertTrue($this->container->get('theme_handler')->themeExists('test_theme_depending_on_modules'), 'test_theme_depending_on_modules theme installed');

    $sync = $this->container->get('config.storage.sync');
    $this->copyConfig($this->container->get('config.storage')$sync);
    $extensions = $sync->read('core.extension');
    // Remove one of the modules the theme depends on.     unset($extensions['module']['test_module_required_by_theme']);
    $sync->write('core.extension', $extensions);

    try {
      $this->configImporter()->validate();
      $this->fail('ConfigImporterException not thrown; an invalid import was not stopped due to missing dependencies.');
    }
    catch (ConfigImporterException $e) {
      $error_message = 'Unable to uninstall the <em class="placeholder">Test Module Required by Theme</em> module because: Required by the theme: Test Theme Depending on Modules.';
      
/** * Tests importing an updated content type. */
  public function testImportChange() {
    $node_type_id = 'default';
    $node_type_config_name = "node.type.$node_type_id";

    // Simulate config data to import:     // - a modified version (modified label) of the node type config.     $active = $this->container->get('config.storage');
    $sync = $this->container->get('config.storage.sync');
    $this->copyConfig($active$sync);

    $node_type = $active->read($node_type_config_name);
    $new_label = 'Test update import field';
    $node_type['name'] = $new_label;
    // Save as files in the sync directory.     $sync->write($node_type_config_name$node_type);

    // Import the content of the sync directory.     $this->configImporter()->import();

    // Check that the updated config was correctly imported.
/** * Tests deleting a contact form entity via a configuration import. * * @see \Drupal\Core\Entity\Event\BundleConfigImportValidate */
  public function testDeleteThroughImport() {
    $this->installConfig(['system']);
    $contact_form = ContactForm::create(['id' => 'test', 'label' => 'Test contact form']);
    $contact_form->save();

    $this->copyConfig($this->container->get('config.storage')$this->container->get('config.storage.sync'));

    // Set up the ConfigImporter object for testing.     $storage_comparer = new StorageComparer(
      $this->container->get('config.storage.sync'),
      $this->container->get('config.storage')
    );
    $config_importer = new ConfigImporter(
      $storage_comparer->createChangelist(),
      $this->container->get('event_dispatcher'),
      $this->container->get('config.manager'),
      $this->container->get('lock'),
      
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();
    if (PHP_SAPI !== 'cli') {
      $this->markTestSkipped('This test has to be run from the CLI');
    }

    $this->installConfig(['system']);
    $this->copyConfig($this->container->get('config.storage')$this->container->get('config.storage.sync'));

    // Set up the ConfigImporter object for testing.     $storage_comparer = new StorageComparer(
      $this->container->get('config.storage.sync'),
      $this->container->get('config.storage')
    );
    $this->configImporter = new ConfigImporter(
      $storage_comparer->createChangelist(),
      $this->container->get('event_dispatcher'),
      $this->container->get('config.manager'),
      $this->container->get('lock'),
      
// 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 = Settings::get('config_sync_directory');
    /** @var \Drupal\Core\File\FileSystemInterface $file_system */
    $file_system = \Drupal::service('file_system');
    $this->assertNotFalse($file_system->copy("$src_dir/$field_storage_config_name.yml", "$target_dir/$field_storage_config_name.yml"));
    $this->assertNotFalse($file_system->copy("$src_dir/$field_config_name.yml", "$target_dir/$field_config_name.yml"));
    $this->assertNotFalse($file_system->copy("$src_dir/$field_storage_config_name_2.yml", "$target_dir/$field_storage_config_name_2.yml"));
    $this->assertNotFalse($file_system->copy("$src_dir/$field_config_name_2a.yml", "$target_dir/$field_config_name_2a.yml"));
    $this->assertNotFalse($file_system->copy("$src_dir/$field_config_name_2b.yml", "$target_dir/$field_config_name_2b.yml"));

    

  protected function setUp(): void {
    parent::setUp();

    $this->installConfig(['system', 'config_test']);
    // Installing config_test's default configuration pollutes the global     // variable being used for recording hook invocations by this test already,     // so it has to be cleared out manually.     unset($GLOBALS['hook_config_test']);

    $this->copyConfig($this->container->get('config.storage')$this->container->get('config.storage.sync'));
  }

  /** * Tests omission of module APIs for bare configuration operations. */
  public function testNoImport() {
    $dynamic_name = 'config_test.dynamic.dotted.default';

    // Verify the default configuration values exist.     $config = $this->config($dynamic_name);
    $this->assertSame('dotted.default', $config->get('id'));

    
protected static $modules = ['system', 'field', 'text', 'user', 'node'];

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->installEntitySchema('node');
    $this->installConfig(['system', 'field', 'node']);

    $this->copyConfig($this->container->get('config.storage')$this->container->get('config.storage.sync'));

    // Set up the ConfigImporter object for testing.     $storage_comparer = new StorageComparer(
      $this->container->get('config.storage.sync'),
      $this->container->get('config.storage')
    );
    $this->configImporter = new ConfigImporter(
      $storage_comparer->createChangelist(),
      $this->container->get('event_dispatcher'),
      $this->container->get('config.manager'),
      $this->container->get('lock'),
      

  public function assertConfigEntityImport(ConfigEntityInterface $entity) {
    // Save original config information.     $entity_uuid = $entity->uuid();
    $entity_type_id = $entity->getEntityTypeId();
    $original_data = $entity->toArray();
    // Copy everything to sync.     $this->copyConfig(\Drupal::service('config.storage'), \Drupal::service('config.storage.sync'));
    // Delete the configuration from active. Don't worry about side effects of     // deleting config like fields cleaning up field storages. The coming import     // should recreate everything as necessary.     $entity->delete();
    $this->configImporter()->reset()->import();
    $imported_entity = \Drupal::service('entity.repository')->loadEntityByUuid($entity_type_id$entity_uuid);
    $this->assertSame($original_data$imported_entity->toArray());
  }

}
    $test_entity_id = $this->randomMachineName();
    $test_entity = \Drupal::entityTypeManager()->getStorage('config_test')->create([
      'id' => $test_entity_id,
      'label' => $this->randomMachineName(),
    ]);
    $test_entity->save();
    $uuid = $test_entity->uuid();

    // Stage the test entity and then delete it from the active storage.     $active = $this->container->get('config.storage');
    $sync = $this->container->get('config.storage.sync');
    $this->copyConfig($active$sync);
    $test_entity->delete();

    // Create a content type with a matching UUID in the active storage.     $content_type = NodeType::create([
      'type' => mb_strtolower($this->randomMachineName(16)),
      'name' => $this->randomMachineName(),
      'uuid' => $uuid,
    ]);
    $content_type->save();

    // Confirm that the staged configuration is detected as a rename since the
protected function setUp(): void {
    parent::setUp();
    $this->installSchema('system', 'sequences');
    $this->installEntitySchema('entity_test');
    $this->installEntitySchema('user');
    $this->installConfig(['system', 'config_test']);
    // Installing config_test's default configuration pollutes the global     // variable being used for recording hook invocations by this test already,     // so it has to be cleared out manually.     unset($GLOBALS['hook_config_test']);

    $this->copyConfig($this->container->get('config.storage')$this->container->get('config.storage.sync'));

    // Set up the ConfigImporter object for testing.     $storage_comparer = new StorageComparer(
      $this->container->get('config.storage.sync'),
      $this->container->get('config.storage')
    );
    $this->configImporter = new ConfigImporter(
      $storage_comparer->createChangelist(),
      $this->container->get('event_dispatcher'),
      $this->container->get('config.manager'),
      $this->container->get('lock'),
      
$this->installConfig(['system']);
  }

  /** * Tests the import transformation. */
  public function testTransform() {
    // Get the raw system.site config and set it in the sync storage.     $rawConfig = $this->config('system.site')->getRawData();

    $storage = new MemoryStorage();
    $this->copyConfig($this->container->get('config.storage')$storage);

    $import = $this->container->get('config.import_transformer')->transform($storage);
    $config = $import->read('system.site');
    // The test subscriber always adds "Arrr" to the current site name.     $this->assertEquals($rawConfig['name'] . ' Arrr', $config['name']);
    $this->assertEquals($rawConfig['slogan']$config['slogan']);

    // Update the site config in the storage to test a second transformation.     $config['name'] = 'New name';
    $config['slogan'] = 'New slogan';
    $storage->write('system.site', $config);

    
Home | Imprint | This part of the site doesn't use cookies.