function MailerDsnConfigValidationTest::testMailerPortValidation
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Config/ MailerDsnConfigValidationTest.php, line 173
Class
- MailerDsnConfigValidationTest
- Tests validation of mailer dsn config.
Namespace
Drupal\KernelTests\Core\ConfigCode
public function testMailerPortValidation() : void {
$config = $this->config('system.mail');
$this->assertFalse($config->isNew());
$data = $config->get();
// If the port is negative, it should be an error.
$data['mailer_dsn']['port'] = -1;
$violations = $this->configManager
->createFromNameAndData($config->getName(), $data)
->validate();
$this->assertCount(1, $violations);
$this->assertSame('mailer_dsn.port', $violations[0]->getPropertyPath());
$this->assertSame('The mailer DSN port must be between 0 and 65535.', (string) $violations[0]->getMessage());
// If the port greater than 65535, it should be an error.
$data['mailer_dsn']['port'] = 655351 + 1;
$violations = $this->configManager
->createFromNameAndData($config->getName(), $data)
->validate();
$this->assertCount(1, $violations);
$this->assertSame('mailer_dsn.port', $violations[0]->getPropertyPath());
$this->assertSame('The mailer DSN port must be between 0 and 65535.', (string) $violations[0]->getMessage());
// If the port is valid, it should be accepted.
$data['mailer_dsn']['port'] = 587;
$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.