You are here

protected function AssertContentTrait::assertTextHelper in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/simpletest/src/AssertContentTrait.php \Drupal\simpletest\AssertContentTrait::assertTextHelper()

Helper for assertText and assertNoText.

It is not recommended to call this function directly.

Parameters

string $text: Plain text to look for.

string $message: (optional) A message to display with the assertion. Do not translate messages: use \Drupal\Component\Utility\SafeMarkup::format() to embed variables in the message text, not t(). If left blank, a default message will be displayed.

string $group: (optional) The group this message is in, which is displayed in a column in test output. Use 'Debug' to indicate this is debugging output. Do not translate this string. Defaults to 'Other'; most tests do not override this default. Defaults to 'Other'.

bool $not_exists: (optional) TRUE if this text should not exist, FALSE if it should. Defaults to TRUE.

Return value

bool TRUE on pass, FALSE on fail.

2 calls to AssertContentTrait::assertTextHelper()
AssertContentTrait::assertNoText in core/modules/simpletest/src/AssertContentTrait.php
Passes if the page (with HTML stripped) does not contains the text.
AssertContentTrait::assertText in core/modules/simpletest/src/AssertContentTrait.php
Passes if the page (with HTML stripped) contains the text.

File

core/modules/simpletest/src/AssertContentTrait.php, line 610
Contains \Drupal\simpletest\AssertContentTrait.

Class

AssertContentTrait
Provides test methods to assert content.

Namespace

Drupal\simpletest

Code

protected function assertTextHelper($text, $message = '', $group = 'Other', $not_exists = TRUE) {
  if (!$message) {
    $message = !$not_exists ? SafeMarkup::format('"@text" found', array(
      '@text' => $text,
    )) : SafeMarkup::format('"@text" not found', array(
      '@text' => $text,
    ));
  }
  return $this
    ->assert($not_exists == (strpos($this
    ->getTextContent(), (string) $text) === FALSE), $message, $group);
}