diff --git a/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageTest.php b/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageTest.php index ec8803e..c1180bf 100644 --- a/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageTest.php @@ -124,6 +124,12 @@ public function testTranslationsLoaded() { } else { $this->assertTrue($override_en->isNew()); + + // Assert that adding English makes the English override available. + $edit = ['predefined_langcode' => 'en']; + $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); + $override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings'); + $this->assertEqual($override_en->get('anonymous'), 'Anonymous'); } } diff --git a/core/modules/system/src/Tests/Installer/InstallerTranslationTest.php b/core/modules/system/src/Tests/Installer/InstallerTranslationTest.php index 8d9305c..f68ccf8 100644 --- a/core/modules/system/src/Tests/Installer/InstallerTranslationTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerTranslationTest.php @@ -11,8 +11,7 @@ use Drupal\user\Entity\User; /** - * Selects German as the installation language and verifies the following page - * is not in English. + * Installs Drupal in German and checks resulting site. * * @group Installer */ @@ -31,14 +30,15 @@ class InstallerTranslationTest extends InstallerTestBase { protected function setUpLanguage() { // Place a custom local translation in the translations directory. mkdir(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE); - file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', "msgid \"\"\nmsgstr \"\"\nmsgid \"Save and continue\"\nmsgstr \"Save and continue German\""); + file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de')); parent::setUpLanguage(); + // After selecting a different language than English, all following screens // should be translated already. $elements = $this->xpath('//input[@type="submit"]/@value'); - $this->assertEqual((string) current($elements), 'Save and continue German'); - $this->translations['Save and continue'] = 'Save and continue German'; + $this->assertEqual((string) current($elements), 'Save and continue de'); + $this->translations['Save and continue'] = 'Save and continue de'; // Check the language direction. $direction = (string) current($this->xpath('/html/@dir')); @@ -46,12 +46,18 @@ protected function setUpLanguage() { } /** - * Verifies that installation succeeded. + * Verifies the expected behaviors of the installation result. */ public function testInstaller() { $this->assertUrl('user/1'); $this->assertResponse(200); + // Verify German was configured but not English. + $this->drupalGet('admin/config/regional/language'); + $this->assertText('German'); + $this->assertNoText('English'); + + /** @var \Drupal\user\Entity\User $account */ $account = User::load(0); $this->assertEqual($account->language()->getId(), 'en', 'Anonymous user is English.'); $account = User::load(1); @@ -68,6 +74,57 @@ public function testInstaller() { $this->drupalPostForm('admin/config/development/performance', $edit, t('Save configuration')); $this->drupalGet(''); $this->assertRaw('classy/css/layout.css'); + + // Verify the strings from the translation files were imported. + $test_samples = ['Save and continue', 'Anonymous']; + foreach($test_samples as $sample) { + $edit = array(); + $edit['langcode'] = 'de'; + $edit['translation'] = 'translated'; + $edit['string'] = $sample; + $this->drupalPostForm('admin/config/regional/translate', $edit, t('Filter')); + $this->assertText($sample . ' de'); + } + + /** @var \Drupal\language\ConfigurableLanguageManager $language_manager */ + $language_manager = \Drupal::languageManager(); + + // Installed in German, configuration should be in German. No German or + // English overrides should be present. + $config = \Drupal::config('user.settings'); + $override_de = $language_manager->getLanguageConfigOverride('de', 'user.settings'); + $override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings'); + $this->assertEqual($config->get('anonymous'), 'Anonymous de'); + $this->assertEqual($config->get('langcode'), 'de'); + $this->assertTrue($override_de->isNew()); + $this->assertTrue($override_en->isNew()); + + // Assert that adding English makes the English override available. + $edit = ['predefined_langcode' => 'en']; + $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language')); + $override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings'); + $this->assertEqual($override_en->get('anonymous'), 'Anonymous'); + } + + /** + * Returns the string for the test .po file. + * + * @param string $langcode + * The language code. + * @return string + * Contents for the test .po file. + */ + protected function getPo($langcode) { + return <<