You are here

protected function WebformAssertLegacyTrait::assertUniqueText in Webform 6.x

Same name and namespace in other branches
  1. 8.5 tests/src/Traits/WebformAssertLegacyTrait.php \Drupal\Tests\webform\Traits\WebformAssertLegacyTrait::assertUniqueText()

Passes if the text is found ONLY ONCE on the text version of the page.

The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.

Parameters

string|\Drupal\Component\Render\MarkupInterface $text: Plain text to look for.

string $message: (optional) A message to display with the assertion. Do not translate messages with t(). If left blank, a default message will be displayed.

File

tests/src/Traits/WebformAssertLegacyTrait.php, line 189

Class

WebformAssertLegacyTrait
Provides convenience methods for assertions in browser tests.

Namespace

Drupal\Tests\webform\Traits

Code

protected function assertUniqueText($text, $message = NULL) {

  // Cast MarkupInterface objects to string.
  $text = (string) $text;
  $message = $message ?: "'{$text}' found only once on the page";
  $page_text = $this
    ->getSession()
    ->getPage()
    ->getText();
  $nr_found = substr_count($page_text, $text);
  $this
    ->assertSame(1, $nr_found, $message);
}