Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/UserTest.php
Show First 20 Lines • Show All 1,154 Lines • ▼ Show 20 Lines | |||||
* Test user account restrict() and unrestrict() | * Test user account restrict() and unrestrict() | ||||
*/ | */ | ||||
public function testRestrictAndUnrestrict(): void | public function testRestrictAndUnrestrict(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
// Test an account with users, domain | // Test an account with users, domain | ||||
$user = $this->getTestUser('UserAccountA@UserAccount.com'); | $user = $this->getTestUser('UserAccountA@UserAccount.com'); | ||||
$userB = $this->getTestUser('UserAccountB@UserAccount.com'); | |||||
$package_kolab = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first(); | |||||
$package_domain = \App\Package::withEnvTenantContext()->where('title', 'domain-hosting')->first(); | |||||
$domain = $this->getTestDomain('UserAccount.com', [ | |||||
'status' => Domain::STATUS_NEW, | |||||
'type' => Domain::TYPE_HOSTED, | |||||
]); | |||||
$user->assignPackage($package_kolab); | |||||
$domain->assignPackage($package_domain, $user); | |||||
$user->assignPackage($package_kolab, $userB); | |||||
$this->assertFalse($user->isRestricted()); | $this->assertFalse($user->isRestricted()); | ||||
$this->assertFalse($userB->isRestricted()); | |||||
$user->restrict(); | $user->restrict(); | ||||
$this->assertTrue($user->fresh()->isRestricted()); | $this->assertTrue($user->fresh()->isRestricted()); | ||||
$this->assertFalse($userB->fresh()->isRestricted()); | |||||
Queue::assertPushed( | Queue::assertPushed( | ||||
\App\Jobs\User\UpdateJob::class, | \App\Jobs\User\UpdateJob::class, | ||||
function ($job) use ($user) { | function ($job) use ($user) { | ||||
return TestCase::getObjectProperty($job, 'userId') == $user->id; | return TestCase::getObjectProperty($job, 'userId') == $user->id; | ||||
} | } | ||||
); | ); | ||||
$userB->restrict(); | |||||
$this->assertTrue($userB->fresh()->isRestricted()); | |||||
Queue::fake(); // reset queue state | Queue::fake(); // reset queue state | ||||
$user->refresh(); | $user->refresh(); | ||||
$user->unrestrict(); | $user->unrestrict(); | ||||
$this->assertFalse($user->fresh()->isRestricted()); | $this->assertFalse($user->fresh()->isRestricted()); | ||||
$this->assertTrue($userB->fresh()->isRestricted()); | |||||
Queue::assertPushed( | Queue::assertPushed( | ||||
\App\Jobs\User\UpdateJob::class, | \App\Jobs\User\UpdateJob::class, | ||||
function ($job) use ($user) { | function ($job) use ($user) { | ||||
return TestCase::getObjectProperty($job, 'userId') == $user->id; | return TestCase::getObjectProperty($job, 'userId') == $user->id; | ||||
} | } | ||||
); | ); | ||||
Queue::fake(); // reset queue state | |||||
$user->unrestrict(true); | |||||
$this->assertFalse($user->fresh()->isRestricted()); | |||||
$this->assertFalse($userB->fresh()->isRestricted()); | |||||
Queue::assertPushed( | |||||
\App\Jobs\User\UpdateJob::class, | |||||
function ($job) use ($userB) { | |||||
return TestCase::getObjectProperty($job, 'userId') == $userB->id; | |||||
} | |||||
); | |||||
} | } | ||||
/** | /** | ||||
* Tests for AliasesTrait::setAliases() | * Tests for AliasesTrait::setAliases() | ||||
*/ | */ | ||||
public function testSetAliases(): void | public function testSetAliases(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
▲ Show 20 Lines • Show All 223 Lines • Show Last 20 Lines |