DistributionProfileTranslationTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 $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. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. protected function setUpLanguage() {
  51. // This step is skipped, because the distribution profile uses a fixed
  52. // language.
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. protected function setUpProfile() {
  58. // This step is skipped, because there is a distribution profile.
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. protected function setUpSettings() {
  64. // The language should have been automatically detected, all following
  65. // screens should be translated already.
  66. $elements = $this->xpath('//input[@type="submit"]/@value');
  67. $this->assertEqual(current($elements)->getText(), 'Save and continue de');
  68. $this->translations['Save and continue'] = 'Save and continue de';
  69. // Check the language direction.
  70. $direction = current($this->xpath('/@dir'))->getText();
  71. $this->assertEqual($direction, 'ltr');
  72. // Verify that the distribution name appears.
  73. $this->assertRaw($this->info['distribution']['name']);
  74. // Verify that the requested theme is used.
  75. $this->assertRaw($this->info['distribution']['install']['theme']);
  76. // Verify that the "Choose profile" step does not appear.
  77. $this->assertNoText('profile');
  78. parent::setUpSettings();
  79. }
  80. /**
  81. * Confirms that the installation succeeded.
  82. */
  83. public function testInstalled() {
  84. $this->assertUrl('user/1');
  85. $this->assertResponse(200);
  86. // Confirm that we are logged-in after installation.
  87. $this->assertText($this->rootUser->getDisplayName());
  88. // Verify German was configured but not English.
  89. $this->drupalGet('admin/config/regional/language');
  90. $this->assertText('German');
  91. $this->assertNoText('English');
  92. }
  93. /**
  94. * Returns the string for the test .po file.
  95. *
  96. * @param string $langcode
  97. * The language code.
  98. * @return string
  99. * Contents for the test .po file.
  100. */
  101. protected function getPo($langcode) {
  102. return <<<ENDPO
  103. msgid ""
  104. msgstr ""
  105. msgid "Save and continue"
  106. msgstr "Save and continue $langcode"
  107. ENDPO;
  108. }
  109. }