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

Merge branch 'release-4.1'

parents 5694f8b1 7b96e587
No related merge requests found
......@@ -248,6 +248,13 @@ abstract class QueryAdapter
'b' => $operator
];
if (null !== ($op = $current->getOperator())) {
// Some search forms omit the operator for the first element;
// if we have an operator in a subsequent element, we should
// backfill a blank here for consistency; otherwise, VuFind
// may not construct correct search URLs.
if (isset($retVal[0]['f']) && !isset($retVal[0]['o'])) {
$retVal[0]['o'] = '';
}
$currentArr['o'] = $op;
}
$retVal[] = $currentArr;
......
File added
......@@ -65,6 +65,36 @@ class QueryAdapterTest extends TestCase
}
}
/**
* Test that when one part of the query contains an operator, ALL parts of the
* query contain an operator. (We want to be sure that in cases where the first
* part of the query has no operator associated with it, a blank value is filled
* in as a placeholder.
*
* @return void
*/
public function testOperatorDefinedEverywhere()
{
$fixturePath = realpath(__DIR__ . '/../../../../fixtures/searches') . '/';
$q = unserialize(file_get_contents($fixturePath . '/operators'));
$minified = QueryAdapter::minify($q);
// First, check that count of 'o' values matches count of queries in group:
$callback = function ($carry, $item) {
return $carry + (isset($item['o']) ? 1 : 0);
};
$this->assertEquals(
count($minified[0]['g']),
array_reduce($minified[0]['g'], $callback, 0)
);
// Next, confirm that first operator is set to empty (filler) value:
$this->assertEquals('', $minified[0]['g'][0]['o']);
// Finally, make sure that we can round-trip back to the input.
$this->assertEquals($q, QueryAdapter::deminify($minified));
}
/**
* Test building an advanced query from a request.
*
......
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