diff --git a/core/dbobjectsearch.class.php b/core/dbobjectsearch.class.php index 0f32ab3efb..d702c1d0bf 100644 --- a/core/dbobjectsearch.class.php +++ b/core/dbobjectsearch.class.php @@ -1928,9 +1928,8 @@ public function GetExpectedArguments(): array /** * @inheritDoc - * @return DBObjectSearch */ - protected function ApplyDataFilters(): DBObjectSearch + protected function ApplyDataFilters(): DBSearch { if ($this->IsAllDataAllowed() || $this->IsDataFiltered()) { return $this; diff --git a/core/dbunionsearch.class.php b/core/dbunionsearch.class.php index a9118974fb..8566655aba 100644 --- a/core/dbunionsearch.class.php +++ b/core/dbunionsearch.class.php @@ -676,9 +676,8 @@ public function GetExpectedArguments(): array /** * @inheritDoc - * @return DBUnionSearch */ - protected function ApplyDataFilters(): DBUnionSearch + protected function ApplyDataFilters(): DBSearch { if ($this->IsAllDataAllowed() || $this->IsDataFiltered()) { return $this; diff --git a/tests/php-unit-tests/unitary-tests/core/DBSearch/DBSearchApplyDataFiltersTest.php b/tests/php-unit-tests/unitary-tests/core/DBSearch/DBSearchApplyDataFiltersTest.php new file mode 100644 index 0000000000..b503023b90 --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/core/DBSearch/DBSearchApplyDataFiltersTest.php @@ -0,0 +1,67 @@ +sOriginalUserRightsSelectModuleClass = get_class(UserRights::GetModuleInstance()); + + $this->RequireOnceUnitTestFile('Fixtures/N9687_CustomGetSelectFilterClass.php'); + } + + /** + * @inheritDoc + */ + public function tearDown(): void + { + // Restore original UserRights select module to not interfere with next tests + UserRights::SelectModule($this->sOriginalUserRightsSelectModuleClass); + + parent::tearDown(); + } + + public function testApplyDataFiltersOnDBObjectSearchShouldAcceptGetSelectFilterClassReturningDBUnionSearch() + { + // Use custom select filter that returns a DBUnionSearch + $sPreviousSelectModuleClass = get_class(UserRights::GetModuleInstance()); + UserRights::SelectModule('\\Combodo\\iTop\\Test\\UnitTest\\Core\\Fixtures\\N9687_CustomGetSelectFilterClass'); + + // Create a user and login, otherwise the select filter won't apply + self::CreateUser('test_dbsearch_applydatafilters', 3); + UserRights::Login('test_dbsearch_applydatafilters'); + + // Create a person + $oCreatedPerson = $this->CreatePerson(microtime()); + + // Try to retrieve it using the select filter + $oSearch = DBObjectSearch::FromOQL("SELECT Person WHERE id = {$oCreatedPerson->GetKey()}"); + $oFilteredSearch = $this->InvokeNonPublicMethod(DBObjectSearch::class, 'ApplyDataFilters', $oSearch); + + // Restore original select module to not interfere with next tests + UserRights::SelectModule($sPreviousSelectModuleClass); + + $this->assertEquals(DBUnionSearch::class, get_class($oFilteredSearch), "DBObjectSearch::ApplyDataFilters() should be able to return a \DBUnionSearch"); + } +} diff --git a/tests/php-unit-tests/unitary-tests/core/DBSearch/Fixtures/N9687_CustomGetSelectFilterClass.php b/tests/php-unit-tests/unitary-tests/core/DBSearch/Fixtures/N9687_CustomGetSelectFilterClass.php new file mode 100644 index 0000000000..fc2a53054b --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/core/DBSearch/Fixtures/N9687_CustomGetSelectFilterClass.php @@ -0,0 +1,24 @@ +