Misleading assertion messages in WebAssert

Created on 27 January 2023, almost 2 years ago
Updated 13 February 2023, almost 2 years ago

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.

📌 Task
Status

Fixed

Version

10.1

Component
PHPUnit 

Last updated about 4 hours ago

Created by

🇬🇧United Kingdom Michelle-Buckby

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024