function SequentiallyConstraintValidatorTest::testConfigValidation
Tests use of Sequentially validation constraint in config.
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Validation/ SequentiallyConstraintValidatorTest.php, line 46
Class
- SequentiallyConstraintValidatorTest
- Tests Sequentially 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.sequentially', 'green');
$result = $typed_config_manager->createFromNameAndData('config_test.validation', $config->get())
->validate();
$this->assertCount(0, $result);
$config->set('composite.sequentially', '');
$result = $typed_config_manager->createFromNameAndData('config_test.validation', $config->get())
->validate();
$this->assertCount(1, $result);
$this->assertEquals('This value should not be blank.', $result->get(0)
->getMessage());
$this->assertEquals('composite.sequentially', $result->get(0)
->getPropertyPath());
$config->set('composite.sequentially', 'im a very long string that should now work');
$result = $typed_config_manager->createFromNameAndData('config_test.validation', $config->get())
->validate();
$this->assertCount(1, $result);
$this->assertEquals('This value is too long. It should have 10 characters or less.', $result->get(0)
->getMessage());
$this->assertEquals('composite.sequentially', $result->get(0)
->getPropertyPath());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.