You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Web/Sources/tests/units/model/UserManagerTest.php

117 lines
3.3 KiB

<?php
use PHPUnit\Framework\TestCase;
use Manager\UserManager;
use Model\User;
use Model\Coach;
use Model\Athlete;
use Network\IAuthService;
class UserManagerTest extends TestCase
{
private $authService;
private $userManager;
protected function setUp(): void
{
$this->authService = $this->createMock(IAuthService::class);
$this->userManager = new UserManager($this->authService);
}
public function testLoginSuccess()
{
$loginUser = 'john.doe@example.com';
$passwordUser = 'password123';
$mockUser = new User(1, "Doe", "John", $loginUser, $passwordUser, 'M', 1.80, 75, new \DateTime("1985-05-15"), new Coach());
$this->authService->expects($this->once())
->method('login')
->with($loginUser, $passwordUser)
->willReturn($mockUser);
$result = $this->userManager->login($loginUser, $passwordUser);
$this->assertTrue($result);
$this->assertSame($mockUser, $this->userManager->currentUser);
}
public function testLoginFailure()
{
$loginUser = 'john.doe@example.com';
$passwordUser = 'wrong_password';
// Configure authService to return null during login
$this->authService->expects($this->once())
->method('login')
->with($loginUser, $passwordUser)
->willReturn(null);
// Ensure currentUser is null before attempting to access it
$this->assertNull($this->userManager->currentUser);
$result = $this->userManager->login($loginUser, $passwordUser);
$this->assertFalse($result);
$this->assertNull($this->userManager->currentUser);
}
public function testRegisterSuccess()
{
$loginUser = 'new.user@example.com';
$passwordUser = 'newpassword123';
$data = [
'nom' => 'New',
'prenom' => 'User',
'taille' => 1.75,
'poids' => 70,
'roleName' => 'Athlete',
'sexe' => 'M',
];
$this->authService->expects($this->once())
->method('register')
->with($loginUser, $passwordUser, $data)
->willReturn(true);
$result = $this->userManager->register($loginUser, $passwordUser, $data);
$this->assertTrue($result);
}
/* Manque les Exception
public function testRegisterValidationException(){
$loginUser = 'invalid.user@example.com';
$passwordUser = 'invalidpassword123';
$data = [
'nom' => 'Invalid',
'prenom' => 'User',
'taille' => 1.75,
'poids' => 70,
'roleName' => 'Athlete',
'sexe' => 'M',
];
$this->expectException(\Exception::class);
$this->userManager->register($loginUser, $passwordUser, $data);
}
*/
/* Manque la fonction de déconnexion
public function testDeconnecterSuccess(){
$this->authService->expects($this->once())
->method('logoutUser');
$result = $this->userManager->deconnecter();
$this->assertTrue($result);
}
public function testDeconnecterFailure(){
$this->authService->expects($this->once())
->method('logoutUser');
$result = $this->userManager->deconnecter();
$this->assertFalse($result);
}
*/
}