You are here

protected function LocalTasksTest::assertLocalTasks in Drupal 10

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

Code

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