You are here

protected function UbercartTestBase::assertNoMailString in Ubercart 8.4

Asserts that the most recently sent e-mails do not have the string in it.

Parameters

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

string $string: String to search for.

int $email_depth: Number of emails to search for string, starting with most recent.

string $message: (optional) A message to display with the assertion. Do not translate messages: use 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.

Return value

bool TRUE on pass, FALSE on fail.

File

uc_store/src/Tests/UbercartTestBase.php, line 413

Class

UbercartTestBase
Base class for Ubercart Simpletest tests.

Namespace

Drupal\uc_store\Tests

Code

protected function assertNoMailString($field_name, $string, $email_depth, $message = '', $group = 'Other') {
  $mails = $this
    ->drupalGetMails();
  $string_found = FALSE;
  for ($i = count($mails) - 1; $i >= count($mails) - $email_depth && $i >= 0; $i--) {
    $mail = $mails[$i];

    // Normalize whitespace, as we don't know what the mail system might have
    // done. Any run of whitespace becomes a single space.
    $normalized_mail = preg_replace('/\\s+/', ' ', $mail[$field_name]);
    $normalized_string = preg_replace('/\\s+/', ' ', $string);
    $string_found = FALSE !== strpos($normalized_mail, $normalized_string);
    if ($string_found) {
      break;
    }
  }
  if (!$message) {
    $message = SafeMarkup::format('Expected text not found in @field of email message: "@expected".', [
      '@field' => $field_name,
      '@expected' => $string,
    ]);
  }
  return $this
    ->assertFalse($string_found, $message, $group);
}