You are here

protected function NodeTranslationUITest::doTestAlternateHreflangLinks in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/node/src/Tests/NodeTranslationUITest.php \Drupal\node\Tests\NodeTranslationUITest::doTestAlternateHreflangLinks()

Tests that the given path provides the correct alternate hreflang links.

Parameters

\Drupal\Core\Url $url: The path to be tested.

1 call to NodeTranslationUITest::doTestAlternateHreflangLinks()
NodeTranslationUITest::testTranslationRendering in core/modules/node/src/Tests/NodeTranslationUITest.php
Tests that translations are rendered properly.

File

core/modules/node/src/Tests/NodeTranslationUITest.php, line 380
Contains \Drupal\node\Tests\NodeTranslationUITest.

Class

NodeTranslationUITest
Tests the Node Translation UI.

Namespace

Drupal\node\Tests

Code

protected function doTestAlternateHreflangLinks(Url $url) {
  $languages = $this->container
    ->get('language_manager')
    ->getLanguages();
  $url
    ->setAbsolute();
  $urls = [];
  foreach ($this->langcodes as $langcode) {
    $language_url = clone $url;
    $urls[$langcode] = $language_url
      ->setOption('language', $languages[$langcode]);
  }
  foreach ($this->langcodes as $langcode) {
    $this
      ->drupalGet($urls[$langcode]);
    foreach ($urls as $alternate_langcode => $language_url) {

      // Retrieve desired link elements from the HTML head.
      $links = $this
        ->xpath('head/link[@rel = "alternate" and @href = :href and @hreflang = :hreflang]', array(
        ':href' => $language_url
          ->toString(),
        ':hreflang' => $alternate_langcode,
      ));
      $this
        ->assert(isset($links[0]), format_string('The %langcode node translation has the correct alternate hreflang link for %alternate_langcode: %link.', array(
        '%langcode' => $langcode,
        '%alternate_langcode' => $alternate_langcode,
        '%link' => $url
          ->toString(),
      )));
    }
  }
}