You are here

public function ConnectionTesterTest::testHookRequirements in SMTP Authentication Support 8

Test for hookRequirements().

@cover ::hookRequirements @dataProvider providerHookRequirements

Parameters

string $message: The test message.

bool $smtp_on: Mock value of whether SMTP is on or not.

bool $result: Mock result of ::SmtpConnect().

string $exception: The exception, if any, that the mock SmtpConnect() should throw.

array $expected: The expected result; ignored if an exception is expected.

File

tests/src/Kernel/ConnectionTester/ConnectionTesterTest.php, line 38

Class

ConnectionTesterTest
Tests SMTP connections.

Namespace

Drupal\Tests\smtp\Kernel\ConnectionTester

Code

public function testHookRequirements(string $message, bool $smtp_on, bool $result, string $exception, array $expected) {
  $smtp_settings = \Drupal::configFactory()
    ->getEditable('smtp.settings');
  $smtp_settings
    ->set('smtp_on', $smtp_on);
  $smtp_settings
    ->save();
  $object = \Drupal::service('smtp.connection_tester');
  $object
    ->setMailer($this
    ->getMockMailer($result, $exception));
  $object
    ->testConnection();
  $output = $object
    ->hookRequirements('runtime');
  if ($output != $expected) {
    print_r([
      'message' => $message,
      'output' => $output,
      'expected' => $expected,
    ]);
  }
  $this
    ->assertTrue($output == $expected, $message);
}