You are here

protected function LanguageSwitchingTest::doTestLanguageLinkActiveClassAnonymous in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/language/tests/src/Functional/LanguageSwitchingTest.php \Drupal\Tests\language\Functional\LanguageSwitchingTest::doTestLanguageLinkActiveClassAnonymous()
  2. 10 core/modules/language/tests/src/Functional/LanguageSwitchingTest.php \Drupal\Tests\language\Functional\LanguageSwitchingTest::doTestLanguageLinkActiveClassAnonymous()

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

See also

self::testLanguageLinkActiveClass()

1 call to LanguageSwitchingTest::doTestLanguageLinkActiveClassAnonymous()
LanguageSwitchingTest::testLanguageLinkActiveClass in core/modules/language/tests/src/Functional/LanguageSwitchingTest.php
Tests active class on links when switching languages.

File

core/modules/language/tests/src/Functional/LanguageSwitchingTest.php, line 361

Class

LanguageSwitchingTest
Functional tests for the language switching feature.

Namespace

Drupal\Tests\language\Functional

Code

protected function doTestLanguageLinkActiveClassAnonymous() {
  $function_name = '#type link';
  $this
    ->drupalLogout();

  // Test links generated by the link generator on an English page.
  $current_language = 'English';
  $this
    ->drupalGet('language_test/type-link-active-class');

  // Language code 'none' link should be active.
  $this
    ->assertSession()
    ->elementExists('xpath', "//a[@id = 'no_lang_link' and contains(@class, 'is-active')]");

  // Language code 'en' link should be active.
  $this
    ->assertSession()
    ->elementExists('xpath', "//a[@id = 'en_link' and contains(@class, 'is-active')]");

  // Language code 'fr' link should not be active.
  $this
    ->assertSession()
    ->elementExists('xpath', "//a[@id = 'fr_link' and not(contains(@class, 'is-active'))]");

  // Test links generated by the link generator on a French page.
  $current_language = 'French';
  $this
    ->drupalGet('fr/language_test/type-link-active-class');

  // Language code 'none' link should be active.
  $this
    ->assertSession()
    ->elementExists('xpath', "//a[@id = 'no_lang_link' and contains(@class, 'is-active')]");

  // Language code 'en' link should not be active.
  $this
    ->assertSession()
    ->elementExists('xpath', "//a[@id = 'en_link' and not(contains(@class, 'is-active'))]");

  // Language code 'fr' link should be active.
  $this
    ->assertSession()
    ->elementExists('xpath', "//a[@id = 'fr_link' and contains(@class, 'is-active')]");
}