Tests whether the specified language switch links are found.
$node: The node to display.
$translation: The translation whose link has to be checked.
$find: TRUE if the link must be present in the node page.
$types: The page areas to be checked.
TRUE if the language switch links are found, FALSE if not.
function assertLanguageSwitchLinks($node, $translation, $find = TRUE, $types = NULL) {
if (empty($types)) {
$types = array(
'node',
'block-language',
);
}
elseif (is_string($types)) {
$types = array(
$types,
);
}
$result = TRUE;
$languages = language_list();
$page_language = $languages[$node->langcode];
$translation_language = $languages[$translation->langcode];
$url = url("node/{$translation->nid}", array(
'language' => $translation_language,
));
$this
->drupalGet("node/{$node->nid}", array(
'language' => $page_language,
));
foreach ($types as $type) {
$args = array(
'%translation_language' => $translation_language->name,
'%page_language' => $page_language->name,
'%type' => $type,
);
if ($find) {
$message = format_string('[%page_language] Language switch item found for %translation_language language in the %type page area.', $args);
}
else {
$message = format_string('[%page_language] Language switch item not found for %translation_language language in the %type page area.', $args);
}
// node uses the article tag.
$tag = $type == 'node' ? 'article' : 'div';
if (!empty($translation->nid)) {
$xpath = '//' . $tag . '[contains(@class, :type)]//a[@href=:url]';
}
else {
$xpath = '//' . $tag . '[contains(@class, :type)]//span[contains(@class, "locale-untranslated")]';
}
$found = $this
->findContentByXPath($xpath, array(
':type' => $type,
':url' => $url,
), $translation_language->name);
$result = $this
->assertTrue($found == $find, $message) && $result;
}
return $result;
}