InstallerTranslationQueryTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace Drupal\FunctionalTests\Installer;
  3. /**
  4. * Installs Drupal in German and checks resulting site.
  5. *
  6. * @group Installer
  7. *
  8. * @see \Drupal\FunctionalTests\Installer\InstallerTranslationTest
  9. */
  10. class InstallerTranslationQueryTest extends InstallerTestBase {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. protected $defaultTheme = 'stark';
  15. /**
  16. * Overrides the language code in which to install Drupal.
  17. *
  18. * @var string
  19. */
  20. protected $langcode = 'de';
  21. /**
  22. * {@inheritdoc}
  23. */
  24. protected function visitInstaller() {
  25. // Place a custom local translation in the translations directory.
  26. mkdir($this->root . '/' . $this->siteDirectory . '/files/translations', 0777, TRUE);
  27. file_put_contents($this->root . '/' . $this->siteDirectory . '/files/translations/drupal-8.0.0.de.po', $this->getPo('de'));
  28. // The unrouted URL assembler does not exist at this point, so we build the
  29. // URL ourselves.
  30. $this->drupalGet($GLOBALS['base_url'] . '/core/install.php' . '?langcode=' . $this->langcode);
  31. // The language should have been automatically detected, all following
  32. // screens should be translated already.
  33. $elements = $this->xpath('//input[@type="submit"]/@value');
  34. $this->assertEqual(current($elements)->getText(), 'Save and continue de');
  35. $this->translations['Save and continue'] = 'Save and continue de';
  36. // Check the language direction.
  37. $direction = current($this->xpath('/@dir'))->getText();
  38. $this->assertEqual($direction, 'ltr');
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. protected function setUpLanguage() {
  44. // The language was was preset by passing a query parameter in the URL, so
  45. // no explicit language selection is necessary.
  46. }
  47. /**
  48. * Verifies the expected behaviors of the installation result.
  49. */
  50. public function testInstaller() {
  51. $this->assertUrl('user/1');
  52. $this->assertSession()->statusCodeEquals(200);
  53. // Verify German was configured but not English.
  54. $this->drupalGet('admin/config/regional/language');
  55. $this->assertText('German');
  56. $this->assertNoText('English');
  57. }
  58. /**
  59. * Returns the string for the test .po file.
  60. *
  61. * @param string $langcode
  62. * The language code.
  63. *
  64. * @return string
  65. * Contents for the test .po file.
  66. */
  67. protected function getPo($langcode) {
  68. return <<<ENDPO
  69. msgid ""
  70. msgstr ""
  71. msgid "Save and continue"
  72. msgstr "Save and continue $langcode"
  73. ENDPO;
  74. }
  75. }