DistributionProfileTranslationQueryTest.php 4.0 KB

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