You are here

protected function UbercartJavascriptTestBase::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 format_string() 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/tests/src/FunctionalJavascript/UbercartJavascriptTestBase.php, line 263

Class

UbercartJavascriptTestBase
Base class for Ubercart PHPUnit browser tests.

Namespace

Drupal\Tests\uc_store\FunctionalJavascript

Code

protected function assertNoMailString($field_name, $string, $email_depth, $message = '', $group = 'Other') {
  $mails = $this
    ->getMails();
  $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 = format_string('Expected text not found in @field of email message: "@expected".', [
      '@field' => $field_name,
      '@expected' => $string,
    ]);
  }
  return $this
    ->assertFalse($string_found, $message, $group);
}