Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / language / tests / src / Functional / LanguageConfigOverrideImportTest.php
1 <?php
2
3 namespace Drupal\Tests\language\Functional;
4
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Ensures the language config overrides can be synchronized.
10  *
11  * @group language
12  */
13 class LanguageConfigOverrideImportTest extends BrowserTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['language', 'config', 'locale', 'config_translation'];
21
22   /**
23    * Tests that language can be enabled and overrides are created during a sync.
24    */
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);
30
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
36     // ConfigFactory.
37     $this->rebuildContainer();
38
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']);
44
45     $this->configImporter()->import();
46     $this->rebuildContainer();
47     \Drupal::service('router.builder')->rebuild();
48
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');
53
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');
57   }
58
59   /**
60    * Tests that configuration events are not fired during a sync of overrides.
61    */
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();
66
67     ConfigurableLanguage::createFromLangcode('fr')->save();
68
69     /* @var \Drupal\Core\Config\StorageInterface $sync */
70     $sync = \Drupal::service('config.storage.sync');
71     $this->copyConfig(\Drupal::service('config.storage'), $sync);
72
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);
78
79     $this->configImporter()->import();
80     $this->rebuildContainer();
81     \Drupal::service('router.builder')->rebuild();
82
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);
87
88     $this->drupalGet('fr');
89     $this->assertText('FR default site name');
90   }
91
92 }