You are here

public function SMTPMailSystemTest::testApplyRerouting in SMTP Authentication Support 8

Test applyRerouting().

File

tests/src/Unit/Plugin/Mail/SMTPMailSystemTest.php, line 157

Class

SMTPMailSystemTest
Validate requirements for SMTPMailSystem.

Namespace

Drupal\Tests\smtp\Unit\Plugin\Mail

Code

public function testApplyRerouting() {
  $mailSystemRerouted = new SMTPMailSystemTestHelper([], '', [], $this->mockLogger
    ->reveal(), $this->mockMessenger
    ->reveal(), $this->emailValidator, $this->mockConfigFactoryRerouted, $this->mockCurrentUser
    ->reveal(), $this->mockFileSystem
    ->reveal(), $this->mimeTypeGuesser
    ->reveal());
  $to = 'abc@example.com';
  $headers = [
    'some' => 'header',
    'cc' => 'xyz@example.com',
    'bcc' => 'ttt@example.com',
  ];
  list($new_to, $new_headers) = $mailSystemRerouted
    ->publicApplyRerouting($to, $headers);
  $this
    ->assertEquals($new_to, 'blackhole@galaxy.com', 'to address is set to the reroute address.');
  $this
    ->assertEquals($new_headers, [
    'some' => 'header',
  ], 'bcc and cc headers are unset when rerouting.');
  $mailSystemNotRerouted = new SMTPMailSystemTestHelper([], '', [], $this->mockLogger
    ->reveal(), $this->mockMessenger
    ->reveal(), $this->emailValidator, $this->mockConfigFactory, $this->mockCurrentUser
    ->reveal(), $this->mockFileSystem
    ->reveal(), $this->mimeTypeGuesser
    ->reveal());
  $to = 'abc@example.com';
  $headers = [
    'some' => 'header',
    'cc' => 'xyz@example.com',
    'bcc' => 'ttt@example.com',
  ];
  list($new_to, $new_headers) = $mailSystemNotRerouted
    ->publicApplyRerouting($to, $headers);
  $this
    ->assertEquals($new_to, $to, 'original to address is preserved when not rerouting.');
  $this
    ->assertEquals($new_headers, $headers, 'bcc and cc headers are preserved when not rerouting.');
}