Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Console/User/AddAliasTest.php
- This file was copied from src/tests/Feature/Console/UserRestoreTest.php.
<?php | <?php | ||||
namespace Tests\Feature\Console; | namespace Tests\Feature\Console\User; | ||||
use Illuminate\Support\Facades\Queue; | |||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class UserRestoreTest extends TestCase | class AddAliasTest extends TestCase | ||||
{ | { | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
Show All 12 Lines | public function tearDown(): void | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test the command | * Test the command | ||||
*/ | */ | ||||
public function testHandle(): void | public function testHandle(): void | ||||
{ | { | ||||
Queue::fake(); | |||||
// Non-existing user | // Non-existing user | ||||
$code = \Artisan::call("user:restore unknown@unknown.org"); | $code = \Artisan::call("user:add-alias unknown unknown"); | ||||
$output = trim(\Artisan::output()); | $output = trim(\Artisan::output()); | ||||
$this->assertSame(1, $code); | $this->assertSame(1, $code); | ||||
$this->assertSame("User not found.", $output); | $this->assertSame("User not found.", $output); | ||||
// Create a user account for delete | |||||
$user = $this->getTestUser('user@force-delete.com'); | $user = $this->getTestUser('user@force-delete.com'); | ||||
$domain = $this->getTestDomain('force-delete.com', [ | $domain = $this->getTestDomain('force-delete.com', [ | ||||
'status' => \App\Domain::STATUS_NEW, | 'status' => \App\Domain::STATUS_NEW, | ||||
'type' => \App\Domain::TYPE_HOSTED, | 'type' => \App\Domain::TYPE_HOSTED, | ||||
]); | ]); | ||||
$package_kolab = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first(); | $package_kolab = \App\Package::withEnvTenantContext()->where('title', 'kolab')->first(); | ||||
$package_domain = \App\Package::withEnvTenantContext()->where('title', 'domain-hosting')->first(); | $package_domain = \App\Package::withEnvTenantContext()->where('title', 'domain-hosting')->first(); | ||||
$user->assignPackage($package_kolab); | $user->assignPackage($package_kolab); | ||||
$domain->assignPackage($package_domain, $user); | $domain->assignPackage($package_domain, $user); | ||||
$wallet = $user->wallets()->first(); | |||||
$entitlements = $wallet->entitlements->pluck('id')->all(); | |||||
$this->assertCount(8, $entitlements); | |||||
// Non-deleted user | // Invalid alias | ||||
$code = \Artisan::call("user:restore {$user->email}"); | $code = \Artisan::call("user:add-alias {$user->email} invalid"); | ||||
$output = trim(\Artisan::output()); | $output = trim(\Artisan::output()); | ||||
$this->assertSame(1, $code); | |||||
$this->assertSame("The user is not yet deleted.", $output); | |||||
$user->delete(); | |||||
$this->assertTrue($user->trashed()); | $this->assertSame(1, $code); | ||||
$this->assertTrue($domain->fresh()->trashed()); | $this->assertSame("The specified alias is invalid.", $output); | ||||
// Deleted user | // Test success | ||||
$code = \Artisan::call("user:restore {$user->email}"); | $code = \Artisan::call("user:add-alias {$user->email} test@force-delete.com"); | ||||
$output = trim(\Artisan::output()); | $output = trim(\Artisan::output()); | ||||
$this->assertSame(0, $code); | $this->assertSame(0, $code); | ||||
$this->assertSame("", $output); | $this->assertSame("", $output); | ||||
$this->assertCount(1, $user->aliases()->where('alias', 'test@force-delete.com')->get()); | |||||
// Alias already exists | |||||
$code = \Artisan::call("user:add-alias {$user->email} test@force-delete.com"); | |||||
$output = trim(\Artisan::output()); | |||||
$this->assertSame(1, $code); | |||||
$this->assertSame("Address is already assigned to the user.", $output); | |||||
$this->assertFalse($user->fresh()->trashed()); | // TODO: test --force option | ||||
$this->assertFalse($domain->fresh()->trashed()); | |||||
} | } | ||||
} | } |