public function TaxonomyTermReferenceItemTest::setUp

Set the default field storage backend for fields created during tests.

Overrides FieldUnitTestBase::setUp

File

drupal/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php, line 35
Contains \Drupal\taxonomy\Tests\TaxonomyTermReferenceItemTest.

Class

TaxonomyTermReferenceItemTest
Tests the new entity API for the taxonomy term reference field type.

Namespace

Drupal\taxonomy\Tests

Code

public function setUp() {
  parent::setUp();
  $this
    ->installSchema('taxonomy', 'taxonomy_term_data');
  $this
    ->installSchema('taxonomy', 'taxonomy_term_hierarchy');
  $vocabulary = entity_create('taxonomy_vocabulary', array(
    'name' => $this
      ->randomName(),
    'vid' => drupal_strtolower($this
      ->randomName()),
    'langcode' => Language::LANGCODE_NOT_SPECIFIED,
  ));
  $vocabulary
    ->save();
  $field = array(
    'field_name' => 'field_test_taxonomy',
    'type' => 'taxonomy_term_reference',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $vocabulary
            ->id(),
          'parent' => 0,
        ),
      ),
    ),
  );
  field_create_field($field);
  $instance = array(
    'entity_type' => 'entity_test',
    'field_name' => 'field_test_taxonomy',
    'bundle' => 'entity_test',
  );
  field_create_instance($instance);
  $this->term = entity_create('taxonomy_term', array(
    'name' => $this
      ->randomName(),
    'vid' => $vocabulary
      ->id(),
    'langcode' => Language::LANGCODE_NOT_SPECIFIED,
  ));
  $this->term
    ->save();
}