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