protected function DrupalWebTestCase::assertMailString

7.x drupal_web_test_case.php protected DrupalWebTestCase::assertMailString($field_name, $string, $email_depth)

Asserts that the most recently sent e-mail message has the string in it.

Parameters

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

$string: String to search for.

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

Return value

TRUE on pass, FALSE on fail.

1 call to DrupalWebTestCase::assertMailString()
TriggerActionTestCase::assertSystemEmailTokenReplacement in drupal-7.x/modules/trigger/trigger.test
Asserts correct token replacement for the given trigger and account.

File

drupal-7.x/modules/simpletest/drupal_web_test_case.php, line 3610

Class

DrupalWebTestCase
Test case for typical Drupal tests.

Code

protected function assertMailString($field_name, $string, $email_depth) {
  $mails = $this->drupalGetMails();
  $string_found = FALSE;
  for ($i = sizeof($mails) -1; $i >= sizeof($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;
    }
  }
  return $this->assertTrue($string_found, t('Expected text found in @field of email message: "@expected".', array('@field' => $field_name, '@expected' => $string)));
}