protected function WebformAssertLegacyTrait::assertTextHelper in Webform 8.5
Same name and namespace in other branches
- 6.x tests/src/Traits/WebformAssertLegacyTrait.php \Drupal\Tests\webform\Traits\WebformAssertLegacyTrait::assertTextHelper()
Helper for assertText and assertNoText.
Parameters
string $text: Plain text to look for.
bool $not_exists: (optional) TRUE if this text should not exist, FALSE if it should. Defaults to TRUE.
Return value
bool TRUE on pass, FALSE on fail.
2 calls to WebformAssertLegacyTrait::assertTextHelper()
- WebformAssertLegacyTrait::assertNoText in tests/
src/ Traits/ WebformAssertLegacyTrait.php - Passes if the page (with HTML stripped) does not contains the text.
- WebformAssertLegacyTrait::assertText in tests/
src/ Traits/ WebformAssertLegacyTrait.php - Passes if the page (with HTML stripped) contains the text.
File
- tests/
src/ Traits/ WebformAssertLegacyTrait.php, line 158
Class
- WebformAssertLegacyTrait
- Provides convenience methods for assertions in browser tests.
Namespace
Drupal\Tests\webform\TraitsCode
protected function assertTextHelper($text, $not_exists = TRUE) {
$args = [
'@text' => $text,
];
$message = $not_exists ? new FormattableMarkup('"@text" not found', $args) : new FormattableMarkup('"@text" found', $args);
$raw_content = $this
->getSession()
->getPage()
->getContent();
// Trying to simulate what the user sees, given that it removes all text
// inside the head tags, removes inline Javascript, fix all HTML entities,
// removes dangerous protocols and filtering out all HTML tags, as they are
// not visible in a normal browser.
$raw_content = preg_replace('@<head>(.+?)</head>@si', '', $raw_content);
$page_text = Xss::filter($raw_content, []);
$actual = $not_exists == (strpos($page_text, (string) $text) === FALSE);
$this
->assertTrue($actual, $message);
return $actual;
}