function TranslationTest::assertLanguageSwitchLinks

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 TranslationTest::assertLanguageSwitchLinks()
TranslationTest::testLanguageSwitcherBlockIntegration in drupal/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php
Tests that the language switcher block alterations work as intended.
TranslationTest::testLanguageSwitchLinks in drupal/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php
Checks that the language switch links behave properly.

File

drupal/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php, line 438
Definition of Drupal\translation\Tests\TranslationTest.

Class

TranslationTest
Functional tests for the Translation module.

Namespace

Drupal\translation\Tests

Code

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;
}