You are here

DomainAllowlistedTest.php in Reroute Email 2.x

File

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

namespace Drupal\Tests\reroute_email\Functional;

use Drupal\Component\Render\FormattableMarkup;

/**
 * Test Reroute Email's with a domain from the allowed list.
 *
 * @ingroup reroute_email_tests
 *
 * @group reroute_email
 */
class DomainAllowlistedTest extends RerouteEmailTestBase {

  /**
   * Basic tests for the domain addresses from the allowed list.
   */
  public function testAllowedByDomain() {

    // Configure rerouting email and add a domain to the allowed list.
    $this
      ->configureRerouteEmail(TRUE, $this->rerouteDestination, $this->allowlistedDomain);

    // Make sure configured emails were set.
    $this
      ->assertEquals($this->rerouteConfig
      ->get(REROUTE_EMAIL_ADDRESS), $this->rerouteDestination, 'Reroute email address was set.');
    $this
      ->assertEquals($this->rerouteConfig
      ->get(REROUTE_EMAIL_ALLOWLIST), $this->allowlistedDomain, 'Value was set to allowed list.');

    // Submit a test email (should be rerouted).
    $to = 'some@not-exist.domain';
    $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', $this->rerouteDestination, new FormattableMarkup('Email was properly rerouted to the email address: @destination.', [
      '@destination' => $this->rerouteDestination,
    ]));

    // Submit a test email (should not be rerouted).
    $this
      ->drupalGet('admin/config/development/reroute_email/test');
    $this
      ->submitForm([
      'to' => $this->originalDestination,
    ], t('Send email'));

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

}

Classes

Namesort descending Description
DomainAllowlistedTest Test Reroute Email's with a domain from the allowed list.