Chris@16
|
1 <?php
|
Chris@16
|
2
|
Chris@16
|
3 namespace Drupal\FunctionalTests\Installer;
|
Chris@16
|
4
|
Chris@16
|
5 /**
|
Chris@16
|
6 * Tests translation files for multiple languages get imported during install.
|
Chris@16
|
7 *
|
Chris@16
|
8 * @group Installer
|
Chris@16
|
9 */
|
Chris@16
|
10 class InstallerTranslationMultipleLanguageTest extends InstallerTestBase {
|
Chris@16
|
11
|
Chris@16
|
12 /**
|
Chris@16
|
13 * Switch to the multilingual testing profile.
|
Chris@16
|
14 *
|
Chris@16
|
15 * @var string
|
Chris@16
|
16 */
|
Chris@16
|
17 protected $profile = 'testing_multilingual';
|
Chris@16
|
18
|
Chris@16
|
19 /**
|
Chris@16
|
20 * {@inheritdoc}
|
Chris@16
|
21 */
|
Chris@16
|
22 protected function setUpLanguage() {
|
Chris@16
|
23 // Place custom local translations in the translations directory.
|
Chris@16
|
24 mkdir(DRUPAL_ROOT . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
|
Chris@16
|
25 file_put_contents(DRUPAL_ROOT . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));
|
Chris@16
|
26 file_put_contents(DRUPAL_ROOT . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.es.po', $this->getPo('es'));
|
Chris@16
|
27
|
Chris@16
|
28 parent::setUpLanguage();
|
Chris@16
|
29 }
|
Chris@16
|
30
|
Chris@16
|
31 /**
|
Chris@16
|
32 * Returns the string for the test .po file.
|
Chris@16
|
33 *
|
Chris@16
|
34 * @param string $langcode
|
Chris@16
|
35 * The language code.
|
Chris@16
|
36 * @return string
|
Chris@16
|
37 * Contents for the test .po file.
|
Chris@16
|
38 */
|
Chris@16
|
39 protected function getPo($langcode) {
|
Chris@16
|
40 return <<<ENDPO
|
Chris@16
|
41 msgid ""
|
Chris@16
|
42 msgstr ""
|
Chris@16
|
43
|
Chris@16
|
44 msgid "Save and continue"
|
Chris@16
|
45 msgstr "Save and continue $langcode"
|
Chris@16
|
46
|
Chris@16
|
47 msgid "Anonymous"
|
Chris@16
|
48 msgstr "Anonymous $langcode"
|
Chris@16
|
49
|
Chris@16
|
50 msgid "Language"
|
Chris@16
|
51 msgstr "Language $langcode"
|
Chris@16
|
52
|
Chris@16
|
53 #: Testing site name configuration during the installer.
|
Chris@16
|
54 msgid "Drupal"
|
Chris@16
|
55 msgstr "Drupal"
|
Chris@16
|
56 ENDPO;
|
Chris@16
|
57 }
|
Chris@16
|
58
|
Chris@16
|
59 /**
|
Chris@16
|
60 * {@inheritdoc}
|
Chris@16
|
61 */
|
Chris@16
|
62 protected function installParameters() {
|
Chris@16
|
63 $params = parent::installParameters();
|
Chris@16
|
64 $params['forms']['install_configure_form']['site_name'] = 'SITE_NAME_' . $this->langcode;
|
Chris@16
|
65 return $params;
|
Chris@16
|
66 }
|
Chris@16
|
67
|
Chris@16
|
68 /**
|
Chris@16
|
69 * Tests that translations ended up at the expected places.
|
Chris@16
|
70 */
|
Chris@16
|
71 public function testTranslationsLoaded() {
|
Chris@16
|
72 // Ensure the title is correct.
|
Chris@16
|
73 $this->assertEqual('SITE_NAME_' . $this->langcode, \Drupal::config('system.site')->get('name'));
|
Chris@16
|
74
|
Chris@16
|
75 // Verify German and Spanish were configured.
|
Chris@16
|
76 $this->drupalGet('admin/config/regional/language');
|
Chris@16
|
77 $this->assertText('German');
|
Chris@16
|
78 $this->assertText('Spanish');
|
Chris@16
|
79 // If the installer was English or we used a profile that keeps English, we
|
Chris@16
|
80 // expect that configured also. Otherwise English should not be configured
|
Chris@16
|
81 // on the site.
|
Chris@16
|
82 if ($this->langcode == 'en' || $this->profile == 'testing_multilingual_with_english') {
|
Chris@16
|
83 $this->assertText('English');
|
Chris@16
|
84 }
|
Chris@16
|
85 else {
|
Chris@16
|
86 $this->assertNoText('English');
|
Chris@16
|
87 }
|
Chris@16
|
88
|
Chris@16
|
89 // Verify the strings from the translation files were imported.
|
Chris@16
|
90 $this->verifyImportedStringsTranslated();
|
Chris@16
|
91
|
Chris@16
|
92 /** @var \Drupal\language\ConfigurableLanguageManager $language_manager */
|
Chris@16
|
93 $language_manager = \Drupal::languageManager();
|
Chris@16
|
94
|
Chris@16
|
95 // If the site was installed in a foreign language (only tested with German
|
Chris@16
|
96 // in subclasses), then the active configuration should be updated and no
|
Chris@16
|
97 // override should exist in German. Otherwise the German translation should
|
Chris@16
|
98 // end up in overrides the same way as Spanish (which is not used as a site
|
Chris@16
|
99 // installation language). English should be available based on profile
|
Chris@16
|
100 // information and should be possible to add if not yet added, making
|
Chris@16
|
101 // English overrides available.
|
Chris@16
|
102
|
Chris@16
|
103 $config = \Drupal::config('user.settings');
|
Chris@16
|
104 $override_de = $language_manager->getLanguageConfigOverride('de', 'user.settings');
|
Chris@16
|
105 $override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings');
|
Chris@16
|
106 $override_es = $language_manager->getLanguageConfigOverride('es', 'user.settings');
|
Chris@16
|
107
|
Chris@16
|
108 if ($this->langcode == 'de') {
|
Chris@16
|
109 // Active configuration should be in German and no German override should
|
Chris@16
|
110 // exist.
|
Chris@16
|
111 $this->assertEqual($config->get('anonymous'), 'Anonymous de');
|
Chris@16
|
112 $this->assertEqual($config->get('langcode'), 'de');
|
Chris@16
|
113 $this->assertTrue($override_de->isNew());
|
Chris@16
|
114
|
Chris@16
|
115 if ($this->profile == 'testing_multilingual_with_english') {
|
Chris@16
|
116 // English is already added in this profile. Should make the override
|
Chris@16
|
117 // available.
|
Chris@16
|
118 $this->assertEqual($override_en->get('anonymous'), 'Anonymous');
|
Chris@16
|
119 }
|
Chris@16
|
120 else {
|
Chris@16
|
121 // English is not yet available.
|
Chris@16
|
122 $this->assertTrue($override_en->isNew());
|
Chris@16
|
123
|
Chris@16
|
124 // Adding English should make the English override available.
|
Chris@16
|
125 $edit = ['predefined_langcode' => 'en'];
|
Chris@16
|
126 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
|
Chris@16
|
127 $override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings');
|
Chris@16
|
128 $this->assertEqual($override_en->get('anonymous'), 'Anonymous');
|
Chris@16
|
129 }
|
Chris@16
|
130
|
Chris@16
|
131 // Activate a module, to make sure that config is not overridden by module
|
Chris@16
|
132 // installation.
|
Chris@16
|
133 $edit = [
|
Chris@16
|
134 'modules[views][enable]' => TRUE,
|
Chris@16
|
135 'modules[filter][enable]' => TRUE,
|
Chris@16
|
136 ];
|
Chris@16
|
137 $this->drupalPostForm('admin/modules', $edit, t('Install'));
|
Chris@16
|
138
|
Chris@16
|
139 // Verify the strings from the translation are still as expected.
|
Chris@16
|
140 $this->verifyImportedStringsTranslated();
|
Chris@16
|
141 }
|
Chris@16
|
142 else {
|
Chris@16
|
143 // Active configuration should be English.
|
Chris@16
|
144 $this->assertEqual($config->get('anonymous'), 'Anonymous');
|
Chris@16
|
145 $this->assertEqual($config->get('langcode'), 'en');
|
Chris@16
|
146 // There should not be an English override.
|
Chris@16
|
147 $this->assertTrue($override_en->isNew());
|
Chris@16
|
148 // German should be an override.
|
Chris@16
|
149 $this->assertEqual($override_de->get('anonymous'), 'Anonymous de');
|
Chris@16
|
150 }
|
Chris@16
|
151
|
Chris@16
|
152 // Spanish is always an override (never used as installation language).
|
Chris@16
|
153 $this->assertEqual($override_es->get('anonymous'), 'Anonymous es');
|
Chris@16
|
154
|
Chris@16
|
155 }
|
Chris@16
|
156
|
Chris@16
|
157 /**
|
Chris@16
|
158 * Helper function to verify that the expected strings are translated.
|
Chris@16
|
159 */
|
Chris@16
|
160 protected function verifyImportedStringsTranslated() {
|
Chris@16
|
161 $test_samples = ['Save and continue', 'Anonymous', 'Language'];
|
Chris@16
|
162 $langcodes = ['de', 'es'];
|
Chris@16
|
163
|
Chris@16
|
164 foreach ($test_samples as $sample) {
|
Chris@16
|
165 foreach ($langcodes as $langcode) {
|
Chris@16
|
166 $edit = [];
|
Chris@16
|
167 $edit['langcode'] = $langcode;
|
Chris@16
|
168 $edit['translation'] = 'translated';
|
Chris@16
|
169 $edit['string'] = $sample;
|
Chris@16
|
170 $this->drupalPostForm('admin/config/regional/translate', $edit, t('Filter'));
|
Chris@16
|
171 $this->assertText($sample . ' ' . $langcode);
|
Chris@16
|
172 }
|
Chris@16
|
173 }
|
Chris@16
|
174 }
|
Chris@16
|
175
|
Chris@16
|
176 }
|