function LanguageSwitchingTest::doTestLanguageLinkActiveClassAnonymous
Same name in other branches
- 9 core/modules/language/tests/src/Functional/LanguageSwitchingTest.php \Drupal\Tests\language\Functional\LanguageSwitchingTest::doTestLanguageLinkActiveClassAnonymous()
- 10 core/modules/language/tests/src/Functional/LanguageSwitchingTest.php \Drupal\Tests\language\Functional\LanguageSwitchingTest::doTestLanguageLinkActiveClassAnonymous()
- 11.x 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 - Test active class on links when switching languages.
File
-
core/
modules/ language/ tests/ src/ Functional/ LanguageSwitchingTest.php, line 368
Class
- LanguageSwitchingTest
- Functional tests for the language switching feature.
Namespace
Drupal\Tests\language\FunctionalCode
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.
$langcode = 'none';
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', [
':id' => 'no_lang_link',
':class' => 'is-active',
]);
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is marked active.', [
':function' => $function_name,
':language' => $current_language,
':langcode' => $langcode,
]));
// Language code 'en' link should be active.
$langcode = 'en';
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', [
':id' => 'en_link',
':class' => 'is-active',
]);
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is marked active.', [
':function' => $function_name,
':language' => $current_language,
':langcode' => $langcode,
]));
// Language code 'fr' link should not be active.
$langcode = 'fr';
$links = $this->xpath('//a[@id = :id and not(contains(@class, :class))]', [
':id' => 'fr_link',
':class' => 'is-active',
]);
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is NOT marked active.', [
':function' => $function_name,
':language' => $current_language,
':langcode' => $langcode,
]));
// 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.
$langcode = 'none';
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', [
':id' => 'no_lang_link',
':class' => 'is-active',
]);
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is marked active.', [
':function' => $function_name,
':language' => $current_language,
':langcode' => $langcode,
]));
// Language code 'en' link should not be active.
$langcode = 'en';
$links = $this->xpath('//a[@id = :id and not(contains(@class, :class))]', [
':id' => 'en_link',
':class' => 'is-active',
]);
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is NOT marked active.', [
':function' => $function_name,
':language' => $current_language,
':langcode' => $langcode,
]));
// Language code 'fr' link should be active.
$langcode = 'fr';
$links = $this->xpath('//a[@id = :id and contains(@class, :class)]', [
':id' => 'fr_link',
':class' => 'is-active',
]);
$this->assertTrue(isset($links[0]), t('A link generated by :function to the current :language page with langcode :langcode is marked active.', [
':function' => $function_name,
':language' => $current_language,
':langcode' => $langcode,
]));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.