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.


$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/modules/trigger/trigger.test
Asserts correct token replacement for the given trigger and account.


drupal/modules/simpletest/drupal_web_test_case.php, line 3590


Test case for typical Drupal tests.


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) {
  return $this->assertTrue($string_found, t('Expected text found in @field of email message: "@expected".', array('@field' => $field_name, '@expected' => $string)));