Test term field validation.
function testTaxonomyTermFieldValidation() {
// Test valid and invalid values with field_attach_validate().
$langcode = Language::LANGCODE_NOT_SPECIFIED;
$entity = entity_create('entity_test', array());
$term = $this
->createTerm($this->vocabulary);
$entity->{$this->field_name}->tid = $term
->id();
try {
field_attach_validate($entity);
$this
->pass('Correct term does not cause validation error.');
} catch (FieldValidationException $e) {
$this
->fail('Correct term does not cause validation error.');
}
$entity = entity_create('entity_test', array());
$bad_term = $this
->createTerm($this
->createVocabulary());
$entity->{$this->field_name}->tid = $bad_term
->id();
try {
field_attach_validate($entity);
$this
->fail('Wrong term causes validation error.');
} catch (FieldValidationException $e) {
$this
->pass('Wrong term causes validation error.');
}
}