Issue #3336981 by Michelle-Buckby, andy_w: Misleading assertion messages in WebAssert

merge-requests/3144/merge
catch 2023-02-13 13:28:28 +00:00
parent 7c4733bdc8
commit 55405352cb
2 changed files with 8 additions and 8 deletions

View File

@ -221,7 +221,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
public function testInvalidLinkExistsExact() {
$this->drupalGet('test-pipe-char');
$this->expectException(ExpectationException::class);
$this->expectExceptionMessage('Link with label foo|bar found');
$this->expectExceptionMessage('Link with label foo|bar not found');
$this->assertSession()->linkExistsExact('foo|bar');
}
@ -253,7 +253,7 @@ class BrowserTestBaseTest extends BrowserTestBase {
public function testInvalidLinkNotExistsExact() {
$this->drupalGet('test-pipe-char');
$this->expectException(ExpectationException::class);
$this->expectExceptionMessage('Link with label foo|bar|baz not found');
$this->expectExceptionMessage('Link with label foo|bar|baz found');
$this->assertSession()->linkNotExistsExact('foo|bar|baz');
}

View File

@ -294,7 +294,7 @@ class WebAssert extends MinkWebAssert {
* Thrown when element doesn't exist, or the link label is a different one.
*/
public function linkExists($label, $index = 0, $message = '') {
$message = ($message ? $message : strtr('Link with label %label found.', ['%label' => $label]));
$message = ($message ? $message : strtr('Link with label %label not found.', ['%label' => $label]));
$links = $this->session->getPage()->findAll('named', ['link', $label]);
$this->assert(!empty($links[$index]), $message);
}
@ -317,7 +317,7 @@ class WebAssert extends MinkWebAssert {
* Thrown when element doesn't exist, or the link label is a different one.
*/
public function linkExistsExact($label, $index = 0, $message = '') {
$message = ($message ? $message : strtr('Link with label %label found.', ['%label' => $label]));
$message = ($message ? $message : strtr('Link with label %label not found.', ['%label' => $label]));
$links = $this->session->getPage()->findAll('named_exact', ['link', $label]);
$this->assert(!empty($links[$index]), $message);
}
@ -338,7 +338,7 @@ class WebAssert extends MinkWebAssert {
* Thrown when element doesn't exist, or the link label is a different one.
*/
public function linkNotExists($label, $message = '') {
$message = ($message ? $message : strtr('Link with label %label not found.', ['%label' => $label]));
$message = ($message ? $message : strtr('Link with label %label found.', ['%label' => $label]));
$links = $this->session->getPage()->findAll('named', ['link', $label]);
$this->assert(empty($links), $message);
}
@ -359,7 +359,7 @@ class WebAssert extends MinkWebAssert {
* Thrown when element doesn't exist, or the link label is a different one.
*/
public function linkNotExistsExact($label, $message = '') {
$message = ($message ? $message : strtr('Link with label %label not found.', ['%label' => $label]));
$message = ($message ? $message : strtr('Link with label %label found.', ['%label' => $label]));
$links = $this->session->getPage()->findAll('named_exact', ['link', $label]);
$this->assert(empty($links), $message);
}
@ -382,7 +382,7 @@ class WebAssert extends MinkWebAssert {
*/
public function linkByHrefExists($href, $index = 0, $message = '') {
$xpath = $this->buildXPathQuery('//a[contains(@href, :href)]', [':href' => $href]);
$message = ($message ? $message : strtr('Link containing href %href found.', ['%href' => $href]));
$message = ($message ? $message : strtr('No link containing href %href found.', ['%href' => $href]));
$links = $this->session->getPage()->findAll('xpath', $xpath);
$this->assert(!empty($links[$index]), $message);
}
@ -403,7 +403,7 @@ class WebAssert extends MinkWebAssert {
*/
public function linkByHrefNotExists($href, $message = '') {
$xpath = $this->buildXPathQuery('//a[contains(@href, :href)]', [':href' => $href]);
$message = ($message ? $message : strtr('No link containing href %href found.', ['%href' => $href]));
$message = ($message ? $message : strtr('Link containing href %href found.', ['%href' => $href]));
$links = $this->session->getPage()->findAll('xpath', $xpath);
$this->assert(empty($links), $message);
}