3 namespace Drupal\FunctionalTests\Installer;
5 use Drupal\Core\Database\Database;
6 use Drupal\user\Entity\User;
9 * Installs Drupal in German and checks resulting site.
13 class InstallerTranslationTest extends InstallerTestBase {
16 * Overrides the language code in which to install Drupal.
20 protected $langcode = 'de';
25 protected function setUpLanguage() {
26 // Place a custom local translation in the translations directory.
27 mkdir($this->root . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
28 file_put_contents($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));
30 parent::setUpLanguage();
32 // After selecting a different language than English, all following screens
33 // should be translated already.
34 $elements = $this->xpath('//input[@type="submit"]/@value');
35 $this->assertEqual(current($elements)->getText(), 'Save and continue de');
36 $this->translations['Save and continue'] = 'Save and continue de';
38 // Check the language direction.
39 $direction = current($this->xpath('/@dir'))->getText();
40 $this->assertEqual($direction, 'ltr');
46 protected function setUpSettings() {
47 // We are creating a table here to force an error in the installer because
48 // it will try and create the drupal_install_test table as this is part of
49 // the standard database tests performed by the installer in
50 // Drupal\Core\Database\Install\Tasks.
51 Database::getConnection('default')->query('CREATE TABLE {drupal_install_test} (id int NULL)');
52 parent::setUpSettings();
54 // Ensure that the error message translation is working.
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/getting-started/install">Installationshandbuch</a>, oder kontaktieren Sie Ihren Hosting-Anbieter.');
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 NULL)</em> fehlgeschlagen.');
58 // Now do it successfully.
59 Database::getConnection('default')->query('DROP TABLE {drupal_install_test}');
60 parent::setUpSettings();
64 * Verifies the expected behaviors of the installation result.
66 public function testInstaller() {
67 $this->assertUrl('user/1');
68 $this->assertResponse(200);
70 // Verify German was configured but not English.
71 $this->drupalGet('admin/config/regional/language');
72 $this->assertText('German');
73 $this->assertNoText('English');
75 // The current container still has the english as current language, rebuild.
76 $this->rebuildContainer();
77 /** @var \Drupal\user\Entity\User $account */
78 $account = User::load(0);
79 $this->assertEqual($account->language()->getId(), 'en', 'Anonymous user is English.');
80 $account = User::load(1);
81 $this->assertEqual($account->language()->getId(), 'en', 'Administrator user is English.');
82 $account = $this->drupalCreateUser();
83 $this->assertEqual($account->language()->getId(), 'de', 'New user is German.');
85 // Ensure that we can enable basic_auth on a non-english site.
86 $this->drupalPostForm('admin/modules', ['modules[basic_auth][enable]' => TRUE], t('Install'));
87 $this->assertResponse(200);
89 // Assert that the theme CSS was added to the page.
90 $edit = ['preprocess_css' => FALSE];
91 $this->drupalPostForm('admin/config/development/performance', $edit, t('Save configuration'));
92 $this->drupalGet('<front>');
93 $this->assertRaw('classy/css/components/action-links.css');
95 // Verify the strings from the translation files were imported.
96 $test_samples = ['Save and continue', 'Anonymous'];
97 foreach ($test_samples as $sample) {
99 $edit['langcode'] = 'de';
100 $edit['translation'] = 'translated';
101 $edit['string'] = $sample;
102 $this->drupalPostForm('admin/config/regional/translate', $edit, t('Filter'));
103 $this->assertText($sample . ' de');
106 /** @var \Drupal\language\ConfigurableLanguageManager $language_manager */
107 $language_manager = \Drupal::languageManager();
109 // Installed in German, configuration should be in German. No German or
110 // English overrides should be present.
111 $config = \Drupal::config('user.settings');
112 $override_de = $language_manager->getLanguageConfigOverride('de', 'user.settings');
113 $override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings');
114 $this->assertEqual($config->get('anonymous'), 'Anonymous de');
115 $this->assertEqual($config->get('langcode'), 'de');
116 $this->assertTrue($override_de->isNew());
117 $this->assertTrue($override_en->isNew());
119 // Assert that adding English makes the English override available.
120 $edit = ['predefined_langcode' => 'en'];
121 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
122 $override_en = $language_manager->getLanguageConfigOverride('en', 'user.settings');
123 $this->assertFalse($override_en->isNew());
124 $this->assertEqual($override_en->get('anonymous'), 'Anonymous');
128 * Returns the string for the test .po file.
130 * @param string $langcode
133 * Contents for the test .po file.
135 protected function getPo($langcode) {
140 msgid "Save and continue"
141 msgstr "Save and continue $langcode"
144 msgstr "Anonymous $langcode"
146 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."
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/getting-started/install">Installationshandbuch</a>, oder kontaktieren Sie Ihren Hosting-Anbieter."
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>"
150 msgstr "<strong>CREATE</strong> ein Test-Tabelle auf Ihrem Datenbankserver mit dem Befehl %query fehlgeschlagen."