You are here

public function viewsFieldApiDataTest::setUp in Views (for Drupal 7) 7.3

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 DrupalWebTestCase::$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 ViewsSqlTest::setUp

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

tests/field/views_fieldapi.test, line 125
Tests the fieldapi integration of viewsdata.

Class

viewsFieldApiDataTest
Test the produced views_data.

Code

public function setUp(array $modules = array()) {
  parent::setUp($modules);
  $langcode = LANGUAGE_NONE;
  $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(
      // @todo Write a helper method to create such values.
      'field_name_0' => array(
        $langcode => array(
          array(
            'value' => $this
              ->randomName(),
          ),
        ),
      ),
      'field_name_2' => array(
        $langcode => array(
          array(
            'value' => $this
              ->randomName(),
          ),
        ),
      ),
    );
    $this->nodes[] = $this
      ->drupalCreateNode($edit);
  }
  for ($i = 0; $i < 5; $i++) {
    $edit = array(
      'field_name_1' => array(
        $langcode => array(
          array(
            'value' => $this
              ->randomName(),
          ),
        ),
      ),
      'field_name_2' => array(
        $langcode => array(
          array(
            'value' => $this
              ->randomName(),
          ),
        ),
      ),
    );
    $this->users[] = $this
      ->createUser($edit);
  }

  // Reset views data cache.
  $this
    ->clearViewsCaches();
}