From 1d9e7f9b5514d3fa9fb98d3a0fc319ba18d5bcf1 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Sat, 20 Jun 2026 17:47:19 +0200 Subject: [PATCH 1/2] :white_check_mark: Update test so it works on both ITIL and standard request management --- .../unitary-tests/application/utilsTest.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/php-unit-tests/unitary-tests/application/utilsTest.php b/tests/php-unit-tests/unitary-tests/application/utilsTest.php index 5d357e846d..aedc7ffb69 100644 --- a/tests/php-unit-tests/unitary-tests/application/utilsTest.php +++ b/tests/php-unit-tests/unitary-tests/application/utilsTest.php @@ -895,8 +895,16 @@ HTML, 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 From d6ef4fb7bb67e07f3b884d11304be8b5df150f34 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Thu, 2 Jul 2026 16:11:32 +0200 Subject: [PATCH 2/2] =?UTF-8?q?N=C2=B09687=20-=20Fix=20incorrect=20return?= =?UTF-8?q?=20type=20for=20the=20DBObjectSearch::ApplyDataFilter()=20funct?= =?UTF-8?q?ion=20(#939)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * N°9687 - Fix incorrect return type for the DBObjectSearch::ApplyDataFilter() function * N°9687 - Add unit test * N°9687 - Improve unit test after code review * N°9687 - Improve unit test after code review --- core/dbobjectsearch.class.php | 3 +- core/dbunionsearch.class.php | 3 +- .../DBSearch/DBSearchApplyDataFiltersTest.php | 67 +++++++++++++++++++ .../N9687_CustomGetSelectFilterClass.php | 24 +++++++ 4 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 tests/php-unit-tests/unitary-tests/core/DBSearch/DBSearchApplyDataFiltersTest.php create mode 100644 tests/php-unit-tests/unitary-tests/core/DBSearch/Fixtures/N9687_CustomGetSelectFilterClass.php 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 @@ 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 a9118974fb..8566655aba 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/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 @@ +