xmlsitemap_i18n.test 5.39 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
    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

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

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.
54
    $node = $this->addSitemapLink(array('type' => 'node', 'language' => LANGUAGE_NONE));
55
56
57
58
    $node_en = $this->addSitemapLink(array('type' => 'node', 'language' => 'en'));
    $node_fr = $this->addSitemapLink(array('type' => 'node', 'language' => 'fr'));

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

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

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

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

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

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

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

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