protected function SearchApiDbTest::regressionTests in Search API Database Search 7
Executes regression tests for issues that were already fixed.
1 call to SearchApiDbTest::regressionTests()
File
- ./
search_api_db.test, line 539
Class
- SearchApiDbTest
- Class for testing index and search capabilities using the Database search module.
Code
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.');
}