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