function LanguageSwitchingTest::testLanguageBodyClass

Same name and namespace in other branches
  1. 9 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 263

Class

LanguageSwitchingTest
Functional tests for the language switching feature.

Namespace

Drupal\Tests\language\Functional

Code

public function testLanguageBodyClass() {
    $searched_class = 'path-admin';
    // Add language.
    $edit = [
        'predefined_langcode' => 'fr',
    ];
    $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));
    // Enable URL language detection and selection.
    $edit = [
        'language_interface[enabled][language-url]' => '1',
    ];
    $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
    // Check if the default (English) admin/config page has the right class.
    $this->drupalGet('admin/config');
    $class = $this->xpath('//body[contains(@class, :class)]', [
        ':class' => $searched_class,
    ]);
    $this->assertTrue(isset($class[0]), t('The path-admin class appears on default language.'));
    // Check if the French admin/config page has the right class.
    $this->drupalGet('fr/admin/config');
    $class = $this->xpath('//body[contains(@class, :class)]', [
        ':class' => $searched_class,
    ]);
    $this->assertTrue(isset($class[0]), t('The path-admin class same as on default language.'));
    // 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>');
    $class = $this->xpath('//body[contains(@class, :class)]', [
        ':class' => 'path-frontpage',
    ]);
    $this->assertTrue(isset($class[0]), 'path-frontpage class found on the body tag');
    // Check if the French frontpage has the right class.
    $this->drupalGet('fr');
    $class = $this->xpath('//body[contains(@class, :class)]', [
        ':class' => 'path-frontpage',
    ]);
    $this->assertTrue(isset($class[0]), 'path-frontpage class found on the body tag with french as the active language');
}

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