From e1d274b855360770c7fa81928431fb172130cc5c Mon Sep 17 00:00:00 2001 From: Molkobain Date: Wed, 17 Jun 2026 09:44:26 +0200 Subject: [PATCH 1/4] =?UTF-8?q?N=C2=B09687=20-=20Fix=20incorrect=20return?= =?UTF-8?q?=20type=20for=20the=20DBObjectSearch::ApplyDataFilter()=20funct?= =?UTF-8?q?ion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/dbobjectsearch.class.php | 3 +-- core/dbunionsearch.class.php | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) 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; From 0f7653a43ee14e40cf95d87c5cad5abe5b4a1540 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Thu, 18 Jun 2026 12:01:22 +0200 Subject: [PATCH 2/4] =?UTF-8?q?N=C2=B09687=20-=20Add=20unit=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DBSearch/DBSearchApplyDataFiltersTest.php | 47 +++++++++++++++++++ .../N9687_CustomGetSelectFilterClass.php | 24 ++++++++++ 2 files changed, 71 insertions(+) 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/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..0ad4f11fa4 --- /dev/null +++ b/tests/php-unit-tests/unitary-tests/core/DBSearch/DBSearchApplyDataFiltersTest.php @@ -0,0 +1,47 @@ +RequireOnceUnitTestFile('Fixtures/N9687_CustomGetSelectFilterClass.php'); + } + + public function testApplyDataFiltersOnDBObjectSearchShouldAcceptGetSelectFilterClassReturningDBUnionSearch() + { + // Use custom select filter that returns a DBUnionSearch + 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); + + $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 @@ + Date: Thu, 18 Jun 2026 19:05:51 +0200 Subject: [PATCH 3/4] =?UTF-8?q?N=C2=B09687=20-=20Improve=20unit=20test=20a?= =?UTF-8?q?fter=20code=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/DBSearch/DBSearchApplyDataFiltersTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/php-unit-tests/unitary-tests/core/DBSearch/DBSearchApplyDataFiltersTest.php b/tests/php-unit-tests/unitary-tests/core/DBSearch/DBSearchApplyDataFiltersTest.php index 0ad4f11fa4..f3ebd47c44 100644 --- a/tests/php-unit-tests/unitary-tests/core/DBSearch/DBSearchApplyDataFiltersTest.php +++ b/tests/php-unit-tests/unitary-tests/core/DBSearch/DBSearchApplyDataFiltersTest.php @@ -29,6 +29,7 @@ protected function setUp(): void 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 @@ -42,6 +43,9 @@ public function testApplyDataFiltersOnDBObjectSearchShouldAcceptGetSelectFilterC $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"); } } From 14d18625dc9a209aabeb10d44f850c7aee6533c3 Mon Sep 17 00:00:00 2001 From: Molkobain Date: Thu, 18 Jun 2026 19:05:51 +0200 Subject: [PATCH 4/4] =?UTF-8?q?N=C2=B09687=20-=20Improve=20unit=20test=20a?= =?UTF-8?q?fter=20code=20review?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DBSearch/DBSearchApplyDataFiltersTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/php-unit-tests/unitary-tests/core/DBSearch/DBSearchApplyDataFiltersTest.php b/tests/php-unit-tests/unitary-tests/core/DBSearch/DBSearchApplyDataFiltersTest.php index f3ebd47c44..b503023b90 100644 --- a/tests/php-unit-tests/unitary-tests/core/DBSearch/DBSearchApplyDataFiltersTest.php +++ b/tests/php-unit-tests/unitary-tests/core/DBSearch/DBSearchApplyDataFiltersTest.php @@ -16,6 +16,8 @@ class DBSearchApplyDataFiltersTest extends ItopDataTestCase { public const CREATE_TEST_ORG = true; + protected string $sOriginalUserRightsSelectModuleClass = ''; + /** * @throws \Exception */ @@ -23,9 +25,23 @@ protected function setUp(): void { parent::setUp(); + // Backup original UserRights select module as it will changed in some tests + $this->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