function RecursiveContextualValidatorTest::testBasicValidateWithConstraint
@covers ::validate
File
-
core/
tests/ Drupal/ Tests/ Core/ TypedData/ RecursiveContextualValidatorTest.php, line 124
Class
- RecursiveContextualValidatorTest
- @coversDefaultClass \Drupal\Core\TypedData\Validation\RecursiveContextualValidator[[api-linebreak]] @group TypedData
Namespace
Drupal\Tests\Core\TypedDataCode
public function testBasicValidateWithConstraint() : void {
$typed_data = $this->typedDataManager
->create(DataDefinition::create('string')->addConstraint('Callback', [
'callback' => function ($value, ExecutionContextInterface $context) {
$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.