You are here

public function TaxonomyContainerTestCase::setUp in Taxonomy container 7

Prepare environment.

Overrides DrupalWebTestCase::setUp

File

./taxonomy_container.test, line 27
Tests for taxonomy_container.module.

Class

TaxonomyContainerTestCase
Base class for all taxonomy container test cases.

Code

public function setUp() {
  parent::setUp('taxonomy', 'taxonomy_container');
  $this->user = $this
    ->drupalCreateUser(array(
    'administer content types',
    'create article content',
  ));
  $this
    ->drupalLogin($this->user);

  // Create a new vocabulary and add a few terms to it.
  $this->vocabulary = $this
    ->createVocabulary();
  $terms = array();
  for ($i = 0; $i < 9; $i++) {
    $terms[$i] = $this
      ->createTerm($this->vocabulary);
    if ($i % 3) {
      $terms[$i]->parent = array(
        $terms[$i - 1]->tid,
      );
      taxonomy_term_save($terms[$i]);
    }
  }
  $this->fieldName = 'taxonomy_container_test_field';

  // Create new taxonomy_term_reference field.
  $field = array(
    'field_name' => $this->fieldName,
    'type' => 'taxonomy_term_reference',
    'cardinality' => 1,
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $this->vocabulary->machine_name,
          'parent' => 0,
        ),
      ),
    ),
  );
  field_create_field($field);

  // Create new instans of taxonomy_term_reference field.
  $this->instance = array(
    'field_name' => $this->fieldName,
    'label' => 'Taxonomy container test field',
    'bundle' => 'article',
    'entity_type' => 'node',
    'required' => 1,
    'widget' => array(
      'settings' => array(
        'prefix' => '+',
      ),
      'type' => 'options_select',
    ),
    'display' => array(
      'default' => array(
        'type' => 'taxonomy_term_reference_link',
      ),
    ),
  );
  field_create_instance($this->instance);
}