$this->typedData =
$this->container->
get('typed_data_manager'
);
} /**
* Tests the AllowedValues validation constraint validator.
*
* For testing we define an integer with a set of allowed values.
*/
public function testValidation() { // Create a definition that specifies some AllowedValues.
$definition = DataDefinition::
create('integer'
) ->
addConstraint('AllowedValues',
[1, 2, 3
]);
// Test the validation.
$typed_data =
$this->typedData->
create($definition, 1
);
$violations =
$typed_data->
validate();
$this->
assertEquals(0,
$violations->
count(), 'Validation passed for correct value.'
);
// Test the validation when an invalid value is passed.
$typed_data =
$this->typedData->
create($definition, 4
);
$violations =
$typed_data->
validate();
$this->
assertEquals(1,
$violations->
count(), 'Validation failed for incorrect value.'
);