function LanguageSwitchingTest::doTestLanguageBlock404
Same name in other branches
- 10 core/modules/language/tests/src/Functional/LanguageSwitchingTest.php \Drupal\Tests\language\Functional\LanguageSwitchingTest::doTestLanguageBlock404()
- 11.x core/modules/language/tests/src/Functional/LanguageSwitchingTest.php \Drupal\Tests\language\Functional\LanguageSwitchingTest::doTestLanguageBlock404()
Tests the language switcher block on 404 pages.
Parameters
string $block_label: The label of the language switching block.
string $system_path: The expected system path for the links in the language switcher.
See also
1 call to LanguageSwitchingTest::doTestLanguageBlock404()
- LanguageSwitchingTest::testLanguageBlock in core/
modules/ language/ tests/ src/ Functional/ LanguageSwitchingTest.php - Functional tests for the language switcher block.
File
-
core/
modules/ language/ tests/ src/ Functional/ LanguageSwitchingTest.php, line 209
Class
- LanguageSwitchingTest
- Functional tests for the language switching feature.
Namespace
Drupal\Tests\language\FunctionalCode
protected function doTestLanguageBlock404(string $block_label, string $system_path) {
$this->drupalGet('does-not-exist-' . $this->randomMachineName());
$this->assertSession()
->pageTextContains($block_label);
// Assert that each list item and anchor element has the appropriate data-
// attributes.
$language_switchers = $this->xpath('//div[@id=:id]/ul/li', [
':id' => 'block-test-language-block',
]);
$list_items = [];
$anchors = [];
$labels = [];
foreach ($language_switchers as $list_item) {
$list_items[] = [
'hreflang' => $list_item->getAttribute('hreflang'),
'data-drupal-link-system-path' => $list_item->getAttribute('data-drupal-link-system-path'),
];
$link = $list_item->find('xpath', 'a');
$anchors[] = [
'hreflang' => $link->getAttribute('hreflang'),
'data-drupal-link-system-path' => $link->getAttribute('data-drupal-link-system-path'),
];
$labels[] = $link->getText();
}
$expected_list_items = [
0 => [
'hreflang' => 'en',
'data-drupal-link-system-path' => $system_path,
],
1 => [
'hreflang' => 'fr',
'data-drupal-link-system-path' => $system_path,
],
];
$this->assertSame($expected_list_items, $list_items, 'The list items have the correct attributes that will allow the drupal.active-link library to mark them as active.');
$expected_anchors = [
0 => [
'hreflang' => 'en',
'data-drupal-link-system-path' => $system_path,
],
1 => [
'hreflang' => 'fr',
'data-drupal-link-system-path' => $system_path,
],
];
$this->assertSame($expected_anchors, $anchors, 'The anchors have the correct attributes that will allow the drupal.active-link library to mark them as active.');
$this->assertSame([
'English',
'français',
], $labels, 'The language links labels are in their own language on the language switcher block.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.