You are here

protected function TaggedWithTest::setUp in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Wizard/TaggedWithTest.php \Drupal\views\Tests\Wizard\TaggedWithTest::setUp()

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

core/modules/views/src/Tests/Wizard/TaggedWithTest.php, line 71
Contains \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

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

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

  // Create the vocabulary for the tag field.
  $this->tagVocabulary = entity_create('taxonomy_vocabulary', array(
    'name' => 'Views testing tags',
    'vid' => 'views_testing_tags',
  ));
  $this->tagVocabulary
    ->save();

  // Create the tag field itself.
  $this->tagFieldName = 'field_views_testing_tags';
  $handler_settings = array(
    'target_bundles' => array(
      $this->tagVocabulary
        ->id() => $this->tagVocabulary
        ->id(),
    ),
    'auto_create' => TRUE,
  );
  $this
    ->createEntityReferenceField('node', $this->nodeTypeWithTags
    ->id(), $this->tagFieldName, NULL, 'taxonomy_term', 'default', $handler_settings, FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
  entity_get_form_display('node', $this->nodeTypeWithTags
    ->id(), 'default')
    ->setComponent($this->tagFieldName, array(
    'type' => 'entity_reference_autocomplete_tags',
  ))
    ->save();
  entity_get_display('node', $this->nodeTypeWithTags
    ->id(), 'default')
    ->setComponent($this->tagFieldName, array(
    'type' => 'entity_reference_label',
    'weight' => 10,
  ))
    ->save();
  entity_get_display('node', $this->nodeTypeWithTags
    ->id(), 'teaser')
    ->setComponent('field_views_testing_tags', array(
    'type' => 'entity_reference_label',
    'weight' => 10,
  ))
    ->save();
}