Skip to content
Snippets Groups Projects
Commit a71c5497 authored by Demian Katz's avatar Demian Katz
Browse files

Better search handler case coverage in tests.

parent 7e9fdac4
No related merge requests found
......@@ -108,43 +108,86 @@ class QueryBuilderTest extends \VuFindTest\Unit\TestCase
*/
protected function getQuestionTests()
{
// Format: [input, expected output, flags array]
// @codingStandardsIgnoreStart
return [
['this?', '(this?) OR (this\?)'], // trailing question mark
['this? that', '((this?) OR (this\?)) that'], // question mark after first word
['start this? that', 'start ((this?) OR (this\?)) that'], // question mark after the middle word
['start AND this? AND that', 'start AND ((this?) OR (this\?)) AND that'], // question mark with boolean operators
['start t?his that', 'start t?his that'], // question mark as a wildcard in the middle of a word
['start? this?', '((start?) OR (start\?)) ((this?) OR (this\?))'], // multiple ? terms
['this? that? this?', '((this?) OR (this\?)) ((that?) OR (that\?)) ((this?) OR (this\?))'], // repeating ? term
['"this? that?"', '"this? that?"'], // ? terms inside quoted phrase
// trailing question mark:
['this?', '(this?) OR (this\?)', []],
// question mark after first word:
['this? that', '((this?) OR (this\?)) that', []],
// question mark after the middle word:
['start this? that', 'start ((this?) OR (this\?)) that', []],
// question mark with boolean operators:
['start AND this? AND that', 'start AND ((this?) OR (this\?)) AND that', []],
// question mark as a wildcard in the middle of a word:
['start t?his that', 'start t?his that', []],
// multiple ? terms:
['start? this?', '((start?) OR (start\?)) ((this?) OR (this\?))', []],
// repeating ? term:
['this? that? this?', '((this?) OR (this\?)) ((that?) OR (that\?)) ((this?) OR (this\?))', []],
// ? terms inside quoted phrase (basic flag set to indicate that
// this does not contain any syntax unsupported by basic Dismax):
['"this? that?"', '"this? that?"', ['basic' => true]],
];
// @codingStandardsIgnoreEnd
}
/**
* Test generation with a query handler
* Run the standard suite of question mark tests, accounting for differences
* between stanard Lucene, basic Dismax and eDismax handlers.
*
* @param array $builderParams Parameters for QueryBuilder constructor
* @param string $handler Search handler: dismax|edismax|standard
*
* @return void
*/
public function testQueryHandler()
protected function runQuestionTests($builderParams, $handler)
{
// Set up an array of expected inputs and outputs:
$tests = $this->getQuestionTests();
$qb = new QueryBuilder(
[
'test' => []
]
);
$qb = new QueryBuilder($builderParams);
foreach ($tests as $test) {
list($input, $output) = $test;
list($input, $output, $flags) = $test;
if ($handler === 'standard'
|| ($handler === 'dismax' && empty($flags['basic']))
) {
$output = '(' . $output . ')';
}
$q = new Query($input, 'test');
$response = $qb->build($q);
$processedQ = $response->get('q');
$this->assertEquals('(' . $output . ')', $processedQ[0]);
$this->assertEquals($output, $processedQ[0]);
}
}
/**
* Test generation with a query handler
*
* @return void
*/
public function testQueryHandler()
{
$this->runQuestionTests(
[
'test' => []
], 'standard'
);
}
/**
* Test generation with a query handler with regular dismax
*
* @return void
*/
public function testQueryHandlerWithDismax()
{
$this->runQuestionTests(
[
'test' => ['DismaxHandler' => 'dismax', 'DismaxFields' => ['foo']]
], 'dismax'
);
}
/**
* Test generation with a query handler with edismax
*
......@@ -152,21 +195,11 @@ class QueryBuilderTest extends \VuFindTest\Unit\TestCase
*/
public function testQueryHandlerWithEdismax()
{
// Set up an array of expected inputs and outputs:
$tests = $this->getQuestionTests();
$qb = new QueryBuilder(
$this->runQuestionTests(
[
'test' => ['DismaxHandler' => 'edismax', 'DismaxFields' => ['foo']]
]
], 'edismax'
);
foreach ($tests as $test) {
list($input, $output) = $test;
$q = new Query($input, 'test');
$response = $qb->build($q);
$processedQ = $response->get('q');
$this->assertEquals($output, $processedQ[0]);
}
}
/**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment