Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/UserTest.php
Show First 20 Lines • Show All 377 Lines • ▼ Show 20 Lines | */ | ||||
/** | /** | ||||
* Test User::getConfig() and setConfig() methods | * Test User::getConfig() and setConfig() methods | ||||
*/ | */ | ||||
public function testConfigTrait(): void | public function testConfigTrait(): void | ||||
{ | { | ||||
$john = $this->getTestUser('john@kolab.org'); | $john = $this->getTestUser('john@kolab.org'); | ||||
$john->setSetting('greylist_enabled', null); | $john->setSetting('greylist_enabled', null); | ||||
$john->setSetting('password_policy', null); | |||||
$this->assertSame(['greylist_enabled' => true], $john->getConfig()); | // Greylist_enabled | ||||
$this->assertSame(true, $john->getConfig()['greylist_enabled']); | |||||
$result = $john->setConfig(['greylist_enabled' => false, 'unknown' => false]); | $result = $john->setConfig(['greylist_enabled' => false, 'unknown' => false]); | ||||
$this->assertSame(['greylist_enabled' => false], $john->getConfig()); | $this->assertSame(['unknown' => "The requested configuration parameter is not supported."], $result); | ||||
$this->assertSame(false, $john->getConfig()['greylist_enabled']); | |||||
$this->assertSame('false', $john->getSetting('greylist_enabled')); | $this->assertSame('false', $john->getSetting('greylist_enabled')); | ||||
$result = $john->setConfig(['greylist_enabled' => true]); | $result = $john->setConfig(['greylist_enabled' => true]); | ||||
$this->assertSame(['greylist_enabled' => true], $john->getConfig()); | $this->assertSame([], $result); | ||||
$this->assertSame(true, $john->getConfig()['greylist_enabled']); | |||||
$this->assertSame('true', $john->getSetting('greylist_enabled')); | $this->assertSame('true', $john->getSetting('greylist_enabled')); | ||||
// Password_policy | |||||
$result = $john->setConfig(['password_policy' => true]); | |||||
$this->assertSame(['password_policy' => "Specified password policy is invalid."], $result); | |||||
$this->assertSame(null, $john->getConfig()['password_policy']); | |||||
$this->assertSame(null, $john->getSetting('password_policy')); | |||||
$result = $john->setConfig(['password_policy' => 'min:-1']); | |||||
$this->assertSame(['password_policy' => "Specified password policy is invalid."], $result); | |||||
$result = $john->setConfig(['password_policy' => 'min:-1']); | |||||
$this->assertSame(['password_policy' => "Specified password policy is invalid."], $result); | |||||
$result = $john->setConfig(['password_policy' => 'min:10,unknown']); | |||||
$this->assertSame(['password_policy' => "Specified password policy is invalid."], $result); | |||||
\config(['app.password_policy' => 'min:5,max:100']); | |||||
$result = $john->setConfig(['password_policy' => 'min:4,max:255']); | |||||
$this->assertSame(['password_policy' => "Minimum password length cannot be less than 5."], $result); | |||||
\config(['app.password_policy' => 'min:5,max:100']); | |||||
$result = $john->setConfig(['password_policy' => 'min:10,max:255']); | |||||
$this->assertSame(['password_policy' => "Maximum password length cannot be more than 100."], $result); | |||||
\config(['app.password_policy' => 'min:5,max:255']); | |||||
$result = $john->setConfig(['password_policy' => 'min:10,max:255']); | |||||
$this->assertSame([], $result); | |||||
$this->assertSame('min:10,max:255', $john->getConfig()['password_policy']); | |||||
$this->assertSame('min:10,max:255', $john->getSetting('password_policy')); | |||||
} | } | ||||
/** | /** | ||||
* Test user account degradation and un-degradation | * Test user account degradation and un-degradation | ||||
*/ | */ | ||||
public function testDegradeAndUndegrade(): void | public function testDegradeAndUndegrade(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
▲ Show 20 Lines • Show All 766 Lines • ▼ Show 20 Lines | public function testUsers(): void | ||||
$this->assertCount(0, $users); | $this->assertCount(0, $users); | ||||
$users = $ned->users()->orderBy('email')->get(); | $users = $ned->users()->orderBy('email')->get(); | ||||
$this->assertCount(4, $users); | $this->assertCount(4, $users); | ||||
} | } | ||||
/** | /** | ||||
* Tests for User::walletOwner() (from EntitleableTrait) | |||||
*/ | |||||
public function testWalletOwner(): void | |||||
{ | |||||
$jack = $this->getTestUser('jack@kolab.org'); | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$ned = $this->getTestUser('ned@kolab.org'); | |||||
$this->assertSame($john->id, $john->walletOwner()->id); | |||||
$this->assertSame($john->id, $jack->walletOwner()->id); | |||||
$this->assertSame($john->id, $ned->walletOwner()->id); | |||||
// User with no entitlements | |||||
$user = $this->getTestUser('UserAccountA@UserAccount.com'); | |||||
$this->assertSame($user->id, $user->walletOwner()->id); | |||||
} | |||||
/** | |||||
* Tests for User::wallets() | * Tests for User::wallets() | ||||
*/ | */ | ||||
public function testWallets(): void | public function testWallets(): void | ||||
{ | { | ||||
$this->markTestIncomplete(); | $john = $this->getTestUser('john@kolab.org'); | ||||
$ned = $this->getTestUser('ned@kolab.org'); | |||||
$this->assertSame(1, $john->wallets()->count()); | |||||
$this->assertCount(1, $john->wallets); | |||||
$this->assertInstanceOf(\App\Wallet::class, $john->wallets->first()); | |||||
$this->assertSame(1, $ned->wallets()->count()); | |||||
$this->assertCount(1, $ned->wallets); | |||||
$this->assertInstanceOf(\App\Wallet::class, $ned->wallets->first()); | |||||
} | } | ||||
} | } |