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:
odain-cbd
2024-12-17 17:27:49 +01:00
committed by GitHub
parent 56d3ac668c
commit 5f85757630
2 changed files with 86 additions and 40 deletions

View File

@@ -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);
});
}
}