function TermFieldTest::testTaxonomyTermFieldWidgets

Test widgets.

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php, line 105
Definition of Drupal\taxonomy\Tests\TermFieldTest.

Class

TermFieldTest
Tests for taxonomy term field and formatter.

Namespace

Drupal\taxonomy\Tests

Code

function testTaxonomyTermFieldWidgets() {

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

  // Display creation form.
  $langcode = LANGUAGE_NOT_SPECIFIED;
  $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
    ->label(), 'Term label 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');
}