| 7 taxonomy.test | TaxonomyTermFieldTestCase::testTaxonomyTermFieldValidation() |
| 8 taxonomy.test | TaxonomyTermFieldTestCase::testTaxonomyTermFieldValidation() |
Test term field validation.
File
- modules/
taxonomy/ taxonomy.test, line 1468 - Tests for taxonomy.module.
Code
function testTaxonomyTermFieldValidation() {
// Test valid and invalid values with field_attach_validate().
$langcode = LANGUAGE_NONE;
$entity = field_test_create_stub_entity();
$term = $this->createTerm($this->vocabulary);
$entity->{$this->field_name}[$langcode][0]['tid'] = $term->tid;
try {
field_attach_validate('test_entity', $entity);
$this->pass(t('Correct term does not cause validation error'));
}
catch (FieldValidationException $e) {
$this->fail(t('Correct term does not cause validation error'));
}
$entity = field_test_create_stub_entity();
$bad_term = $this->createTerm($this->createVocabulary());
$entity->{$this->field_name}[$langcode][0]['tid'] = $bad_term->tid;
try {
field_attach_validate('test_entity', $entity);
$this->fail(t('Wrong term causes validation error'));
}
catch (FieldValidationException $e) {
$this->pass(t('Wrong term causes validation error'));
}
}
Login or register to post comments