You are here

public function WebAssert::elementTextEquals in Drupal 10

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/WebAssert.php \Drupal\Tests\WebAssert::elementTextEquals()

Asserts a specific element's text equals an expected text.

Parameters

string $selectorType: Element selector type (css, xpath).

string|array $selector: Element selector.

string $text: Expected text.

File

core/tests/Drupal/Tests/WebAssert.php, line 913

Class

WebAssert
Defines a class with methods for asserting presence of elements during tests.

Namespace

Drupal\Tests

Code

public function elementTextEquals(string $selectorType, $selector, string $text) : void {
  $selector_string = is_array($selector) ? '[' . implode(', ', $selector) . ']' : $selector;
  $message = "Failed asserting that the text of the element identified by '{$selector_string}' equals '{$text}'.";
  $constraint = new IsEqual($text);
  Assert::assertThat($this
    ->elementExists($selectorType, $selector)
    ->getText(), $constraint, $message);
}