You are here

public function RerouteEmailTestBase::assertEmailOriginallyTo in Reroute Email 8

Same name and namespace in other branches
  1. 2.x tests/src/Functional/RerouteEmailTestBase.php \Drupal\Tests\reroute_email\Functional\RerouteEmailTestBase::assertEmailOriginallyTo()

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

Parameters

string $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 RerouteEmailTestBase::assertEmailOriginallyTo()
ContactTest::testBasicNotification in tests/src/Functional/ContactTest.php
Basic tests of email rerouting for emails sent through the Contact forms.
DomainWhitelistedTest::testDomainWhitelistedEmail in tests/src/Functional/DomainWhitelistedTest.php
Basic tests for the domain whitelisted addresses.
MailKeysTest::testMailKeysFilter in tests/src/Functional/MailKeysTest.php
Test Reroute Email with mail keys filter.
MultipleRecipientsTest::testMultipleRecipients in tests/src/Functional/MultipleRecipientsTest.php
Test Reroute Email with multiple recipients.
TestEmailFormTest::testFormTestEmail in tests/src/Functional/TestEmailFormTest.php
Basic tests for reroute_email Test Email form.

... See full list

File

tests/src/Functional/RerouteEmailTestBase.php, line 149

Class

RerouteEmailTestBase
Base test class for Reroute Email test cases.

Namespace

Drupal\Tests\reroute_email\Functional

Code

public function assertEmailOriginallyTo($original_destination = NULL) {

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

  // 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".
  $mail_body = end($mails)['body'];
  $search_for = t('Originally to: @to', [
    '@to' => $original_destination,
  ]);
  $has_info = (bool) preg_match("/{$search_for}/", $mail_body);

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