LanguageConfigOverrideImportTest.php in Drupal 10
File
core/modules/language/tests/src/Functional/LanguageConfigOverrideImportTest.php
View source
<?php
namespace Drupal\Tests\language\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\BrowserTestBase;
class LanguageConfigOverrideImportTest extends BrowserTestBase {
protected static $modules = [
'language',
'config',
'locale',
'config_translation',
];
protected $defaultTheme = 'stark';
public function testConfigOverrideImport() {
ConfigurableLanguage::createFromLangcode('fr')
->save();
$sync = \Drupal::service('config.storage.sync');
$this
->copyConfig(\Drupal::service('config.storage'), $sync);
\Drupal::service('module_installer')
->uninstall([
'language',
]);
$this
->rebuildContainer();
$override_sync = $sync
->createCollection('language.fr');
$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->rootUser);
$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');
}
public function testConfigOverrideImportEvents() {
\Drupal::service('module_installer')
->install([
'config_events_test',
]);
$this
->rebuildContainer();
ConfigurableLanguage::createFromLangcode('fr')
->save();
$sync = \Drupal::service('config.storage.sync');
$this
->copyConfig(\Drupal::service('config.storage'), $sync);
$override_sync = $sync
->createCollection('language.fr');
$override_sync
->write('system.site', [
'name' => 'FR default site name',
]);
\Drupal::state()
->set('config_events_test.event', FALSE);
$this
->configImporter()
->import();
$this
->rebuildContainer();
$event_recorder = \Drupal::state()
->get('config_events_test.event', FALSE);
$this
->assertFalse($event_recorder);
$this
->drupalGet('fr');
$this
->assertSession()
->pageTextContains('FR default site name');
}
}