forked from fschmtt/keycloak-rest-api-client-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRealmsTest.php
More file actions
124 lines (89 loc) · 3.7 KB
/
Copy pathRealmsTest.php
File metadata and controls
124 lines (89 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
declare(strict_types=1);
namespace Fschmtt\Keycloak\Test\Integration\Resource;
use Fschmtt\Keycloak\Collection\RealmCollection;
use Fschmtt\Keycloak\Representation\Realm;
use Fschmtt\Keycloak\Test\Integration\IntegrationTestBehaviour;
use Fschmtt\Keycloak\Type\Map;
use PHPUnit\Framework\TestCase;
class RealmsTest extends TestCase
{
use IntegrationTestBehaviour;
public function testCanGetAllRealms(): void
{
$realms = $this->getKeycloak()->realms()->all();
static::assertInstanceOf(RealmCollection::class, $realms);
static::assertGreaterThanOrEqual(1, $realms->count());
}
public function testCanGetRealm(): void
{
$realm = $this->getKeycloak()->realms()->get(realm: 'master');
static::assertEquals('master', $realm->getRealm());
}
public function testCanGetRealmKeys(): void
{
$realmkeys = $this->getKeycloak()->realms()->keys(realm: 'master');
static::assertArrayHasKey('AES', $realmkeys->getActive());
static::assertGreaterThan(1, $realmkeys->getKeys()->count());
}
public function testCanUpdateRealm(): void
{
$realm = $this->getKeycloak()->realms()->get(realm: 'master');
static::assertFalse($realm->getRegistrationAllowed());
$realm = $realm->withRegistrationAllowed(true);
$realm = $this->getKeycloak()->realms()->update($realm->getRealm(), $realm);
static::assertTrue($realm->getRegistrationAllowed());
}
public function testCanImportRealm(): void
{
$realm = new Realm(id: 'testing-id', realm: 'testing-realm');
$realm = $this->getKeycloak()->realms()->import(realm: $realm);
static::assertEquals('testing-id', $realm->getId());
static::assertEquals('testing-realm', $realm->getRealm());
static::assertCount(2, $this->getKeycloak()->realms()->all());
}
public function testCanClearCaches(): void
{
$this->expectNotToPerformAssertions();
$realm = new Realm(realm: 'master');
$this->getKeycloak()->realms()->clearKeysCache($realm->getRealm());
$this->getKeycloak()->realms()->clearRealmCache($realm->getRealm());
$this->getKeycloak()->realms()->clearUserCache($realm->getRealm());
}
public function testCanClearKeysCache(): void
{
$this->expectNotToPerformAssertions();
$this->getKeycloak()->realms()->clearKeysCache('master');
}
public function testCanClearRealmCache(): void
{
$this->expectNotToPerformAssertions();
$this->getKeycloak()->realms()->clearRealmCache('master');
}
public function testCanClearUserCache(): void
{
$this->expectNotToPerformAssertions();
$this->getKeycloak()->realms()->clearUserCache('master');
}
public function testCanGetAdminEvents(): void
{
$adminEvents = $this->getKeycloak()->realms()->adminEvents('master');
static::assertEmpty($adminEvents);
}
public function testCanDeleteAdminEvents(): void
{
$this->expectNotToPerformAssertions();
$this->getKeycloak()->realms()->deleteAdminEvents('master');
}
public function testCanUpdateRealmAttributes(): void
{
$realm = $this->getKeycloak()->realms()->get(realm: 'master');
static::assertFalse($realm->getAttributes()->contains('termsUrl'));
$realm = $realm->withAttributes(new Map([
'termsUrl' => 'https://example.com/terms',
]));
$this->getKeycloak()->realms()->update($realm->getRealm(), $realm);
$updatedRealm = $this->getKeycloak()->realms()->get(realm: $realm->getRealm());
static::assertEquals('https://example.com/terms', $updatedRealm->getAttributes()->get('termsUrl'));
}
}