function AssertContentTrait::assertTextPattern

Same name in other branches
  1. 9 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertTextPattern()
  2. 8.9.x core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertTextPattern()
  3. 10 core/tests/Drupal/KernelTests/AssertContentTrait.php \Drupal\KernelTests\AssertContentTrait::assertTextPattern()

Asserts that a Perl regex pattern is found in the plain-text content.

Parameters

string $pattern: Perl regex to look for including the regex delimiters.

string $message: (optional) A message to display with the assertion.

Return value

bool TRUE on pass.

File

core/tests/Drupal/KernelTests/AssertContentTrait.php, line 682

Class

AssertContentTrait
Provides test methods to assert content.

Namespace

Drupal\KernelTests

Code

protected function assertTextPattern($pattern, $message = NULL) : bool {
    if (!isset($message)) {
        $message = new FormattableMarkup('Pattern "@pattern" found', [
            '@pattern' => $pattern,
        ]);
    }
    $this->assertMatchesRegularExpression($pattern, $this->getTextContent(), $message);
    return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.