protected function LocalTasksTest::assertLocalTasks

Asserts local tasks in the page output.

Parameters

array $hrefs: A list of expected link hrefs of local tasks 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.

1 call to LocalTasksTest::assertLocalTasks()
LocalTasksTest::testLocalTasks in drupal/core/modules/system/lib/Drupal/system/Tests/Menu/LocalTasksTest.php
Tests appearance of local tasks.

File

drupal/core/modules/system/lib/Drupal/system/Tests/Menu/LocalTasksTest.php, line 127
Contains Drupal\system\Tests\Menu\LocalTasksTest.

Class

LocalTasksTest
Tests local tasks derived from router and added/altered via hooks.

Namespace

Drupal\system\Tests\Menu

Code

protected function assertLocalTasks(array $hrefs, $level = 0) {
  $elements = $this
    ->xpath('//*[contains(@class, :class)]//a', array(
    ':class' => $level == 0 ? 'tabs primary' : 'tabs secondary',
  ));
  $this
    ->assertTrue(count($elements), 'Local tasks found.');
  foreach ($hrefs as $index => $element) {
    $expected = url($hrefs[$index]);
    $method = $elements[$index]['href'] == $expected ? 'pass' : 'fail';
    $this
      ->{$method}(format_string('Task @number href @value equals @expected.', array(
      '@number' => $index + 1,
      '@value' => (string) $elements[$index]['href'],
      '@expected' => $expected,
    )));
  }
}