upgrade.locale.test 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * Upgrade test for locale.module.
  4. */
  5. class LocaleUpgradePathTestCase extends UpgradePathTestCase {
  6. public static function getInfo() {
  7. return array(
  8. 'name' => 'Locale upgrade path',
  9. 'description' => 'Upgrade path tests for the Locale module.',
  10. 'group' => 'Upgrade path',
  11. );
  12. }
  13. public function setUp() {
  14. // Path to the database dump files.
  15. $this->databaseDumpFiles = array(
  16. drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php',
  17. drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.locale.database.php',
  18. );
  19. parent::setUp();
  20. $this->uninstallModulesExcept(array('locale', 'comment'));
  21. }
  22. /**
  23. * Test a successful upgrade (no negotiation).
  24. */
  25. public function testLocaleUpgrade() {
  26. if ($this->skipUpgradeTest) {
  27. return;
  28. }
  29. $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
  30. // The home page should be in French.
  31. $this->assertPageInLanguage('', 'fr');
  32. // No prefixed page should exist.
  33. $this->drupalGet('en');
  34. $this->assertResponse(404);
  35. $this->drupalGet('fr');
  36. $this->assertResponse(404);
  37. }
  38. /**
  39. * Test an upgrade with path-based negotiation.
  40. */
  41. public function testLocaleUpgradePathDefault() {
  42. if ($this->skipUpgradeTest) {
  43. return;
  44. }
  45. // LANGUAGE_NEGOTIATION_PATH_DEFAULT.
  46. $this->variable_set('language_negotiation', 1);
  47. $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
  48. // The home page should be in French.
  49. $this->assertPageInLanguage('', 'fr');
  50. // The language switcher block should be displayed.
  51. $this->assertRaw('block-locale-language', 'The language switcher block is displayed.');
  52. // The French prefix should not be active because French is the default language.
  53. $this->drupalGet('fr');
  54. $this->assertResponse(404);
  55. // The English prefix should be active.
  56. $this->assertPageInLanguage('en', 'en');
  57. }
  58. /**
  59. * Test an upgrade with path-based (with fallback) negotiation.
  60. */
  61. public function testLocaleUpgradePathFallback() {
  62. if ($this->skipUpgradeTest) {
  63. return;
  64. }
  65. // LANGUAGE_NEGOTIATION_PATH.
  66. $this->variable_set('language_negotiation', 2);
  67. // Set the language of the admin user to English.
  68. db_update('users')
  69. ->fields(array('language' => 'en'))
  70. ->condition('uid', 1)
  71. ->execute();
  72. $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
  73. // Both prefixes should be active.
  74. $this->assertPageInLanguage('fr', 'fr');
  75. $this->assertPageInLanguage('en', 'en');
  76. // The home page should be in the admin user language.
  77. $this->assertPageInLanguage('', 'en');
  78. // The language switcher block should be displayed.
  79. $this->assertRaw('block-locale-language', 'The language switcher block is displayed.');
  80. }
  81. /**
  82. * Test an upgrade with domain-based negotiation.
  83. */
  84. public function testLocaleUpgradeDomain() {
  85. if ($this->skipUpgradeTest) {
  86. return;
  87. }
  88. // LANGUAGE_NEGOTIATION_DOMAIN.
  89. $this->variable_set('language_negotiation', 3);
  90. $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
  91. // The home page should be in French.
  92. $this->assertPageInLanguage('', 'fr');
  93. // The language switcher block should be displayed.
  94. $this->assertRaw('block-locale-language', 'The language switcher block is displayed.');
  95. // The language switcher block should point to http://en.example.com.
  96. $language_links = $this->xpath('//ul[contains(@class, :class)]/li/a', array(':class' => 'language-switcher-locale-url'));
  97. $found_english_link = FALSE;
  98. foreach ($language_links as $link) {
  99. if ((string) $link['href'] == 'http://en.example.com/') {
  100. $found_english_link = TRUE;
  101. }
  102. }
  103. $this->assertTrue($found_english_link, 'The English link points to the correct domain.');
  104. // Both prefixes should be inactive.
  105. $this->drupalGet('en');
  106. $this->assertResponse(404);
  107. $this->drupalGet('fr');
  108. $this->assertResponse(404);
  109. }
  110. /**
  111. * Asserts that a page exists and is in the specified language.
  112. */
  113. public function assertPageInLanguage($path, $langcode) {
  114. if (isset($path)) {
  115. $this->drupalGet($path);
  116. }
  117. if (!$this->assertResponse(200)) {
  118. return FALSE;
  119. }
  120. if ($this->parse()) {
  121. return $this->assertIdentical($langcode, (string) $this->elements['xml:lang']);
  122. }
  123. else {
  124. return FALSE;
  125. }
  126. }
  127. }