function AtLeastOneOfConstraintValidatorTest::testConfigValidation
Tests use of AtLeastOneOf validation constraint in config.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Validation/ AtLeastOneOfConstraintValidatorTest.php, line 125
Class
- AtLeastOneOfConstraintValidatorTest
- Tests AtLeastOneOf validation constraint with both valid and invalid values.
Namespace
Drupal\KernelTests\Core\ValidationCode
public function testConfigValidation() : void {
$this->installConfig('config_test');
$config = \Drupal::configFactory()->getEditable('config_test.validation');
/** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager */
$typed_config_manager = \Drupal::service('config.typed');
$config->set('composite.at_least_one_of', 6);
$result = $typed_config_manager->createFromNameAndData('config_test.validation', $config->get())
->validate();
$this->assertCount(0, $result);
$config->set('composite.at_least_one_of', 25);
$result = $typed_config_manager->createFromNameAndData('config_test.validation', $config->get())
->validate();
$this->assertCount(0, $result);
$config->set('composite.at_least_one_of', 15);
$result = $typed_config_manager->createFromNameAndData('config_test.validation', $config->get())
->validate();
$this->assertCount(1, $result);
$this->assertEquals('This value should satisfy at least one of the following constraints: [1] This value should be between 0 and 10. [2] This value should be between 20 and 30.', $result->get(0)
->getMessage());
$this->assertEquals('composite.at_least_one_of', $result->get(0)
->getPropertyPath());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.