You are here

protected function AssertLegacyTrait::assertNoUniqueText in Drupal 8

Same name and namespace in other branches
  1. 9 core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php \Drupal\FunctionalTests\AssertLegacyTrait::assertNoUniqueText()

Passes if the text is found MORE THAN 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.

Deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->getPage()->getText() and substr_count() instead.

7 calls to AssertLegacyTrait::assertNoUniqueText()
AssertLegacyTraitTest::testAssertNoUniqueText in core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
@covers ::assertNoUniqueText
AssertLegacyTraitTest::testAssertNoUniqueTextFail in core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
@covers ::assertNoUniqueText
AssertLegacyTraitTest::testAssertNoUniqueTextMarkup in core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
@covers ::assertNoUniqueText
AssertLegacyTraitTest::testAssertNoUniqueTextUnknown in core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
@covers ::assertNoUniqueText
ContactSitewideTest::testSiteWideContact in core/modules/contact/tests/src/Functional/ContactSitewideTest.php
Tests configuration options and the site-wide contact form.

... See full list

File

core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php, line 190

Class

AssertLegacyTrait
Provides convenience methods for assertions in browser tests.

Namespace

Drupal\FunctionalTests

Code

protected function assertNoUniqueText($text, $message = '') {

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