You are here

public function MultipleRecipientsTest::testMultipleRecipients in Reroute Email 8

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

Test Reroute Email with multiple recipients.

File

tests/src/Functional/MultipleRecipientsTest.php, line 19

Class

MultipleRecipientsTest
Test Reroute Email with multiple recipients.

Namespace

Drupal\Tests\reroute_email\Functional

Code

public function testMultipleRecipients() {

  // Set multiple whitelisted domain and rerouting emails. Multiple commas and
  // semicolons are added for validation tests.
  $this
    ->configureRerouteEmail(TRUE, 'user1@example.com, user2@example.com,;;,,user@example.com', $this->whitelistedDomain);

  // Make sure configured emails were set properly.
  $reroute_to = 'user1@example.com,user2@example.com,user@example.com';
  $this
    ->assertEqual($this->rerouteConfig
    ->get(REROUTE_EMAIL_ADDRESS), $reroute_to, 'Reroute email address was set.');
  $this
    ->assertEqual($this->rerouteConfig
    ->get(REROUTE_EMAIL_WHITELIST), $this->whitelistedDomain, 'Whitelisted value was set.');

  // Submit a test email (should be rerouted).
  $to = 'some@not-exist.domain, whitelisted@example.com';
  $this
    ->drupalPostForm('admin/config/development/reroute_email/test', [
    'to' => $to,
  ], t('Send email'));

  // Check if the email was rerouted properly.
  $this
    ->assertEmailOriginallyTo($to);
  $this
    ->assertMail('to', $reroute_to, new FormattableMarkup('Email was properly rerouted to the email address: @destination.', [
    '@destination' => $reroute_to,
  ]));

  // Submit a test email (should not be rerouted).
  $to = 'whitelisted@example.com, user2@example.com, allowed@example.com';
  $this
    ->drupalPostForm('admin/config/development/reroute_email/test', [
    'to' => $to,
  ], t('Send email'));

  // Check if the email was not rerouted.
  $this
    ->assertMail('to', $to, new FormattableMarkup('Email was properly sent the email addresses: @destination.', [
    '@destination' => $to,
  ]));
}