annotate core/modules/system/src/Tests/Installer/DistributionProfileTranslationTest.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children 1fec387a4317
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\system\Tests\Installer;
Chris@0 4
Chris@0 5 use Drupal\Core\Serialization\Yaml;
Chris@0 6 use Drupal\simpletest\InstallerTestBase;
Chris@0 7
Chris@0 8 /**
Chris@0 9 * Tests distribution profile support.
Chris@0 10 *
Chris@0 11 * @group Installer
Chris@0 12 *
Chris@0 13 * @see \Drupal\system\Tests\Installer\DistributionProfileTest
Chris@0 14 */
Chris@0 15 class DistributionProfileTranslationTest extends InstallerTestBase {
Chris@0 16
Chris@0 17 /**
Chris@0 18 * {@inheritdoc}
Chris@0 19 */
Chris@0 20 protected $langcode = 'de';
Chris@0 21
Chris@0 22 /**
Chris@0 23 * The distribution profile info.
Chris@0 24 *
Chris@0 25 * @var array
Chris@0 26 */
Chris@0 27 protected $info;
Chris@0 28
Chris@0 29 /**
Chris@0 30 * {@inheritdoc}
Chris@0 31 */
Chris@0 32 protected function setUp() {
Chris@0 33 $this->info = [
Chris@0 34 'type' => 'profile',
Chris@0 35 'core' => \Drupal::CORE_COMPATIBILITY,
Chris@0 36 'name' => 'Distribution profile',
Chris@0 37 'distribution' => [
Chris@0 38 'name' => 'My Distribution',
Chris@0 39 'langcode' => $this->langcode,
Chris@0 40 'install' => [
Chris@0 41 'theme' => 'bartik',
Chris@0 42 ],
Chris@0 43 ],
Chris@0 44 ];
Chris@0 45 // File API functions are not available yet.
Chris@0 46 $path = $this->siteDirectory . '/profiles/mydistro';
Chris@0 47 mkdir($path, 0777, TRUE);
Chris@0 48 file_put_contents("$path/mydistro.info.yml", Yaml::encode($this->info));
Chris@0 49
Chris@0 50 parent::setUp();
Chris@0 51 }
Chris@0 52
Chris@0 53 /**
Chris@0 54 * {@inheritdoc}
Chris@0 55 */
Chris@0 56 protected function visitInstaller() {
Chris@0 57 // Place a custom local translation in the translations directory.
Chris@0 58 mkdir(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
Chris@0 59 file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));
Chris@0 60
Chris@0 61 parent::visitInstaller();
Chris@0 62
Chris@0 63 // The language should have been automatically detected, all following
Chris@0 64 // screens should be translated already.
Chris@0 65 $elements = $this->xpath('//input[@type="submit"]/@value');
Chris@0 66 $this->assertEqual((string) current($elements), 'Save and continue de');
Chris@0 67 $this->translations['Save and continue'] = 'Save and continue de';
Chris@0 68
Chris@0 69 // Check the language direction.
Chris@0 70 $direction = (string) current($this->xpath('/html/@dir'));
Chris@0 71 $this->assertEqual($direction, 'ltr');
Chris@0 72
Chris@0 73 // Verify that the distribution name appears.
Chris@0 74 $this->assertRaw($this->info['distribution']['name']);
Chris@0 75 // Verify that the requested theme is used.
Chris@0 76 $this->assertRaw($this->info['distribution']['install']['theme']);
Chris@0 77 // Verify that the "Choose profile" step does not appear.
Chris@0 78 $this->assertNoText('profile');
Chris@0 79 }
Chris@0 80
Chris@0 81 /**
Chris@0 82 * {@inheritdoc}
Chris@0 83 */
Chris@0 84 protected function setUpLanguage() {
Chris@0 85 // This step is skipped, because the distribution profile uses a fixed
Chris@0 86 // language.
Chris@0 87 }
Chris@0 88
Chris@0 89 /**
Chris@0 90 * {@inheritdoc}
Chris@0 91 */
Chris@0 92 protected function setUpProfile() {
Chris@0 93 // This step is skipped, because there is a distribution profile.
Chris@0 94 }
Chris@0 95
Chris@0 96 /**
Chris@0 97 * Confirms that the installation succeeded.
Chris@0 98 */
Chris@0 99 public function testInstalled() {
Chris@0 100 $this->assertUrl('user/1');
Chris@0 101 $this->assertResponse(200);
Chris@0 102
Chris@0 103 // Confirm that we are logged-in after installation.
Chris@0 104 $this->assertText($this->rootUser->getDisplayName());
Chris@0 105
Chris@0 106 // Verify German was configured but not English.
Chris@0 107 $this->drupalGet('admin/config/regional/language');
Chris@0 108 $this->assertText('German');
Chris@0 109 $this->assertNoText('English');
Chris@0 110 }
Chris@0 111
Chris@0 112 /**
Chris@0 113 * Returns the string for the test .po file.
Chris@0 114 *
Chris@0 115 * @param string $langcode
Chris@0 116 * The language code.
Chris@0 117 * @return string
Chris@0 118 * Contents for the test .po file.
Chris@0 119 */
Chris@0 120 protected function getPo($langcode) {
Chris@0 121 return <<<ENDPO
Chris@0 122 msgid ""
Chris@0 123 msgstr ""
Chris@0 124
Chris@0 125 msgid "Save and continue"
Chris@0 126 msgstr "Save and continue $langcode"
Chris@0 127 ENDPO;
Chris@0 128 }
Chris@0 129
Chris@0 130 }