function NavigationMenuBlockTest::testHtmlMarkup
Same name in other branches
- 10 core/modules/navigation/tests/src/Kernel/NavigationMenuBlockTest.php \Drupal\Tests\navigation\Kernel\NavigationMenuBlockTest::testHtmlMarkup()
Tests the generated HTML markup.
File
-
core/
modules/ navigation/ tests/ src/ Kernel/ NavigationMenuBlockTest.php, line 319
Class
Namespace
Drupal\Tests\navigation\KernelCode
public function testHtmlMarkup() {
$block = $this->blockManager
->createInstance('navigation_menu:' . $this->menu
->id(), [
'region' => 'content',
'id' => 'machine_name',
'level' => 1,
'depth' => NavigationMenuBlock::NAVIGATION_MAX_DEPTH - 1,
]);
$block_build = $block->build();
$render = \Drupal::service('renderer')->renderRoot($block_build);
$dom = new \DOMDocument();
$dom->loadHTML((string) $render);
$xpath = new \DOMXPath($dom);
$items_query = [
"//li[contains(@class,'toolbar-block__list-item')]/span/span[text()='title 1']",
"//li[contains(@class,'toolbar-block__list-item')]/button/span[text()='title 2']",
"//li[contains(@class,'toolbar-menu__item--level-1')]/button/span[text()='title 3']",
"//li[contains(@class,'toolbar-menu__item--level-2')]/a[text()='title 4']",
"//li[contains(@class,'toolbar-block__list-item')]/button/span[text()='title 5']",
"//li[contains(@class,'toolbar-block__list-item')]/a/span[text()='title 6']",
"//li[contains(@class,'toolbar-block__list-item')]/a[contains(@class, 'external-link')]",
"//li[contains(@class,'toolbar-block__list-item')]/a[contains(@class, 'external-link')]",
"//li[contains(@class,'toolbar-block__list-item')]/a[@target='_blank']",
"//li[contains(@class,'toolbar-menu__item--level-1')]/button/span[text()='title 7']",
"//li[contains(@class,'toolbar-block__list-item')]/button/span[text()='title 8']",
"//li[contains(@class,'toolbar-menu__item--level-2')]/span[text()='title 10']",
"//li[contains(@class,'toolbar-menu__item--level-1')]/button/span[text()='title 11']",
"//li[contains(@class,'toolbar-menu__item--level-2')]/button[text()='title 12']",
];
foreach ($items_query as $query) {
$span = $xpath->query($query);
$this->assertEquals(1, $span->length, $query);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.