You are here

protected function LocalActionTest::assertLocalAction in Drupal 10

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

Asserts local actions in the page output.

@internal

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 76

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) : void {
  $elements = $this
    ->xpath('//a[contains(@class, :class)]', [
    ':class' => 'button-action',
  ]);
  $index = 0;
  foreach ($actions as $action) {

    /** @var \Drupal\Core\Url $url */
    [
      $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
      ->assertSession()
      ->responseMatches('@<a [^>]*class="[^"]*button-action[^"]*"[^>]*>' . preg_quote($title, '@') . '</@');
    $this
      ->assertEquals($url
      ->toString(), $elements[$index]
      ->getAttribute('href'));
    $index++;
  }
}