$this->typedData =
$this->container->
get('typed_data_manager'
);
} /**
* Tests the ComplexData validation constraint validator.
*
* For testing a map including a constraint on one of its keys is defined.
*/
public function testValidation() { // Create a definition that specifies some ComplexData constraint.
$definition = MapDataDefinition::
create() ->
setPropertyDefinition('key', DataDefinition::
create('integer'
)) ->
addConstraint('ComplexData',
[ 'key' =>
[ 'AllowedValues' =>
[1, 2, 3
],
],
]);
// Test the validation.
$typed_data =
$this->typedData->
create($definition,
['key' => 1
]);
$violations =
$typed_data->
validate();
$this->
assertEquals(0,
$violations->
count(), 'Validation passed for correct value.'
);