xmlsitemap_i18n.test 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. /**
  3. * @file
  4. * Unit tests for the xmlsitemap_i18n project.
  5. */
  6. /**
  7. * Common base test class for XML sitemap internationalization tests.
  8. */
  9. class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper {
  10. /**
  11. * Admin User.
  12. *
  13. * @var string
  14. *
  15. * @codingStandardsIgnoreStart
  16. */
  17. protected $admin_user;
  18. /**
  19. * Set up an administrative user account and testing keys.
  20. *
  21. * @codingStandardsIgnoreEnd
  22. */
  23. public function setUp($modules = array()) {
  24. // Call parent::setUp() allowing test cases to pass further modules.
  25. $modules[] = 'locale';
  26. $modules[] = 'translation';
  27. $modules[] = 'i18n';
  28. $modules[] = 'xmlsitemap_i18n';
  29. parent::setUp($modules);
  30. // Add predefined language and reset the locale cache.
  31. require_once DRUPAL_ROOT . '/includes/locale.inc';
  32. locale_add_language('fr', NULL, NULL, LANGUAGE_LTR, '', 'fr');
  33. drupal_language_initialize();
  34. variable_set('language_negotiation', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX);
  35. // Create the two different language-context sitemaps.
  36. db_delete('xmlsitemap_sitemap')->execute();
  37. $sitemap = new stdClass();
  38. $sitemap->context = array('language' => 'en');
  39. xmlsitemap_sitemap_save($sitemap);
  40. $sitemap = new stdClass();
  41. $sitemap->context = array('language' => 'fr');
  42. xmlsitemap_sitemap_save($sitemap);
  43. }
  44. }
  45. /**
  46. * I18n Test.
  47. */
  48. class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase {
  49. /**
  50. * Get Info.
  51. */
  52. public static function getInfo() {
  53. return array(
  54. 'name' => 'XML sitemap i18n tests',
  55. 'description' => 'Functional and integration tests for the XML sitemap and internationalization modules.',
  56. 'group' => 'XML sitemap',
  57. 'dependencies' => array('i18n', 'disable-this-test-for-now'),
  58. );
  59. }
  60. /**
  61. * Language Selection.
  62. */
  63. public function testLanguageSelection() {
  64. // Create our three different language nodes.
  65. $node = $this->addSitemapLink(array('type' => 'node', 'language' => LANGUAGE_NONE));
  66. $node_en = $this->addSitemapLink(array('type' => 'node', 'language' => 'en'));
  67. $node_fr = $this->addSitemapLink(array('type' => 'node', 'language' => 'fr'));
  68. // Create three non-node language nodes.
  69. $link = $this->addSitemapLink(array('language' => LANGUAGE_NONE));
  70. $link_en = $this->addSitemapLink(array('language' => 'en'));
  71. $link_fr = $this->addSitemapLink(array('language' => 'fr'));
  72. variable_set('i18n_selection_mode', 'off');
  73. $this->regenerateSitemap();
  74. $this->drupalGetSitemap(array('language' => 'en'));
  75. $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
  76. $this->drupalGetSitemap(array('language' => 'fr'));
  77. $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
  78. variable_set('i18n_selection_mode', 'simple');
  79. $this->regenerateSitemap();
  80. $this->drupalGetSitemap(array('language' => 'en'));
  81. $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
  82. $this->assertNoRawSitemapLinks($node_fr, $link_fr);
  83. $this->drupalGetSitemap(array('language' => 'fr'));
  84. $this->assertRawSitemapLinks($node, $node_fr, $link, $link_fr);
  85. $this->assertNoRawSitemapLinks($node_en, $link_en);
  86. variable_set('i18n_selection_mode', 'mixed');
  87. $this->regenerateSitemap();
  88. $this->drupalGetSitemap(array('language' => 'en'));
  89. $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
  90. $this->assertNoRawSitemapLinks($node_fr, $link_fr);
  91. $this->drupalGetSitemap(array('language' => 'fr'));
  92. $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
  93. variable_set('i18n_selection_mode', 'default');
  94. $this->regenerateSitemap();
  95. $this->drupalGetSitemap(array('language' => 'en'));
  96. $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
  97. $this->assertNoRawSitemapLinks($node_fr, $link_fr);
  98. $this->drupalGetSitemap(array('language' => 'fr'));
  99. $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
  100. $this->assertNoRawSitemapLinks($node_fr, $link_fr);
  101. // With strict mode, the language neutral node should not be found, but the
  102. // language neutral non-node should be.
  103. variable_set('i18n_selection_mode', 'strict');
  104. $this->regenerateSitemap();
  105. $this->drupalGetSitemap(array('language' => 'en'));
  106. $this->assertRawSitemapLinks($node_en, $link, $link_en);
  107. $this->assertNoRawSitemapLinks($node, $node_fr, $link_fr);
  108. $this->drupalGetSitemap(array('language' => 'fr'));
  109. $this->assertRawSitemapLinks($node_fr, $link, $link_fr);
  110. $this->assertNoRawSitemapLinks($node, $node_en, $link_en);
  111. }
  112. }
  113. /**
  114. * Node Test.
  115. */
  116. class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase {
  117. /**
  118. * Get Info.
  119. */
  120. public static function getInfo() {
  121. return array(
  122. 'name' => 'XML sitemap i18n node tests',
  123. 'description' => 'Functional and integration tests for the XML sitemap node and internationalization modules.',
  124. 'group' => 'XML sitemap',
  125. 'dependencies' => array('i18n', 'disable-this-test-for-now'),
  126. );
  127. }
  128. /**
  129. * Setup.
  130. */
  131. public function setUp($modules = array()) {
  132. $modules[] = 'xmlsitemap_node';
  133. parent::setUp($modules);
  134. variable_set('language_content_type_page', 1);
  135. $this->admin_user = $this->drupalCreateUser(array('administer nodes'));
  136. $this->drupalLogin($this->admin_user);
  137. }
  138. /**
  139. * Node Language Data.
  140. */
  141. public function testNodeLanguageData() {
  142. $node = $this->drupalCreateNode(array());
  143. $this->drupalPost('node/' . $node->nid . '/edit', array('language' => 'en'), t('Save'));
  144. $link = $this->assertSitemapLink('node', $node->nid);
  145. $this->assertIdentical($link['language'], 'en');
  146. $this->drupalPost('node/' . $node->nid . '/edit', array('language' => 'fr'), t('Save'));
  147. $link = $this->assertSitemapLink('node', $node->nid);
  148. $this->assertIdentical($link['language'], 'fr');
  149. }
  150. }