function NavigationMenuMarkupTest::testToolbarButtonAttributes

Same name in other branches
  1. 10 core/modules/navigation/tests/src/Kernel/NavigationMenuMarkupTest.php \Drupal\Tests\navigation\Kernel\NavigationMenuMarkupTest::testToolbarButtonAttributes()

Tests the generated HTML markup.

File

core/modules/navigation/tests/src/Kernel/NavigationMenuMarkupTest.php, line 132

Class

NavigationMenuMarkupTest
Tests \Drupal\navigation\Plugin\Block\NavigationMenuBlock.

Namespace

Drupal\Tests\navigation\Kernel

Code

public function testToolbarButtonAttributes() : void {
    $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')]/a[@data-index-text='t']",
        "//li[contains(@class,'toolbar-block__list-item')]/a[@data-icon-text='ti']",
        "//li[contains(@class,'toolbar-block__list-item')]/button[@data-index-text='a']",
        "//li[contains(@class,'toolbar-block__list-item')]/button[@data-icon-text='An']",
        "//li[contains(@class,'toolbar-menu__item--level-1')]/a[@data-index-text='n']",
        "//li[contains(@class,'toolbar-menu__item--level-1')]/a[@data-icon-text='Ne']",
    ];
    foreach ($items_query as $query) {
        $element = $xpath->query($query);
        $this->assertEquals(1, $element->length, $query);
    }
}

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