diff --git a/core/dbobjectsearch.class.php b/core/dbobjectsearch.class.php index ad5e0c6e59..08164adff1 100644 --- a/core/dbobjectsearch.class.php +++ b/core/dbobjectsearch.class.php @@ -1935,9 +1935,8 @@ class DBObjectSearch extends DBSearch /** * @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 5be4a4d7ed..9e808183ae 100644 --- a/core/dbunionsearch.class.php +++ b/core/dbunionsearch.class.php @@ -676,9 +676,8 @@ class DBUnionSearch extends DBSearch /** * @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/application/utilsTest.php b/tests/php-unit-tests/unitary-tests/application/utilsTest.php index 593883a314..6084e3453b 100644 --- a/tests/php-unit-tests/unitary-tests/application/utilsTest.php +++ b/tests/php-unit-tests/unitary-tests/application/utilsTest.php @@ -835,8 +835,16 @@ class utilsTest extends ItopTestCase public function testFileGetContentsAndMIMETypeOnLocalURL() { - $sURL = utils::GetAbsoluteUrlAppRoot().'env-production/itop-request-mgmt/images/user-request.svg'; - $sPath = APPROOT.'env-production/itop-request-mgmt/images/user-request.svg'; + // For the test to work on most dev / CI environments, we need to use a module with an SVG image that is installed with the current setup choices + if (file_exists(APPROOT.'env-production/itop-request-mgmt/images/user-request.svg')) { + $sImgRelPath = 'itop-request-mgmt/images/user-request.svg'; + } elseif (file_exists(APPROOT.'env-production/itop-request-mgmt-itil/images/user-request.svg')) { + $sImgRelPath = 'itop-request-mgmt-itil/images/user-request.svg'; + } + + $sURL = utils::GetAbsoluteUrlModulesRoot().$sImgRelPath; + $sPath = APPROOT.'env-production/'.$sImgRelPath; + $oExpectedDocument = new ormDocument(file_get_contents($sPath), 'image/svg+xml; charset=us-ascii', 'user-request.svg'); $this->assertEquals($oExpectedDocument, utils::FileGetContentsAndMIMEType($sURL)); // Read local URL directly on disk 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 @@ +