From d6415042ae4ea930b39e8fb3b76d77bc20ad2822 Mon Sep 17 00:00:00 2001 From: Romain Quetiez Date: Thu, 26 Oct 2023 21:10:07 +0200 Subject: [PATCH] :white_check_mark: Optimize tests execution time (no need for process isolation as long as we leave the premises clean) --- addons/userrights/userrightsprofile.class.inc.php | 12 ++++++------ .../unitary-tests/core/UserRightsTest.php | 4 +--- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/addons/userrights/userrightsprofile.class.inc.php b/addons/userrights/userrightsprofile.class.inc.php index f91149843..c41aa5083 100644 --- a/addons/userrights/userrightsprofile.class.inc.php +++ b/addons/userrights/userrightsprofile.class.inc.php @@ -490,6 +490,7 @@ class UserRightsProfile extends UserRightsAddOnAPI } protected $m_aUserOrgs = array(); // userid -> array of orgid + protected $m_aAdministrators = null; // [user id] // Built on demand, could be optimized if necessary (doing a query for each attribute that needs to be read) protected $m_aObjectActionGrants = array(); @@ -546,6 +547,7 @@ class UserRightsProfile extends UserRightsAddOnAPI // Cache $this->m_aObjectActionGrants = array(); + $this->m_aAdministrators = null; } public function LoadCache() @@ -688,12 +690,10 @@ class UserRightsProfile extends UserRightsAddOnAPI */ private function GetAdministrators() { - static $aAdministrators = null; - - if ($aAdministrators === null) + if ($this->m_aAdministrators === null) { // Find all administrators - $aAdministrators = array(); + $this->m_aAdministrators = array(); $oAdministratorsFilter = new DBObjectSearch('User'); $oLnkFilter = new DBObjectSearch('URP_UserProfile'); $oExpression = new FieldExpression('profileid', 'URP_UserProfile'); @@ -706,10 +706,10 @@ class UserRightsProfile extends UserRightsAddOnAPI $oSet->OptimizeColumnLoad(array('User' => array('login'))); while($oUser = $oSet->Fetch()) { - $aAdministrators[] = $oUser->GetKey(); + $this->m_aAdministrators[] = $oUser->GetKey(); } } - return $aAdministrators; + return $this->m_aAdministrators; } /** diff --git a/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php b/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php index b9ee0dcb5..af6eb3e74 100644 --- a/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php +++ b/tests/php-unit-tests/unitary-tests/core/UserRightsTest.php @@ -50,7 +50,6 @@ class UserRightsTest extends ItopDataTestCase try { utils::GetConfig()->SetModuleSetting('authent-local', 'password_validation.pattern', ''); - self::CreateUser('admin', 1); } catch (CoreCannotSaveObjectException $e) { } @@ -487,8 +486,7 @@ class UserRightsTest extends ItopDataTestCase ]; } /** - * @runInSeparateProcess - *@dataProvider NonAdminCannotListAdminProfilesProvider + * @dataProvider NonAdminCannotListAdminProfilesProvider */ public function testNonAdminCannotListAdminProfiles($bHideAdministrators, $iExpectedCount) {