function LanguageSwitchingTest::doTestLanguageLinkActiveClassAuthenticated

Same name and namespace in other branches
  1. 8.9.x core/modules/language/tests/src/Functional/LanguageSwitchingTest.php \Drupal\Tests\language\Functional\LanguageSwitchingTest::doTestLanguageLinkActiveClassAuthenticated()
  2. 10 core/modules/language/tests/src/Functional/LanguageSwitchingTest.php \Drupal\Tests\language\Functional\LanguageSwitchingTest::doTestLanguageLinkActiveClassAuthenticated()
  3. 11.x core/modules/language/tests/src/Functional/LanguageSwitchingTest.php \Drupal\Tests\language\Functional\LanguageSwitchingTest::doTestLanguageLinkActiveClassAuthenticated()

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

See also

self::testLanguageLinkActiveClass()

1 call to LanguageSwitchingTest::doTestLanguageLinkActiveClassAuthenticated()
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 365

Class

LanguageSwitchingTest
Functional tests for the language switching feature.

Namespace

Drupal\Tests\language\Functional

Code

protected function doTestLanguageLinkActiveClassAuthenticated() {
    $function_name = '#type link';
    $path = 'language_test/type-link-active-class';
    // Test links generated by the link generator on an English page.
    $current_language = 'English';
    $this->drupalGet($path);
    // Language code 'none' link should be active.
    $this->assertSession()
        ->elementAttributeContains('named', [
        'id',
        'no_lang_link',
    ], 'data-drupal-link-system-path', $path);
    // Language code 'en' link should be active.
    $this->assertSession()
        ->elementAttributeContains('named', [
        'id',
        'en_link',
    ], 'hreflang', 'en');
    $this->assertSession()
        ->elementAttributeContains('named', [
        'id',
        'en_link',
    ], 'data-drupal-link-system-path', $path);
    // Language code 'fr' link should not be active.
    $this->assertSession()
        ->elementAttributeContains('named', [
        'id',
        'fr_link',
    ], 'hreflang', 'fr');
    $this->assertSession()
        ->elementAttributeContains('named', [
        'id',
        'fr_link',
    ], 'data-drupal-link-system-path', $path);
    // Verify that drupalSettings contains the correct values.
    $settings = $this->getDrupalSettings();
    $this->assertSame($path, $settings['path']['currentPath'], 'drupalSettings.path.currentPath is set correctly to allow drupal.active-link to mark the correct links as active.');
    $this->assertFalse($settings['path']['isFront'], 'drupalSettings.path.isFront is set correctly to allow drupal.active-link to mark the correct links as active.');
    $this->assertSame('en', $settings['path']['currentLanguage'], 'drupalSettings.path.currentLanguage is set correctly to allow drupal.active-link to mark the correct links as 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()
        ->elementAttributeContains('named', [
        'id',
        'no_lang_link',
    ], 'data-drupal-link-system-path', $path);
    // Language code 'en' link should not be active.
    $this->assertSession()
        ->elementAttributeContains('named', [
        'id',
        'en_link',
    ], 'hreflang', 'en');
    $this->assertSession()
        ->elementAttributeContains('named', [
        'id',
        'en_link',
    ], 'data-drupal-link-system-path', $path);
    // Language code 'fr' link should be active.
    $this->assertSession()
        ->elementAttributeContains('named', [
        'id',
        'fr_link',
    ], 'hreflang', 'fr');
    $this->assertSession()
        ->elementAttributeContains('named', [
        'id',
        'fr_link',
    ], 'data-drupal-link-system-path', $path);
    // Verify that drupalSettings contains the correct values.
    $settings = $this->getDrupalSettings();
    $this->assertSame($path, $settings['path']['currentPath'], 'drupalSettings.path.currentPath is set correctly to allow drupal.active-link to mark the correct links as active.');
    $this->assertFalse($settings['path']['isFront'], 'drupalSettings.path.isFront is set correctly to allow drupal.active-link to mark the correct links as active.');
    $this->assertSame('fr', $settings['path']['currentLanguage'], 'drupalSettings.path.currentLanguage is set correctly to allow drupal.active-link to mark the correct links as active.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.