BUGFIX: Do not remove submitted filter if configured one is empty

This will be the case if you add a flexform to the plugin with no value.
Then an empty filter is configured and you will not be able to submit a
value for this filter.
This commit is contained in:
Daniel Siepmann 2017-10-29 17:08:33 +01:00
parent b0eccc241d
commit 8206a1ec59
Signed by: Daniel Siepmann
GPG key ID: 33D6629915560EF4
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\SearchResultInterface;
use Codappix\SearchCore\Domain\Model\FacetRequest;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
/**
@ -123,10 +124,16 @@ class SearchService
protected function addConfiguredFilters(SearchRequestInterface $searchRequest)
{
try {
$searchRequest->setFilter(array_merge(
$searchRequest->getFilter(),
$this->configuration->get('searching.filter')
));
$filter = $searchRequest->getFilter();
ArrayUtility::mergeRecursiveWithOverrule(
$filter,
$this->configuration->get('searching.filter'),
true,
false
);
$searchRequest->setFilter($filter);
} catch (InvalidArgumentException $e) {
// Nothing todo, no filter configured.
}

View file

@ -178,4 +178,29 @@ class SearchServiceTest extends AbstractUnitTestCase
$searchRequest->setFilter(['anotherProperty' => 'anything']);
$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);
}
}