You are here

function TaxonomyTermFieldTestCase::testTaxonomyTermFieldWidgets in Drupal 7

Test widgets.

File

modules/taxonomy/taxonomy.test, line 1541
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
    ->drupalGet('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
    ->drupalPost(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 = drupal_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->vid);
  $this
    ->drupalGet('test-entity/add/test-bundle');
  $this
    ->assertNoFieldByName("{$this->field_name}[{$langcode}]", '', 'Widget is not displayed.');
}