public function XMLSitemapLanguageHierarchyStringTranslationWebTestCase::testSiteMapLanguageLinks in Language Hierarchy 7
File
- modules/
xmlsitemap_language_hierarchy/ tests/ xmlsitemap_language_hierarchy.test, line 34 - Tests for the XMLSiteMap Language Hierarchy module.
Class
- XMLSitemapLanguageHierarchyStringTranslationWebTestCase
- @file Tests for the XMLSiteMap Language Hierarchy module.
Code
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.");
}