function AssertLegacyTrait::assertUniqueText

Same name in other branches
  1. 8.9.x core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php \Drupal\FunctionalTests\AssertLegacyTrait::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.

Deprecated

in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->pageTextContainsOnce() or $this->getSession()->pageTextMatchesCount() instead.

See also

https://www.drupal.org/node/3129738

4 calls to AssertLegacyTrait::assertUniqueText()
AssertLegacyTraitTest::testAssertUniqueText in core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
@covers ::assertUniqueText
AssertLegacyTraitTest::testAssertUniqueTextFail in core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
@covers ::assertUniqueText
AssertLegacyTraitTest::testAssertUniqueTextMarkup in core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
@covers ::assertUniqueText
AssertLegacyTraitTest::testAssertUniqueTextUnknown in core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php
@covers ::assertUniqueText

File

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

Class

AssertLegacyTrait
Provides convenience methods for assertions in browser tests.

Namespace

Drupal\FunctionalTests

Code

protected function assertUniqueText($text, $message = NULL) {
    @trigger_error('AssertLegacyTrait::assertUniqueText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->getSession()->pageTextContainsOnce() or $this->getSession()->pageTextMatchesCount() instead. See https://www.drupal.org/node/3129738', E_USER_DEPRECATED);
    // 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);
}

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