You are here

MultipleRecipientsTest.php in Reroute Email 2.x

Same filename and directory in other branches
  1. 8 tests/src/Functional/MultipleRecipientsTest.php

File

tests/src/Functional/MultipleRecipientsTest.php
View source
<?php

namespace Drupal\Tests\reroute_email\Functional;

use Drupal\Component\Render\FormattableMarkup;

/**
 * Test Reroute Email with multiple recipients.
 *
 * @ingroup reroute_email_tests
 *
 * @group reroute_email
 */
class MultipleRecipientsTest extends RerouteEmailTestBase {

  /**
   * Test Reroute Email with multiple recipients.
   */
  public function testMultipleRecipients() {

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

    // Make sure configured emails were set properly.
    $reroute_to = 'user1@example.com,user2@example.com,user@example.com';
    $this
      ->assertEquals($this->rerouteConfig
      ->get(REROUTE_EMAIL_ADDRESS), $reroute_to, 'Reroute email address was set.');
    $this
      ->assertEquals($this->rerouteConfig
      ->get(REROUTE_EMAIL_ALLOWLIST), $this->allowlistedDomain, 'Value was set to the allowed list.');

    // Submit a test email (should be rerouted).
    $to = 'email@not-allowlisted.com, allowlisted@example.com';
    $this
      ->drupalGet('admin/config/development/reroute_email/test');
    $this
      ->submitForm([
      '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 = 'allowlisted@example.com, user2@example.com, allowed@example.com';
    $this
      ->drupalGet('admin/config/development/reroute_email/test');
    $this
      ->submitForm([
      '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,
    ]));
  }

}

Classes

Namesort descending Description
MultipleRecipientsTest Test Reroute Email with multiple recipients.