diff --git a/src/Search/SearchHandler.php b/src/Search/SearchHandler.php index 94bf590616..6e2e4785dc 100644 --- a/src/Search/SearchHandler.php +++ b/src/Search/SearchHandler.php @@ -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; diff --git a/tests/Search/SearchHandlerTest.php b/tests/Search/SearchHandlerTest.php index 54abc105e2..e2f0e17b69 100644 --- a/tests/Search/SearchHandlerTest.php +++ b/tests/Search/SearchHandlerTest.php @@ -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'); @@ -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')); @@ -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'); @@ -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);