annotate core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationQueryTest.php @ 19:fa3358dc1485 tip

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