You are here

class SearchApiDbTest in Search API Database Search 7

Class for testing index and search capabilities using the Database search module.

Hierarchy

Expanded class hierarchy of SearchApiDbTest

File

./search_api_db.test, line 7

View source
class SearchApiDbTest extends DrupalWebTestCase {
  protected $server_id;
  protected $index_id;
  protected function assertText($text, $message = '', $group = 'Other') {
    return parent::assertText($text, $message ? $message : $text, $group);
  }
  protected function drupalGet($path, array $options = array(), array $headers = array()) {
    $ret = parent::drupalGet($path, $options, $headers);
    $this
      ->assertResponse(200, t('HTTP code 200 returned.'));
    return $ret;
  }
  protected function drupalPost($path, $edit, $submit, array $options = array(), array $headers = array(), $form_html_id = NULL, $extra_post = NULL) {
    $ret = parent::drupalPost($path, $edit, $submit, $options, $headers, $form_html_id, $extra_post);
    $this
      ->assertResponse(200, t('HTTP code 200 returned.'));
    return $ret;
  }
  public static function getInfo() {
    return array(
      'name' => 'Test "Database search" module',
      'description' => 'Tests indexing and searching with the "Database search" module.',
      'group' => 'Search API Database Search',
    );
  }
  public function setUp() {
    parent::setUp('entity', 'search_api', 'search_api_db', 'search_api_test');
  }
  public function testFramework() {
    if (Database::getConnection()
      ->databaseType() == 'mysql') {
      try {
        db_query("SET SESSION sql_mode = 'ANSI,ONLY_FULL_GROUP_BY'");
      } catch (Exception $e) {

        // It was worth a try, but if it fails just go on.
      }
    }
    $this
      ->drupalLogin($this
      ->drupalCreateUser(array(
      'administer search_api',
    )));
    $this
      ->insertItems();
    $this
      ->createServer();
    $this
      ->createIndex();
    $this
      ->searchNoResults();
    $this
      ->indexItems();
    $this
      ->searchSuccess1();
    $this
      ->checkFacets();
    $this
      ->regressionTests();
    $this
      ->editServerPartial();
    $this
      ->searchSuccessPartial();
    $this
      ->editServer();
    $this
      ->searchSuccess2();
    $this
      ->clearIndex();
    $this
      ->searchNoResults();
    $this
      ->regressionTests2();
    $this
      ->uninstallModule();
  }
  protected function insertItems() {
    $this
      ->drupalGet('search_api_test/insert');
    $count = db_query('SELECT COUNT(*) FROM {search_api_test}')
      ->fetchField();
    $this
      ->insertItem(array(
      'id' => 1,
      'title' => 'foo bar baz foobaz',
      'body' => 'test test',
      'type' => 'item',
      'keywords' => 'orange',
    ));
    $this
      ->insertItem(array(
      'id' => 2,
      'title' => 'foo test foobuz',
      'body' => 'bar test',
      'type' => 'item',
      'keywords' => 'orange,apple,grape',
    ));
    $this
      ->insertItem(array(
      'id' => 3,
      'title' => 'bar',
      'body' => 'test foobar',
    ));
    $this
      ->insertItem(array(
      'id' => 4,
      'title' => 'foo baz',
      'body' => 'test test test',
      'type' => 'article',
      'keywords' => 'apple,strawberry,grape',
    ));
    $this
      ->insertItem(array(
      'id' => 5,
      'title' => 'bar baz',
      'body' => 'foo',
      'type' => 'article',
      'keywords' => 'orange,strawberry,grape,banana,orange,Orange',
    ));
    $count = db_query('SELECT COUNT(*) FROM {search_api_test}')
      ->fetchField() - $count;
    $this
      ->assertEqual($count, 5, "{$count} items inserted.");
  }
  protected function insertItem($values) {
    $this
      ->drupalPost(NULL, $values, t('Save'));
  }
  protected function createServer() {
    $this->server_id = 'database_search_server';
    global $databases;
    $database = 'default:default';

    // Make sure to pick an available connection and to not rely on any
    // defaults.
    foreach ($databases as $key => $targets) {
      foreach ($targets as $target => $info) {
        $database = "{$key}:{$target}";
        break;
      }
    }
    $values = array(
      'name' => 'Database search server',
      'machine_name' => $this->server_id,
      'enabled' => 1,
      'description' => 'A server used for testing.',
      'class' => 'search_api_db_service',
      'options' => array(
        'min_chars' => 3,
        'database' => $database,
        'partial_matches' => FALSE,
      ),
    );
    $success = (bool) entity_create('search_api_server', $values)
      ->save();
    $this
      ->assertTrue($success, 'The server was successfully created.');
  }
  protected function createIndex() {
    $this->index_id = 'test_index';
    $values = array(
      'name' => 'Test index',
      'machine_name' => $this->index_id,
      'item_type' => 'search_api_test',
      'enabled' => 1,
      'description' => 'An index used for testing.',
      'server' => $this->server_id,
      'options' => array(
        'cron_limit' => -1,
        'index_directly' => TRUE,
        'fields' => array(
          'id' => array(
            'type' => 'integer',
          ),
          'title' => array(
            'type' => 'text',
            'boost' => '5.0',
          ),
          'body' => array(
            'type' => 'text',
          ),
          'type' => array(
            'type' => 'string',
          ),
          'keywords' => array(
            'type' => 'list<string>',
          ),
          'search_api_language' => array(
            'type' => 'string',
          ),
        ),
      ),
    );
    $index = entity_create('search_api_index', $values);
    $success = (bool) $index
      ->save();
    $this
      ->assertTrue($success, 'The index was successfully created.');
    $status = search_api_index_status($index);
    $this
      ->assertEqual($status['total'], 5, 'Correct item count.');
    $this
      ->assertEqual($status['indexed'], 0, 'All items still need to be indexed.');
  }
  protected function buildSearch($keys = NULL, array $filters = array(), array $fields = array()) {
    $query = search_api_query($this->index_id);
    if ($keys) {
      $query
        ->keys($keys);
      if ($fields) {
        $query
          ->fields($fields);
      }
    }
    foreach ($filters as $filter) {
      list($field, $value) = explode(',', $filter, 2);
      $query
        ->condition($field, $value);
    }
    $query
      ->range(0, 10);
    return $query;
  }
  protected function searchNoResults() {
    $results = $this
      ->buildSearch('test')
      ->execute();
    $this
      ->assertEqual($results['result count'], 0, 'No search results returned without indexing.');
    $this
      ->assertEqual(array_keys($results['results']), array(), 'No search results returned without indexing.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
  }
  protected function indexItems() {
    search_api_index_items(search_api_index_load($this->index_id));
  }
  protected function searchSuccess1() {
    $results = $this
      ->buildSearch('test')
      ->range(1, 2)
      ->execute();
    $this
      ->assertEqual($results['result count'], 4, 'Search for »test« returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      4,
      1,
    ), 'Search for »test« returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $results = $this
      ->buildSearch('test foo')
      ->execute();
    $this
      ->assertEqual($results['result count'], 3, 'Search for »test foo« returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      2,
      4,
      1,
    ), 'Search for »test foo« returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $results = $this
      ->buildSearch('foo', array(
      'type,item',
    ))
      ->sort('id', 'ASC')
      ->execute();
    $this
      ->assertEqual($results['result count'], 2, 'Search for »foo« returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
    ), 'Search for »foo« returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $keys = array(
      '#conjunction' => 'AND',
      'test',
      array(
        '#conjunction' => 'OR',
        'baz',
        'foobar',
      ),
      array(
        '#conjunction' => 'OR',
        '#negation' => TRUE,
        'bar',
        'fooblob',
      ),
    );
    $results = $this
      ->buildSearch($keys)
      ->execute();
    $this
      ->assertEqual($results['result count'], 1, 'Complex search 1 returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      4,
    ), 'Complex search 1 returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $query = $this
      ->buildSearch()
      ->sort('id');
    $filter = $query
      ->createFilter('OR');
    $filter
      ->condition('title', 'bar');
    $filter
      ->condition('body', 'bar');
    $query
      ->filter($filter);
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 4, 'Search with multi-field fulltext filter returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
      3,
      5,
    ), 'Search with multi-field fulltext filter returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
  }
  protected function checkFacets() {
    $query = $this
      ->buildSearch();
    $filter = $query
      ->createFilter('OR', array(
      'facet:type',
    ));
    $filter
      ->condition('type', 'article');
    $query
      ->filter($filter);
    $facets['type'] = array(
      'field' => 'type',
      'limit' => 0,
      'min_count' => 1,
      'missing' => TRUE,
      'operator' => 'or',
    );
    $query
      ->setOption('search_api_facets', $facets);
    $query
      ->range(0, 0);
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 2, 'OR facets query returned correct number of results.');
    $expected = array(
      array(
        'count' => 2,
        'filter' => '"article"',
      ),
      array(
        'count' => 2,
        'filter' => '"item"',
      ),
      array(
        'count' => 1,
        'filter' => '!',
      ),
    );
    usort($results['search_api_facets']['type'], array(
      $this,
      'facetCompare',
    ));
    $this
      ->assertEqual($results['search_api_facets']['type'], $expected, 'Correct OR facets were returned');
    $query = $this
      ->buildSearch();
    $filter = $query
      ->createFilter('OR', array(
      'facet:type',
    ));
    $filter
      ->condition('type', 'article');
    $query
      ->filter($filter);
    $filter = $query
      ->createFilter('AND');
    $filter
      ->condition('type', NULL, '<>');
    $query
      ->filter($filter);
    $facets['type'] = array(
      'field' => 'type',
      'limit' => 0,
      'min_count' => 1,
      'missing' => TRUE,
      'operator' => 'or',
    );
    $query
      ->setOption('search_api_facets', $facets);
    $query
      ->range(0, 0);
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 2, 'OR facets query returned correct number of results.');
    $expected = array(
      array(
        'count' => 2,
        'filter' => '"article"',
      ),
      array(
        'count' => 2,
        'filter' => '"item"',
      ),
    );
    usort($results['search_api_facets']['type'], array(
      $this,
      'facetCompare',
    ));
    $this
      ->assertEqual($results['search_api_facets']['type'], $expected, 'Correct OR facets were returned');
    $query = $this
      ->buildSearch();
    $filter = $query
      ->createFilter('OR', array(
      'facet:type',
    ));
    $filter
      ->condition('type', 'article');
    $query
      ->filter($filter);
    $facets['type'] = array(
      'field' => 'type',
      'limit' => 0,
      'min_count' => 2,
      'missing' => TRUE,
      'operator' => 'or',
    );
    $query
      ->setOption('search_api_facets', $facets);
    $query
      ->range(0, 0);
    $results = $query
      ->execute();
    $expected = array(
      array(
        'count' => 2,
        'filter' => '"article"',
      ),
      array(
        'count' => 2,
        'filter' => '"item"',
      ),
    );
    usort($results['search_api_facets']['type'], array(
      $this,
      'facetCompare',
    ));
    $this
      ->assertEqual($results['search_api_facets']['type'], $expected, 'Correct OR facets were returned with min_count');
    $query = $this
      ->buildSearch();
    $filter = $query
      ->createFilter('OR', array(
      'facet:type',
    ));
    $filter
      ->condition('type', 'article');
    $query
      ->filter($filter);
    $filter = $query
      ->createFilter('AND');
    $filter
      ->condition('type', NULL, '<>');
    $query
      ->filter($filter);
    $facets['type'] = array(
      'field' => 'type',
      'limit' => 0,
      'min_count' => 2,
      'missing' => TRUE,
      'operator' => 'or',
    );
    $query
      ->setOption('search_api_facets', $facets);
    $query
      ->range(0, 0);
    $results = $query
      ->execute();
    $expected = array(
      array(
        'count' => 2,
        'filter' => '"article"',
      ),
      array(
        'count' => 2,
        'filter' => '"item"',
      ),
    );
    usort($results['search_api_facets']['type'], array(
      $this,
      'facetCompare',
    ));
    $this
      ->assertEqual($results['search_api_facets']['type'], $expected, 'Correct OR facets were returned with min_count');
  }
  protected function editServer() {
    $server = search_api_server_load($this->server_id, TRUE);
    $server->options['min_chars'] = 4;
    $server->options['partial_matches'] = FALSE;
    $success = (bool) $server
      ->save();
    $this
      ->assertTrue($success, 'The server was successfully edited.');
    $this
      ->clearIndex();
    $this
      ->indexItems();

    // Reset the internal cache so the new values will be available.
    search_api_index_load($this->index_id, TRUE);
  }
  protected function searchSuccess2() {
    $results = $this
      ->buildSearch('test')
      ->range(1, 2)
      ->execute();
    $this
      ->assertEqual($results['result count'], 4, 'Search for »test« returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      4,
      1,
    ), 'Search for »test« returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $query = $this
      ->buildSearch()
      ->sort('id');
    $filter = $query
      ->createFilter('OR');
    $filter
      ->condition('title', 'test');
    $filter
      ->condition('body', 'test');
    $query
      ->filter($filter);
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 4, 'Search with multi-field fulltext filter returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
      3,
      4,
    ), 'Search with multi-field fulltext filter returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $results = $this
      ->buildSearch(NULL, array(
      'body,test foobar',
    ))
      ->execute();
    $this
      ->assertEqual($results['result count'], 1, 'Search with multi-term fulltext filter returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      3,
    ), 'Search with multi-term fulltext filter returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $results = $this
      ->buildSearch('test foo')
      ->execute();
    $this
      ->assertEqual($results['result count'], 4, 'Search for »test foo« returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      2,
      4,
      1,
      3,
    ), 'Search for »test foo« returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(
      'foo',
    ), 'Short key was ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $results = $this
      ->buildSearch('foo', array(
      'type,item',
    ))
      ->execute();
    $this
      ->assertEqual($results['result count'], 2, 'Search for »foo« returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
    ), 'Search for »foo« returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(
      'foo',
    ), 'Short key was ignored.');
    $this
      ->assertEqual($results['warnings'], array(
      t('No valid search keys were present in the query.'),
    ), 'No warnings were displayed.');
    $keys = array(
      '#conjunction' => 'AND',
      'test',
      array(
        '#conjunction' => 'OR',
        'baz',
        'foobar',
      ),
      array(
        '#conjunction' => 'OR',
        '#negation' => TRUE,
        'bar',
        'fooblob',
      ),
    );
    $results = $this
      ->buildSearch($keys)
      ->execute();
    $this
      ->assertEqual($results['result count'], 1, 'Complex search 1 returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      3,
    ), 'Complex search 1 returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(
      'baz',
      'bar',
    ), 'Correct keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $keys = array(
      '#conjunction' => 'AND',
      'test',
      array(
        '#conjunction' => 'OR',
        'baz',
        'foobar',
      ),
      array(
        '#conjunction' => 'OR',
        '#negation' => TRUE,
        'bar',
        'fooblob',
      ),
    );
    $results = $this
      ->buildSearch($keys)
      ->execute();
    $this
      ->assertEqual($results['result count'], 1, 'Complex search 2 returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      3,
    ), 'Complex search 2 returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(
      'baz',
      'bar',
    ), 'Correct keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $results = $this
      ->buildSearch(NULL, array(
      'keywords,orange',
    ))
      ->execute();
    $this
      ->assertEqual($results['result count'], 3, 'Filter query 1 on multi-valued field returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
      5,
    ), 'Filter query 1 on multi-valued field returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'Warning displayed.');
    $results = $this
      ->buildSearch()
      ->condition('keywords', 'orange', '<>')
      ->execute();
    $this
      ->assertEqual($results['result count'], 2, 'Negated filter on multi-valued field returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      3,
      4,
    ), 'Negated filter on multi-valued field returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'Warning displayed.');
    $filters = array(
      'keywords,orange',
      'keywords,apple',
    );
    $results = $this
      ->buildSearch(NULL, $filters)
      ->execute();
    $this
      ->assertEqual($results['result count'], 1, 'Filter query 2 on multi-valued field returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      2,
    ), 'Filter query 2 on multi-valued field returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $results = $this
      ->buildSearch()
      ->condition('keywords', NULL)
      ->execute();
    $this
      ->assertEqual($results['result count'], 1, 'Query with NULL filter returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      3,
    ), 'Query with NULL filter returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $results = $this
      ->buildSearch()
      ->condition('keywords', NULL, '<>')
      ->execute();
    $this
      ->assertEqual($results['result count'], 4, 'Query with NOT NULL filter returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
      4,
      5,
    ), 'Query with NOT NULL filter returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
  }

  /**
   * Edits the server to enable partial matches.
   *
   * @param bool $enable
   *   (optional) Whether partial matching should be enabled or disabled.
   */
  protected function editServerPartial($enable = TRUE) {
    $server = search_api_server_load($this->server_id, TRUE);
    $server->options['partial_matches'] = $enable;
    $success = (bool) $server
      ->save();
    $this
      ->assertTrue($success, 'The server was successfully edited.');

    // Reset the internal cache so the index won't use the old server.
    search_api_index_load($this->index_id, TRUE);
  }

  /**
   * Tests whether partial searches work.
   */
  protected function searchSuccessPartial() {
    $results = $this
      ->buildSearch('foobaz')
      ->range(0, 1)
      ->execute();
    $this
      ->assertEqual($results['result count'], 1, 'Partial search for »foobaz« returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
    ), 'Partial search for »foobaz« returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $results = $this
      ->buildSearch('foo')
      ->sort('search_api_relevance', 'DESC')
      ->sort('id', 'ASC')
      ->execute();
    $this
      ->assertEqual($results['result count'], 5, 'Partial search for »foo« returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
      4,
      3,
      5,
    ), 'Partial search for »foo« returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $results = $this
      ->buildSearch('foo', array(
      'type,item',
    ))
      ->sort('id', 'DESC')
      ->execute();
    $this
      ->assertEqual($results['result count'], 2, 'Partial search for »foo« of type »item« returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      2,
      1,
    ), 'Partial search for »foo« of type »item« returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $query = $this
      ->buildSearch()
      ->sort('id');
    $filter = $query
      ->createFilter('OR');
    $filter
      ->condition('title', 'test');
    $filter
      ->condition('body', 'test');
    $query
      ->filter($filter);
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 4, 'Partial search with multi-field fulltext filter returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
      3,
      4,
    ), 'Partial search with multi-field fulltext filter returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
  }

  /**
   * Executes regression tests for issues that were already fixed.
   */
  protected function regressionTests() {

    // Regression tests for #2007872.
    $results = $this
      ->buildSearch('test')
      ->sort('id', 'ASC')
      ->sort('type', 'ASC')
      ->execute();
    $this
      ->assertEqual($results['result count'], 4, 'Sorting on field with NULLs returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
      3,
      4,
    ), 'Sorting on field with NULLs returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $query = $this
      ->buildSearch();
    $filter = $query
      ->createFilter('OR');
    $filter
      ->condition('id', 3);
    $filter
      ->condition('type', 'article');
    $query
      ->filter($filter);
    $query
      ->sort('id', 'ASC');
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 3, 'OR filter on field with NULLs returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      3,
      4,
      5,
    ), 'OR filter on field with NULLs returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');

    // Regression tests for #1863672.
    $query = $this
      ->buildSearch();
    $filter = $query
      ->createFilter('OR');
    $filter
      ->condition('keywords', 'orange');
    $filter
      ->condition('keywords', 'apple');
    $query
      ->filter($filter);
    $query
      ->sort('id', 'ASC');
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 4, 'OR filter on multi-valued field returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
      4,
      5,
    ), 'OR filter on multi-valued field returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $query = $this
      ->buildSearch();
    $filter = $query
      ->createFilter('OR');
    $filter
      ->condition('keywords', 'orange');
    $filter
      ->condition('keywords', 'strawberry');
    $query
      ->filter($filter);
    $filter = $query
      ->createFilter('OR');
    $filter
      ->condition('keywords', 'apple');
    $filter
      ->condition('keywords', 'grape');
    $query
      ->filter($filter);
    $query
      ->sort('id', 'ASC');
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 3, 'Multiple OR filters on multi-valued field returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      2,
      4,
      5,
    ), 'Multiple OR filters on multi-valued field returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $query = $this
      ->buildSearch();
    $filter1 = $query
      ->createFilter('OR');
    $filter = $query
      ->createFilter('AND');
    $filter
      ->condition('keywords', 'orange');
    $filter
      ->condition('keywords', 'apple');
    $filter1
      ->filter($filter);
    $filter = $query
      ->createFilter('AND');
    $filter
      ->condition('keywords', 'strawberry');
    $filter
      ->condition('keywords', 'grape');
    $filter1
      ->filter($filter);
    $query
      ->filter($filter1);
    $query
      ->sort('id', 'ASC');
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 3, 'Complex nested filters on multi-valued field returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      2,
      4,
      5,
    ), 'Complex nested filters on multi-valued field returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');

    // Regression tests for #2040543.
    $query = $this
      ->buildSearch();
    $facets['type'] = array(
      'field' => 'type',
      'limit' => 0,
      'min_count' => 1,
      'missing' => TRUE,
    );
    $query
      ->setOption('search_api_facets', $facets);
    $query
      ->range(0, 0);
    $results = $query
      ->execute();
    $expected = array(
      array(
        'count' => 2,
        'filter' => '"article"',
      ),
      array(
        'count' => 2,
        'filter' => '"item"',
      ),
      array(
        'count' => 1,
        'filter' => '!',
      ),
    );
    usort($results['search_api_facets']['type'], array(
      $this,
      'facetCompare',
    ));
    $this
      ->assertEqual($results['search_api_facets']['type'], $expected, 'Correct facets were returned');
    $query = $this
      ->buildSearch();
    $facets['type']['missing'] = FALSE;
    $query
      ->setOption('search_api_facets', $facets);
    $query
      ->range(0, 0);
    $results = $query
      ->execute();
    $expected = array(
      array(
        'count' => 2,
        'filter' => '"article"',
      ),
      array(
        'count' => 2,
        'filter' => '"item"',
      ),
    );
    usort($results['search_api_facets']['type'], array(
      $this,
      'facetCompare',
    ));
    $this
      ->assertEqual($results['search_api_facets']['type'], $expected, 'Correct facets were returned');

    // Regression tests for #2111753.
    $keys = array(
      '#conjunction' => 'OR',
      'foo',
      'test',
    );
    $query = $this
      ->buildSearch($keys, array(), array(
      'title',
    ));
    $query
      ->sort('id', 'ASC');
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 3, 'OR keywords returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
      4,
    ), 'OR keywords returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $query = $this
      ->buildSearch($keys, array(), array(
      'title',
      'body',
    ));
    $query
      ->range(0, 0);
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 5, 'Multi-field OR keywords returned correct number of results.');
    $this
      ->assertTrue(empty($results['results']), 'Multi-field OR keywords returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $keys = array(
      '#conjunction' => 'OR',
      'foo',
      'test',
      array(
        '#conjunction' => 'AND',
        'bar',
        'baz',
      ),
    );
    $query = $this
      ->buildSearch($keys, array(), array(
      'title',
    ));
    $query
      ->sort('id', 'ASC');
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 4, 'Nested OR keywords returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
      4,
      5,
    ), 'Nested OR keywords returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $keys = array(
      '#conjunction' => 'OR',
      array(
        '#conjunction' => 'AND',
        'foo',
        'test',
      ),
      array(
        '#conjunction' => 'AND',
        'bar',
        'baz',
      ),
    );
    $query = $this
      ->buildSearch($keys, array(), array(
      'title',
      'body',
    ));
    $query
      ->sort('id', 'ASC');
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 4, 'Nested multi-field OR keywords returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
      4,
      5,
    ), 'Nested multi-field OR keywords returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');

    // Regression tests for #2127001.
    $keys = array(
      '#conjunction' => 'AND',
      '#negation' => TRUE,
      'foo',
      'bar',
    );
    $results = $this
      ->buildSearch($keys)
      ->sort('search_api_id', 'ASC')
      ->execute();
    $this
      ->assertEqual($results['result count'], 2, 'Negated AND fulltext search returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      3,
      4,
    ), 'Negated AND fulltext search returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $keys = array(
      '#conjunction' => 'OR',
      '#negation' => TRUE,
      'foo',
      'baz',
    );
    $results = $this
      ->buildSearch($keys)
      ->execute();
    $this
      ->assertEqual($results['result count'], 1, 'Negated OR fulltext search returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      3,
    ), 'Negated OR fulltext search returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $keys = array(
      '#conjunction' => 'AND',
      'test',
      array(
        '#conjunction' => 'AND',
        '#negation' => TRUE,
        'foo',
        'bar',
      ),
    );
    $results = $this
      ->buildSearch($keys)
      ->sort('search_api_id', 'ASC')
      ->execute();
    $this
      ->assertEqual($results['result count'], 2, 'Nested NOT AND fulltext search returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      3,
      4,
    ), 'Nested NOT AND fulltext search returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');

    // Regression tests for #2136409
    $query = $this
      ->buildSearch();
    $query
      ->condition('type', NULL);
    $query
      ->sort('id', 'ASC');
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 1, 'NULL filter returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      3,
    ), 'NULL filter returned correct result.');
    $query = $this
      ->buildSearch();
    $query
      ->condition('type', NULL, '<>');
    $query
      ->sort('id', 'ASC');
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 4, 'NOT NULL filter returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
      4,
      5,
    ), 'NOT NULL filter returned correct result.');

    // Regression tests for #1658964.
    $query = $this
      ->buildSearch();
    $facets['type'] = array(
      'field' => 'type',
      'limit' => 0,
      'min_count' => 0,
      'missing' => TRUE,
    );
    $query
      ->setOption('search_api_facets', $facets);
    $query
      ->condition('type', 'article');
    $query
      ->range(0, 0);
    $results = $query
      ->execute();
    $expected = array(
      array(
        'count' => 2,
        'filter' => '"article"',
      ),
      array(
        'count' => 0,
        'filter' => '!',
      ),
      array(
        'count' => 0,
        'filter' => '"item"',
      ),
    );
    usort($results['search_api_facets']['type'], array(
      $this,
      'facetCompare',
    ));
    $this
      ->assertEqual($results['search_api_facets']['type'], $expected, 'Correct facets were returned');

    // Regression tests for #1403916.
    $query = $this
      ->buildSearch('test foo');
    $facets['type'] = array(
      'field' => 'type',
      'limit' => 0,
      'min_count' => 1,
      'missing' => TRUE,
    );
    $query
      ->setOption('search_api_facets', $facets);
    $query
      ->range(0, 0);
    $results = $query
      ->execute();
    $expected = array(
      array(
        'count' => 2,
        'filter' => '"item"',
      ),
      array(
        'count' => 1,
        'filter' => '"article"',
      ),
    );
    $this
      ->assertEqual($results['search_api_facets']['type'], $expected, 'Correct facets were returned');

    // Regression tests for #2305107.
    $results = $this
      ->buildSearch('test')
      ->execute();
    $expected = array(
      2 => 6,
      4 => 3,
      1 => 2,
      3 => 1,
    );
    $scores = array();
    foreach ($results['results'] as $item_id => $result) {
      $scores[$item_id] = $result['score'];
    }
    $this
      ->assertIdentical($scores, $expected, 'Correct scores were computed.');
    $this
      ->editServerPartial();
    $results = $this
      ->buildSearch('test')
      ->execute();
    $this
      ->editServerPartial(FALSE);
    $scores = array();
    foreach ($results['results'] as $item_id => $result) {
      $scores[$item_id] = $result['score'];
    }
    $this
      ->assertIdentical($scores, $expected, 'Correct scores were computed with partial matching.');
    $results = $this
      ->buildSearch('test baz')
      ->execute();
    $expected = array(
      4 => 8,
      1 => 7,
    );
    $scores = array();
    foreach ($results['results'] as $item_id => $result) {
      $scores[$item_id] = $result['score'];
    }
    $this
      ->assertIdentical($scores, $expected, 'Correct scores were computed for two keywords.');
    $this
      ->editServerPartial();
    $results = $this
      ->buildSearch('test baz')
      ->execute();
    $expected = array(
      1 => 12,
      4 => 8,
    );
    $scores = array();
    foreach ($results['results'] as $item_id => $result) {
      $scores[$item_id] = $result['score'];
    }
    $this
      ->assertIdentical($scores, $expected, 'Correct scores were computed for two keywords with partial matching.');
    $results = $this
      ->buildSearch('nonexistent baz')
      ->execute();
    $this
      ->assertEqual($results['result count'], 0, 'No incorrect results returned with partial matching.');
    $query = $this
      ->buildSearch('test');
    $facets['type'] = array(
      'field' => 'type',
      'limit' => 0,
      'min_count' => 1,
      'missing' => TRUE,
    );
    $query
      ->setOption('search_api_facets', $facets);
    $query
      ->range(0, 0);
    $results = $query
      ->execute();
    $this
      ->editServerPartial(FALSE);
    $expected = array(
      array(
        'count' => 2,
        'filter' => '"item"',
      ),
      array(
        'count' => 1,
        'filter' => '!',
      ),
      array(
        'count' => 1,
        'filter' => '"article"',
      ),
    );
    usort($results['search_api_facets']['type'], array(
      $this,
      'facetCompare',
    ));
    $this
      ->assertEqual($results['search_api_facets']['type'], $expected, 'Correct facets were returned with partial matching.');

    // Regression tests for #2469547.
    $query = $this
      ->buildSearch();
    $query
      ->condition('id', 5, '<>');
    $facets['body'] = array(
      'field' => 'body',
      'limit' => 0,
      'min_count' => 1,
      'missing' => FALSE,
    );
    $query
      ->setOption('search_api_facets', $facets);
    $query
      ->range(0, 0);
    $results = $query
      ->execute();
    $expected = array(
      array(
        'count' => 4,
        'filter' => '"test"',
      ),
      array(
        'count' => 1,
        'filter' => '"bar"',
      ),
      array(
        'count' => 1,
        'filter' => '"foobar"',
      ),
    );
    usort($results['search_api_facets']['body'], array(
      $this,
      'facetCompare',
    ));
    $this
      ->assertEqual($results['search_api_facets']['body'], $expected, 'Correct facets were returned for a fulltext field.');

    // Regression tests for #2511860.
    $query = $this
      ->buildSearch();
    $query
      ->condition('body', 'ab xy');
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 5, 'Fulltext filters on short words do not change the result.');
    $query = $this
      ->buildSearch();
    $query
      ->condition('body', 'ab ab');
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 5, 'Fulltext filters on duplicate short words do not change the result.');

    // Regression test for #2632426.
    $query = $this
      ->buildSearch();
    $query
      ->condition('type', 'unknown_type');
    $query
      ->setOption('skip result count', TRUE);
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], FALSE, 'Search for unknown type returned correct result count.');
    $this
      ->assertEqual($results['results'], array(), 'Search for unknown type returned an empty result set.');

    // Regression tests for #2566329.
    $query = $this
      ->buildSearch();
    $query
      ->condition('id', 5, '<>');
    $facets['body'] = array(
      'field' => 'body',
      'limit' => 0,
      'min_count' => 0,
      'missing' => FALSE,
    );
    $query
      ->setOption('search_api_facets', $facets);
    $query
      ->range(0, 0);
    $results = $query
      ->execute();
    $expected = array(
      array(
        'count' => 4,
        'filter' => '"test"',
      ),
      array(
        'count' => 1,
        'filter' => '"bar"',
      ),
      array(
        'count' => 1,
        'filter' => '"foobar"',
      ),
      array(
        'count' => 0,
        'filter' => '"foo"',
      ),
    );
    usort($results['search_api_facets']['body'], array(
      $this,
      'facetCompare',
    ));
    $this
      ->assertEqual($results['search_api_facets']['body'], $expected, 'Correct facets were returned for a fulltext field with minimum count 0.');
  }

  /**
   * Compares two facets for ordering.
   *
   * Used as a callback for usort() in checkFacets() and regressionTests().
   */
  public function facetCompare($a, $b) {
    if ($a['count'] != $b['count']) {
      return $b['count'] - $a['count'];
    }
    return strcasecmp($a['filter'], $b['filter']);
  }
  protected function clearIndex() {
    $success = search_api_index_load($this->index_id)
      ->clear();
    $this
      ->assertTrue($success, 'The index was successfully cleared.');
  }

  /**
   * Executes regression tests which are unpractical to run in between.
   */
  protected function regressionTests2() {

    // Regression test for #1916474.
    $index = search_api_index_load($this->index_id, TRUE);
    $index->options['fields']['prices']['type'] = 'list<decimal>';
    $success = $index
      ->save();
    $this
      ->assertTrue($success, 'The index field settings were successfully changed.');

    // Reset the internal cache so the new values will be available.
    search_api_server_load($this->server_id, TRUE);
    search_api_index_load($this->index_id, TRUE);
    $this
      ->indexItems();
    $this
      ->drupalGet('search_api_test/insert');
    $mb_string = 'äöüßáŧæøðđŋħĸµäöüßáŧæøðđŋħĸµ';
    $this
      ->insertItem(array(
      'id' => 6,
      'body' => $mb_string,
      'prices' => '3.5,3.25,3.75,3.5',
    ));
    $query = $this
      ->buildSearch(NULL, array(
      'prices,3.25',
    ));
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 1, 'Filter on decimal field returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      6,
    ), 'Filter on decimal field returned correct result.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $query = $this
      ->buildSearch(NULL, array(
      'prices,3.5',
    ));
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 1, 'Filter on decimal field returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      6,
    ), 'Filter on decimal field returned correct result.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');

    // Regression test for #2616804.
    // The word has 28 Unicode characters but 56 bytes. Verify that it was still
    // indexed correctly.
    $query = $this
      ->buildSearch($mb_string);
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 1, 'Search for word with 28 multi-byte characters returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      6,
    ), 'Search for word with 28 multi-byte characters returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $query = $this
      ->buildSearch($mb_string . 'ä');
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 0, 'Search for unknown word with 29 multi-byte characters returned no results.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');

    // Regression tests for #2745655.
    $results = $this
      ->buildSearch()
      ->condition('title', NULL)
      ->execute();

    // "Minimum chars" is 3 at this point, so all items with no longer words in
    // their titles will be returned, too.
    $this
      ->assertEqual($results['result count'], 4, 'Search for items without title returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      3,
      4,
      5,
      6,
    ), 'Search for items without title returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $results = $this
      ->buildSearch()
      ->condition('title', NULL, '<>')
      ->execute();
    $this
      ->assertEqual($results['result count'], 2, 'Search for items with title returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
    ), 'Search for items with title returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');

    // Regression tests for #2795245.
    // Make sure changing a field's type from something else to "text" works
    // correctly.
    $index->options['fields']['type']['type'] = 'text';
    $index
      ->save();
    search_api_index_items($index);
    $results = $this
      ->buildSearch()
      ->condition('type', NULL)
      ->execute();
    $this
      ->assertEqual($results['result count'], 2, 'Search for items without type returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      3,
      6,
    ), 'Search for items without type returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
    $results = $this
      ->buildSearch()
      ->condition('type', NULL, '<>')
      ->execute();
    $this
      ->assertEqual($results['result count'], 4, 'Search for items with type returned correct number of results.');
    $this
      ->assertEqual(array_keys($results['results']), array(
      1,
      2,
      4,
      5,
    ), 'Search for items with type returned correct result.');
    $this
      ->assertEqual($results['ignored'], array(), 'No keys were ignored.');
    $this
      ->assertEqual($results['warnings'], array(), 'No warnings were displayed.');
  }

  /**
   * Tests whether removing the configuration again works as it should.
   */
  protected function uninstallModule() {

    // See whether clearing the server works.
    // Regression test for #2156151.
    $server = search_api_server_load($this->server_id, TRUE);
    $server
      ->deleteItems();
    $query = $this
      ->buildSearch();
    $results = $query
      ->execute();
    $this
      ->assertEqual($results['result count'], 0, 'Clearing the server worked correctly.');
    $table = 'search_api_db_' . $this->index_id;
    $this
      ->assertTrue(db_table_exists($table), 'The index tables were left in place.');

    // Remove first the index and then the server.
    $index = search_api_index_load($this->index_id, TRUE);
    $index
      ->update(array(
      'server' => NULL,
    ));
    $server = search_api_server_load($this->server_id, TRUE);
    $this
      ->assertEqual($server->options['indexes'], array(), 'The index was successfully removed from the server.');
    $this
      ->assertFalse(db_table_exists($table), 'The index tables were deleted.');
    $server
      ->delete();

    // Uninstall the module.
    module_disable(array(
      'search_api_db',
    ), FALSE);
    $this
      ->assertFalse(module_exists('search_api_db'), 'The Database Search module was successfully disabled.');
    drupal_uninstall_modules(array(
      'search_api_db',
    ), FALSE);
    $prefix = Database::getConnection()
      ->prefixTables('{search_api_db_}') . '%';
    $this
      ->assertEqual(db_find_tables($prefix), array(), 'The Database Search module was successfully uninstalled.');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalTestCase::$assertions protected property Assertions thrown in that test case.
DrupalTestCase::$databasePrefix protected property The database prefix of this test run.
DrupalTestCase::$originalFileDirectory protected property The original file directory, before it was changed for testing purposes.
DrupalTestCase::$results public property Current results of this test case.
DrupalTestCase::$setup protected property Flag to indicate whether the test has been set up.
DrupalTestCase::$setupDatabasePrefix protected property
DrupalTestCase::$setupEnvironment protected property
DrupalTestCase::$skipClasses protected property This class is skipped when looking for the source of an assertion.
DrupalTestCase::$testId protected property The test run ID.
DrupalTestCase::$timeLimit protected property Time limit for the test.
DrupalTestCase::$useSetupInstallationCache public property Whether to cache the installation part of the setUp() method.
DrupalTestCase::$useSetupModulesCache public property Whether to cache the modules installation part of the setUp() method.
DrupalTestCase::$verboseDirectoryUrl protected property URL to the verbose output file directory.
DrupalTestCase::assert protected function Internal helper: stores the assert.
DrupalTestCase::assertEqual protected function Check to see if two values are equal.
DrupalTestCase::assertFalse protected function Check to see if a value is false (an empty string, 0, NULL, or FALSE).
DrupalTestCase::assertIdentical protected function Check to see if two values are identical.
DrupalTestCase::assertNotEqual protected function Check to see if two values are not equal.
DrupalTestCase::assertNotIdentical protected function Check to see if two values are not identical.
DrupalTestCase::assertNotNull protected function Check to see if a value is not NULL.
DrupalTestCase::assertNull protected function Check to see if a value is NULL.
DrupalTestCase::assertTrue protected function Check to see if a value is not false (not an empty string, 0, NULL, or FALSE).
DrupalTestCase::deleteAssert public static function Delete an assertion record by message ID.
DrupalTestCase::error protected function Fire an error assertion. 1
DrupalTestCase::errorHandler public function Handle errors during test runs. 1
DrupalTestCase::exceptionHandler protected function Handle exceptions.
DrupalTestCase::fail protected function Fire an assertion that is always negative.
DrupalTestCase::generatePermutations public static function Converts a list of possible parameters into a stack of permutations.
DrupalTestCase::getAssertionCall protected function Cycles through backtrace until the first non-assertion method is found.
DrupalTestCase::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
DrupalTestCase::insertAssert public static function Store an assertion from outside the testing context.
DrupalTestCase::pass protected function Fire an assertion that is always positive.
DrupalTestCase::randomName public static function Generates a random string containing letters and numbers.
DrupalTestCase::randomString public static function Generates a random string of ASCII characters of codes 32 to 126.
DrupalTestCase::run public function Run all tests in this class.
DrupalTestCase::verbose protected function Logs a verbose message in a text file.
DrupalWebTestCase::$additionalCurlOptions protected property Additional cURL options.
DrupalWebTestCase::$content protected property The content of the page currently loaded in the internal browser.
DrupalWebTestCase::$cookieFile protected property The current cookie file used by cURL.
DrupalWebTestCase::$cookies protected property The cookies of the page currently loaded in the internal browser.
DrupalWebTestCase::$curlHandle protected property The handle of the current cURL connection.
DrupalWebTestCase::$drupalSettings protected property The value of the Drupal.settings JavaScript variable for the page currently loaded in the internal browser.
DrupalWebTestCase::$elements protected property The parsed version of the page.
DrupalWebTestCase::$generatedTestFiles protected property Whether the files were copied to the test files directory.
DrupalWebTestCase::$headers protected property The headers of the page currently loaded in the internal browser.
DrupalWebTestCase::$httpauth_credentials protected property HTTP authentication credentials (<username>:<password>).
DrupalWebTestCase::$httpauth_method protected property HTTP authentication method
DrupalWebTestCase::$loggedInUser protected property The current user logged in using the internal browser.
DrupalWebTestCase::$originalShutdownCallbacks protected property The original shutdown handlers array, before it was cleaned for testing purposes.
DrupalWebTestCase::$originalUser protected property The original user, before it was changed to a clean uid = 1 for testing purposes.
DrupalWebTestCase::$plainTextContent protected property The content of the page currently loaded in the internal browser (plain text version).
DrupalWebTestCase::$profile protected property The profile to install as a basis for testing. 20
DrupalWebTestCase::$redirect_count protected property The number of redirects followed during the handling of a request.
DrupalWebTestCase::$session_id protected property The current session ID, if available.
DrupalWebTestCase::$session_name protected property The current session name, if available.
DrupalWebTestCase::$url protected property The URL currently loaded in the internal browser.
DrupalWebTestCase::assertField protected function Asserts that a field exists with the given name or ID.
DrupalWebTestCase::assertFieldById protected function Asserts that a field exists in the current page with the given ID and value.
DrupalWebTestCase::assertFieldByName protected function Asserts that a field exists in the current page with the given name and value.
DrupalWebTestCase::assertFieldByXPath protected function Asserts that a field exists in the current page by the given XPath.
DrupalWebTestCase::assertFieldChecked protected function Asserts that a checkbox field in the current page is checked.
DrupalWebTestCase::assertLink protected function Pass if a link with the specified label is found, and optional with the specified index.
DrupalWebTestCase::assertLinkByHref protected function Pass if a link containing a given href (part) is found.
DrupalWebTestCase::assertMail protected function Asserts that the most recently sent e-mail message has the given value.
DrupalWebTestCase::assertMailPattern protected function Asserts that the most recently sent e-mail message has the pattern in it.
DrupalWebTestCase::assertMailString protected function Asserts that the most recently sent e-mail message has the string in it.
DrupalWebTestCase::assertNoDuplicateIds protected function Asserts that each HTML ID is used for just a single element.
DrupalWebTestCase::assertNoField protected function Asserts that a field does not exist with the given name or ID.
DrupalWebTestCase::assertNoFieldById protected function Asserts that a field does not exist with the given ID and value.
DrupalWebTestCase::assertNoFieldByName protected function Asserts that a field does not exist with the given name and value.
DrupalWebTestCase::assertNoFieldByXPath protected function Asserts that a field doesn't exist or its value doesn't match, by XPath.
DrupalWebTestCase::assertNoFieldChecked protected function Asserts that a checkbox field in the current page is not checked.
DrupalWebTestCase::assertNoLink protected function Pass if a link with the specified label is not found.
DrupalWebTestCase::assertNoLinkByHref protected function Pass if a link containing a given href (part) is not found.
DrupalWebTestCase::assertNoOptionSelected protected function Asserts that a select option in the current page is not checked.
DrupalWebTestCase::assertNoPattern protected function Will trigger a pass if the perl regex pattern is not present in raw content.
DrupalWebTestCase::assertNoRaw protected function Pass if the raw text is NOT found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertNoResponse protected function Asserts the page did not return the specified response code.
DrupalWebTestCase::assertNoText protected function Pass if the text is NOT found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents.
DrupalWebTestCase::assertNoTitle protected function Pass if the page title is not the given string.
DrupalWebTestCase::assertNoUniqueText protected function Pass if the text is found MORE THAN ONCE on the text version of the page.
DrupalWebTestCase::assertOptionSelected protected function Asserts that a select option in the current page is checked.
DrupalWebTestCase::assertPattern protected function Will trigger a pass if the Perl regex pattern is found in the raw content.
DrupalWebTestCase::assertRaw protected function Pass if the raw text IS found on the loaded page, fail otherwise. Raw text refers to the raw HTML that the page generated.
DrupalWebTestCase::assertResponse protected function Asserts the page responds with the specified response code.
DrupalWebTestCase::assertTextHelper protected function Helper for assertText and assertNoText.
DrupalWebTestCase::assertThemeOutput protected function Asserts themed output.
DrupalWebTestCase::assertTitle protected function Pass if the page title is the given string.
DrupalWebTestCase::assertUniqueText protected function Pass if the text is found ONLY ONCE on the text version of the page.
DrupalWebTestCase::assertUniqueTextHelper protected function Helper for assertUniqueText and assertNoUniqueText.
DrupalWebTestCase::assertUrl protected function Pass if the internal browser's URL matches the given path.
DrupalWebTestCase::buildXPathQuery protected function Builds an XPath query.
DrupalWebTestCase::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
DrupalWebTestCase::checkForMetaRefresh protected function Check for meta refresh tag and if found call drupalGet() recursively. This function looks for the http-equiv attribute to be set to "Refresh" and is case-sensitive.
DrupalWebTestCase::checkPermissions protected function Check to make sure that the array of permissions are valid.
DrupalWebTestCase::clickLink protected function Follows a link by name.
DrupalWebTestCase::constructFieldXpath protected function Helper function: construct an XPath for the given set of attributes and value.
DrupalWebTestCase::copySetupCache protected function Copy the setup cache from/to another table and files directory.
DrupalWebTestCase::cronRun protected function Runs cron in the Drupal installed by Simpletest.
DrupalWebTestCase::curlClose protected function Close the cURL handler and unset the handler.
DrupalWebTestCase::curlExec protected function Initializes and executes a cURL request.
DrupalWebTestCase::curlHeaderCallback protected function Reads headers and registers errors received from the tested site.
DrupalWebTestCase::curlInitialize protected function Initializes the cURL connection.
DrupalWebTestCase::drupalCompareFiles protected function Compare two files based on size and file name.
DrupalWebTestCase::drupalCreateContentType protected function Creates a custom content type based on default settings.
DrupalWebTestCase::drupalCreateNode protected function Creates a node based on default settings.
DrupalWebTestCase::drupalCreateRole protected function Creates a role with specified permissions.
DrupalWebTestCase::drupalCreateUser protected function Create a user with a given set of permissions.
DrupalWebTestCase::drupalGetAJAX protected function Retrieve a Drupal path or an absolute path and JSON decode the result.
DrupalWebTestCase::drupalGetContent protected function Gets the current raw HTML of requested page.
DrupalWebTestCase::drupalGetHeader protected function Gets the value of an HTTP response header. If multiple requests were required to retrieve the page, only the headers from the last request will be checked by default. However, if TRUE is passed as the second argument, all requests will be processed…
DrupalWebTestCase::drupalGetHeaders protected function Gets the HTTP response headers of the requested page. Normally we are only interested in the headers returned by the last request. However, if a page is redirected or HTTP authentication is in use, multiple requests will be required to retrieve the…
DrupalWebTestCase::drupalGetMails protected function Gets an array containing all e-mails sent during this test case.
DrupalWebTestCase::drupalGetNodeByTitle function Get a node from the database based on its title.
DrupalWebTestCase::drupalGetSettings protected function Gets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::drupalGetTestFiles protected function Get a list files that can be used in tests.
DrupalWebTestCase::drupalGetToken protected function Generate a token for the currently logged in user.
DrupalWebTestCase::drupalHead protected function Retrieves only the headers for a Drupal path or an absolute path.
DrupalWebTestCase::drupalLogin protected function Log in a user with the internal browser.
DrupalWebTestCase::drupalLogout protected function
DrupalWebTestCase::drupalPostAJAX protected function Execute an Ajax submission.
DrupalWebTestCase::drupalSetContent protected function Sets the raw HTML content. This can be useful when a page has been fetched outside of the internal browser and assertions need to be made on the returned page.
DrupalWebTestCase::drupalSetSettings protected function Sets the value of the Drupal.settings JavaScript variable for the currently loaded page.
DrupalWebTestCase::getAbsoluteUrl protected function Takes a path and returns an absolute path.
DrupalWebTestCase::getAllOptions protected function Get all option elements, including nested options, in a select.
DrupalWebTestCase::getSelectedItem protected function Get the selected value from a select field.
DrupalWebTestCase::getSetupCacheKey protected function Returns the cache key used for the setup caching.
DrupalWebTestCase::getUrl protected function Get the current URL from the cURL handler.
DrupalWebTestCase::handleForm protected function Handle form input related to drupalPost(). Ensure that the specified fields exist and attempt to create POST data in the correct manner for the particular field type.
DrupalWebTestCase::loadSetupCache protected function Copies the cached tables and files for a cached installation setup.
DrupalWebTestCase::parse protected function Parse content returned from curlExec using DOM and SimpleXML.
DrupalWebTestCase::preloadRegistry protected function Preload the registry from the testing site.
DrupalWebTestCase::prepareDatabasePrefix protected function Generates a database prefix for running tests.
DrupalWebTestCase::prepareEnvironment protected function Prepares the current environment for running the test.
DrupalWebTestCase::recursiveDirectoryCopy protected function Recursively copy one directory to another.
DrupalWebTestCase::refreshVariables protected function Refresh the in-memory set of variables. Useful after a page request is made that changes a variable in a different thread. 1
DrupalWebTestCase::resetAll protected function Reset all data structures after having enabled new modules.
DrupalWebTestCase::storeSetupCache protected function Store the installation setup to a cache.
DrupalWebTestCase::tearDown protected function Delete created files and temporary files directory, delete the tables created by setUp(), and reset the database prefix. 6
DrupalWebTestCase::verboseEmail protected function Outputs to verbose the most recent $count emails sent.
DrupalWebTestCase::xpath protected function Perform an xpath search on the contents of the internal browser. The search is relative to the root element (HTML tag normally) of the page.
DrupalWebTestCase::__construct function Constructor for DrupalWebTestCase. Overrides DrupalTestCase::__construct 1
SearchApiDbTest::$index_id protected property
SearchApiDbTest::$server_id protected property
SearchApiDbTest::assertText protected function Pass if the text IS found on the text version of the page. The text version is the equivalent of what a user would see when viewing through a web browser. In other words the HTML has been filtered out of the contents. Overrides DrupalWebTestCase::assertText
SearchApiDbTest::buildSearch protected function
SearchApiDbTest::checkFacets protected function
SearchApiDbTest::clearIndex protected function
SearchApiDbTest::createIndex protected function
SearchApiDbTest::createServer protected function
SearchApiDbTest::drupalGet protected function Retrieves a Drupal path or an absolute path. Overrides DrupalWebTestCase::drupalGet
SearchApiDbTest::drupalPost protected function Execute a POST request on a Drupal page. It will be done as usual POST request with SimpleBrowser. Overrides DrupalWebTestCase::drupalPost
SearchApiDbTest::editServer protected function
SearchApiDbTest::editServerPartial protected function Edits the server to enable partial matches.
SearchApiDbTest::facetCompare public function Compares two facets for ordering.
SearchApiDbTest::getInfo public static function
SearchApiDbTest::indexItems protected function
SearchApiDbTest::insertItem protected function
SearchApiDbTest::insertItems protected function
SearchApiDbTest::regressionTests protected function Executes regression tests for issues that were already fixed.
SearchApiDbTest::regressionTests2 protected function Executes regression tests which are unpractical to run in between.
SearchApiDbTest::searchNoResults protected function
SearchApiDbTest::searchSuccess1 protected function
SearchApiDbTest::searchSuccess2 protected function
SearchApiDbTest::searchSuccessPartial protected function Tests whether partial searches work.
SearchApiDbTest::setUp public function Sets up a Drupal site for running functional and integration tests. Overrides DrupalWebTestCase::setUp
SearchApiDbTest::testFramework public function
SearchApiDbTest::uninstallModule protected function Tests whether removing the configuration again works as it should.