DistributionProfileTranslationTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. namespace Drupal\FunctionalTests\Installer;
  3. use Drupal\Core\Serialization\Yaml;
  4. /**
  5. * Tests distribution profile support.
  6. *
  7. * @group Installer
  8. *
  9. * @see \Drupal\FunctionalTests\Installer\DistributionProfileTest
  10. */
  11. class DistributionProfileTranslationTest 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. // We set core_version_requirement to '*' for the test so that it does not
  32. // need to be updated between major versions.
  33. $this->info = [
  34. 'type' => 'profile',
  35. 'core_version_requirement' => '*',
  36. 'name' => 'Distribution profile',
  37. 'distribution' => [
  38. 'name' => 'My Distribution',
  39. 'langcode' => $this->langcode,
  40. 'install' => [
  41. 'theme' => 'bartik',
  42. ],
  43. ],
  44. ];
  45. // File API functions are not available yet.
  46. $path = $this->root . DIRECTORY_SEPARATOR . $this->siteDirectory . '/profiles/mydistro';
  47. mkdir($path, 0777, TRUE);
  48. file_put_contents("$path/mydistro.info.yml", Yaml::encode($this->info));
  49. // Place a custom local translation in the translations directory.
  50. mkdir($this->root . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
  51. file_put_contents($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));
  52. }
  53. /**
  54. * {@inheritdoc}
  55. */
  56. protected function setUpLanguage() {
  57. // This step is skipped, because the distribution profile uses a fixed
  58. // language.
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. protected function setUpProfile() {
  64. // This step is skipped, because there is a distribution profile.
  65. }
  66. /**
  67. * {@inheritdoc}
  68. */
  69. protected function setUpSettings() {
  70. // The language should have been automatically detected, all following
  71. // screens should be translated already.
  72. $elements = $this->xpath('//input[@type="submit"]/@value');
  73. $this->assertEqual(current($elements)->getText(), 'Save and continue de');
  74. $this->translations['Save and continue'] = 'Save and continue de';
  75. // Check the language direction.
  76. $direction = current($this->xpath('/@dir'))->getText();
  77. $this->assertEqual($direction, 'ltr');
  78. // Verify that the distribution name appears.
  79. $this->assertRaw($this->info['distribution']['name']);
  80. // Verify that the requested theme is used.
  81. $this->assertRaw($this->info['distribution']['install']['theme']);
  82. // Verify that the "Choose profile" step does not appear.
  83. $this->assertNoText('profile');
  84. parent::setUpSettings();
  85. }
  86. /**
  87. * Confirms that the installation succeeded.
  88. */
  89. public function testInstalled() {
  90. $this->assertUrl('user/1');
  91. $this->assertSession()->statusCodeEquals(200);
  92. // Confirm that we are logged-in after installation.
  93. $this->assertText($this->rootUser->getDisplayName());
  94. // Verify German was configured but not English.
  95. $this->drupalGet('admin/config/regional/language');
  96. $this->assertText('German');
  97. $this->assertNoText('English');
  98. }
  99. /**
  100. * Returns the string for the test .po file.
  101. *
  102. * @param string $langcode
  103. * The language code.
  104. *
  105. * @return string
  106. * Contents for the test .po file.
  107. */
  108. protected function getPo($langcode) {
  109. return <<<ENDPO
  110. msgid ""
  111. msgstr ""
  112. msgid "Save and continue"
  113. msgstr "Save and continue $langcode"
  114. ENDPO;
  115. }
  116. }