function TaxonomyTermFieldTestCase::testEmptyTaxonomyTermReferenceField

Test empty taxonomy term reference field.

File

modules/taxonomy/taxonomy.test, line 1691

Class

TaxonomyTermFieldTestCase
Tests for taxonomy term field and formatter.

Code

function testEmptyTaxonomyTermReferenceField() {
    // Test if an empty value in the taxonomy reference field would trigger
    // autocreate or if the value would be saved correctly.
    $langcode = LANGUAGE_NONE;
    $entity = field_test_create_stub_entity(NULL, NULL);
    $entity->{$this->field_name}[$langcode][0]['tid'] = 0;
    field_test_entity_save($entity);
    $entity = field_test_entity_test_load($entity->ftid);
    field_test_entity_save($entity);
    $this->pass('Empty term ID does not trigger autocreate.');
    // Try also NULL value.
    $entity->{$this->field_name}[$langcode][0]['tid'] = NULL;
    field_test_entity_save($entity);
    $this->pass('NULL term ID does not trigger autocreate.');
    field_attach_prepare_view('test_entity', array(
        $entity->ftid => $entity,
    ), 'full');
    $this->pass('NULL term ID prepared to display.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.