You are here

protected function LocalActionTest::assertLocalAction in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/src/Functional/Menu/LocalActionTest.php \Drupal\Tests\system\Functional\Menu\LocalActionTest::assertLocalAction()
  2. 10 core/modules/system/tests/src/Functional/Menu/LocalActionTest.php \Drupal\Tests\system\Functional\Menu\LocalActionTest::assertLocalAction()

Asserts local actions in the page output.

Parameters

array $actions: A list of expected action link titles, keyed by the hrefs.

1 call to LocalActionTest::assertLocalAction()
LocalActionTest::testLocalAction in core/modules/system/tests/src/Functional/Menu/LocalActionTest.php
Tests appearance of local actions.

File

core/modules/system/tests/src/Functional/Menu/LocalActionTest.php, line 75

Class

LocalActionTest
Tests local actions derived from router and added/altered via hooks.

Namespace

Drupal\Tests\system\Functional\Menu

Code

protected function assertLocalAction(array $actions) {
  $elements = $this
    ->xpath('//a[contains(@class, :class)]', [
    ':class' => 'button-action',
  ]);
  $index = 0;
  foreach ($actions as $action) {

    /** @var \Drupal\Core\Url $url */
    list($url, $title) = $action;

    // SimpleXML gives us the unescaped text, not the actual escaped markup,
    // so use a pattern instead to check the raw content.
    // This behavior is a bug in libxml, see
    // https://bugs.php.net/bug.php?id=49437.
    $this
      ->assertPattern('@<a [^>]*class="[^"]*button-action[^"]*"[^>]*>' . preg_quote($title, '@') . '</@');
    $this
      ->assertEqual($elements[$index]
      ->getAttribute('href'), $url
      ->toString());
    $index++;
  }
}