xmlsitemap_i18n.test 5.38 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?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.
   */
  function setUp() {
19
    // Call parent::setUp() allowing test cases to pass further modules.
20
21
    $modules = func_get_args();
    $modules = array_merge(array('locale', 'translation', 'i18n', 'xmlsitemap_i18n'), $modules);
22
    call_user_func_array(array($this, 'parent::setUp'), $modules);
23
24

    // Add predefined language and reset the locale cache.
25
26
    require_once DRUPAL_ROOT . '/includes/locale.inc';
    locale_add_language('fr', NULL, NULL, LANGUAGE_LTR, '', 'fr');
27
    drupal_language_initialize();
28
29
30

    variable_set('xmlsitemap_languages', array('en', 'fr'));
    variable_set('language_negotiation', LANGUAGE_NEGOTIATION_PATH);
31
32
33
34
35

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

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',
      'dependencies' => array('i18n'),
    );
  }

  function testLanguageSelection() {
    // Create our three different language nodes.
51
    $node = $this->addSitemapLink(array('type' => 'node', 'language' => LANGUAGE_NONE));
52
53
54
55
    $node_en = $this->addSitemapLink(array('type' => 'node', 'language' => 'en'));
    $node_fr = $this->addSitemapLink(array('type' => 'node', 'language' => 'fr'));

    // Create three non-node language nodes.
56
    $link = $this->addSitemapLink(array('language' => LANGUAGE_NONE));
57
58
59
60
61
    $link_en = $this->addSitemapLink(array('language' => 'en'));
    $link_fr = $this->addSitemapLink(array('language' => 'fr'));

    variable_set('i18n_selection_mode', 'off');
    $this->regenerateSitemap();
62
    $this->drupalGetSitemap(array('language' => 'en'));
63
    $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
64
    $this->drupalGetSitemap(array('language' => 'fr'));
65
    $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
66
67
68

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

    variable_set('i18n_selection_mode', 'mixed');
    $this->regenerateSitemap();
78
    $this->drupalGetSitemap(array('language' => 'en'));
79
80
    $this->assertRawSitemapLinks($node, $node_en, $link, $link_en);
    $this->assertNoRawSitemapLinks($node_fr, $link_fr);
81
    $this->drupalGetSitemap(array('language' => 'fr'));
82
    $this->assertRawSitemapLinks($node, $node_en, $node_fr, $link, $link_en, $link_fr);
83
84
85

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

    // 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();
97
    $this->drupalGetSitemap(array('language' => 'en'));
98
99
    $this->assertRawSitemapLinks($node_en, $link, $link_en);
    $this->assertNoRawSitemapLinks($node, $node_fr, $link_fr);
100
    $this->drupalGetSitemap(array('language' => 'fr'));
101
102
    $this->assertRawSitemapLinks($node_fr, $link, $link_fr);
    $this->assertNoRawSitemapLinks($node, $node_en, $link_en);
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
  }
}

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',
      'dependencies' => array('i18n'),
    );
  }

  function setUp() {
    parent::setUp('xmlsitemap_node');

    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'));
128
129
    $link = $this->assertSitemapLink('node', $node->nid);
    $this->assertIdentical($link['language'], 'en');
130
131

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