You are here

function TaggedWithTest::setUp in Views (for Drupal 7) 8.3

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

Installs Drupal with the installation profile specified in \Drupal\simpletest\WebTestBase::$profile into the prefixed database.

Afterwards, installs any additional modules specified in the static \Drupal\simpletest\WebTestBase::$modules property of each class in the class hierarchy.

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.

Overrides WizardTestBase::setUp

File

lib/Drupal/views/Tests/Wizard/TaggedWithTest.php, line 40
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',
    'machine_name' => '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->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);
}