Merge pull request #93 from Codappix/hotfix/allow-empty-filter

BUGFIX: Do not remove submitted filter if configured one is empty
This commit is contained in:
Daniel Siepmann 2017-11-02 22:41:20 +01:00 committed by GitHub
commit 43ec410eb5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 4 deletions

View file

@ -26,6 +26,7 @@ use Codappix\SearchCore\Connection\ConnectionInterface;
use Codappix\SearchCore\Connection\SearchRequestInterface; use Codappix\SearchCore\Connection\SearchRequestInterface;
use Codappix\SearchCore\Connection\SearchResultInterface; use Codappix\SearchCore\Connection\SearchResultInterface;
use Codappix\SearchCore\Domain\Model\FacetRequest; use Codappix\SearchCore\Domain\Model\FacetRequest;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface; use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
/** /**
@ -123,10 +124,16 @@ class SearchService
protected function addConfiguredFilters(SearchRequestInterface $searchRequest) protected function addConfiguredFilters(SearchRequestInterface $searchRequest)
{ {
try { try {
$searchRequest->setFilter(array_merge( $filter = $searchRequest->getFilter();
$searchRequest->getFilter(),
$this->configuration->get('searching.filter') ArrayUtility::mergeRecursiveWithOverrule(
)); $filter,
$this->configuration->get('searching.filter'),
true,
false
);
$searchRequest->setFilter($filter);
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
// Nothing todo, no filter configured. // Nothing todo, no filter configured.
} }

View file

@ -178,4 +178,29 @@ class SearchServiceTest extends AbstractUnitTestCase
$searchRequest->setFilter(['anotherProperty' => 'anything']); $searchRequest->setFilter(['anotherProperty' => 'anything']);
$this->subject->search($searchRequest); $this->subject->search($searchRequest);
} }
/**
* @test
*/
public function emptyConfiguredFilterIsNotChangingRequestWithExistingFilter()
{
$this->configuration->expects($this->exactly(2))
->method('getIfExists')
->withConsecutive(['searching.size'], ['searching.facets'])
->will($this->onConsecutiveCalls(null, null));
$this->configuration->expects($this->exactly(1))
->method('get')
->with('searching.filter')
->willReturn(['anotherProperty' => '']);
$this->connection->expects($this->once())
->method('search')
->with($this->callback(function ($searchRequest) {
return $searchRequest->getFilter() === ['anotherProperty' => 'anything'];
}));
$searchRequest = new SearchRequest('SearchWord');
$searchRequest->setFilter(['anotherProperty' => 'anything']);
$this->subject->search($searchRequest);
}
} }