-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(organizations): add integration tests
- Loading branch information
Showing
5 changed files
with
86 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Fschmtt\Keycloak\Test\Integration\Resource; | ||
|
||
use Fschmtt\Keycloak\Collection\OrganizationDomainCollection; | ||
use Fschmtt\Keycloak\Representation\Organization; | ||
use Fschmtt\Keycloak\Representation\OrganizationDomain; | ||
use Fschmtt\Keycloak\Representation\Realm; | ||
use Fschmtt\Keycloak\Test\Integration\IntegrationTestBehaviour; | ||
use PHPUnit\Framework\Attributes\AfterClass; | ||
use PHPUnit\Framework\Attributes\BeforeClass; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class OrganizationsTest extends TestCase | ||
{ | ||
use IntegrationTestBehaviour; | ||
private const REALM = 'organizations-tests'; | ||
|
||
#[BeforeClass] | ||
public static function createRealmWithOrganizationsEnabled(): void | ||
{ | ||
static::getKeycloak()->realms()->import(new Realm(realm: self::REALM, organizationsEnabled: true)); | ||
} | ||
|
||
#[AfterClass] | ||
public static function deleteRealmWithOrganizationsEnabled(): void | ||
{ | ||
static::getKeycloak()->realms()->delete(self::REALM); | ||
} | ||
|
||
public function testOrganizations(): void | ||
{ | ||
// No organizations exist yet in realm | ||
$organizations = $this->getKeycloak()->organizations()->all(self::REALM); | ||
static::assertCount(0, $organizations); | ||
|
||
// Create a new organization in realm | ||
$createdOrganization = new Organization( | ||
name: 'created-organization', | ||
domains: new OrganizationDomainCollection([ | ||
new OrganizationDomain('foo.bar', true), | ||
new OrganizationDomain('bar.foo', false), | ||
]), | ||
); | ||
$this->getKeycloak()->organizations()->create(self::REALM, $createdOrganization); | ||
|
||
$organizations = $this->getKeycloak()->organizations()->all(self::REALM); | ||
static::assertCount(1, $organizations); | ||
static::assertSame($createdOrganization->getName(), $organizations->first()->getName()); | ||
|
||
// Get newly created organization | ||
$organization = static::getKeycloak()->organizations()->get(self::REALM, $organizations->first()->getId()); | ||
static::assertSame($createdOrganization->getName(), $organization->getName()); | ||
|
||
// Invite user to newly created organization | ||
static::getKeycloak()->organizations()->inviteUser( | ||
self::REALM, | ||
$organizations->first()->getId(), | ||
'[email protected]', | ||
'John', | ||
'Doe', | ||
); | ||
|
||
// Delete newly created organization | ||
static::getKeycloak()->organizations()->delete(self::REALM, $organizations->first()->getId()); | ||
$organizations = $this->getKeycloak()->organizations()->all(self::REALM); | ||
static::assertCount(0, $organizations); | ||
} | ||
} |