You are here

protected function RangeViewsBaseTestCase::setUp in Range 7

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

See also

DrupalWebTestCase::prepareDatabasePrefix()

DrupalWebTestCase::changeDatabasePrefix()

DrupalWebTestCase::prepareEnvironment()

File

tests/views/range.views.base.test, line 53
Contains range views base test class.

Class

RangeViewsBaseTestCase
Base class for testing range views handlers.

Code

protected function setUp(array $modules = array()) {
  $modules[] = 'range';
  $modules[] = 'search_api';
  $modules[] = 'search_api_db';
  $modules[] = 'search_api_views';
  $modules[] = 'views';
  parent::setUp($modules);

  // Add a date field to page nodes.
  $content_type = new stdClass();
  $content_type->type = $this->contentType;
  $content_type->name = $this->contentType;
  $content_type->base = 'node_content';
  $content_type->custom = 1;
  $content_type->locked = 0;
  $content_type->modified = 1;
  node_type_save($content_type);
  node_types_rebuild();
  menu_rebuild();

  // Reset permissions so that permissions for this content type are available.
  $this
    ->checkPermissions(array(), TRUE);
  $field = array(
    'field_name' => $this->fieldName,
    'type' => 'range_integer',
    'cardinality' => 1,
    'settings' => array(),
  );
  field_create_field($field);
  $instance = array(
    'field_name' => $this->fieldName,
    'entity_type' => $this->entityTypeId,
    'bundle' => $this->contentType,
    'label' => $this
      ->randomName(),
  );
  field_create_instance($instance);

  // Add some basic test nodes.
  $ranges = array(
    array(
      'from' => 0,
      'to' => 10,
    ),
    array(
      'from' => 5,
      'to' => 9,
    ),
    array(
      'from' => -5,
      'to' => 15,
    ),
    array(
      'from' => 6,
      'to' => 10,
    ),
  );
  foreach ($ranges as $range) {
    $this->nodes[] = $this
      ->drupalCreateNode(array(
      'type' => $this->contentType,
      $this->fieldName => array(
        LANGUAGE_NONE => array(
          $range,
        ),
      ),
    ));
  }
}