You are here

protected function LanguageSwitchingTest::doTestLanguageBlockAnonymous in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/language/src/Tests/LanguageSwitchingTest.php \Drupal\language\Tests\LanguageSwitchingTest::doTestLanguageBlockAnonymous()

For anonymous users, the "active" class is set by PHP.

Parameters

string $block_label: The label of the language switching block.

See also

testLanguageBlock()

1 call to LanguageSwitchingTest::doTestLanguageBlockAnonymous()
LanguageSwitchingTest::testLanguageBlock in core/modules/language/src/Tests/LanguageSwitchingTest.php
Functional tests for the language switcher block.

File

core/modules/language/src/Tests/LanguageSwitchingTest.php, line 123
Contains \Drupal\language\Tests\LanguageSwitchingTest.

Class

LanguageSwitchingTest
Functional tests for the language switching feature.

Namespace

Drupal\language\Tests

Code

protected function doTestLanguageBlockAnonymous($block_label) {
  $this
    ->drupalLogout();

  // Assert that the language switching block is displayed on the frontpage.
  $this
    ->drupalGet('');
  $this
    ->assertText($block_label, 'Language switcher block found.');

  // Assert that only the current language is marked as active.
  list($language_switcher) = $this
    ->xpath('//div[@id=:id]', array(
    ':id' => 'block-test-language-block',
  ));
  $links = array(
    'active' => array(),
    'inactive' => array(),
  );
  $anchors = array(
    'active' => array(),
    'inactive' => array(),
  );
  $labels = array();
  foreach ($language_switcher->ul->li as $link) {
    $classes = explode(" ", (string) $link['class']);
    list($langcode) = array_intersect($classes, array(
      'en',
      'fr',
    ));
    if (in_array('is-active', $classes)) {
      $links['active'][] = $langcode;
    }
    else {
      $links['inactive'][] = $langcode;
    }
    $anchor_classes = explode(" ", (string) $link->a['class']);
    if (in_array('is-active', $anchor_classes)) {
      $anchors['active'][] = $langcode;
    }
    else {
      $anchors['inactive'][] = $langcode;
    }
    $labels[] = (string) $link->a;
  }
  $this
    ->assertIdentical($links, array(
    'active' => array(
      'en',
    ),
    'inactive' => array(
      'fr',
    ),
  ), 'Only the current language list item is marked as active on the language switcher block.');
  $this
    ->assertIdentical($anchors, array(
    'active' => array(
      'en',
    ),
    'inactive' => array(
      'fr',
    ),
  ), 'Only the current language anchor is marked as active on the language switcher block.');
  $this
    ->assertIdentical($labels, array(
    'English',
    'français',
  ), 'The language links labels are in their own language on the language switcher block.');
}