1 translation.test TranslationTestCase::assertLanguageSwitchLinks($node, $translation, $find = TRUE, $types = NULL)

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.:

File

core/modules/translation/tests/translation.test, line 419
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();
  $node_langcode = $node->langcode === LANGUAGE_NONE ? config_get('system.core', 'language_default') : $node->langcode;
  $translation_langcode = $translation->langcode === LANGUAGE_NONE ? config_get('system.core', 'language_default') : $translation->langcode;
  $page_language = $languages[$node_langcode];
  $translation_language = $languages[$translation_langcode];
  $url = url("node/$translation->nid", array('language' => $translation_language));

  $this->backdropGet("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);
    }

    if ($type == 'node') {
      // Nodes use post tags, so need a different xpath expression.
      if (!empty($translation->nid)) {
        $xpath = '//article[contains(@class, :type)]//a[@href=:url]';
      }
      else {
        $xpath = '//article[contains(@class, :type)]//span[contains(@class, "locale-untranslated")]';
      }
    }
    else {
      // Blocks and most other types use a div.
      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->name);
    $result = $this->assertTrue($found == $find, $message) && $result;
  }

  return $result;
}