function LocalTasksTest::assertLocalTasks

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php \Drupal\Tests\system\Functional\Menu\LocalTasksTest::assertLocalTasks()
  2. 10 core/modules/system/tests/src/Functional/Menu/LocalTasksTest.php \Drupal\Tests\system\Functional\Menu\LocalTasksTest::assertLocalTasks()
  3. 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.

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\Menu

Code

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}.");
    }
}

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