You are here

public function DomainContentTestBase::checkContent in Domain Access 8

Strips whitespace from a page response and runs assertRaw() equivalent.

In tests, we were having difficulty with spacing in tables. This method takes some concepts from Mink and rearranges them to work for our tests. Notably, we don't pull page content from the session request.

Parameters

string $content: The generated HTML, such as from drupalGet().

string $text: The text string to search for.

1 call to DomainContentTestBase::checkContent()
DomainContentCountTest::testDomainContentCount in domain_content/tests/src/Functional/DomainContentCountTest.php
Tests domain content count.

File

domain_content/tests/src/Functional/DomainContentTestBase.php, line 93

Class

DomainContentTestBase
Base class and helper methods for testing domain content.

Namespace

Drupal\Tests\domain_content\Functional

Code

public function checkContent($content, $text) {

  // Convert all whitespace to spaces.
  $content = preg_replace('/\\s+/u', ' ', $content);

  // Strip all whitespace between tags.
  $content = preg_replace('@>\\s+<@', '><', $content);
  $regex = '/' . preg_quote($text, '/') . '/ui';
  $message = sprintf('The text "%s" was found in the text of the current page.', $text);
  $this
    ->assert((bool) preg_match($regex, $content), $message);
}