DistributionProfileTranslationTest.php in Drupal 9
File
core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationTest.php
View source
<?php
namespace Drupal\FunctionalTests\Installer;
use Drupal\Core\Serialization\Yaml;
class DistributionProfileTranslationTest extends InstallerTestBase {
protected $defaultTheme = 'stark';
protected $langcode = 'de';
protected $info;
protected function prepareEnvironment() {
parent::prepareEnvironment();
$this->info = [
'type' => 'profile',
'core_version_requirement' => '*',
'name' => 'Distribution profile',
'distribution' => [
'name' => 'My Distribution',
'langcode' => $this->langcode,
'install' => [
'theme' => 'bartik',
],
],
];
$path = $this->root . DIRECTORY_SEPARATOR . $this->siteDirectory . '/profiles/my_distro';
mkdir($path, 0777, TRUE);
file_put_contents("{$path}/my_distro.info.yml", Yaml::encode($this->info));
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'));
}
protected function setUpLanguage() {
}
protected function setUpProfile() {
}
protected function setUpSettings() {
$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);
$this
->assertSession()
->pageTextContains($this->info['distribution']['name']);
$this
->assertSession()
->responseContains($this->info['distribution']['install']['theme']);
$this
->assertSession()
->pageTextNotContains('profile');
parent::setUpSettings();
}
public function testInstalled() {
$this
->assertSession()
->addressEquals('user/1');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->pageTextContains($this->rootUser
->getDisplayName());
$this
->drupalGet('admin/config/regional/language');
$this
->assertSession()
->pageTextContains('German');
$this
->assertSession()
->pageTextNotContains('English');
}
protected function getPo($langcode) {
return <<<ENDPO
msgid ""
msgstr ""
msgid "Save and continue"
msgstr "Save and continue {<span class="php-variable">$langcode</span>}"
ENDPO;
}
}