protected function LocalTasksTest::assertLocalTasks in Drupal 8
Same name and namespace in other branches
- 9 core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php \Drupal\Tests\system\Functional\Menu\LocalTasksTest::assertLocalTasks()
Asserts local tasks in the page output.
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 - Test 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 55
Class
- LocalTasksTest
- Tests local tasks derived from router and added/altered via hooks.
Namespace
Drupal\Tests\system\Functional\MenuCode
protected function assertLocalTasks(array $routes, $level = 0) {
$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) {
list($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}.");
}
}