You are here

protected function Maillog::emailsMatch in Maillog / Mail Developer 7

Determine if the actual email matches the expected email.

Parameters

array $actual: An associative array of all the columns in the actual maillog database table row.

array $expected: The expected email values. Allowed, case insensitive keys are:

  • Subject: strcasecmp comparison
  • To: strcasecmp comparison
  • From: strcasecmp comparison
  • Reply to: strcasecmp comparison
  • Body: stristr comparison.

Return value

bool Whether the expected message matches the actual message.

1 call to Maillog::emailsMatch()
Maillog::emailsWereSent in ./maillog.behat.inc
@Then /^(\d+) emails? should be sent:$/i.

File

./maillog.behat.inc, line 111
Behat subcontext for testing whether specific emails have been sent.

Class

Maillog
Behat subcontext for testing whether specific emails have been sent.

Code

protected function emailsMatch(array $actual, array $expected) {
  foreach ($expected as $part => $passed_value) {
    $expected_value = trim($passed_value);
    $part = strtolower($part);
    if ('subject' == $part) {
      $actual_value = trim($actual['subject']);
    }
    elseif ('to' == $part) {
      $actual_value = trim($actual['header_to']);
    }
    elseif ('from' == $part) {
      $actual_value = trim($actual['header_from']);
    }
    elseif ('reply to' == $part) {
      $actual_value = trim($actual['header_reply_to']);
    }
    elseif ('body' == $part) {

      // Since the body will be long it is more useful to check whether it
      // contains the expected value.
      if (!stristr(trim($actual['body']), $expected_value)) {
        return FALSE;
      }
      continue;
    }
    else {
      throw new Exception("Unknown part in expected email '{$part}'");
    }
    if (strcasecmp($actual_value, $expected_value) != 0) {
      return FALSE;
    }
  }
  return TRUE;
}