Change record status: 
Project: 
Introduced in branch: 
10.1.x
Introduced in version: 
10.1.5
Description: 

Previously there was no API for asserting that a link exists or does note exist based on exactly matching the href of the link.

\Drupal\Tests\WebAssert::linkByHrefExistsExactand \Drupal\Tests\WebAssert::linkByHrefNotExistsExact have been added to match an href exactly.

Examples

Both methods can be used to match a links href exactly.
$this->assertSession()->linkByHrefExistsExact('admin/structure/block');

$this->assertSession()->linkByHrefNotExistsExact('admin/structure/block/list/' . $default_theme);

Impacts: 
Module developers

Comments

andyf’s picture

To get this working on GitLab CI, which runs tests in a subdirectory, I used the following:

$this->assertSession()->linkByHrefExistsExact(Url::fromUserInput('/admin/structure/block')->toString());