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