function LocalTasksTest::assertLocalTasks
Same name in other branches
- 8.9.x core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php \Drupal\Tests\system\Functional\Menu\LocalTasksTest::assertLocalTasks()
- 10 core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php \Drupal\Tests\system\Functional\Menu\LocalTasksTest::assertLocalTasks()
- 11.x core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php \Drupal\Tests\system\Functional\Menu\LocalTasksTest::assertLocalTasks()
Asserts local tasks in the page output.
@internal
Parameters
array $routes: A list of expected local tasks, prepared as an array of route names and their associated route parameters, to assert on the page (in the given order).
int $level: (optional) The local tasks level to assert; 0 for primary, 1 for secondary. Defaults to 0.
3 calls to LocalTasksTest::assertLocalTasks()
- LocalTasksTest::testLocalTaskBlock in core/
modules/ system/ tests/ src/ Functional/ Menu/ LocalTasksTest.php - Tests that local task blocks are configurable to show a specific level.
- LocalTasksTest::testLocalTaskBlockCache in core/
modules/ system/ tests/ src/ Functional/ Menu/ LocalTasksTest.php - Tests that local tasks blocks cache is invalidated correctly.
- LocalTasksTest::testPluginLocalTask in core/
modules/ system/ tests/ src/ Functional/ Menu/ LocalTasksTest.php - Tests the plugin based local tasks.
File
-
core/
modules/ system/ tests/ src/ Functional/ Menu/ LocalTasksTest.php, line 57
Class
- LocalTasksTest
- Tests local tasks derived from router and added/altered via hooks.
Namespace
Drupal\Tests\system\Functional\MenuCode
protected function assertLocalTasks(array $routes, int $level = 0) : void {
$elements = $this->xpath('//*[contains(@class, :class)]//a', [
':class' => $level == 0 ? 'tabs primary' : 'tabs secondary',
]);
$this->assertGreaterThan(0, count($elements), 'Local tasks found.');
foreach ($routes as $index => $route_info) {
[
$route_name,
$route_parameters,
] = $route_info;
$expected = Url::fromRoute($route_name, $route_parameters)->toString();
$this->assertEquals($expected, $elements[$index]->getAttribute('href'), "Task " . ($index + 1) . "number href " . $elements[$index]->getAttribute('href') . " equals {$expected}.");
}
$this->assertEquals(count($routes), count($elements), 'Only expected local tasks are found.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.