xmlsitemap_i18n.test 5.83 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Unit tests for the xmlsitemap_i18n project.
6 7 8 9 10 11
 */

/**
 * Common base test class for XML sitemap internationalization tests.
 */
class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper {
12 13 14 15 16 17 18 19

  /**
   * Admin User.
   *
   * @var string
   *
   * @codingStandardsIgnoreStart
   */
20 21 22 23
  protected $admin_user;

  /**
   * Set up an administrative user account and testing keys.
24 25
   *
   * @codingStandardsIgnoreEnd
26
   */
27
  public function setUp($modules = array()) {
28
    // Call parent::setUp() allowing test cases to pass further modules.
29 30 31 32
    $modules[] = 'locale';
    $modules[] = 'translation';
    $modules[] = 'i18n';
    $modules[] = 'xmlsitemap_i18n';
33
    parent::setUp($modules);
34 35

    // Add predefined language and reset the locale cache.
36 37
    require_once DRUPAL_ROOT . '/includes/locale.inc';
    locale_add_language('fr', NULL, NULL, LANGUAGE_LTR, '', 'fr');
38
    drupal_language_initialize();
39
    variable_set('language_negotiation', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX);
40 41 42

    // Create the two different language-context sitemaps.
    db_query("DELETE FROM {xmlsitemap_sitemap}");
43

44 45 46
    $sitemap = new stdClass();
    $sitemap->context = array('language' => 'en');
    xmlsitemap_sitemap_save($sitemap);
47
    $sitemap = new stdClass();
48
    $sitemap->context = array('language' => 'fr');
49
    xmlsitemap_sitemap_save($sitemap);
50
  }
51

52 53
}

54 55 56
/**
 * I18n Test.
 */
57
class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase {
58 59 60 61

  /**
   * Get Info.
   */
62 63 64 65 66
  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',
67
      'dependencies' => array('i18n', 'disable-this-test-for-now'),
68 69 70
    );
  }

71 72 73 74
  /**
   * Language Selection.
   */
  public function testLanguageSelection() {
75
    // Create our three different language nodes.
76
    $node = $this->addSitemapLink(array('type' => 'node', 'language' => LANGUAGE_NONE));
77 78 79 80
    $node_en = $this->addSitemapLink(array('type' => 'node', 'language' => 'en'));
    $node_fr = $this->addSitemapLink(array('type' => 'node', 'language' => 'fr'));

    // Create three non-node language nodes.
81
    $link = $this->addSitemapLink(array('language' => LANGUAGE_NONE));
82 83 84 85 86
    $link_en = $this->addSitemapLink(array('language' => 'en'));
    $link_fr = $this->addSitemapLink(array('language' => 'fr'));

    variable_set('i18n_selection_mode', 'off');
    $this->regenerateSitemap();
87
    $this->drupalGetSitemap(array('language' => 'en'));
88
    $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
89
    $this->drupalGetSitemap(array('language' => 'fr'));
90
    $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
91 92 93

    variable_set('i18n_selection_mode', 'simple');
    $this->regenerateSitemap();
94
    $this->drupalGetSitemap(array('language' => 'en'));
95 96
    $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
    $this->assertNoRawSitemapLinks($node_fr, $link_fr);
97
    $this->drupalGetSitemap(array('language' => 'fr'));
98 99
    $this->assertRawSitemapLinks($node, $node_fr, $link, $link_fr);
    $this->assertNoRawSitemapLinks($node_en, $link_en);
100 101 102

    variable_set('i18n_selection_mode', 'mixed');
    $this->regenerateSitemap();
103
    $this->drupalGetSitemap(array('language' => 'en'));
104 105
    $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
    $this->assertNoRawSitemapLinks($node_fr, $link_fr);
106
    $this->drupalGetSitemap(array('language' => 'fr'));
107
    $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
108 109 110

    variable_set('i18n_selection_mode', 'default');
    $this->regenerateSitemap();
111
    $this->drupalGetSitemap(array('language' => 'en'));
112 113
    $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
    $this->assertNoRawSitemapLinks($node_fr, $link_fr);
114
    $this->drupalGetSitemap(array('language' => 'fr'));
115 116
    $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
    $this->assertNoRawSitemapLinks($node_fr, $link_fr);
117 118 119 120 121

    // 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();
122
    $this->drupalGetSitemap(array('language' => 'en'));
123 124
    $this->assertRawSitemapLinks($node_en, $link, $link_en);
    $this->assertNoRawSitemapLinks($node, $node_fr, $link_fr);
125
    $this->drupalGetSitemap(array('language' => 'fr'));
126 127
    $this->assertRawSitemapLinks($node_fr, $link, $link_fr);
    $this->assertNoRawSitemapLinks($node, $node_en, $link_en);
128
  }
129

130 131
}

132 133 134
/**
 * Node Test.
 */
135
class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase {
136 137 138 139

  /**
   * Get Info.
   */
140 141 142 143 144
  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',
145
      'dependencies' => array('i18n', 'disable-this-test-for-now'),
146 147 148
    );
  }

149 150 151 152
  /**
   * Setup.
   */
  public function setUp($modules = array()) {
153 154
    $modules[] = 'xmlsitemap_node';
    parent::setUp($modules);
155 156 157 158 159 160

    variable_set('language_content_type_page', 1);
    $this->admin_user = $this->drupalCreateUser(array('administer nodes'));
    $this->drupalLogin($this->admin_user);
  }

161 162 163 164
  /**
   * Node Language Data.
   */
  public function testNodeLanguageData() {
165 166 167
    $node = $this->drupalCreateNode(array());

    $this->drupalPost('node/' . $node->nid . '/edit', array('language' => 'en'), t('Save'));
168 169
    $link = $this->assertSitemapLink('node', $node->nid);
    $this->assertIdentical($link['language'], 'en');
170 171

    $this->drupalPost('node/' . $node->nid . '/edit', array('language' => 'fr'), t('Save'));
172 173
    $link = $this->assertSitemapLink('node', $node->nid);
    $this->assertIdentical($link['language'], 'fr');
174
  }
175

176
}