diff --git a/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageForeignTest.php b/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageForeignTest.php index 248d485..918e85e 100644 --- a/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageForeignTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageForeignTest.php @@ -26,7 +26,7 @@ class InstallerTranslationMultipleLanguageForeignTest extends InstallerTranslati */ protected function setUpLanguage() { parent::setUpLanguage(); - $this->translations['Save and continue'] = 'Save and continue German'; + $this->translations['Save and continue'] = 'Save and continue de'; } } diff --git a/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageKeepEnglishTest.php b/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageKeepEnglishTest.php index 0c01fe6..79085db 100644 --- a/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageKeepEnglishTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageKeepEnglishTest.php @@ -2,51 +2,23 @@ /** * @file - * Contains \Drupal\system\Tests\Installer\InstallerTranslationMultipleLanguageForeignTest. + * Contains \Drupal\system\Tests\Installer\InstallerTranslationMultipleLanguageKeepEnglishTest. */ namespace Drupal\system\Tests\Installer; -use Drupal\simpletest\InstallerTestBase; /** - * Tests translation files for multiple languages get imported during install. + * Tests that keeping English in a foreign language install works. * * @group Installer */ -class InstallerTranslationMultipleLanguageKeepEnglishTest extends InstallerTestBase { +class InstallerTranslationMultipleLanguageKeepEnglishTest extends InstallerTranslationMultipleLanguageForeignTest { /** - * Overrides the language code in which to install Drupal. + * Switch to the multilingual testing profile with English kept. * * @var string */ - protected $langcode = 'de'; - - /** - * Switch to the multilingual testing profile - * - * @var string - */ - protected $profile = 'testing_multilingual'; - - /** - * {@inheritdoc} - */ - protected function setUpLanguage() { - // Place custom local translations 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.es.po', "msgid \"\"\nmsgstr \"\"\nmsgid \"Save and continue\"\nmsgstr \"Save and continue Spanish\""); - - parent::setUpLanguage(); - $this->translations['Save and continue'] = 'Save and continue German'; - } - - /** - * Tests that English is still present. - */ - public function testKeepEnglish() { - $this->assertTrue((bool) \Drupal::languageManager()->getLanguage('en'), 'English is present.'); - } + protected $profile = 'testing_multilingual_with_english'; } diff --git a/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageTest.php b/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageTest.php index 588f9ca..d985473 100644 --- a/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerTranslationMultipleLanguageTest.php @@ -17,7 +17,7 @@ class InstallerTranslationMultipleLanguageTest extends InstallerTestBase { /** - * Switch to the multilingual testing profile + * Switch to the multilingual testing profile. * * @var string */ @@ -29,54 +29,91 @@ class InstallerTranslationMultipleLanguageTest extends InstallerTestBase { protected function setUpLanguage() { // Place custom local translations 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\"\nmsgid\"Anonymous\"\nmsgstr\"Anonymous German\""); - file_put_contents(DRUPAL_ROOT . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.es.po', "msgid \"\"\nmsgstr \"\"\nmsgid \"Save and continue\"\nmsgstr \"Save and continue Spanish\"\nmsgid\"Anonymous\"\nmsgstr\"Anonymous Spanish\""); + file_put_contents(DRUPAL_ROOT . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de')); + file_put_contents(DRUPAL_ROOT . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.es.po', $this->getPo('es')); parent::setUpLanguage(); } /** - * Tests that translations for each language were loaded. + * 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 <<drupalGet('admin/config/regional/language'); $this->assertText('German'); $this->assertText('Spanish'); - // If the installer was English, we expect that configured also. - if ($this->langcode == 'en') { + // If the installer was English or we used a profile that keeps English, we + // expect that configured also. Otherwise English should not be configured + // on the site. + if ($this->langcode == 'en' || $this->profile == 'testing_multilingual_with_english') { $this->assertText('English'); } + else { + $this->assertNoText('English'); + } // Verify the strings from the translation files were imported. - $test_samples = array('Save and continue', 'Anonymous'); - $languages = array( - 'de' => 'German', - 'es' => 'Spanish', - ); + $test_samples = ['Save and continue', 'Anonymous']; + $langcodes = ['de', 'es']; foreach($test_samples as $sample) { - foreach($languages as $langcode => $name) { + foreach($langcodes as $langcode) { $edit = array(); $edit['langcode'] = $langcode; $edit['translation'] = 'translated'; $edit['string'] = $sample; $this->drupalPostForm('admin/config/regional/translate', $edit, t('Filter')); - $this->assertText($sample . ' ' . $name); + $this->assertText($sample . ' ' . $langcode); } } - // German may be in the active config or an override if not set as the - // default language. + /** @var \Drupal\language\ConfigurableLanguageManager $language_manager */ + $language_manager = \Drupal::languageManager(); + + // If the site was installed in a foreign language (only tested with German + // in the InstallerTranslationMultipleLanguageForeignTest subclass), then + // the active configuration should be updated and no override should exist + // in German. Otherwise the German translation should end up in overrides + // the same way as Spanish (which is not used as a site installation + // language). $config = \Drupal::config('user.settings'); - if ($this->langcode != 'de') { - $config = \Drupal::languageManager()->getLanguageConfigOverride('de', 'user.settings'); + $override_de = $language_manager->getLanguageConfigOverride('de', 'user.settings'); + if ($this->langcode == 'de') { + $this->assertEqual($config->get('anonymous'), 'Anonymous de'); + $this->assertEqual($config->get('langcode'), 'de'); + $this->assertTrue($override_de->isNew()); + } + else { + $this->assertEqual($config->get('anonymous'), 'Anonymous'); + $this->assertEqual($config->get('langcode'), 'en'); + $this->assertEqual($override_de->get('anonymous'), 'Anonymous de'); } - $this->assertEqual($config->get('anonymous'), 'Anonymous German'); - // Spanish is always an override (never used as default language). - $config = \Drupal::languageManager()->getLanguageConfigOverride('es', 'user.settings'); - $this->assertEqual($config->get('anonymous'), 'Anonymous Spanish'); + // Spanish is always an override (never used as installation language). + $override_es = $language_manager->getLanguageConfigOverride('es', 'user.settings'); + $this->assertEqual($override_es->get('anonymous'), 'Anonymous es'); } } diff --git a/core/profiles/testing_multilingual/testing_multilingual.info.yml b/core/profiles/testing_multilingual/testing_multilingual.info.yml index c33045a..3615e0b 100644 --- a/core/profiles/testing_multilingual/testing_multilingual.info.yml +++ b/core/profiles/testing_multilingual/testing_multilingual.info.yml @@ -6,4 +6,3 @@ core: 8.x hidden: true dependencies: - locale -keep_english: true diff --git a/core/profiles/testing_multilingual_with_english/config/install/language.entity.de.yml b/core/profiles/testing_multilingual_with_english/config/install/language.entity.de.yml new file mode 100644 index 0000000..22c040a --- /dev/null +++ b/core/profiles/testing_multilingual_with_english/config/install/language.entity.de.yml @@ -0,0 +1,7 @@ +id: de +label: German +direction: 'ltr' +weight: 0 +locked: false +status: true +langcode: en diff --git a/core/profiles/testing_multilingual_with_english/config/install/language.entity.es.yml b/core/profiles/testing_multilingual_with_english/config/install/language.entity.es.yml new file mode 100644 index 0000000..626b343 --- /dev/null +++ b/core/profiles/testing_multilingual_with_english/config/install/language.entity.es.yml @@ -0,0 +1,7 @@ +id: es +label: Spanish +direction: 'ltr' +weight: 0 +locked: false +status: true +langcode: en diff --git a/core/profiles/testing_multilingual_with_english/testing_multilingual_with_english.info.yml b/core/profiles/testing_multilingual_with_english/testing_multilingual_with_english.info.yml new file mode 100644 index 0000000..70ea627 --- /dev/null +++ b/core/profiles/testing_multilingual_with_english/testing_multilingual_with_english.info.yml @@ -0,0 +1,9 @@ +name: 'Testing multilingual with English' +type: profile +description: 'Minimal profile for running tests with a multilingual installer.' +version: VERSION +core: 8.x +hidden: true +dependencies: + - locale +keep_english: true