DistributionProfileTranslationQueryTest.php 3.9 KB

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