Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/UserTest.php
<?php | <?php | ||||
namespace Tests\Feature; | namespace Tests\Feature; | ||||
use App\User; | use App\User; | ||||
use Illuminate\Support\Facades\Queue; | use Illuminate\Support\Facades\Queue; | ||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class UserTest extends TestCase | class UserTest extends TestCase | ||||
{ | { | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
User::where('email', 'user-create-test@' . \config('app.domain'))->delete(); | $this->deleteTestUser('user-create-test@' . \config('app.domain')); | ||||
$this->deleteTestUser('UserAccountA@UserAccount.com'); | |||||
$this->deleteTestUser('UserAccountB@UserAccount.com'); | |||||
$this->deleteTestUser('userdeletejob@kolabnow.com'); | |||||
} | |||||
public function tearDown(): void | |||||
{ | |||||
$this->deleteTestUser('user-create-test@' . \config('app.domain')); | |||||
$this->deleteTestUser('UserAccountA@UserAccount.com'); | |||||
$this->deleteTestUser('UserAccountB@UserAccount.com'); | |||||
$this->deleteTestUser('userdeletejob@kolabnow.com'); | |||||
parent::tearDown(); | |||||
} | } | ||||
/** | /** | ||||
* Verify user creation process | * Verify user creation process | ||||
*/ | */ | ||||
public function testUserCreateJob(): void | public function testUserCreateJob(): void | ||||
{ | { | ||||
// Fake the queue, assert that no jobs were pushed... | // Fake the queue, assert that no jobs were pushed... | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | public function testUserDomains(): void | ||||
foreach ($user->domains() as $domain) { | foreach ($user->domains() as $domain) { | ||||
$domains[] = $domain->namespace; | $domains[] = $domain->namespace; | ||||
} | } | ||||
$this->assertContains('kolabnow.com', $domains); | $this->assertContains('kolabnow.com', $domains); | ||||
$this->assertContains('kolab.org', $domains); | $this->assertContains('kolab.org', $domains); | ||||
} | } | ||||
public function testUserQuota(): void | |||||
{ | |||||
$user = $this->getTestUser('john@kolab.org'); | |||||
$storage_sku = \App\Sku::where('title', 'storage')->first(); | |||||
$count = 0; | |||||
foreach ($user->entitlements()->get() as $entitlement) { | |||||
if ($entitlement->sku_id == $storage_sku->id) { | |||||
$count += 1; | |||||
} | |||||
} | |||||
$this->assertTrue($count == 2); | |||||
} | |||||
/** | |||||
* Test user deletion | |||||
*/ | |||||
public function testUserDelete(): void | |||||
{ | |||||
$user = $this->getTestUser('userdeletejob@kolabnow.com'); | |||||
$package = \App\Package::where('title', 'kolab')->first(); | |||||
$user->assignPackage($package); | |||||
$id = $user->id; | |||||
$user->delete(); | |||||
$job = new \App\Jobs\UserDelete($id); | |||||
$job->handle(); | |||||
$user->forceDelete(); | |||||
$entitlements = \App\Entitlement::where('owner_id', 'id')->get(); | |||||
$this->assertCount(0, $entitlements); | |||||
} | |||||
/** | /** | ||||
* Tests for User::findByEmail() | * Tests for User::findByEmail() | ||||
*/ | */ | ||||
public function testFindByEmail(): void | public function testFindByEmail(): void | ||||
{ | { | ||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$result = User::findByEmail('john'); | $result = User::findByEmail('john'); | ||||
Show All 13 Lines |