You are here

public function OverriddenConfigImportTest::testConfigImportUpdates in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/language/tests/src/Kernel/OverriddenConfigImportTest.php \Drupal\Tests\language\Kernel\OverriddenConfigImportTest::testConfigImportUpdates()

Tests importing overridden config alongside config in the default language.

File

core/modules/language/tests/src/Kernel/OverriddenConfigImportTest.php, line 59

Class

OverriddenConfigImportTest
Tests importing of config with language overrides.

Namespace

Drupal\Tests\language\Kernel

Code

public function testConfigImportUpdates() {
  $storage = $this->container
    ->get('config.storage');
  $sync = $this->container
    ->get('config.storage.sync');

  /** @var \Drupal\language\ConfigurableLanguageManagerInterface $language_manager */
  $language_manager = $this->container
    ->get('language_manager');

  // Make a change to the site configuration in the default collection.
  $data = $storage
    ->read('system.site');
  $data['name'] = 'English site name';
  $sync
    ->write('system.site', $data);

  // Also make a change to the same config object, but using a language
  // override.

  /** @var \Drupal\Core\Config\StorageInterface $overridden_sync */
  $overridden_sync = $sync
    ->createCollection('language.fr');
  $overridden_sync
    ->write('system.site', [
    'name' => 'French site name',
  ]);

  // Before we start the import, the change to the site name should not be
  // present. This action also primes the cache in the config factory so that
  // we can test whether the cached data is correctly updated.
  $config = $this
    ->config('system.site');
  $this
    ->assertNotEquals('English site name', $config
    ->getRawData()['name']);

  // Before the import is started the site name should not yet be overridden.
  $this
    ->assertFalse($config
    ->hasOverrides());
  $override = $language_manager
    ->getLanguageConfigOverride('fr', 'system.site');
  $this
    ->assertTrue($override
    ->isNew());

  // Start the import of the new configuration.
  $this->configImporter
    ->reset()
    ->import();

  // Verify the new site name in the default language.
  $config = $this
    ->config('system.site')
    ->getRawData();
  $this
    ->assertEquals('English site name', $config['name']);

  // Verify the overridden site name.
  $override = $language_manager
    ->getLanguageConfigOverride('fr', 'system.site');
  $this
    ->assertEquals('French site name', $override
    ->get('name'));
}