InstallerTranslationTest.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace Drupal\FunctionalTests\Installer;
  3. use Drupal\Core\Database\Database;
  4. use Drupal\user\Entity\User;
  5. /**
  6. * Installs Drupal in German and checks resulting site.
  7. *
  8. * @group Installer
  9. */
  10. class InstallerTranslationTest extends InstallerTestBase {
  11. /**
  12. * Overrides the language code in which to install Drupal.
  13. *
  14. * @var string
  15. */
  16. protected $langcode = 'de';
  17. /**
  18. * {@inheritdoc}
  19. */
  20. protected function setUpLanguage() {
  21. // Place a custom local translation in the translations directory.
  22. mkdir($this->root . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
  23. file_put_contents($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));
  24. parent::setUpLanguage();
  25. // After selecting a different language than English, all following screens
  26. // should be translated already.
  27. $elements = $this->xpath('//input[@type="submit"]/@value');
  28. $this->assertEqual(current($elements)->getText(), 'Save and continue de');
  29. $this->translations['Save and continue'] = 'Save and continue de';
  30. // Check the language direction.
  31. $direction = current($this->xpath('/@dir'))->getText();
  32. $this->assertEqual($direction, 'ltr');
  33. }
  34. /**
  35. * {@inheritdoc}
  36. */
  37. protected function setUpSettings() {
  38. // We are creating a table here to force an error in the installer because
  39. // it will try and create the drupal_install_test table as this is part of
  40. // the standard database tests performed by the installer in
  41. // Drupal\Core\Database\Install\Tasks.
  42. Database::getConnection('default')->query('CREATE TABLE {drupal_install_test} (id int NULL)');
  43. parent::setUpSettings();
  44. // Ensure that the error message translation is working.
  45. $this->assertRaw('Beheben Sie alle Probleme unten, um die Installation fortzusetzen. Informationen zur Konfiguration der Datenbankserver finden Sie in der <a href="https://www.drupal.org/getting-started/install">Installationshandbuch</a>, oder kontaktieren Sie Ihren Hosting-Anbieter.');
  46. $this->assertRaw('<strong>CREATE</strong> ein Test-Tabelle auf Ihrem Datenbankserver mit dem Befehl <em class="placeholder">CREATE TABLE {drupal_install_test} (id int NULL)</em> fehlgeschlagen.');
  47. // Now do it successfully.
  48. Database::getConnection('default')->query('DROP TABLE {drupal_install_test}');
  49. parent::setUpSettings();
  50. }
  51. /**
  52. * Verifies the expected behaviors of the installation result.
  53. */
  54. public function testInstaller() {
  55. $this->assertUrl('user/1');
  56. $this->assertResponse(200);
  57. // Verify German was configured but not English.
  58. $this->drupalGet('admin/config/regional/language');
  59. $this->assertText('German');
  60. $this->assertNoText('English');
  61. // The current container still has the english as current language, rebuild.
  62. $this->rebuildContainer();
  63. /** @var \Drupal\user\Entity\User $account */
  64. $account = User::load(0);
  65. $this->assertEqual($account->language()->getId(), 'en', 'Anonymous user is English.');
  66. $account = User::load(1);
  67. $this->assertEqual($account->language()->getId(), 'en', 'Administrator user is English.');
  68. $account = $this->drupalCreateUser();
  69. $this->assertEqual($account->language()->getId(), 'de', 'New user is German.');
  70. // Ensure that we can enable basic_auth on a non-english site.
  71. $this->drupalPostForm('admin/modules', ['modules[basic_auth][enable]' => TRUE], t('Install'));
  72. $this->assertResponse(200);
  73. // Assert that the theme CSS was added to the page.
  74. $edit = ['preprocess_css' => FALSE];
  75. $this->drupalPostForm('admin/config/development/performance', $edit, t('Save configuration'));
  76. $this->drupalGet('<front>');
  77. $this->assertRaw('classy/css/components/action-links.css');
  78. // Verify the strings from the translation files were imported.
  79. $test_samples = ['Save and continue', 'Anonymous'];
  80. foreach ($test_samples as $sample) {
  81. $edit = [];
  82. $edit['langcode'] = 'de';
  83. $edit['translation'] = 'translated';
  84. $edit['string'] = $sample;
  85. $this->drupalPostForm('admin/config/regional/translate', $edit, t('Filter'));
  86. $this->assertText($sample . ' de');
  87. }
  88. /** @var \Drupal\language\ConfigurableLanguageManager $language_manager */
  89. $language_manager = \Drupal::languageManager();
  90. // Installed in German, configuration should be in German. No German or
  91. // English overrides should be present.
  92. $config = \Drupal::config('user.settings');
  93. $override_de = $language_manager->getLanguageConfigOverride('de', 'user.settings');
  94. $override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings');
  95. $this->assertEqual($config->get('anonymous'), 'Anonymous de');
  96. $this->assertEqual($config->get('langcode'), 'de');
  97. $this->assertTrue($override_de->isNew());
  98. $this->assertTrue($override_en->isNew());
  99. // Assert that adding English makes the English override available.
  100. $edit = ['predefined_langcode' => 'en'];
  101. $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
  102. $override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings');
  103. $this->assertFalse($override_en->isNew());
  104. $this->assertEqual($override_en->get('anonymous'), 'Anonymous');
  105. }
  106. /**
  107. * Returns the string for the test .po file.
  108. *
  109. * @param string $langcode
  110. * The language code.
  111. * @return string
  112. * Contents for the test .po file.
  113. */
  114. protected function getPo($langcode) {
  115. return <<<ENDPO
  116. msgid ""
  117. msgstr ""
  118. msgid "Save and continue"
  119. msgstr "Save and continue $langcode"
  120. msgid "Anonymous"
  121. msgstr "Anonymous $langcode"
  122. msgid "Resolve all issues below to continue the installation. For help configuring your database server, see the <a href="https://www.drupal.org/getting-started/install">installation handbook</a>, or contact your hosting provider."
  123. msgstr "Beheben Sie alle Probleme unten, um die Installation fortzusetzen. Informationen zur Konfiguration der Datenbankserver finden Sie in der <a href="https://www.drupal.org/getting-started/install">Installationshandbuch</a>, oder kontaktieren Sie Ihren Hosting-Anbieter."
  124. msgid "Failed to <strong>CREATE</strong> a test table on your database server with the command %query. The server reports the following message: %error.<p>Are you sure the configured username has the necessary permissions to create tables in the database?</p>"
  125. msgstr "<strong>CREATE</strong> ein Test-Tabelle auf Ihrem Datenbankserver mit dem Befehl %query fehlgeschlagen."
  126. ENDPO;
  127. }
  128. }