annotate core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationTest.php @ 5:12f9dff5fda9 tip

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