upgrade.locale.test 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
  27. // The home page should be in French.
  28. $this->assertPageInLanguage('', 'fr');
  29. // No prefixed page should exist.
  30. $this->drupalGet('en');
  31. $this->assertResponse(404);
  32. $this->drupalGet('fr');
  33. $this->assertResponse(404);
  34. }
  35. /**
  36. * Test an upgrade with path-based negotiation.
  37. */
  38. public function testLocaleUpgradePathDefault() {
  39. // LANGUAGE_NEGOTIATION_PATH_DEFAULT.
  40. $this->variable_set('language_negotiation', 1);
  41. $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
  42. // The home page should be in French.
  43. $this->assertPageInLanguage('', 'fr');
  44. // The language switcher block should be displayed.
  45. $this->assertRaw('block-locale-language', 'The language switcher block is displayed.');
  46. // The French prefix should not be active because French is the default language.
  47. $this->drupalGet('fr');
  48. $this->assertResponse(404);
  49. // The English prefix should be active.
  50. $this->assertPageInLanguage('en', 'en');
  51. }
  52. /**
  53. * Test an upgrade with path-based (with fallback) negotiation.
  54. */
  55. public function testLocaleUpgradePathFallback() {
  56. // LANGUAGE_NEGOTIATION_PATH.
  57. $this->variable_set('language_negotiation', 2);
  58. // Set the language of the admin user to English.
  59. db_update('users')
  60. ->fields(array('language' => 'en'))
  61. ->condition('uid', 1)
  62. ->execute();
  63. $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
  64. // Both prefixes should be active.
  65. $this->assertPageInLanguage('fr', 'fr');
  66. $this->assertPageInLanguage('en', 'en');
  67. // The home page should be in the admin user language.
  68. $this->assertPageInLanguage('', 'en');
  69. // The language switcher block should be displayed.
  70. $this->assertRaw('block-locale-language', 'The language switcher block is displayed.');
  71. }
  72. /**
  73. * Test an upgrade with domain-based negotiation.
  74. */
  75. public function testLocaleUpgradeDomain() {
  76. // LANGUAGE_NEGOTIATION_DOMAIN.
  77. $this->variable_set('language_negotiation', 3);
  78. $this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
  79. // The home page should be in French.
  80. $this->assertPageInLanguage('', 'fr');
  81. // The language switcher block should be displayed.
  82. $this->assertRaw('block-locale-language', 'The language switcher block is displayed.');
  83. // The language switcher block should point to http://en.example.com.
  84. $language_links = $this->xpath('//ul[contains(@class, :class)]/li/a', array(':class' => 'language-switcher-locale-url'));
  85. $found_english_link = FALSE;
  86. foreach ($language_links as $link) {
  87. if ((string) $link['href'] == 'http://en.example.com/') {
  88. $found_english_link = TRUE;
  89. }
  90. }
  91. $this->assertTrue($found_english_link, 'The English link points to the correct domain.');
  92. // Both prefixes should be inactive.
  93. $this->drupalGet('en');
  94. $this->assertResponse(404);
  95. $this->drupalGet('fr');
  96. $this->assertResponse(404);
  97. }
  98. /**
  99. * Asserts that a page exists and is in the specified language.
  100. */
  101. public function assertPageInLanguage($path = NULL, $langcode) {
  102. if (isset($path)) {
  103. $this->drupalGet($path);
  104. }
  105. if (!$this->assertResponse(200)) {
  106. return FALSE;
  107. }
  108. if ($this->parse()) {
  109. return $this->assertIdentical($langcode, (string) $this->elements['xml:lang']);
  110. }
  111. else {
  112. return FALSE;
  113. }
  114. }
  115. }