diff --git a/core/modules/simpletest/src/InstallerTestBase.php b/core/modules/simpletest/src/InstallerTestBase.php index 8115840..adc5463 100644 --- a/core/modules/simpletest/src/InstallerTestBase.php +++ b/core/modules/simpletest/src/InstallerTestBase.php @@ -118,7 +118,7 @@ protected function setUp() { ->set('app.root', DRUPAL_ROOT); \Drupal::setContainer($this->container); - $this->drupalGet($GLOBALS['base_url'] . '/core/install.php'); + $this->visitInstaller(); // Select language. $this->setUpLanguage(); @@ -165,6 +165,13 @@ protected function setUp() { } /** + * Visits the interactive installer. + */ + protected function visitInstaller() { + $this->drupalGet($GLOBALS['base_url'] . '/core/install.php'); + } + + /** * Installer step: Select language. */ protected function setUpLanguage() { diff --git a/core/modules/system/src/Tests/Installer/DistributionProfileTranslationQueryTest.php b/core/modules/system/src/Tests/Installer/DistributionProfileTranslationQueryTest.php new file mode 100644 index 0000000..01a7104 --- /dev/null +++ b/core/modules/system/src/Tests/Installer/DistributionProfileTranslationQueryTest.php @@ -0,0 +1,136 @@ +info = array( + 'type' => 'profile', + 'core' => \Drupal::CORE_COMPATIBILITY, + 'name' => 'Distribution profile', + 'distribution' => array( + 'name' => 'My Distribution', + 'langcode' => $this->langcode, + 'install' => array( + 'theme' => 'bartik', + ), + ), + ); + // File API functions are not available yet. + $path = $this->siteDirectory . '/profiles/mydistro'; + mkdir($path, 0777, TRUE); + file_put_contents("$path/mydistro.info.yml", Yaml::encode($this->info)); + + parent::setUp(); + } + + /** + * {@inheritdoc} + */ + protected function visitInstaller() { + // 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', $this->getPo('de')); + file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.fr.po', $this->getPo('fr')); + + // Pass a different language code than the one set in the distribution + // profile. This distribution language should still be used. + // The unrouted URL assembler does not exist at this point, so we build the + // URL ourselves. + $this->drupalGet($GLOBALS['base_url'] . '/core/install.php' . '?langcode=fr'); + // The language should have been automatically detected, all following + // screens should be translated already. + $elements = $this->xpath('//input[@type="submit"]/@value'); + $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')); + $this->assertEqual($direction, 'ltr'); + + // Verify that the distribution name appears. + $this->assertRaw($this->info['distribution']['name']); + // Verify that the requested theme is used. + $this->assertRaw($this->info['distribution']['install']['theme']); + // Verify that the "Choose profile" step does not appear. + $this->assertNoText('profile'); + } + + /** + * {@inheritdoc} + */ + protected function setUpLanguage() { + // This step is skipped, because the distribution profile uses a fixed + // language. + } + + /** + * {@inheritdoc} + */ + protected function setUpProfile() { + // This step is skipped, because there is a distribution profile. + } + + /** + * Confirms that the installation succeeded. + */ + public function testInstalled() { + $this->assertUrl('user/1'); + $this->assertResponse(200); + + // Confirm that we are logged-in after installation. + $this->assertText($this->rootUser->getDisplayName()); + + // Verify German was configured but not English. + $this->drupalGet('admin/config/regional/language'); + $this->assertText('German'); + $this->assertNoText('English'); + } + + /** + * 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 <<info = array( + 'type' => 'profile', + 'core' => \Drupal::CORE_COMPATIBILITY, + 'name' => 'Distribution profile', + 'distribution' => array( + 'name' => 'My Distribution', + 'langcode' => $this->langcode, + 'install' => array( + 'theme' => 'bartik', + ), + ), + ); + // File API functions are not available yet. + $path = $this->siteDirectory . '/profiles/mydistro'; + mkdir($path, 0777, TRUE); + file_put_contents("$path/mydistro.info.yml", Yaml::encode($this->info)); + + parent::setUp(); + } + + /** + * {@inheritdoc} + */ + protected function visitInstaller() { + // 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', $this->getPo('de')); + + parent::visitInstaller(); + + // The language should have been automatically detected, all following + // screens should be translated already. + $elements = $this->xpath('//input[@type="submit"]/@value'); + $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')); + $this->assertEqual($direction, 'ltr'); + + // Verify that the distribution name appears. + $this->assertRaw($this->info['distribution']['name']); + // Verify that the requested theme is used. + $this->assertRaw($this->info['distribution']['install']['theme']); + // Verify that the "Choose profile" step does not appear. + $this->assertNoText('profile'); + } + + /** + * {@inheritdoc} + */ + protected function setUpLanguage() { + // This step is skipped, because the distribution profile uses a fixed + // language. + } + + /** + * {@inheritdoc} + */ + protected function setUpProfile() { + // This step is skipped, because there is a distribution profile. + } + + /** + * Confirms that the installation succeeded. + */ + public function testInstalled() { + $this->assertUrl('user/1'); + $this->assertResponse(200); + + // Confirm that we are logged-in after installation. + $this->assertText($this->rootUser->getDisplayName()); + + // Verify German was configured but not English. + $this->drupalGet('admin/config/regional/language'); + $this->assertText('German'); + $this->assertNoText('English'); + } + + /** + * 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($GLOBALS['base_url'] . '/core/install.php'); + $this->visitInstaller(); $this->assertRaw('Drupal already installed'); // Delete settings.php and attempt to reinstall again. unlink($this->siteDirectory . '/settings.php'); - $this->drupalGet($GLOBALS['base_url'] . '/core/install.php'); + $this->visitInstaller(); $this->setUpLanguage(); $this->setUpProfile(); $this->setUpSettings(); diff --git a/core/modules/system/src/Tests/Installer/InstallerLanguagePageTest.php b/core/modules/system/src/Tests/Installer/InstallerLanguagePageTest.php index d469532..4d9383e 100644 --- a/core/modules/system/src/Tests/Installer/InstallerLanguagePageTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerLanguagePageTest.php @@ -26,7 +26,7 @@ protected function setUpLanguage() { touch(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.xoxo.po'); // Check that all predefined languages show up with their native names. - $this->drupalGet($GLOBALS['base_url'] . '/core/install.php'); + $this->visitInstaller(); foreach (LanguageManager::getStandardLanguageList() as $langcode => $names) { $this->assertOption('edit-langcode', $langcode); $this->assertRaw('>' . $names[1] . '<'); diff --git a/core/modules/system/src/Tests/Installer/InstallerTranslationQueryTest.php b/core/modules/system/src/Tests/Installer/InstallerTranslationQueryTest.php new file mode 100644 index 0000000..49b1dfd --- /dev/null +++ b/core/modules/system/src/Tests/Installer/InstallerTranslationQueryTest.php @@ -0,0 +1,90 @@ +siteDirectory . '/files/translations', 0777, TRUE); + file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de')); + + // The unrouted URL assembler does not exist at this point, so we build the + // URL ourselves. + $this->drupalGet($GLOBALS['base_url'] . '/core/install.php' . '?langcode=' . $this->langcode); + + // The language should have been automatically detected, all following + // screens should be translated already. + $elements = $this->xpath('//input[@type="submit"]/@value'); + $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')); + $this->assertEqual($direction, 'ltr'); + } + + /** + * {@inheritdoc} + */ + protected function setUpLanguage() { + // The language was was preset by passing a query parameter in the URL, so + // no explicit language selection is necessary. + } + + /** + * 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'); + } + + /** + * 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 <<