Skip to content

Commit

Permalink
Set "or_group" filter option at SearchHandler::search() (#6992)
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys authored Mar 30, 2021
1 parent 86def1a commit 09e8b7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Search/SearchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function search(AdminInterface $admin, $term, $page = 0, $offset = 20)

if ($filter->getOption('global_search', false)) {
$filter->setOption('case_sensitive', $this->caseSensitive);
$filter->setOption('or_group', $admin->getCode());
$filter->setCondition(FilterInterface::CONDITION_OR);
$datagrid->setValue($formName, null, $term);
$found = true;
Expand Down
24 changes: 21 additions & 3 deletions tests/Search/SearchHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function testBuildPagerWithGlobalSearchField(bool $caseSensitive): void
{
$filter = $this->createMock(FilterInterface::class);
$filter->expects($this->once())->method('getOption')->with('global_search')->willReturn(true);
$filter->expects($this->once())->method('setOption')->with('case_sensitive', $caseSensitive);

$pager = $this->createMock(PagerInterface::class);
$pager->expects($this->once())->method('setPage');
Expand All @@ -56,8 +55,19 @@ public function testBuildPagerWithGlobalSearchField(bool $caseSensitive): void
$datagrid->expects($this->once())->method('setValue');
$datagrid->expects($this->once())->method('getPager')->willReturn($pager);

$adminCode = 'my.admin';

$admin = $this->createMock(AdminInterface::class);
$admin->expects($this->once())->method('getDatagrid')->willReturn($datagrid);
$admin->expects($this->exactly(2))->method('getCode')->willReturn($adminCode);

$filter
->expects($this->exactly(2))
->method('setOption')
->withConsecutive(
[$this->equalTo('case_sensitive'), $caseSensitive],
[$this->equalTo('or_group'), $adminCode]
);

$handler = new SearchHandler($caseSensitive);
$this->assertInstanceOf(PagerInterface::class, $handler->search($admin, 'myservice'));
Expand All @@ -78,7 +88,6 @@ public function testAdminSearch($expected, $filterCallsCount, ?bool $enabled, st
{
$filter = $this->createMock(FilterInterface::class);
$filter->expects($this->exactly($filterCallsCount))->method('getOption')->with('global_search')->willReturn(true);
$filter->expects($this->exactly($filterCallsCount))->method('setOption')->with('case_sensitive', true);

$pager = $this->createMock(PagerInterface::class);
$pager->expects($this->exactly($filterCallsCount))->method('setPage');
Expand All @@ -91,7 +100,16 @@ public function testAdminSearch($expected, $filterCallsCount, ?bool $enabled, st

$admin = $this->createMock(AdminInterface::class);
$admin->expects($this->exactly($filterCallsCount))->method('getDatagrid')->willReturn($datagrid);
$admin->expects($this->once())->method('getCode')->willReturn($adminCode);

$admin->expects($this->exactly(false === $expected ? 1 : 2))->method('getCode')->willReturn($adminCode);

$filter
->expects($this->exactly(false === $expected ? 0 : 2))
->method('setOption')
->withConsecutive(
[$this->equalTo('case_sensitive'), true],
[$this->equalTo('or_group'), $adminCode]
);

$handler = new SearchHandler(true);

Expand Down

0 comments on commit 09e8b7d

Please sign in to comment.