Optimize tests execution time (no need for process isolation as long as we leave the premises clean)

This commit is contained in:
Romain Quetiez
2023-10-26 21:10:07 +02:00
parent 90006667fe
commit d6415042ae
2 changed files with 7 additions and 9 deletions

View File

@@ -490,6 +490,7 @@ class UserRightsProfile extends UserRightsAddOnAPI
} }
protected $m_aUserOrgs = array(); // userid -> array of orgid 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) // Built on demand, could be optimized if necessary (doing a query for each attribute that needs to be read)
protected $m_aObjectActionGrants = array(); protected $m_aObjectActionGrants = array();
@@ -546,6 +547,7 @@ class UserRightsProfile extends UserRightsAddOnAPI
// Cache // Cache
$this->m_aObjectActionGrants = array(); $this->m_aObjectActionGrants = array();
$this->m_aAdministrators = null;
} }
public function LoadCache() public function LoadCache()
@@ -688,12 +690,10 @@ class UserRightsProfile extends UserRightsAddOnAPI
*/ */
private function GetAdministrators() private function GetAdministrators()
{ {
static $aAdministrators = null; if ($this->m_aAdministrators === null)
if ($aAdministrators === null)
{ {
// Find all administrators // Find all administrators
$aAdministrators = array(); $this->m_aAdministrators = array();
$oAdministratorsFilter = new DBObjectSearch('User'); $oAdministratorsFilter = new DBObjectSearch('User');
$oLnkFilter = new DBObjectSearch('URP_UserProfile'); $oLnkFilter = new DBObjectSearch('URP_UserProfile');
$oExpression = new FieldExpression('profileid', 'URP_UserProfile'); $oExpression = new FieldExpression('profileid', 'URP_UserProfile');
@@ -706,10 +706,10 @@ class UserRightsProfile extends UserRightsAddOnAPI
$oSet->OptimizeColumnLoad(array('User' => array('login'))); $oSet->OptimizeColumnLoad(array('User' => array('login')));
while($oUser = $oSet->Fetch()) while($oUser = $oSet->Fetch())
{ {
$aAdministrators[] = $oUser->GetKey(); $this->m_aAdministrators[] = $oUser->GetKey();
} }
} }
return $aAdministrators; return $this->m_aAdministrators;
} }
/** /**

View File

@@ -50,7 +50,6 @@ class UserRightsTest extends ItopDataTestCase
try { try {
utils::GetConfig()->SetModuleSetting('authent-local', 'password_validation.pattern', ''); utils::GetConfig()->SetModuleSetting('authent-local', 'password_validation.pattern', '');
self::CreateUser('admin', 1);
} }
catch (CoreCannotSaveObjectException $e) { catch (CoreCannotSaveObjectException $e) {
} }
@@ -487,8 +486,7 @@ class UserRightsTest extends ItopDataTestCase
]; ];
} }
/** /**
* @runInSeparateProcess * @dataProvider NonAdminCannotListAdminProfilesProvider
*@dataProvider NonAdminCannotListAdminProfilesProvider
*/ */
public function testNonAdminCannotListAdminProfiles($bHideAdministrators, $iExpectedCount) public function testNonAdminCannotListAdminProfiles($bHideAdministrators, $iExpectedCount)
{ {