Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / tests / Drupal / FunctionalTests / Installer / DistributionProfileTranslationQueryTest.php
1 <?php
2
3 namespace Drupal\FunctionalTests\Installer;
4
5 use Drupal\Core\Serialization\Yaml;
6
7 /**
8  * Tests distribution profile support with a 'langcode' query string.
9  *
10  * @group Installer
11  *
12  * @see \Drupal\FunctionalTests\Installer\DistributionProfileTranslationTest
13  */
14 class DistributionProfileTranslationQueryTest 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     // Place a custom local translation in the translations directory.
50     mkdir($this->root . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
51     file_put_contents($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));
52     file_put_contents($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.fr.po', $this->getPo('fr'));
53   }
54
55   /**
56    * {@inheritdoc}
57    */
58   protected function visitInstaller() {
59     // Pass a different language code than the one set in the distribution
60     // profile. This distribution language should still be used.
61     // The unrouted URL assembler does not exist at this point, so we build the
62     // URL ourselves.
63     $this->drupalGet($GLOBALS['base_url'] . '/core/install.php' . '?langcode=fr');
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   protected function setUpLanguage() {
70     // This step is skipped, because the distribution profile uses a fixed
71     // language.
72   }
73
74   /**
75    * {@inheritdoc}
76    */
77   protected function setUpProfile() {
78     // This step is skipped, because there is a distribution profile.
79   }
80
81   /**
82    * {@inheritdoc}
83    */
84   protected function setUpSettings() {
85     // The language should have been automatically detected, all following
86     // screens should be translated already.
87     $elements = $this->xpath('//input[@type="submit"]/@value');
88     $this->assertEqual(current($elements)->getText(), 'Save and continue de');
89     $this->translations['Save and continue'] = 'Save and continue de';
90
91     // Check the language direction.
92     $direction = $this->getSession()->getPage()->find('xpath', '/@dir')->getText();
93     $this->assertEqual($direction, 'ltr');
94
95     // Verify that the distribution name appears.
96     $this->assertRaw($this->info['distribution']['name']);
97     // Verify that the requested theme is used.
98     $this->assertRaw($this->info['distribution']['install']['theme']);
99     // Verify that the "Choose profile" step does not appear.
100     $this->assertNoText('profile');
101
102     parent::setUpSettings();
103   }
104
105   /**
106    * Confirms that the installation succeeded.
107    */
108   public function testInstalled() {
109     $this->assertUrl('user/1');
110     $this->assertResponse(200);
111
112     // Confirm that we are logged-in after installation.
113     $this->assertText($this->rootUser->getDisplayName());
114
115     // Verify German was configured but not English.
116     $this->drupalGet('admin/config/regional/language');
117     $this->assertText('German');
118     $this->assertNoText('English');
119   }
120
121   /**
122    * Returns the string for the test .po file.
123    *
124    * @param string $langcode
125    *   The language code.
126    * @return string
127    *   Contents for the test .po file.
128    */
129   protected function getPo($langcode) {
130     return <<<ENDPO
131 msgid ""
132 msgstr ""
133
134 msgid "Save and continue"
135 msgstr "Save and continue $langcode"
136 ENDPO;
137   }
138
139 }