function ApiDataTest::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 FieldTestBase::setUp

See also

Drupal\simpletest\WebTestBase::prepareDatabasePrefix()

Drupal\simpletest\WebTestBase::changeDatabasePrefix()

Drupal\simpletest\WebTestBase::prepareEnvironment()

File

drupal/core/modules/field/lib/Drupal/field/Tests/Views/ApiDataTest.php, line 28
Contains \Drupal\field\Tests\Views\ApiDataTest.

Class

ApiDataTest
Test the produced views_data.

Namespace

Drupal\field\Tests\Views

Code

function setUp() {
  parent::setUp();
  $field_names = $this
    ->setUpFields();

  // The first one will be attached to nodes only.
  $instance = array(
    'field_name' => $field_names[0],
    'entity_type' => 'node',
    'bundle' => 'page',
  );
  field_create_instance($instance);

  // The second one will be attached to users only.
  $instance = array(
    'field_name' => $field_names[1],
    'entity_type' => 'user',
    'bundle' => 'user',
  );
  field_create_instance($instance);

  // The third will be attached to both nodes and users.
  $instance = array(
    'field_name' => $field_names[2],
    'entity_type' => 'node',
    'bundle' => 'page',
  );
  field_create_instance($instance);
  $instance = array(
    'field_name' => $field_names[2],
    'entity_type' => 'user',
    'bundle' => 'user',
  );
  field_create_instance($instance);

  // Now create some example nodes/users for the view result.
  for ($i = 0; $i < 5; $i++) {
    $edit = array(
      'field_name_0' => array(
        array(
          'value' => $this
            ->randomName(),
        ),
      ),
      'field_name_2' => array(
        array(
          'value' => $this
            ->randomName(),
        ),
      ),
    );
    $this->nodes[] = $this
      ->drupalCreateNode($edit);
  }
  $this->container
    ->get('views.views_data')
    ->clear();
}