function TranslationTestCase::assertLanguageSwitchLinks in Drupal 7
Tests whether the specified language switch links are found.
Parameters
$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.
Return value
TRUE if the language switch links are found, FALSE if not.
2 calls to TranslationTestCase::assertLanguageSwitchLinks()
- TranslationTestCase::testLanguageSwitcherBlockIntegration in modules/
translation/ translation.test - Tests that the language switcher block alterations work as intended.
- TranslationTestCase::testLanguageSwitchLinks in modules/
translation/ translation.test - Checks that the language switch links behave properly.
File
- modules/
translation/ translation.test, line 422 - Tests for the Translation module.
Class
- TranslationTestCase
- Functional tests for the Translation module.
Code
function assertLanguageSwitchLinks($node, $translation, $find = TRUE, $types = NULL) {
if (empty($types)) {
$types = array(
'node',
'block-locale',
);
}
elseif (is_string($types)) {
$types = array(
$types,
);
}
$result = TRUE;
$languages = language_list();
$page_language = $languages[entity_language('node', $node)];
$translation_language = $languages[$translation->language];
$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->native,
'%page_language' => $page_language->native,
'%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);
}
if (!empty($translation->nid)) {
$xpath = '//div[contains(@class, :type)]//a[@href=:url]';
}
else {
$xpath = '//div[contains(@class, :type)]//span[contains(@class, "locale-untranslated")]';
}
$found = $this
->findContentByXPath($xpath, array(
':type' => $type,
':url' => $url,
), $translation_language->native);
$result = $this
->assertTrue($found == $find, $message) && $result;
}
return $result;
}