function LocalActionTest::assertLocalAction

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Menu/LocalActionTest.php \Drupal\Tests\system\Functional\Menu\LocalActionTest::assertLocalAction()
  2. 8.9.x core/modules/system/tests/src/Functional/Menu/LocalActionTest.php \Drupal\Tests\system\Functional\Menu\LocalActionTest::assertLocalAction()
  3. 11.x 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++;
    }
}

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