annotate core/modules/system/src/Tests/Installer/DistributionProfileTranslationQueryTest.php @ 12:7a779792577d

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