function MailerDsnConfigValidationTest::testMailerTransportSendmailOptionsValidation

File

core/tests/Drupal/KernelTests/Core/Config/MailerDsnConfigValidationTest.php, line 267

Class

MailerDsnConfigValidationTest
Tests validation of mailer dsn config.

Namespace

Drupal\KernelTests\Core\Config

Code

public function testMailerTransportSendmailOptionsValidation() : void {
    $config = $this->config('system.mail');
    $this->assertFalse($config->isNew());
    $data = $config->get();
    // Set scheme to sendmail.
    $data['mailer_dsn']['scheme'] = 'sendmail';
    // If the options contain an invalid command, it should be an error.
    $data['mailer_dsn']['options'] = [
        'command' => "sendmail\t-bs\n",
    ];
    $violations = $this->configManager
        ->createFromNameAndData($config->getName(), $data)
        ->validate();
    $this->assertCount(1, $violations);
    $this->assertSame('mailer_dsn.options.command', $violations[0]->getPropertyPath());
    $this->assertSame('The command option is not allowed to span multiple lines or contain control characters.', (string) $violations[0]->getMessage());
    // If the options contain an invalid key, it should be an error.
    $data['mailer_dsn']['options'] = [
        'invalid_key' => 'Hello',
    ];
    $violations = $this->configManager
        ->createFromNameAndData($config->getName(), $data)
        ->validate();
    $this->assertCount(1, $violations);
    $this->assertSame('mailer_dsn.options.invalid_key', $violations[0]->getPropertyPath());
    $this->assertSame("'invalid_key' is not a supported key.", (string) $violations[0]->getMessage());
    // If the options contain a command, it should accepted.
    $data['mailer_dsn']['options'] = [
        'command' => 'sendmail -bs',
    ];
    $violations = $this->configManager
        ->createFromNameAndData($config->getName(), $data)
        ->validate();
    $this->assertCount(0, $violations);
    // If options is an empty map, it should be accepted.
    $data['mailer_dsn']['options'] = [];
    $violations = $this->configManager
        ->createFromNameAndData($config->getName(), $data)
        ->validate();
    $this->assertCount(0, $violations);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.