public function LanguageSwitchingTest::testLanguageBodyClass in Drupal 9
Same name and namespace in other branches
- 8 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 262
Class
- LanguageSwitchingTest
- Functional tests for the language switching feature.
Namespace
Drupal\Tests\language\FunctionalCode
public function testLanguageBodyClass() {
$searched_class = 'path-admin';
// 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');
$class = $this
->xpath('//body[contains(@class, :class)]', [
':class' => $searched_class,
]);
$this
->assertTrue(isset($class[0]), '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]), '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');
}