You are here

public function RerouteEmailTestCase::assertEmailOriginallyTo in Reroute Email 7

Assert whether the text "Originally to: @to_email" is found in email body.

Parameters

bool $original_destination: (optional) The original email address to be found in rerouted email body. Defaults to $this->originalDestination if set to NULL.

6 calls to RerouteEmailTestCase::assertEmailOriginallyTo()
RerouteEmailContactTestCase::testBasicNotification in ./reroute_email.test
Basic tests of email rerouting for emails sent through the Contact forms.
RerouteEmailDomainWhitelistedTestCase::testDomainWhitelistedEmail in ./reroute_email.test
Basic tests for the domain whitelisted addresses.
RerouteEmailMailKeysTest::testMailKeysFilter in ./reroute_email.test
Test Reroute Email with mail keys filter.
RerouteEmailMultipleRecipientsTest::testMultipleRecipients in ./reroute_email.test
Test Reroute Email with multiple recipients.
RerouteEmailSpecialTestCase::testBodyStringRobustHeaders in ./reroute_email.test
Test handling of message body as a string and header keys' robustness.

... See full list

File

./reroute_email.test, line 122
Test the Reroute Email module.

Class

RerouteEmailTestCase
Provides common functionality for the Reroute Email test classes.

Code

public function assertEmailOriginallyTo($original_destination = NULL) {

  // Check most recent email.
  $mails = $this
    ->drupalGetMails();
  if (empty($mails)) {
    $this
      ->assert(FALSE, 'Email was not sent.');
    return;
  }
  $mail = end($mails);

  // Initialize $original_destination by default if no value is provided.
  if (NULL === $original_destination) {
    $original_destination = $this->originalDestination;
  }

  // Search in $mailbody for "Originally to: $original_destination".
  $search_for = t('Originally to: @to', array(
    '@to' => $original_destination,
  ));
  $has_info = preg_match("/{$search_for}/", $mail['body']);

  // Asserts whether searched text was found.
  $this
    ->assertTrue($has_info, t('Found the correct "Originally to" line in the body.'));
  $this
    ->verbose(t('Email body was: <pre>@mail_body</pre>', array(
    '@mail_body' => $mail['body'],
  )));
}