function AssertContentTrait::assertTextHelper
Same name in other branches
- 9 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertTextHelper()
- 8.9.x core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertTextHelper()
- 11.x core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertTextHelper()
Helper for assertText and assertNoText.
It is not recommended to call this function directly.
Parameters
string $text: Plain text to look for.
string $message: (optional) A message to display with the assertion. Do not translate messages with t(). Use double quotes and embed variables directly in message text, or use sprintf() if necessary. Avoid the use of \Drupal\Component\Render\FormattableMarkup unless you cast the object to a string. If left blank, a default message will be displayed.
string $group: Deprecated.
bool $not_exists: (optional) TRUE if this text should not exist, FALSE if it should. Defaults to TRUE.
2 calls to AssertContentTrait::assertTextHelper()
- AssertContentTrait::assertNoText in core/
tests/ Drupal/ KernelTests/ AssertContentTrait.php - Passes if the page (with HTML stripped) does not contains the text.
- AssertContentTrait::assertText in core/
tests/ Drupal/ KernelTests/ AssertContentTrait.php - Passes if the page (with HTML stripped) contains the text.
File
-
core/
tests/ Drupal/ KernelTests/ AssertContentTrait.php, line 527
Class
- AssertContentTrait
- Provides test methods to assert content.
Namespace
Drupal\KernelTestsCode
protected function assertTextHelper($text, $message = '', $group = NULL, $not_exists = TRUE) : void {
if (!$message) {
$message = !$not_exists ? new FormattableMarkup('"@text" found', [
'@text' => $text,
]) : new FormattableMarkup('"@text" not found', [
'@text' => $text,
]);
}
if ($not_exists) {
$this->assertStringNotContainsString((string) $text, $this->getTextContent(), $message);
}
else {
$this->assertStringContainsString((string) $text, $this->getTextContent(), $message);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.