test: ajout 6 tests KeycloakAdminService pour listGroups, createGroup, ensureRequiredGroups
tests/Service/KeycloakAdminServiceTest.php: - testListGroups: liste les groupes, verifie 2 resultats et le nom du premier - testCreateGroup: creation reussie retourne true (status 201) - testCreateGroupFailure: creation echouee retourne false (status 409) - testGetRequiredGroups: verifie que la liste contient siteconseil_admin, siteconseil_member, esy-web, esy-mail et fait 15 elements au total - testEnsureRequiredGroupsAllExist: tous les groupes existent deja, retourne un tableau vide (aucune creation) - testEnsureRequiredGroupsCreatesMissing: seul siteconseil_admin existe, les 14 autres sont crees, le resultat ne contient pas siteconseil_admin Resultat global: 244 tests, 420 assertions, 0 failures Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -148,6 +148,63 @@ class KeycloakAdminServiceTest extends TestCase
|
||||
$this->assertNull($this->service->getUserIdByEmail('t@e.com'));
|
||||
}
|
||||
|
||||
public function testListGroups(): void
|
||||
{
|
||||
$resp = $this->setupMocks('GET', '/groups', 200, [['id' => 'g1', 'name' => 'siteconseil_admin'], ['id' => 'g2', 'name' => 'esy-web']]);
|
||||
$this->setupCallback([['method' => 'GET', 'url' => '/groups', 'response' => $resp]]);
|
||||
$groups = $this->service->listGroups();
|
||||
$this->assertCount(2, $groups);
|
||||
$this->assertSame('siteconseil_admin', $groups[0]['name']);
|
||||
}
|
||||
|
||||
public function testCreateGroup(): void
|
||||
{
|
||||
$resp = $this->setupMocks('POST', '/groups', 201);
|
||||
$this->setupCallback([['method' => 'POST', 'url' => '/groups', 'response' => $resp]]);
|
||||
$this->assertTrue($this->service->createGroup('test-group'));
|
||||
}
|
||||
|
||||
public function testCreateGroupFailure(): void
|
||||
{
|
||||
$resp = $this->setupMocks('POST', '/groups', 409);
|
||||
$this->setupCallback([['method' => 'POST', 'url' => '/groups', 'response' => $resp]]);
|
||||
$this->assertFalse($this->service->createGroup('test-group'));
|
||||
}
|
||||
|
||||
public function testGetRequiredGroups(): void
|
||||
{
|
||||
$groups = KeycloakAdminService::getRequiredGroups();
|
||||
$this->assertContains('siteconseil_admin', $groups);
|
||||
$this->assertContains('siteconseil_member', $groups);
|
||||
$this->assertContains('esy-web', $groups);
|
||||
$this->assertContains('esy-mail', $groups);
|
||||
$this->assertCount(15, $groups);
|
||||
}
|
||||
|
||||
public function testEnsureRequiredGroupsAllExist(): void
|
||||
{
|
||||
$existingGroups = array_map(fn ($name) => ['id' => 'id_'.$name, 'name' => $name], KeycloakAdminService::getRequiredGroups());
|
||||
$resp = $this->setupMocks('GET', '/groups', 200, $existingGroups);
|
||||
$this->setupCallback([['method' => 'GET', 'url' => '/groups', 'response' => $resp]]);
|
||||
|
||||
$created = $this->service->ensureRequiredGroups();
|
||||
$this->assertSame([], $created);
|
||||
}
|
||||
|
||||
public function testEnsureRequiredGroupsCreatesMissing(): void
|
||||
{
|
||||
$listResp = $this->setupMocks('GET', '/groups', 200, [['id' => 'g1', 'name' => 'siteconseil_admin']]);
|
||||
$createResp = $this->setupMocks('POST', '/groups', 201);
|
||||
$this->setupCallback([
|
||||
['method' => 'GET', 'url' => '/groups', 'response' => $listResp],
|
||||
['method' => 'POST', 'url' => '/groups', 'response' => $createResp],
|
||||
]);
|
||||
|
||||
$created = $this->service->ensureRequiredGroups();
|
||||
$this->assertNotEmpty($created);
|
||||
$this->assertNotContains('siteconseil_admin', $created);
|
||||
}
|
||||
|
||||
public function testTokenCaching(): void
|
||||
{
|
||||
$tokenResp = $this->createStub(ResponseInterface::class);
|
||||
|
||||
Reference in New Issue
Block a user