You are here

protected function WebTestBase::assertMailPattern in Zircon Profile 8

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

Asserts that the most recently sent email message has the pattern in it.

Parameters

$field_name: Name of field or message property to assert: subject, body, id, ...

$regex: Pattern to search for.

$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.

$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.

Return value

TRUE on pass, FALSE on fail.

File

core/modules/simpletest/src/WebTestBase.php, line 2875
Contains \Drupal\simpletest\WebTestBase.

Class

WebTestBase
Test case for typical Drupal tests.

Namespace

Drupal\simpletest

Code

protected function assertMailPattern($field_name, $regex, $message = '', $group = 'Other') {
  $mails = $this
    ->drupalGetMails();
  $mail = end($mails);
  $regex_found = preg_match("/{$regex}/", $mail[$field_name]);
  if (!$message) {
    $message = format_string('Expected text found in @field of email message: "@expected".', array(
      '@field' => $field_name,
      '@expected' => $regex,
    ));
  }
  return $this
    ->assertTrue($regex_found, $message, $group);
}