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]));
    …
  }

( https://git.drupalcode.org/project/drupal/-/blob/8.2.7/core/tests/Drupal/Tests/WebAssert.php#L255-297 )

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.

Comments

Michelle-Buckby created an issue. See original summary.

andy_w’s picture

Status: Active » Needs review
StatusFileSize
new4.71 KB

Really 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).

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Seems like a good message cleanup task.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 5540535 and pushed to 10.1.x. Thanks!

  • catch committed 55405352 on 10.1.x
    Issue #3336981 by Michelle-Buckby, andy_w: Misleading assertion messages...
catch’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.