annotate core/tests/Drupal/FunctionalTests/Installer/InstallerTranslationTest.php @ 19:fa3358dc1485 tip

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