You are here

public function XMLSitemapI18nTest::testLanguageSelection in XML sitemap 7.2

Same name and namespace in other branches
  1. 6.2 xmlsitemap_i18n/xmlsitemap_i18n.test \XMLSitemapI18nTest::testLanguageSelection()

Language Selection.

File

xmlsitemap_i18n/xmlsitemap_i18n.test, line 74
Unit tests for the xmlsitemap_i18n project.

Class

XMLSitemapI18nTest
I18n Test.

Code

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);
}