InstallerTranslationQueryTest.php 2.3 KB

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