You are here

public function SearchApiSortsTest::setUp in Search API sorts 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

./search_api_sorts.test, line 19

Class

SearchApiSortsTest
Class for testing search api sorts capabilities.

Code

public function setUp() {
  parent::setUp('entity', 'search_api', 'search_api_db', 'search_api_sorts');
  $this
    ->drupalLogin($this
    ->drupalCreateUser(array(
    'administer search_api',
  )));

  // Create Search Api DB Server.
  $edit = array(
    'name' => 'TestSearchApiDB Server',
    'machine_name' => 'testserver',
    'enabled' => TRUE,
    'class' => 'search_api_db_service',
  );
  $this
    ->drupalPost('admin/config/search/search_api/add_server', $edit, t('Create server'));
  $this
    ->drupalPost(NULL, array(), t('Create server'));
  $this
    ->assertText(t('The server was successfully created.'));

  // Create Search Api Index.
  $values = array(
    'name' => 'TestSearchApi Index',
    'machine_name' => 'testindex',
    'item_type' => 'node',
    'options' => array(
      'datasource' => array(
        'bundles' => array(),
      ),
      'index_directly' => 1,
      'cron_limit' => 50,
    ),
    'enabled' => 1,
    'description' => 'An index used for testing.',
    'server' => 'testserver',
    'read_only' => 0,
    'old_type' => 'node',
    'datasource_config' => TRUE,
  );
  $index = entity_create('search_api_index', $values);
  $index->is_new = TRUE;
  $index
    ->save();

  // Select fields to index.
  $edit = array(
    'fields[type][indexed]' => TRUE,
    'fields[type][type]' => 'string',
    'fields[title][indexed]' => TRUE,
    'fields[title][type]' => 'string',
    'fields[created][indexed]' => TRUE,
    'fields[created][type]' => 'date',
    'fields[changed][indexed]' => TRUE,
    'fields[changed][type]' => 'integer',
    'fields[url][indexed]' => TRUE,
    'fields[url][type]' => 'uri',
    'fields[status][indexed]' => TRUE,
    'fields[status][type]' => 'boolean',
    'fields[edit_url][indexed]' => TRUE,
    'fields[edit_url][type]' => 'text',
    'fields[edit_url][boost]' => '1.0',
  );
  $this
    ->drupalPost('admin/config/search/search_api/index/testindex/fields', $edit, t('Save changes'));
  $this
    ->drupalGet('admin/config/search/search_api/index/testindex/fields');
}