xmlsitemap_language_hierarchy.test in Language Hierarchy 7
Tests for the XMLSiteMap Language Hierarchy module.
File
modules/xmlsitemap_language_hierarchy/tests/xmlsitemap_language_hierarchy.testView source
<?php
/**
* @file
* Tests for the XMLSiteMap Language Hierarchy module.
*/
class XMLSitemapLanguageHierarchyStringTranslationWebTestCase extends EntityTranslationHierarchyBaseTestCase {
public static function getInfo() {
return array(
'name' => 'XMLSitemap translation hierarchy',
'description' => 'Test XMLSitemap translation with language inheritance.',
'group' => 'Language Hierarchy',
);
}
public function setUp() {
parent::setUp('xmlsitemap_language_hierarchy');
}
// Hierarchical list of languages used in this test.
protected $languages = array(
// Portuguese, International
array(
'langcode' => 'pt',
'parent' => '',
),
// Portuguese, Brazil
array(
'langcode' => 'pt-br',
'parent' => 'pt',
),
// Portuguese, Portugal
array(
'langcode' => 'pt-pt',
'parent' => 'pt',
),
// French
array(
'langcode' => 'fr',
'parent' => '',
),
);
public function testSiteMapLanguageLinks() {
$node = $this
->createPageNode($this
->randomString(), $this
->randomString(), 'pt');
// We should now have some links in the xmlsitemap.
$xmlsitemap_node_links = db_query('SELECT language, loc FROM {xmlsitemap} WHERE id = :id AND type = :type AND subtype = :subtype', array(
':id' => $node->nid,
':type' => 'node',
':subtype' => $node->type,
))
->fetchAllKeyed();
$xmlsitemap_language_hierarchy_links = db_query('SELECT language, loc FROM {xmlsitemap} WHERE id = :id AND type LIKE :type AND subtype = :subtype', array(
':id' => $node->nid,
':type' => db_like('node_translation_') . '%',
':subtype' => $node->type,
))
->fetchAllKeyed();
// We should have sitemap links for all our enabled sub-languages.
$this
->assertTrue(isset($xmlsitemap_language_hierarchy_links['pt-br']), format_string("Sublanguage xmlsitemap links are created for @language", array(
'@language' => 'pt-br',
)));
$this
->assertTrue(isset($xmlsitemap_language_hierarchy_links['pt-pt']), format_string("Sublanguage xmlsitemap links are created for @language", array(
'@language' => 'pt-pt',
)));
// But not created for a language that isn't related.
$this
->assertFalse(isset($xmlsitemap_language_hierarchy_links['fr']), format_string("Sublanguage xmlsitemap links are correctly not created for @language", array(
'@language' => 'fr',
)));
// We should find that $hierarchy_sitemap_links doesn't contain the same language as $sitemap_links.
$this
->assertFalse(count(array_intersect_key($xmlsitemap_language_hierarchy_links, $xmlsitemap_node_links)), "Ensure that language hierarchy xmlsitemap links don't duplicate xmlsitemap_node ones.");
// Add a translation for the node too, and re-test.
$this
->createTranslation($node, $this
->randomString(), 'pt-br', 'pt');
// We should now have some links in the xmlsitemap.
$xmlsitemap_node_links = db_query('SELECT language, loc FROM {xmlsitemap} WHERE id = :id AND type = :type AND subtype = :subtype', array(
':id' => $node->nid,
':type' => 'node',
':subtype' => $node->type,
))
->fetchAllKeyed();
$xmlsitemap_language_hierarchy_links = db_query('SELECT language, loc FROM {xmlsitemap} WHERE id = :id AND type LIKE :type AND subtype = :subtype', array(
':id' => $node->nid,
':type' => db_like('node_translation_') . '%',
':subtype' => $node->type,
))
->fetchAllKeyed();
// We should have sitemap links for all our enabled sub-languages.
$this
->assertTrue(isset($xmlsitemap_language_hierarchy_links['pt-br']), format_string("Sublanguage xmlsitemap links are created for @language", array(
'@language' => 'pt-br',
)));
$this
->assertTrue(isset($xmlsitemap_language_hierarchy_links['pt-pt']), format_string("Sublanguage xmlsitemap links are created for @language", array(
'@language' => 'pt-pt',
)));
// But not created for a language that isn't related.
$this
->assertFalse(isset($xmlsitemap_language_hierarchy_links['fr']), format_string("Sublanguage xmlsitemap links are correctly not created for @language", array(
'@language' => 'fr',
)));
// We should find that $hierarchy_sitemap_links doesn't contain the same language as $sitemap_links.
$this
->assertFalse(count(array_intersect_key($xmlsitemap_language_hierarchy_links, $xmlsitemap_node_links)), "Ensure that language hierarchy xmlsitemap links don't duplicate xmlsitemap_node ones.");
// Add a translation for French too, and re-test.
$this
->createTranslation($node, $this
->randomString(), 'fr', 'pt');
// We should now have some links in the xmlsitemap.
$xmlsitemap_node_links = db_query('SELECT language, loc FROM {xmlsitemap} WHERE id = :id AND type = :type AND subtype = :subtype', array(
':id' => $node->nid,
':type' => 'node',
':subtype' => $node->type,
))
->fetchAllKeyed();
$xmlsitemap_language_hierarchy_links = db_query('SELECT language, loc FROM {xmlsitemap} WHERE id = :id AND type LIKE :type AND subtype = :subtype', array(
':id' => $node->nid,
':type' => db_like('node_translation_') . '%',
':subtype' => $node->type,
))
->fetchAllKeyed();
// We should have sitemap links for all our enabled sub-languages.
$this
->assertTrue(isset($xmlsitemap_language_hierarchy_links['pt-br']), format_string("Sublanguage xmlsitemap links are created for @language", array(
'@language' => 'pt-br',
)));
$this
->assertTrue(isset($xmlsitemap_language_hierarchy_links['pt-pt']), format_string("Sublanguage xmlsitemap links are created for @language", array(
'@language' => 'pt-pt',
)));
$this
->assertTrue(isset($xmlsitemap_language_hierarchy_links['fr']), format_string("Sublanguage xmlsitemap links are created for @language", array(
'@language' => 'fr',
)));
// We should find that $hierarchy_sitemap_links doesn't contain the same language as $sitemap_links.
$this
->assertFalse(count(array_intersect_key($xmlsitemap_language_hierarchy_links, $xmlsitemap_node_links)), "Ensure that language hierarchy xmlsitemap links don't duplicate xmlsitemap_node ones.");
}
}
Classes
Name | Description |
---|---|
XMLSitemapLanguageHierarchyStringTranslationWebTestCase | @file Tests for the XMLSiteMap Language Hierarchy module. |