You are here

protected function LanguageSwitchingTest::doTestLanguageBlockAuthenticated 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::doTestLanguageBlockAuthenticated()

For authenticated users, the "active" class is set by JavaScript.

Parameters

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

See also

testLanguageBlock()

1 call to LanguageSwitchingTest::doTestLanguageBlockAuthenticated()
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 74
Contains \Drupal\language\Tests\LanguageSwitchingTest.

Class

LanguageSwitchingTest
Functional tests for the language switching feature.

Namespace

Drupal\language\Tests

Code

protected function doTestLanguageBlockAuthenticated($block_label) {

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

  // Assert that each list item and anchor element has the appropriate data-
  // attributes.
  list($language_switcher) = $this
    ->xpath('//div[@id=:id]', array(
    ':id' => 'block-test-language-block',
  ));
  $list_items = array();
  $anchors = array();
  $labels = array();
  foreach ($language_switcher->ul->li as $list_item) {
    $classes = explode(" ", (string) $list_item['class']);
    list($langcode) = array_intersect($classes, array(
      'en',
      'fr',
    ));
    $list_items[] = array(
      'langcode_class' => $langcode,
      'data-drupal-link-system-path' => (string) $list_item['data-drupal-link-system-path'],
    );
    $anchors[] = array(
      'hreflang' => (string) $list_item->a['hreflang'],
      'data-drupal-link-system-path' => (string) $list_item->a['data-drupal-link-system-path'],
    );
    $labels[] = (string) $list_item->a;
  }
  $expected_list_items = array(
    0 => array(
      'langcode_class' => 'en',
      'data-drupal-link-system-path' => 'user/2',
    ),
    1 => array(
      'langcode_class' => 'fr',
      'data-drupal-link-system-path' => 'user/2',
    ),
  );
  $this
    ->assertIdentical($list_items, $expected_list_items, 'The list items have the correct attributes that will allow the drupal.active-link library to mark them as active.');
  $expected_anchors = array(
    0 => array(
      'hreflang' => 'en',
      'data-drupal-link-system-path' => 'user/2',
    ),
    1 => array(
      'hreflang' => 'fr',
      'data-drupal-link-system-path' => 'user/2',
    ),
  );
  $this
    ->assertIdentical($anchors, $expected_anchors, 'The anchors have the correct attributes that will allow the drupal.active-link library to mark them as active.');
  $settings = $this
    ->getDrupalSettings();
  $this
    ->assertIdentical($settings['path']['currentPath'], 'user/2', 'drupalSettings.path.currentPath is set correctly to allow drupal.active-link to mark the correct links as active.');
  $this
    ->assertIdentical($settings['path']['isFront'], FALSE, 'drupalSettings.path.isFront is set correctly to allow drupal.active-link to mark the correct links as active.');
  $this
    ->assertIdentical($settings['path']['currentLanguage'], 'en', 'drupalSettings.path.currentLanguage is set correctly to allow drupal.active-link to mark the correct links as active.');
  $this
    ->assertIdentical($labels, array(
    'English',
    'français',
  ), 'The language links labels are in their own language on the language switcher block.');
}