$this->
assertEquals('This value should not be null.',
$violations[0
]->
getMessage());
$test_entity =
clone $entity;
$test_entity->name->value =
$this->
randomString(65
);
$violations =
$test_entity->
validate();
$this->
assertEquals(1,
$violations->
count(), 'Validation failed.'
);
$this->
assertEquals(t('%name: may not be longer than @max characters.',
['%name' => 'Name', '@max' => 64
]),
$violations[0
]->
getMessage());
// Make sure the information provided by a violation is correct.
$violation =
$violations[0
];
$this->
assertEquals($test_entity,
$violation->
getRoot()->
getValue(), 'Violation root is entity.'
);
$this->
assertEquals('name.0.value',
$violation->
getPropertyPath(), 'Violation property path is correct.'
);
$this->
assertEquals($test_entity->name->value,
$violation->
getInvalidValue(), 'Violation contains invalid value.'
);
$test_entity =
clone $entity;
$test_entity->
set('user_id', 9999
);
$violations =
$test_entity->
validate();
$this->
assertEquals(1,
$violations->
count(), 'Validation failed.'
);
$this->
assertEquals(t('The referenced entity (%type: %id) does not exist.',
['%type' => 'user', '%id' => 9999
]),
$violations[0
]->
getMessage());
$test_entity =
clone $entity;
$test_entity->field_test_text->format =
$this->
randomString(33
);
$violations =
$test_entity->
validate();