123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- /**
- * @file
- * Unit tests for the xmlsitemap_i18n project.
- */
- /**
- * Common base test class for XML sitemap internationalization tests.
- */
- class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper {
- /**
- * Admin User.
- *
- * @var string
- *
- * @codingStandardsIgnoreStart
- */
- protected $admin_user;
- /**
- * Set up an administrative user account and testing keys.
- *
- * @codingStandardsIgnoreEnd
- */
- public function setUp($modules = array()) {
- // Call parent::setUp() allowing test cases to pass further modules.
- $modules[] = 'locale';
- $modules[] = 'translation';
- $modules[] = 'i18n';
- $modules[] = 'xmlsitemap_i18n';
- parent::setUp($modules);
- // Add predefined language and reset the locale cache.
- require_once DRUPAL_ROOT . '/includes/locale.inc';
- locale_add_language('fr', NULL, NULL, LANGUAGE_LTR, '', 'fr');
- drupal_language_initialize();
- variable_set('language_negotiation', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX);
- // Create the two different language-context sitemaps.
- db_delete('xmlsitemap_sitemap')->execute();
- $sitemap = new stdClass();
- $sitemap->context = array('language' => 'en');
- xmlsitemap_sitemap_save($sitemap);
- $sitemap = new stdClass();
- $sitemap->context = array('language' => 'fr');
- xmlsitemap_sitemap_save($sitemap);
- }
- }
- /**
- * I18n Test.
- */
- class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase {
- /**
- * Get Info.
- */
- public static function getInfo() {
- return array(
- 'name' => 'XML sitemap i18n tests',
- 'description' => 'Functional and integration tests for the XML sitemap and internationalization modules.',
- 'group' => 'XML sitemap',
- 'dependencies' => array('i18n', 'disable-this-test-for-now'),
- );
- }
- /**
- * Language Selection.
- */
- public function testLanguageSelection() {
- // Create our three different language nodes.
- $node = $this->addSitemapLink(array('type' => 'node', 'language' => LANGUAGE_NONE));
- $node_en = $this->addSitemapLink(array('type' => 'node', 'language' => 'en'));
- $node_fr = $this->addSitemapLink(array('type' => 'node', 'language' => 'fr'));
- // Create three non-node language nodes.
- $link = $this->addSitemapLink(array('language' => LANGUAGE_NONE));
- $link_en = $this->addSitemapLink(array('language' => 'en'));
- $link_fr = $this->addSitemapLink(array('language' => 'fr'));
- variable_set('i18n_selection_mode', 'off');
- $this->regenerateSitemap();
- $this->drupalGetSitemap(array('language' => 'en'));
- $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
- $this->drupalGetSitemap(array('language' => 'fr'));
- $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
- variable_set('i18n_selection_mode', 'simple');
- $this->regenerateSitemap();
- $this->drupalGetSitemap(array('language' => 'en'));
- $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
- $this->assertNoRawSitemapLinks($node_fr, $link_fr);
- $this->drupalGetSitemap(array('language' => 'fr'));
- $this->assertRawSitemapLinks($node, $node_fr, $link, $link_fr);
- $this->assertNoRawSitemapLinks($node_en, $link_en);
- variable_set('i18n_selection_mode', 'mixed');
- $this->regenerateSitemap();
- $this->drupalGetSitemap(array('language' => 'en'));
- $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
- $this->assertNoRawSitemapLinks($node_fr, $link_fr);
- $this->drupalGetSitemap(array('language' => 'fr'));
- $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
- variable_set('i18n_selection_mode', 'default');
- $this->regenerateSitemap();
- $this->drupalGetSitemap(array('language' => 'en'));
- $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
- $this->assertNoRawSitemapLinks($node_fr, $link_fr);
- $this->drupalGetSitemap(array('language' => 'fr'));
- $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
- $this->assertNoRawSitemapLinks($node_fr, $link_fr);
- // With strict mode, the language neutral node should not be found, but the
- // language neutral non-node should be.
- variable_set('i18n_selection_mode', 'strict');
- $this->regenerateSitemap();
- $this->drupalGetSitemap(array('language' => 'en'));
- $this->assertRawSitemapLinks($node_en, $link, $link_en);
- $this->assertNoRawSitemapLinks($node, $node_fr, $link_fr);
- $this->drupalGetSitemap(array('language' => 'fr'));
- $this->assertRawSitemapLinks($node_fr, $link, $link_fr);
- $this->assertNoRawSitemapLinks($node, $node_en, $link_en);
- }
- }
- /**
- * Node Test.
- */
- class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase {
- /**
- * Get Info.
- */
- public static function getInfo() {
- return array(
- 'name' => 'XML sitemap i18n node tests',
- 'description' => 'Functional and integration tests for the XML sitemap node and internationalization modules.',
- 'group' => 'XML sitemap',
- 'dependencies' => array('i18n', 'disable-this-test-for-now'),
- );
- }
- /**
- * Setup.
- */
- public function setUp($modules = array()) {
- $modules[] = 'xmlsitemap_node';
- parent::setUp($modules);
- variable_set('language_content_type_page', 1);
- $this->admin_user = $this->drupalCreateUser(array('administer nodes'));
- $this->drupalLogin($this->admin_user);
- }
- /**
- * Node Language Data.
- */
- public function testNodeLanguageData() {
- $node = $this->drupalCreateNode(array());
- $this->drupalPost('node/' . $node->nid . '/edit', array('language' => 'en'), t('Save'));
- $link = $this->assertSitemapLink('node', $node->nid);
- $this->assertIdentical($link['language'], 'en');
- $this->drupalPost('node/' . $node->nid . '/edit', array('language' => 'fr'), t('Save'));
- $link = $this->assertSitemapLink('node', $node->nid);
- $this->assertIdentical($link['language'], 'fr');
- }
- }
|