function LanguageHierarchyPathsFunctionalTest::testLanguageHierarchyPathsLookup in Language Hierarchy 7
Test if language hierarchies are used for path aliases associated with language.
See also
LocalePathFunctionalTest::testPathLanguageConfiguration()
File
- modules/
language_hierarchy_paths/ language_hierarchy_paths.test, line 56 - Tests for language_hierarchy_paths.module.
Class
- LanguageHierarchyPathsFunctionalTest
- Functional tests for configuring a different path alias per language.
Code
function testLanguageHierarchyPathsLookup() {
// 1. Set up admin user & languages.
$this
->createAdminUserAndLanguages();
// 2. Set up a node with paths in parent languages & LANGUAGE_NONE.
$page_node = $this
->drupalCreateNode(array(
'type' => 'page',
));
$page_node_paths = array(
// Create a path alias in default language (English).
'en' => array(
'source' => 'node/' . $page_node->nid,
'alias' => $this
->randomName(8),
'language' => 'en',
),
// Create a path alias in new custom language.
'xx' => array(
'source' => 'node/' . $page_node->nid,
'alias' => $this
->randomName(8),
'language' => 'xx',
),
);
$this
->createPathsThroughUI($page_node_paths);
// Also create a custom path in LANGUAGE_NONE, which should not be
// prioritized over the specific language even though it is newer.
$edit = array(
'source' => 'node/' . $page_node->nid,
'alias' => $this
->randomName(8),
'language' => LANGUAGE_NONE,
);
path_save($edit);
// 3. Check sublanguages inherit aliases from parent languages, including
// priority of languages for alias by source path.
$lookups = array(
'en',
'xx',
'xx-xx',
'en-xx',
);
$this
->checkLookups($lookups, $page_node->title, $page_node_paths, 'node/' . $page_node->nid);
// 4. Check direct lookups too, to be sure.
foreach ($lookups as $langcode) {
if (isset($this->languages[$langcode]['parent_language_list'])) {
$language_name = $this->languages[$langcode]['name'];
$parent_langcode = $this->languages[$langcode]['parent_language_list'];
$alias = $page_node_paths[$parent_langcode]['alias'];
}
else {
$language_name = isset($this->languages[$langcode]) ? $this->languages[$langcode]['name'] : 'English';
if (isset($page_node_paths[$langcode]['alias'])) {
$alias = $page_node_paths[$langcode]['alias'];
}
else {
$this
->fail($language_name . ' has no alias.');
continue;
}
}
$this
->checkDirectLookup($langcode, 'node/' . $page_node->nid, $alias, $language_name . ' sublanguage alias has priority.');
}
// 5. Repeat test from step 3 to use cache, since the first page visits
// would have missed the cache, which uses different code to get path
// aliases in bulk.
$this
->checkLookups($lookups, $page_node->title, $page_node_paths, NULL);
}