You are here

public function SMTPMailSystemTest::testMailValidator in SMTP Authentication Support 8

Test mail() with focus on the mail validator.

@dataProvider mailValidatorProvider

File

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

Class

SMTPMailSystemTest
Validate requirements for SMTPMailSystem.

Namespace

Drupal\Tests\smtp\Unit\Plugin\Mail

Code

public function testMailValidator(string $to, string $from, EmailValidatorInterface $validator, $exception) {
  $this->emailValidator = $validator;
  $mailSystem = new SMTPMailSystemTestHelper([], '', [], $this->mockLogger
    ->reveal(), $this->mockMessenger
    ->reveal(), $validator, $this->mockConfigFactory, $this->mockCurrentUser
    ->reveal(), $this->mockFileSystem
    ->reveal(), $this->mimeTypeGuesser
    ->reveal());
  $message = [
    'to' => $to,
    'from' => $from,
    'body' => 'Some test content for testMailValidatorDrupal',
    'headers' => [
      'content-type' => 'text/plain',
    ],
    'subject' => 'testMailValidatorDrupal',
  ];
  if (isset($exception)) {
    $this
      ->expectException($exception);
  }

  // Call function.
  $result = $mailSystem
    ->mail($message);

  // More important than the result is that no exception was thrown, if
  // $exception is unset.
  self::assertTrue($result);
}