3 namespace Drupal\Tests\language\Functional;
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\Tests\BrowserTestBase;
9 * Ensures the language config overrides can be synchronized.
13 class LanguageConfigOverrideImportTest extends BrowserTestBase {
20 public static $modules = ['language', 'config', 'locale', 'config_translation'];
23 * Tests that language can be enabled and overrides are created during a sync.
25 public function testConfigOverrideImport() {
26 ConfigurableLanguage::createFromLangcode('fr')->save();
27 /* @var \Drupal\Core\Config\StorageInterface $sync */
28 $sync = \Drupal::service('config.storage.sync');
29 $this->copyConfig(\Drupal::service('config.storage'), $sync);
31 // Uninstall the language module and its dependencies so we can test
32 // enabling the language module and creating overrides at the same time
33 // during a configuration synchronization.
34 \Drupal::service('module_installer')->uninstall(['language']);
35 // Ensure that the current site has no overrides registered to the
37 $this->rebuildContainer();
39 /* @var \Drupal\Core\Config\StorageInterface $override_sync */
40 $override_sync = $sync->createCollection('language.fr');
41 // Create some overrides in sync.
42 $override_sync->write('system.site', ['name' => 'FR default site name']);
43 $override_sync->write('system.maintenance', ['message' => 'FR message: @site is currently under maintenance. We should be back shortly. Thank you for your patience']);
45 $this->configImporter()->import();
46 $this->rebuildContainer();
47 \Drupal::service('router.builder')->rebuild();
49 $override = \Drupal::languageManager()->getLanguageConfigOverride('fr', 'system.site');
50 $this->assertEqual('FR default site name', $override->get('name'));
51 $this->drupalGet('fr');
52 $this->assertText('FR default site name');
54 $this->drupalLogin($this->rootUser);
55 $this->drupalGet('admin/config/development/maintenance/translate/fr/edit');
56 $this->assertText('FR message: @site is currently under maintenance. We should be back shortly. Thank you for your patience');
60 * Tests that configuration events are not fired during a sync of overrides.
62 public function testConfigOverrideImportEvents() {
63 // Enable the config_events_test module so we can record events occurring.
64 \Drupal::service('module_installer')->install(['config_events_test']);
65 $this->rebuildContainer();
67 ConfigurableLanguage::createFromLangcode('fr')->save();
69 /* @var \Drupal\Core\Config\StorageInterface $sync */
70 $sync = \Drupal::service('config.storage.sync');
71 $this->copyConfig(\Drupal::service('config.storage'), $sync);
73 /* @var \Drupal\Core\Config\StorageInterface $override_sync */
74 $override_sync = $sync->createCollection('language.fr');
75 // Create some overrides in sync.
76 $override_sync->write('system.site', ['name' => 'FR default site name']);
77 \Drupal::state()->set('config_events_test.event', FALSE);
79 $this->configImporter()->import();
80 $this->rebuildContainer();
81 \Drupal::service('router.builder')->rebuild();
83 // Test that no config save event has been fired during the import because
84 // language configuration overrides do not fire events.
85 $event_recorder = \Drupal::state()->get('config_events_test.event', FALSE);
86 $this->assertFalse($event_recorder);
88 $this->drupalGet('fr');
89 $this->assertText('FR default site name');