annotate core/tests/Drupal/FunctionalTests/Installer/DistributionProfileTranslationQueryTest.php @ 0:c75dbcec494b

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