// Test the validation when an invalid value (in this case a user entity)
// is passed.
$account =
$this->
createUser();
$typed_data =
$this->typedData->
create($definition,
$account);
$violations =
$typed_data->
validate();
$this->
assertEquals(1,
$violations->
count(), 'Validation failed for incorrect value.'
);
// Make sure the information provided by a violation is correct.
$violation =
$violations[0
];
$this->
assertEquals(t('The entity must be of type %type.',
['%type' =>
$entity_type]),
$violation->
getMessage(), 'The message for invalid value is correct.'
);
$this->
assertEquals($typed_data,
$violation->
getRoot(), 'Violation root is correct.'
);
$this->
assertEquals($account,
$violation->
getInvalidValue(), 'The invalid value is set correctly in the violation.'
);
}}