xmlsitemap_i18n.test 5.49 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
// $Id$

/**
 * @file
 * Unit tests for the xmlsitemap_i18n module.
 */

/**
 * Common base test class for XML sitemap internationalization tests.
 */
class XMLSitemapI18nWebTestCase extends XMLSitemapTestHelper {
  protected $admin_user;

  /**
   * Set up an administrative user account and testing keys.
   */
18
  function setUp($modules = array()) {
19
    // Call parent::setUp() allowing test cases to pass further modules.
20
21
22
23
    $modules[] = 'locale';
    $modules[] = 'translation';
    $modules[] = 'i18n';
    $modules[] = 'xmlsitemap_i18n';
24
    parent::setUp($modules);
25
26

    // Add predefined language and reset the locale cache.
27
28
    require_once DRUPAL_ROOT . '/includes/locale.inc';
    locale_add_language('fr', NULL, NULL, LANGUAGE_LTR, '', 'fr');
29
    drupal_language_initialize();
30
    variable_set('language_negotiation', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX);
31
32
33

    // Create the two different language-context sitemaps.
    db_query("DELETE FROM {xmlsitemap_sitemap}");
34
35
36
    $sitemap = new stdClass();
    $sitemap->context = array('language' => 'en');
    xmlsitemap_sitemap_save($sitemap);
37
    $sitemap = new stdClass();
38
    $sitemap->context = array('language' => 'fr');
39
    xmlsitemap_sitemap_save($sitemap);
40
41
42
43
44
45
46
47
48
  }
}

class XMLSitemapI18nTest extends XMLSitemapI18nWebTestCase {
  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',
49
      'dependencies' => array('i18n', 'disable-this-test-for-now'),
50
51
52
53
54
    );
  }

  function testLanguageSelection() {
    // Create our three different language nodes.
55
    $node = $this->addSitemapLink(array('type' => 'node', 'language' => LANGUAGE_NONE));
56
57
58
59
    $node_en = $this->addSitemapLink(array('type' => 'node', 'language' => 'en'));
    $node_fr = $this->addSitemapLink(array('type' => 'node', 'language' => 'fr'));

    // Create three non-node language nodes.
60
    $link = $this->addSitemapLink(array('language' => LANGUAGE_NONE));
61
62
63
64
65
    $link_en = $this->addSitemapLink(array('language' => 'en'));
    $link_fr = $this->addSitemapLink(array('language' => 'fr'));

    variable_set('i18n_selection_mode', 'off');
    $this->regenerateSitemap();
66
    $this->drupalGetSitemap(array('language' => 'en'));
67
    $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
68
    $this->drupalGetSitemap(array('language' => 'fr'));
69
    $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
70
71
72

    variable_set('i18n_selection_mode', 'simple');
    $this->regenerateSitemap();
73
    $this->drupalGetSitemap(array('language' => 'en'));
74
75
    $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
    $this->assertNoRawSitemapLinks($node_fr, $link_fr);
76
    $this->drupalGetSitemap(array('language' => 'fr'));
77
78
    $this->assertRawSitemapLinks($node, $node_fr, $link, $link_fr);
    $this->assertNoRawSitemapLinks($node_en, $link_en);
79
80
81

    variable_set('i18n_selection_mode', 'mixed');
    $this->regenerateSitemap();
82
    $this->drupalGetSitemap(array('language' => 'en'));
83
84
    $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
    $this->assertNoRawSitemapLinks($node_fr, $link_fr);
85
    $this->drupalGetSitemap(array('language' => 'fr'));
86
    $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
87
88
89

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

    // 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();
101
    $this->drupalGetSitemap(array('language' => 'en'));
102
103
    $this->assertRawSitemapLinks($node_en, $link, $link_en);
    $this->assertNoRawSitemapLinks($node, $node_fr, $link_fr);
104
    $this->drupalGetSitemap(array('language' => 'fr'));
105
106
    $this->assertRawSitemapLinks($node_fr, $link, $link_fr);
    $this->assertNoRawSitemapLinks($node, $node_en, $link_en);
107
108
109
110
111
112
113
114
115
  }
}

class XMLSitemapI18nNodeTest extends XMLSitemapI18nWebTestCase {
  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',
116
      'dependencies' => array('i18n', 'disable-this-test-for-now'),
117
118
119
    );
  }

120
121
122
  function setUp($modules = array()) {
    $modules[] = 'xmlsitemap_node';
    parent::setUp($modules);
123
124
125
126
127
128
129
130
131
132

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

  function testNodeLanguageData() {
    $node = $this->drupalCreateNode(array());

    $this->drupalPost('node/' . $node->nid . '/edit', array('language' => 'en'), t('Save'));
133
134
    $link = $this->assertSitemapLink('node', $node->nid);
    $this->assertIdentical($link['language'], 'en');
135
136

    $this->drupalPost('node/' . $node->nid . '/edit', array('language' => 'fr'), t('Save'));
137
138
    $link = $this->assertSitemapLink('node', $node->nid);
    $this->assertIdentical($link['language'], 'fr');
139
140
  }
}