Problem/Motivation
Currently the linkByHrefExists, linkExists and linkExistsExact assertions in WebAssert display misleading messages. The message parameter determines the exception to be thrown when the condition is not met.
It looks like these methods were created in Drupal 8.2, as duplicates of each other (linkByHrefExists and linkByHrefNotExists) with both containing the same message (“Link containing href %href found.“), and then subsequently one was changed in error.
public function linkByHrefExists($href, $index = 0, $message = '') {
…
$message = ($message ? $message : strtr('Link containing href %href found.', ['%href' => $href]));
…
}
public function linkByHrefNotExists($href, $message = '') {
…
$message = ($message ? $message : strtr('Link containing href %href found.', ['%href' => $href]));
…
}
Proposed resolution
I have attached a patch to resolve this issue within the WebAssert method, however this issue is also replicated throughout the Drupal codebase as others have mirrored this misleading message.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 3336981-web-assert-link-href-found-error-message.patch | 4.71 KB | andy_w |
| web-assert-link-href-found-error-message.patch | 3.59 KB | michelle-buckby |
Comments
Comment #2
andy_w commentedReally impressive find, but as you mentioned it does seem to be throughout the drupal core codebase. Including the tests themselves. So I've added the update to the the tests in BrowserTestBaseTest (which failed above).
Comment #3
smustgrave commentedSeems like a good message cleanup task.
Comment #4
catchCommitted 5540535 and pushed to 10.1.x. Thanks!
Comment #6
catch