You are here

public function DomainAllowlistedTest::testAllowedByDomain in Reroute Email 2.x

Basic tests for the domain addresses from the allowed list.

File

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

Class

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

Namespace

Drupal\Tests\reroute_email\Functional

Code

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,
  ]));
}