comparison core/modules/system/src/Tests/Installer/DistributionProfileTranslationQueryTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 1fec387a4317
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
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 with a 'langcode' query string.
10 *
11 * @group Installer
12 *
13 * @see \Drupal\system\Tests\Installer\DistributionProfileTranslationTest
14 */
15 class DistributionProfileTranslationQueryTest 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 file_put_contents(\Drupal::root() . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.fr.po', $this->getPo('fr'));
61
62 // Pass a different language code than the one set in the distribution
63 // profile. This distribution language should still be used.
64 // The unrouted URL assembler does not exist at this point, so we build the
65 // URL ourselves.
66 $this->drupalGet($GLOBALS['base_url'] . '/core/install.php' . '?langcode=fr');
67 // The language should have been automatically detected, all following
68 // screens should be translated already.
69 $elements = $this->xpath('//input[@type="submit"]/@value');
70 $this->assertEqual((string) current($elements), 'Save and continue de');
71 $this->translations['Save and continue'] = 'Save and continue de';
72
73 // Check the language direction.
74 $direction = (string) current($this->xpath('/html/@dir'));
75 $this->assertEqual($direction, 'ltr');
76
77 // Verify that the distribution name appears.
78 $this->assertRaw($this->info['distribution']['name']);
79 // Verify that the requested theme is used.
80 $this->assertRaw($this->info['distribution']['install']['theme']);
81 // Verify that the "Choose profile" step does not appear.
82 $this->assertNoText('profile');
83 }
84
85 /**
86 * {@inheritdoc}
87 */
88 protected function setUpLanguage() {
89 // This step is skipped, because the distribution profile uses a fixed
90 // language.
91 }
92
93 /**
94 * {@inheritdoc}
95 */
96 protected function setUpProfile() {
97 // This step is skipped, because there is a distribution profile.
98 }
99
100 /**
101 * Confirms that the installation succeeded.
102 */
103 public function testInstalled() {
104 $this->assertUrl('user/1');
105 $this->assertResponse(200);
106
107 // Confirm that we are logged-in after installation.
108 $this->assertText($this->rootUser->getDisplayName());
109
110 // Verify German was configured but not English.
111 $this->drupalGet('admin/config/regional/language');
112 $this->assertText('German');
113 $this->assertNoText('English');
114 }
115
116 /**
117 * Returns the string for the test .po file.
118 *
119 * @param string $langcode
120 * The language code.
121 * @return string
122 * Contents for the test .po file.
123 */
124 protected function getPo($langcode) {
125 return <<<ENDPO
126 msgid ""
127 msgstr ""
128
129 msgid "Save and continue"
130 msgstr "Save and continue $langcode"
131 ENDPO;
132 }
133
134 }