From 07ca64c9d3be03961ed211376e2d392520917927 Mon Sep 17 00:00:00 2001 From: Benjamin DALSASS Date: Wed, 22 Jul 2026 08:18:01 +0200 Subject: [PATCH 1/3] =?UTF-8?q?N=C2=B09829=20-=20Add=20unit=20tests=20for?= =?UTF-8?q?=20parent=20ticket=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unitary-tests/core/UserRightsTest.php | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php b/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php index d84c2e9621..74f755417c 100644 --- a/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php +++ b/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php @@ -37,6 +37,7 @@ use MetaModel; use UserLocal; use UserRights; +use UserRightsProfile; use utils; /** @@ -155,6 +156,127 @@ protected function GivenUserWithProfiles(string $sLogin, array $aProfileIds): DB return $oUser; } + /** + * Ensure profiles are obtained with persisted user when profiles list has NOT been changed. + * @see N°9723 - IsActionAllowed should work with non instantiated users objects + */ + public function testListProfilesUsesPersistedProfilesWhenOnlyNonProfileChangesExist(): void + { + // Create a user with a set of profiles and save it + $oUserInDataBase = $this->GivenUserWithProfiles('test1', [ + self::$aURP_Profiles['Configuration Manager'], + self::$aURP_Profiles['Support Agent'], + self::$aURP_Profiles['Service Manager'], + ]); + $oUserInDataBase->DBInsert(); + + // User to check profiles (give the persisted user id) + $oUser = new class ($oUserInDataBase) { + private $oUserInDataBase; + + public function __construct($oUserInDataBase) + { + $this->oUserInDataBase = $oUserInDataBase; + } + + public function ListChanges(): array + { + return ['login' => 'changed']; + } + + public function GetKey(): int + { + return $this->oUserInDataBase->GetKey(); + } + + public function Get(string $sAttCode) + { + if ($sAttCode === 'profile_list') { + throw new \LogicException('profile_list should not be read when it is not part of ListChanges'); + } + return null; + } + }; + + // List the profiles (persisted) + $oUserRights = new UserRightsProfile(); + $aProfiles = $oUserRights->ListProfiles($oUser); + + // Asserts + $this->assertCount(3, $aProfiles); + $this->assertArrayHasKey(3, $aProfiles); + $this->assertArrayHasKey(5, $aProfiles); + $this->assertArrayHasKey(10, $aProfiles); + } + + /** + * Ensure profiles are obtained with object in memory when profiles list has been changed. + * @see N°9723 - IsActionAllowed should work with non instantiated users objects + */ + public function testListProfilesUsesInMemoryProfilesWhenProfileListChanged(): void + { + // First profile + $oUserProfile1 = new class () { + public function Get(string $sAttCode) + { + if ($sAttCode === 'profileid') { + return 3; + } + if ($sAttCode === 'profileid_friendlyname') { + return 'Configuration Manager'; + } + return null; + } + }; + + // Second profile + $oUserProfile2 = new class () { + public function Get(string $sAttCode) + { + if ($sAttCode === 'profileid') { + return 10; + } + if ($sAttCode === 'profileid_friendlyname') { + return 'Portal power user'; + } + return null; + } + }; + + // User in memory with first and second profile + $oUser = new class ($oUserProfile1, $oUserProfile2) { + private $aProfileList; + + public function __construct($oUserProfile1, $oUserProfile2) + { + $this->aProfileList = [$oUserProfile1, $oUserProfile2]; + } + + public function ListChanges(): array + { + return ['profile_list' => true, 'login' => 'changed']; + } + + public function Get(string $sAttCode) + { + if ($sAttCode === 'profile_list') { + return $this->aProfileList; + } + return null; + } + }; + + // List the profiles (memory) + $oUserRights = new UserRightsProfile(); + $aProfiles = $oUserRights->ListProfiles($oUser); + + // Asserts + $this->assertSame([ + 3 => 'Configuration Manager', + 10 => 'Portal power user', + ], $aProfiles); + } + public function testIsLoggedIn() { $this->assertFalse(UserRights::IsLoggedIn()); From bc1b9eefa378dc302eb5228019169d129bbda41c Mon Sep 17 00:00:00 2001 From: Benjamin DALSASS Date: Wed, 22 Jul 2026 08:50:46 +0200 Subject: [PATCH 2/3] =?UTF-8?q?N=C2=B09829=20-=20Add=20unit=20tests=20for?= =?UTF-8?q?=20parent=20ticket=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/php-unit-tests/unitary-tests/core/UserRightsTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php b/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php index 74f755417c..13679185ec 100644 --- a/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php +++ b/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php @@ -159,6 +159,7 @@ protected function GivenUserWithProfiles(string $sLogin, array $aProfileIds): DB /** * Ensure profiles are obtained with persisted user when profiles list has NOT been changed. * @see N°9723 - IsActionAllowed should work with non instantiated users objects + * @covers UserRightsProfile::ListProfiles */ public function testListProfilesUsesPersistedProfilesWhenOnlyNonProfileChangesExist(): void { @@ -212,6 +213,7 @@ public function Get(string $sAttCode) /** * Ensure profiles are obtained with object in memory when profiles list has been changed. * @see N°9723 - IsActionAllowed should work with non instantiated users objects + * @covers UserRightsProfile::ListProfiles */ public function testListProfilesUsesInMemoryProfilesWhenProfileListChanged(): void { From 033843244d9773921d1ee9edd68208c98dd77dfe Mon Sep 17 00:00:00 2001 From: Benjamin DALSASS Date: Thu, 23 Jul 2026 08:55:00 +0200 Subject: [PATCH 3/3] =?UTF-8?q?N=C2=B09829=20-=20Add=20unit=20tests=20for?= =?UTF-8?q?=20parent=20ticket=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/php-unit-tests/unitary-tests/core/UserRightsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php b/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php index 13679185ec..adf5d2eda6 100644 --- a/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php +++ b/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php @@ -236,7 +236,7 @@ public function Get(string $sAttCode) public function Get(string $sAttCode) { if ($sAttCode === 'profileid') { - return 10; + return 12; } if ($sAttCode === 'profileid_friendlyname') { return 'Portal power user'; @@ -275,7 +275,7 @@ public function Get(string $sAttCode) // Asserts $this->assertSame([ 3 => 'Configuration Manager', - 10 => 'Portal power user', + 12 => 'Portal power user', ], $aProfiles); }