function RecursiveContextualValidatorTest::testBasicValidateWithConstraint
Same name and namespace in other branches
- 10 core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest::testBasicValidateWithConstraint()
- 9 core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest::testBasicValidateWithConstraint()
- 8.9.x core/tests/Drupal/Tests/Core/TypedData/RecursiveContextualValidatorTest.php \Drupal\Tests\Core\TypedData\RecursiveContextualValidatorTest::testBasicValidateWithConstraint()
Tests basic validate with constraint.
@legacy-covers ::validate
File
-
core/
tests/ Drupal/ Tests/ Core/ TypedData/ RecursiveContextualValidatorTest.php, line 129
Class
- RecursiveContextualValidatorTest
- Tests Drupal\Core\TypedData\Validation\RecursiveContextualValidator.
Namespace
Drupal\Tests\Core\TypedDataCode
public function testBasicValidateWithConstraint() : void {
$typed_data = $this->typedDataManager
->create(DataDefinition::create('string')->addConstraint('Callback', [
'callback' => function ($value, ExecutionContextInterface $context) : void {
$context->addViolation('test violation: ' . $value);
},
]));
$typed_data->setValue('foo');
$violations = $this->recursiveValidator
->validate($typed_data);
$this->assertCount(1, $violations);
// Ensure that the right value is passed into the validator.
$this->assertEquals('test violation: foo', $violations->get(0)
->getMessage());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.