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