Commit e562b4e1 authored by larowlan's avatar larowlan

Issue #2860175 by GoZ, Jo Fitzgerald, dawehner, klausi: Add exact option to...

Issue #2860175 by GoZ, Jo Fitzgerald, dawehner, klausi: Add exact option to AssertLegacyTrait::assertLink(), WebAssert::linkExists() and WebAssert::linkNotExists()
parent 69a64406
......@@ -137,6 +137,48 @@ public function testPipeCharInLocator() {
$this->assertSession()->linkExists('foo|bar|baz');
}
/**
* Tests linkExistsExact() functionality.
*
* @see \Drupal\Tests\WebAssert::linkExistsExact()
*/
public function testLinkExistsExact() {
$this->drupalGet('test-pipe-char');
$this->assertSession()->linkExistsExact('foo|bar|baz');
}
/**
* Tests linkExistsExact() functionality fail.
*
* @see \Drupal\Tests\WebAssert::linkExistsExact()
*/
public function testInvalidLinkExistsExact() {
$this->drupalGet('test-pipe-char');
$this->setExpectedException(ExpectationException::class, 'Link with label foo|bar found');
$this->assertSession()->linkExistsExact('foo|bar');
}
/**
* Tests linkNotExistsExact() functionality.
*
* @see \Drupal\Tests\WebAssert::linkNotExistsExact()
*/
public function testLinkNotExistsExact() {
$this->drupalGet('test-pipe-char');
$this->assertSession()->linkNotExistsExact('foo|bar');
}
/**
* Tests linkNotExistsExact() functionality fail.
*
* @see \Drupal\Tests\WebAssert::linkNotExistsExact()
*/
public function testInvalidLinkNotExistsExact() {
$this->drupalGet('test-pipe-char');
$this->setExpectedException(ExpectationException::class, 'Link with label foo|bar|baz not found');
$this->assertSession()->linkNotExistsExact('foo|bar|baz');
}
/**
* Tests legacy text asserts.
*/
......
......@@ -231,6 +231,29 @@ public function linkExists($label, $index = 0, $message = '') {
$this->assert(!empty($links[$index]), $message);
}
/**
* Passes if a link with the exactly specified label is found.
*
* An optional link index may be passed.
*
* @param string $label
* Text between the anchor tags.
* @param int $index
* Link position counting from zero.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use strtr() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
*
* @throws \Behat\Mink\Exception\ExpectationException
* 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]));
$links = $this->session->getPage()->findAll('named_exact', ['link', $label]);
$this->assert(!empty($links[$index]), $message);
}
/**
* Passes if a link with the specified label is not found.
*
......@@ -252,6 +275,27 @@ public function linkNotExists($label, $message = '') {
$this->assert(empty($links), $message);
}
/**
* Passes if a link with the exactly specified label is not found.
*
* An optional link index may be passed.
*
* @param string $label
* Text between the anchor tags.
* @param string $message
* (optional) A message to display with the assertion. Do not translate
* messages: use strtr() to embed variables in the message text, not
* t(). If left blank, a default message will be displayed.
*
* @throws \Behat\Mink\Exception\ExpectationException
* 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]));
$links = $this->session->getPage()->findAll('named_exact', ['link', $label]);
$this->assert(empty($links), $message);
}
/**
* Passes if a link containing a given href (part) is found.
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment