function AssertLegacyTrait::assertText

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

Passes if the page (with HTML stripped) contains the text.

Note that stripping HTML tags also removes their attributes, such as the values of text fields.

Parameters

string $text: Plain text to look for.

Deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use

  • $this->assertSession()->responseContains() for non-HTML responses, like XML or Json.
  • $this->assertSession()->pageTextContains() for HTML responses. Unlike the deprecated assertText(), the passed text should be HTML decoded, exactly as a human sees it in the browser.
679 calls to AssertLegacyTrait::assertText()
AccessDeniedTest::testAccessDenied in core/modules/system/tests/src/Functional/System/AccessDeniedTest.php
AccessDeniedTest::testAccessDeniedCustomPageWithAccessDenied in core/modules/system/tests/src/Functional/System/AccessDeniedTest.php
Tests that an inaccessible custom 403 page falls back to the default.
AddFeedTest::testAddFeed in core/modules/aggregator/tests/src/Functional/AddFeedTest.php
Creates and ensures that a feed is unique, checks source, and deletes feed.
AddFeedTest::testAddLongFeed in core/modules/aggregator/tests/src/Functional/AddFeedTest.php
Tests feeds with very long URLs.
AdminTest::testAdminPages in core/modules/system/tests/src/Functional/System/AdminTest.php
Tests output on administrative listing pages.

... See full list

1 method overrides AssertLegacyTrait::assertText()
UncaughtExceptionTest::assertText in core/tests/Drupal/FunctionalTests/Bootstrap/UncaughtExceptionTest.php
Passes if the page (with HTML stripped) contains the text.

File

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

Class

AssertLegacyTrait
Provides convenience methods for assertions in browser tests.

Namespace

Drupal\FunctionalTests

Code

protected function assertText($text) {
    // Cast MarkupInterface to string.
    $text = (string) $text;
    $content_type = $this->getSession()
        ->getResponseHeader('Content-type');
    // In case of a Non-HTML response (example: XML) check the original
    // response.
    if (strpos($content_type, 'html') === FALSE) {
        $this->assertSession()
            ->responseContains($text);
    }
    else {
        $this->assertTextHelper($text, FALSE);
    }
}

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