You are here

function TaxonomyTermIndexTestCase::setUp in Drupal 7

Sets up a Drupal site for running functional and integration tests.

Generates a random database prefix and installs Drupal with the specified installation profile in DrupalWebTestCase::$profile into the prefixed database. Afterwards, installs any additional modules specified by the test.

After installation all caches are flushed and several configuration values are reset to the values of the parent site executing the test, since the default values may be incompatible with the environment in which tests are being executed.

Parameters

...: List of modules to enable for the duration of the test. This can be either a single array or a variable number of string arguments.

Overrides DrupalWebTestCase::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

modules/taxonomy/taxonomy.test, line 1120
Tests for taxonomy.module.

Class

TaxonomyTermIndexTestCase
Tests the hook implementations that maintain the taxonomy index.

Code

function setUp() {
  parent::setUp('taxonomy');

  // Create an administrative user.
  $this->admin_user = $this
    ->drupalCreateUser(array(
    'administer taxonomy',
    'bypass node access',
  ));
  $this
    ->drupalLogin($this->admin_user);

  // Create a vocabulary and add two term reference fields to article nodes.
  $this->vocabulary = $this
    ->createVocabulary();
  $this->field_name_1 = drupal_strtolower($this
    ->randomName());
  $this->field_1 = array(
    'field_name' => $this->field_name_1,
    'type' => 'taxonomy_term_reference',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $this->vocabulary->machine_name,
          'parent' => 0,
        ),
      ),
    ),
  );
  field_create_field($this->field_1);
  $this->instance_1 = array(
    'field_name' => $this->field_name_1,
    'bundle' => 'article',
    'entity_type' => 'node',
    'widget' => array(
      'type' => 'options_select',
    ),
    'display' => array(
      'default' => array(
        'type' => 'taxonomy_term_reference_link',
      ),
    ),
  );
  field_create_instance($this->instance_1);
  $this->field_name_2 = drupal_strtolower($this
    ->randomName());
  $this->field_2 = array(
    'field_name' => $this->field_name_2,
    'type' => 'taxonomy_term_reference',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $this->vocabulary->machine_name,
          'parent' => 0,
        ),
      ),
    ),
  );
  field_create_field($this->field_2);
  $this->instance_2 = array(
    'field_name' => $this->field_name_2,
    'bundle' => 'article',
    'entity_type' => 'node',
    'widget' => array(
      'type' => 'options_select',
    ),
    'display' => array(
      'default' => array(
        'type' => 'taxonomy_term_reference_link',
      ),
    ),
  );
  field_create_instance($this->instance_2);
}