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 ...@@ -108,43 +108,86 @@ class QueryBuilderTest extends \VuFindTest\Unit\TestCase
*/ */
protected function getQuestionTests() protected function getQuestionTests()
{ {
// Format: [input, expected output, flags array]
// @codingStandardsIgnoreStart // @codingStandardsIgnoreStart
return [ return [
['this?', '(this?) OR (this\?)'], // trailing question mark // trailing question mark:
['this? that', '((this?) OR (this\?)) that'], // question mark after first word ['this?', '(this?) OR (this\?)', []],
['start this? that', 'start ((this?) OR (this\?)) that'], // question mark after the middle word // question mark after first word:
['start AND this? AND that', 'start AND ((this?) OR (this\?)) AND that'], // question mark with boolean operators ['this? that', '((this?) OR (this\?)) that', []],
['start t?his that', 'start t?his that'], // question mark as a wildcard in the middle of a word // question mark after the middle word:
['start? this?', '((start?) OR (start\?)) ((this?) OR (this\?))'], // multiple ? terms ['start this? that', 'start ((this?) OR (this\?)) that', []],
['this? that? this?', '((this?) OR (this\?)) ((that?) OR (that\?)) ((this?) OR (this\?))'], // repeating ? term // question mark with boolean operators:
['"this? that?"', '"this? that?"'], // ? terms inside quoted phrase ['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 // @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 * @return void
*/ */
public function testQueryHandler() protected function runQuestionTests($builderParams, $handler)
{ {
// Set up an array of expected inputs and outputs: // Set up an array of expected inputs and outputs:
$tests = $this->getQuestionTests(); $tests = $this->getQuestionTests();
$qb = new QueryBuilder( $qb = new QueryBuilder($builderParams);
[
'test' => []
]
);
foreach ($tests as $test) { 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'); $q = new Query($input, 'test');
$response = $qb->build($q); $response = $qb->build($q);
$processedQ = $response->get('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 * Test generation with a query handler with edismax
* *
...@@ -152,21 +195,11 @@ class QueryBuilderTest extends \VuFindTest\Unit\TestCase ...@@ -152,21 +195,11 @@ class QueryBuilderTest extends \VuFindTest\Unit\TestCase
*/ */
public function testQueryHandlerWithEdismax() public function testQueryHandlerWithEdismax()
{ {
// Set up an array of expected inputs and outputs: $this->runQuestionTests(
$tests = $this->getQuestionTests();
$qb = new QueryBuilder(
[ [
'test' => ['DismaxHandler' => 'edismax', 'DismaxFields' => ['foo']] '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