1 taxonomy.test TaxonomyTermFieldTestCase::testTaxonomyTermFieldWidgets()

Test widgets.

File

core/modules/taxonomy/tests/taxonomy.test, line 1555
Tests for taxonomy.module.

Class

TaxonomyTermFieldTestCase
Tests for taxonomy term field and formatter.

Code

function testTaxonomyTermFieldWidgets() {
  // Create a term in the vocabulary.
  $term = $this->createTerm($this->vocabulary);

  // Display creation form.
  $langcode = LANGUAGE_NONE;
  $this->backdropGet('test-entity/add/test-bundle');
  $this->assertFieldByName("{$this->field_name}[$langcode]", '', 'Widget is displayed.');

  // Submit with some value.
  $edit = array(
    "{$this->field_name}[$langcode]" => array($term->tid),
  );
  $this->backdropPost(NULL, $edit, t('Save'));
  preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match);
  $id = $match[1];
  $this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), 'Entity was created.');

  // Display the object.
  $entity = field_test_entity_test_load($id);
  $entities = array($id => $entity);
  field_attach_prepare_view('test_entity', $entities, 'full');
  $entity->content = field_attach_view('test_entity', $entity, 'full');
  $this->content = backdrop_render($entity->content);
  $this->assertText($term->name, 'Term name is displayed.');

  // Delete the vocabulary and verify that the widget is gone.
  taxonomy_vocabulary_delete($this->vocabulary->machine_name);
  $this->backdropGet('test-entity/add/test-bundle');
  $this->assertNoFieldByName("{$this->field_name}[$langcode]", '', 'Widget is not displayed.');
}