function LanguageSwitchingTest::testLanguageBodyClass

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

Check the path-admin class, as same as on default language.

File

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

Class

LanguageSwitchingTest
Functional tests for the language switching feature.

Namespace

Drupal\Tests\language\Functional

Code

public function testLanguageBodyClass() {
    // Add language.
    $edit = [
        'predefined_langcode' => 'fr',
    ];
    $this->drupalGet('admin/config/regional/language/add');
    $this->submitForm($edit, 'Add language');
    // Enable URL language detection and selection.
    $edit = [
        'language_interface[enabled][language-url]' => '1',
    ];
    $this->drupalGet('admin/config/regional/language/detection');
    $this->submitForm($edit, 'Save settings');
    // Check if the default (English) admin/config page has the right class.
    $this->drupalGet('admin/config');
    $this->assertSession()
        ->elementAttributeContains('xpath', '//body', 'class', 'path-admin');
    // Check if the French admin/config page has the right class.
    $this->drupalGet('fr/admin/config');
    $this->assertSession()
        ->elementAttributeContains('xpath', '//body', 'class', 'path-admin');
    // The testing profile sets the user/login page as the frontpage. That
    // redirects authenticated users to their profile page, so check with an
    // anonymous user instead.
    $this->drupalLogout();
    // Check if the default (English) frontpage has the right class.
    $this->drupalGet('<front>');
    $this->assertSession()
        ->elementAttributeContains('xpath', '//body', 'class', 'path-frontpage');
    // Check if the French frontpage has the right class.
    $this->drupalGet('fr');
    $this->assertSession()
        ->elementAttributeContains('xpath', '//body', 'class', 'path-frontpage');
}

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