function LanguageConfigOverrideImportTest::testConfigOverrideImport

Same name in other branches
  1. 9 core/modules/language/tests/src/Functional/LanguageConfigOverrideImportTest.php \Drupal\Tests\language\Functional\LanguageConfigOverrideImportTest::testConfigOverrideImport()
  2. 8.9.x core/modules/language/tests/src/Functional/LanguageConfigOverrideImportTest.php \Drupal\Tests\language\Functional\LanguageConfigOverrideImportTest::testConfigOverrideImport()
  3. 11.x core/modules/language/tests/src/Functional/LanguageConfigOverrideImportTest.php \Drupal\Tests\language\Functional\LanguageConfigOverrideImportTest::testConfigOverrideImport()

Tests that language can be enabled and overrides are created during a sync.

File

core/modules/language/tests/src/Functional/LanguageConfigOverrideImportTest.php, line 36

Class

LanguageConfigOverrideImportTest
Ensures the language config overrides can be synchronized.

Namespace

Drupal\Tests\language\Functional

Code

public function testConfigOverrideImport() : void {
    ConfigurableLanguage::createFromLangcode('fr')->save();
    
    /** @var \Drupal\Core\Config\StorageInterface $sync */
    $sync = \Drupal::service('config.storage.sync');
    $this->copyConfig(\Drupal::service('config.storage'), $sync);
    // Uninstall the language module and its dependencies so we can test
    // enabling the language module and creating overrides at the same time
    // during a configuration synchronization.
    \Drupal::service('module_installer')->uninstall([
        'language',
    ]);
    // Ensure that the current site has no overrides registered to the
    // ConfigFactory.
    $this->rebuildContainer();
    
    /** @var \Drupal\Core\Config\StorageInterface $override_sync */
    $override_sync = $sync->createCollection('language.fr');
    // Create some overrides in sync.
    $override_sync->write('system.site', [
        'name' => 'FR default site name',
    ]);
    $override_sync->write('system.maintenance', [
        'message' => 'FR message: @site is currently under maintenance. We should be back shortly. Thank you for your patience',
    ]);
    $this->configImporter()
        ->import();
    $this->rebuildContainer();
    $override = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'system.site');
    $this->assertEquals('FR default site name', $override->get('name'));
    $this->drupalGet('fr');
    $this->assertSession()
        ->pageTextContains('FR default site name');
    $this->drupalLogin($this->drupalCreateUser([
        'translate configuration',
    ]));
    $this->drupalGet('admin/config/development/maintenance/translate/fr/edit');
    $this->assertSession()
        ->pageTextContains('FR message: @site is currently under maintenance. We should be back shortly. Thank you for your patience');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.