mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-28 04:58:46 +02:00
N°7633 - Reloads the same user multiple times if it no longer exists (#692)
* N°7633 - Reloads the same user multiple times if it no longer exists * Update core/userrights.class.inc.php good catch Co-authored-by: Thomas Casteleyn <thomas.casteleyn@super-visions.com> * Update core/userrights.class.inc.php good catch (again) Co-authored-by: Thomas Casteleyn <thomas.casteleyn@super-visions.com> * Update core/userrights.class.inc.php Co-authored-by: Thomas Casteleyn <thomas.casteleyn@super-visions.com> * PR feedbacks from Romain * ci: rename user logins --------- Co-authored-by: Thomas Casteleyn <thomas.casteleyn@super-visions.com>
This commit is contained in:
@@ -488,4 +488,55 @@ class UserRightsTest extends ItopDataTestCase
|
||||
'with Admins hidden' => [true, 0],
|
||||
];
|
||||
}
|
||||
|
||||
public function testFindUser_ExistingInternalUser()
|
||||
{
|
||||
$sLogin = 'UserRightsFindUser'.uniqid();
|
||||
$iKey = $this->CreateUser($sLogin, self::$aURP_Profiles['Administrator'])->GetKey();
|
||||
$oUser = $this->InvokeNonPublicStaticMethod(UserRights::class, "FindUser", [$sLogin]);
|
||||
|
||||
$this->assertNotNull($oUser);
|
||||
$this->assertEquals($iKey, $oUser->GetKey());
|
||||
$this->assertEquals(\UserLocal::class, get_class($oUser));
|
||||
|
||||
$this->assertDBQueryCount(0, function() use ($sLogin, $iKey){
|
||||
$oUser = $this->InvokeNonPublicStaticMethod(UserRights::class, "FindUser", [$sLogin]);
|
||||
static::assertEquals($iKey, $oUser->GetKey());
|
||||
static::assertEquals(\UserLocal::class, get_class($oUser));
|
||||
});
|
||||
}
|
||||
|
||||
public function testFindUser_ExistingExternalUser()
|
||||
{
|
||||
$sLogin = 'UserRightsFindUser'.uniqid();
|
||||
|
||||
$iKey = $this->GivenObjectInDB(\UserExternal::class, [
|
||||
'login' => $sLogin,
|
||||
'language' => 'EN US',
|
||||
]);
|
||||
|
||||
$oUser = $this->InvokeNonPublicStaticMethod(UserRights::class, "FindUser", [$sLogin]);
|
||||
|
||||
$this->assertNotNull($oUser);
|
||||
$this->assertEquals($iKey, $oUser->GetKey());
|
||||
$this->assertEquals(\UserExternal::class, get_class($oUser));
|
||||
|
||||
$this->assertDBQueryCount(0, function() use ($sLogin, $iKey){
|
||||
$oUser = $this->InvokeNonPublicStaticMethod(UserRights::class, "FindUser", [$sLogin]);
|
||||
static::assertEquals($iKey, $oUser->GetKey());
|
||||
static::assertEquals(\UserExternal::class, get_class($oUser));
|
||||
});
|
||||
}
|
||||
|
||||
public function testFindUser_UnknownLogin_AvoidSameSqlQueryTwice()
|
||||
{
|
||||
$sLogin = 'UserRightsFindUser'.uniqid();
|
||||
$oUser = $this->InvokeNonPublicStaticMethod(UserRights::class, "FindUser", [$sLogin]);
|
||||
$this->assertNull($oUser);
|
||||
|
||||
$this->assertDBQueryCount(0, function() use ($sLogin){
|
||||
$oUser = $this->InvokeNonPublicStaticMethod(UserRights::class, "FindUser", [$sLogin]);
|
||||
$this->assertNull($oUser);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user