View source
<?php
namespace Drupal\FunctionalTests\Installer;
use Drupal\Core\Database\Database;
use Drupal\user\Entity\User;
class InstallerTranslationTest extends InstallerTestBase {
protected $defaultTheme = 'classy';
protected $langcode = 'de';
protected function setUpLanguage() {
mkdir($this->root . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
file_put_contents($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this
->getPo('de'));
parent::setUpLanguage();
$this
->assertSession()
->buttonExists('Save and continue de');
$this->translations['Save and continue'] = 'Save and continue de';
$direction = current($this
->xpath('/@dir'))
->getText();
$this
->assertEquals('ltr', $direction);
}
protected function setUpSettings() {
$spec = [
'fields' => [
'id' => [
'type' => 'int',
'not null' => TRUE,
],
],
'primary key' => [
'id',
],
];
Database::getConnection('default')
->schema()
->createTable('drupal_install_test', $spec);
parent::setUpSettings();
$this
->assertSession()
->responseContains('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.');
$this
->assertSession()
->responseContains('<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.');
Database::getConnection('default')
->schema()
->dropTable('drupal_install_test');
parent::setUpSettings();
}
public function testInstaller() {
$this
->assertSession()
->addressEquals('user/1');
$this
->assertSession()
->statusCodeEquals(200);
$this
->drupalGet('admin/config/regional/language');
$this
->assertSession()
->pageTextContains('German');
$this
->assertSession()
->pageTextNotContains('English');
$this
->rebuildContainer();
$account = User::load(0);
$this
->assertEquals('de', $account
->language()
->getId(), 'Anonymous user is German.');
$account = User::load(1);
$this
->assertEquals('de', $account
->language()
->getId(), 'Administrator user is German.');
$account = $this
->drupalCreateUser();
$this
->assertEquals('de', $account
->language()
->getId(), 'New user is German.');
$this
->drupalGet('admin/modules');
$this
->submitForm([
'modules[basic_auth][enable]' => TRUE,
], 'Install');
$this
->assertSession()
->statusCodeEquals(200);
$edit = [
'preprocess_css' => FALSE,
];
$this
->drupalGet('admin/config/development/performance');
$this
->submitForm($edit, 'Save configuration');
$this
->drupalGet('<front>');
$this
->assertSession()
->responseContains('classy/css/components/action-links.css');
$test_samples = [
'Save and continue',
'Anonymous',
];
foreach ($test_samples as $sample) {
$edit = [];
$edit['langcode'] = 'de';
$edit['translation'] = 'translated';
$edit['string'] = $sample;
$this
->drupalGet('admin/config/regional/translate');
$this
->submitForm($edit, 'Filter');
$this
->assertSession()
->pageTextContains($sample . ' de');
}
$language_manager = \Drupal::languageManager();
$config = \Drupal::config('user.settings');
$override_de = $language_manager
->getLanguageConfigOverride('de', 'user.settings');
$override_en = $language_manager
->getLanguageConfigOverride('en', 'user.settings');
$this
->assertEquals('Anonymous de', $config
->get('anonymous'));
$this
->assertEquals('de', $config
->get('langcode'));
$this
->assertTrue($override_de
->isNew());
$this
->assertTrue($override_en
->isNew());
$edit = [
'predefined_langcode' => 'en',
];
$this
->drupalGet('admin/config/regional/language/add');
$this
->submitForm($edit, 'Add language');
$override_en = $language_manager
->getLanguageConfigOverride('en', 'user.settings');
$this
->assertFalse($override_en
->isNew());
$this
->assertEquals('Anonymous', $override_en
->get('anonymous'));
}
protected function getPo($langcode) {
return <<<ENDPO
msgid ""
msgstr ""
msgid "Save and continue"
msgstr "Save and continue {<span class="php-variable">$langcode</span>}"
msgid "Anonymous"
msgstr "Anonymous {<span class="php-variable">$langcode</span>}"
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."
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."
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>"
msgstr "<strong>CREATE</strong> ein Test-Tabelle auf Ihrem Datenbankserver mit dem Befehl %query fehlgeschlagen."
ENDPO;
}
}