You are here

public function ViewsUIWizardTaggedWithTestCase::setUp in Views (for Drupal 7) 7.3

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 ViewsUIWizardHelper::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

tests/views_ui.test, line 320
Tests Views UI Wizard.

Class

ViewsUIWizardTaggedWithTestCase
Tests the ability of the views wizard to create views filtered by taxonomy.

Code

public function setUp(array $modules = array()) {
  parent::setUp($modules);

  // Create two content types. One will have an autocomplete tagging field,
  // and one won't.
  $this->node_type_with_tags = $this
    ->drupalCreateContentType();
  $this->node_type_without_tags = $this
    ->drupalCreateContentType();

  // Create the vocabulary for the tag field.
  $this->tag_vocabulary = new stdClass();
  $this->tag_vocabulary->name = 'Views testing tags';
  $this->tag_vocabulary->machine_name = 'views_testing_tags';
  taxonomy_vocabulary_save($this->tag_vocabulary);

  // Create the tag field itself.
  $this->tag_field = array(
    'field_name' => 'field_views_testing_tags',
    'type' => 'taxonomy_term_reference',
    'cardinality' => FIELD_CARDINALITY_UNLIMITED,
    'settings' => array(
      'allowed_values' => array(
        array(
          'vocabulary' => $this->tag_vocabulary->machine_name,
          'parent' => 0,
        ),
      ),
    ),
  );
  field_create_field($this->tag_field);

  // Create an instance of the tag field on one of the content types, and
  // configure it to display an autocomplete widget.
  $this->tag_instance = array(
    'field_name' => 'field_views_testing_tags',
    'entity_type' => 'node',
    'bundle' => $this->node_type_with_tags->type,
    'widget' => array(
      'type' => 'taxonomy_autocomplete',
    ),
    'display' => array(
      'default' => array(
        'type' => 'taxonomy_term_reference_link',
        'weight' => 10,
      ),
      'teaser' => array(
        'type' => 'taxonomy_term_reference_link',
        'weight' => 10,
      ),
    ),
  );
  field_create_instance($this->tag_instance);
}