function NavigationTopBarTest::testTopBarPluginWeights
Tests the plugin weights in the top bar.
File
-
core/
modules/ navigation/ tests/ src/ Functional/ NavigationTopBarTest.php, line 168
Class
- NavigationTopBarTest
- Tests the top bar functionality.
Namespace
Drupal\Tests\navigation\FunctionalCode
public function testTopBarPluginWeights() : void {
$this->drupalGet($this->node
->toUrl());
// Select only the test plugins by their known data-plugin-id attributes.
$selectors = [
'[data-plugin-id="test_item_low"]',
'[data-plugin-id="test_item_zero"]',
'[data-plugin-id="test_item_high"]',
];
$elements = [];
foreach ($selectors as $selector) {
$element = $this->getSession()
->getPage()
->find('css', $selector);
if ($element) {
$elements[] = $element;
}
}
// Capture text values in the order they appear in the DOM.
$labels = array_map(fn($element) => trim($element->getText()), $elements);
// Expected order based on weights: low (-10), zero (0), high (10).
$expected = [
'Low Weight',
'Zero Weight',
'High Weight',
];
$this->assertSame($expected, $labels, 'Top bar test plugins are rendered in the correct order.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.