mirror of
https://github.com/Codappix/search_core.git
synced 2024-12-22 18:16:11 +01:00
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:
parent
b0eccc241d
commit
8206a1ec59
2 changed files with 36 additions and 4 deletions
|
@ -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.
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue