comparison core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationTest.php @ 16:c2387f117808

Routine composer update
author Chris Cannam
date Tue, 10 Jul 2018 15:07:59 +0100
parents
children 129ea1e6d783
comparison
equal deleted inserted replaced
15:e200cb7efeb3 16:c2387f117808
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 /**
96 * Confirms that the installation succeeded.
97 */
98 public function testInstalled() {
99 $this->assertUrl('user/1');
100 $this->assertResponse(200);
101
102 // Confirm that we are logged-in after installation.
103 $this->assertText($this->rootUser->getDisplayName());
104
105 // Verify German was configured but not English.
106 $this->drupalGet('admin/config/regional/language');
107 $this->assertText('German');
108 $this->assertNoText('English');
109 }
110
111 /**
112 * Returns the string for the test .po file.
113 *
114 * @param string $langcode
115 * The language code.
116 * @return string
117 * Contents for the test .po file.
118 */
119 protected function getPo($langcode) {
120 return <<<ENDPO
121 msgid ""
122 msgstr ""
123
124 msgid "Save and continue"
125 msgstr "Save and continue $langcode"
126 ENDPO;
127 }
128
129 }