function TaggedWithTest::setUp

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 Drupal\simpletest\WebTestBase::$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 WizardTestBase::setUp

See also

Drupal\simpletest\WebTestBase::prepareDatabasePrefix()

Drupal\simpletest\WebTestBase::changeDatabasePrefix()

Drupal\simpletest\WebTestBase::prepareEnvironment()

File

drupal/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php, line 42
Definition of Drupal\views\Tests\Wizard\TaggedWithTest.

Class

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

Namespace

Drupal\views\Tests\Wizard

Code

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

  // 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 = entity_create('taxonomy_vocabulary', array(
    'name' => 'Views testing tags',
    'vid' => 'views_testing_tags',
  ));
  $this->tag_vocabulary
    ->save();

  // 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
            ->id(),
          '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,
  );
  field_create_instance($this->tag_instance);
  entity_get_form_display('node', $this->node_type_with_tags->type, 'default')
    ->setComponent('field_views_testing_tags', array(
    'type' => 'taxonomy_autocomplete',
  ))
    ->save();
  entity_get_display('node', $this->node_type_with_tags->type, 'default')
    ->setComponent('field_views_testing_tags', array(
    'type' => 'taxonomy_term_reference_link',
    'weight' => 10,
  ))
    ->save();
  entity_get_display('node', $this->node_type_with_tags->type, 'teaser')
    ->setComponent('field_views_testing_tags', array(
    'type' => 'taxonomy_term_reference_link',
    'weight' => 10,
  ))
    ->save();
}