You are here

function TagadelicServiceTest::setUp in Tagadelic 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 WebTestBase::setUp

File

src/Tests/TagadelicServiceTest.php, line 38

Class

TagadelicServiceTest
Tests for tagadelic service.

Namespace

Drupal\tagadelic\Tests

Code

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

  // Create an article content type
  $this
    ->drupalCreateContentType(array(
    'type' => 'article',
  ));

  // Create the vocabulary for the tag field.
  $this->vocabulary = Vocabulary::create(array(
    'name' => 'Views testing tags',
    'vid' => 'views_testing_tags',
  ));
  $this->vocabulary
    ->save();
  $field_name = 'field_' . $this->vocabulary
    ->id();
  $handler_settings = array(
    'target_bundles' => array(
      $this->vocabulary
        ->id() => $this->vocabulary
        ->id(),
    ),
    'auto_create' => TRUE,
  );

  // Create the tag field
  if (!FieldStorageConfig::loadByName('node', $field_name)) {
    FieldStorageConfig::create(array(
      'field_name' => $field_name,
      'type' => 'entity_reference',
      'entity_type' => 'node',
      'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
      'settings' => array(
        'target_type' => 'taxonomy_term',
      ),
    ))
      ->save();
  }
  if (!FieldConfig::loadByName('node', 'article', $field_name)) {
    $handler_settings = array(
      'target_bundles' => array(
        $this->vocabulary
          ->id() => $this->vocabulary
          ->id(),
      ),
      'auto_create' => TRUE,
    );
    FieldConfig::create(array(
      'field_name' => $field_name,
      'entity_type' => 'node',
      'bundle' => 'article',
      'label' => 'Tags',
      'settings' => array(
        'handler' => 'default',
        'handler_settings' => $handler_settings,
      ),
    ))
      ->save();
  }
  entity_get_form_display('node', 'article', 'default')
    ->setComponent($field_name, array(
    'type' => 'entity_reference_autocomplete_tags',
    'weight' => -4,
  ))
    ->save();
  entity_get_display('node', 'article', 'default')
    ->setComponent($field_name, array(
    'type' => 'entity_reference_label',
    'weight' => 10,
  ))
    ->save();
  entity_get_display('node', 'article', 'teaser')
    ->setComponent($field_name, array(
    'type' => 'entity_reference_label',
    'weight' => 10,
  ))
    ->save();
}