public function WebAssert::pageTextMatchesCount in Drupal 9
Asserts that the current page text matches regex a number of times.
Parameters
int $count: The number of times the pattern is expected to be present.
string $regex: The regex pattern.
string $message: (Optional) the failure message.
1 call to WebAssert::pageTextMatchesCount()
- WebAssert::pageTextContainsOnce in core/
tests/ Drupal/ Tests/ WebAssert.php - Checks that current page contains text only once.
File
- core/
tests/ Drupal/ Tests/ WebAssert.php, line 116
Class
- WebAssert
- Defines a class with methods for asserting presence of elements during tests.
Namespace
Drupal\TestsCode
public function pageTextMatchesCount(int $count, string $regex, string $message = '') : void {
$actual = preg_replace('/\\s+/u', ' ', $this->session
->getPage()
->getText());
$matches = preg_match_all($regex, $actual);
if ($message === '') {
$message = "Failed asserting that the page matches the pattern '{$regex}' {$count} time(s), {$matches} found.";
}
$constraint = new IsIdentical($count);
Assert::assertThat($matches, $constraint, $message);
}