function SequentiallyConstraintValidatorTest::testValidation
Tests the Sequentially validation constraint validator.
Attributes
#[DataProvider('dataProvider')]
File
-
core/
tests/ Drupal/ KernelTests/ Core/ Validation/ SequentiallyConstraintValidatorTest.php, line 73
Class
- SequentiallyConstraintValidatorTest
- Tests Sequentially validation constraint with both valid and invalid values.
Namespace
Drupal\KernelTests\Core\ValidationCode
public function testValidation(string $type, mixed $value, array $constraints, array $expectedViolations, array $extra_constraints = []) : void {
// Create a definition that specifies some AllowedValues.
$definition = DataDefinition::create($type);
if (count($extra_constraints) > 0) {
foreach ($extra_constraints as $name => $settings) {
$definition->addConstraint($name, $settings);
}
}
$definition->addConstraint('Sequentially', [
'constraints' => $constraints,
]);
// Test the validation.
$typed_data = $this->typedData
->create($definition, $value);
$violations = $typed_data->validate();
$violationMessages = [];
foreach ($violations as $violation) {
$violationMessages[] = (string) $violation->getMessage();
}
$this->assertEquals($expectedViolations, $violationMessages, 'Validation passed for correct value.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.