Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/GroupTest.php
Show All 37 Lines | public function testAssignToWallet(): void | ||||
$this->assertSame(1, $group->entitlements()->count()); | $this->assertSame(1, $group->entitlements()->count()); | ||||
// Can't be done twice on the same group | // Can't be done twice on the same group | ||||
$this->expectException(\Exception::class); | $this->expectException(\Exception::class); | ||||
$result->assignToWallet($user->wallets->first()); | $result->assignToWallet($user->wallets->first()); | ||||
} | } | ||||
/** | /** | ||||
* Test Group::getConfig() and setConfig() methods | |||||
*/ | |||||
public function testConfigTrait(): void | |||||
{ | |||||
$group = $this->getTestGroup('group-test@kolabnow.com'); | |||||
$group->setSetting('sender_policy', '["test","-"]'); | |||||
$this->assertSame(['sender_policy' => ['test']], $group->getConfig()); | |||||
$result = $group->setConfig(['sender_policy' => [], 'unknown' => false]); | |||||
$this->assertSame(['sender_policy' => []], $group->getConfig()); | |||||
$this->assertSame('[]', $group->getSetting('sender_policy')); | |||||
$this->assertSame(['unknown' => "The requested configuration parameter is not supported."], $result); | |||||
$result = $group->setConfig(['sender_policy' => ['test']]); | |||||
$this->assertSame(['sender_policy' => ['test']], $group->getConfig()); | |||||
$this->assertSame('["test","-"]', $group->getSetting('sender_policy')); | |||||
$this->assertSame([], $result); | |||||
} | |||||
/** | |||||
* Test group status assignment and is*() methods | * Test group status assignment and is*() methods | ||||
*/ | */ | ||||
public function testStatus(): void | public function testStatus(): void | ||||
{ | { | ||||
$group = new Group(); | $group = new Group(); | ||||
$this->assertSame(false, $group->isNew()); | $this->assertSame(false, $group->isNew()); | ||||
$this->assertSame(false, $group->isActive()); | $this->assertSame(false, $group->isActive()); | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | public function testEmailExists(): void | ||||
$this->assertTrue(Group::emailExists($group->email)); | $this->assertTrue(Group::emailExists($group->email)); | ||||
$result = Group::emailExists($group->email, true); | $result = Group::emailExists($group->email, true); | ||||
$this->assertSame($result->id, $group->id); | $this->assertSame($result->id, $group->id); | ||||
} | } | ||||
/** | /** | ||||
* Tests for GroupSettingsTrait functionality and GroupSettingObserver | |||||
*/ | |||||
public function testSettings(): void | |||||
{ | |||||
Queue::fake(); | |||||
Queue::assertNothingPushed(); | |||||
$group = $this->getTestGroup('group-test@kolabnow.com'); | |||||
Queue::assertPushed(\App\Jobs\Group\UpdateJob::class, 0); | |||||
// Add a setting | |||||
$group->setSetting('unknown', 'test'); | |||||
Queue::assertPushed(\App\Jobs\Group\UpdateJob::class, 0); | |||||
// Add a setting that is synced to LDAP | |||||
$group->setSetting('sender_policy', '[]'); | |||||
Queue::assertPushed(\App\Jobs\Group\UpdateJob::class, 1); | |||||
// Note: We test both current group as well as fresh group object | |||||
// to make sure cache works as expected | |||||
$this->assertSame('test', $group->getSetting('unknown')); | |||||
$this->assertSame('[]', $group->fresh()->getSetting('sender_policy')); | |||||
Queue::fake(); | |||||
// Update a setting | |||||
$group->setSetting('unknown', 'test1'); | |||||
Queue::assertPushed(\App\Jobs\Group\UpdateJob::class, 0); | |||||
// Update a setting that is synced to LDAP | |||||
$group->setSetting('sender_policy', '["-"]'); | |||||
Queue::assertPushed(\App\Jobs\Group\UpdateJob::class, 1); | |||||
$this->assertSame('test1', $group->getSetting('unknown')); | |||||
$this->assertSame('["-"]', $group->fresh()->getSetting('sender_policy')); | |||||
Queue::fake(); | |||||
// Delete a setting (null) | |||||
$group->setSetting('unknown', null); | |||||
Queue::assertPushed(\App\Jobs\Group\UpdateJob::class, 0); | |||||
// Delete a setting that is synced to LDAP | |||||
$group->setSetting('sender_policy', null); | |||||
Queue::assertPushed(\App\Jobs\Group\UpdateJob::class, 1); | |||||
$this->assertSame(null, $group->getSetting('unknown')); | |||||
$this->assertSame(null, $group->fresh()->getSetting('sender_policy')); | |||||
} | |||||
/** | |||||
* Tests for Group::suspend() | * Tests for Group::suspend() | ||||
*/ | */ | ||||
public function testSuspend(): void | public function testSuspend(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
$group = $this->getTestGroup('group-test@kolabnow.com'); | $group = $this->getTestGroup('group-test@kolabnow.com'); | ||||
$group->suspend(); | $group->suspend(); | ||||
▲ Show 20 Lines • Show All 66 Lines • Show Last 20 Lines |