You are here

public function WebAssertTest::testPageTextContainsOnce in Drupal 10

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

@covers ::pageTextContainsOnce

File

core/tests/Drupal/FunctionalTests/WebAssertTest.php, line 77

Class

WebAssertTest
Tests WebAssert functionality.

Namespace

Drupal\FunctionalTests

Code

public function testPageTextContainsOnce() {
  $this
    ->drupalLogin($this
    ->drupalCreateUser());

  // Visit a Drupal page that requires login.
  $this
    ->drupalGet('test-page');
  $this
    ->assertSession()
    ->pageTextContainsOnce('Test page text.');
  $this
    ->expectException(ResponseTextException::class);
  $this
    ->expectExceptionMessage("Failed asserting that the page matches the pattern '/does\\-not\\-exist/ui' 1 time(s), 0 found.");
  $this
    ->assertSession()
    ->pageTextContainsOnce('does-not-exist');
}