Page MenuHomePhorge

D2936.1775573107.diff
No OneTemporary

Authored By
Unknown
Size
36 KB
Referenced Files
None
Subscribers
None

D2936.1775573107.diff

diff --git a/src/app/Console/Commands/UserAddAlias.php b/src/app/Console/Commands/User/AddAliasCommand.php
rename from src/app/Console/Commands/UserAddAlias.php
rename to src/app/Console/Commands/User/AddAliasCommand.php
--- a/src/app/Console/Commands/UserAddAlias.php
+++ b/src/app/Console/Commands/User/AddAliasCommand.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
use App\Console\Command;
use App\Http\Controllers\API\V4\UsersController;
-class UserAddAlias extends Command
+class AddAliasCommand extends Command
{
/**
* The name and signature of the console command.
@@ -31,6 +31,7 @@
$user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
diff --git a/src/app/Console/Commands/UserAssignSku.php b/src/app/Console/Commands/User/AssignSkuCommand.php
rename from src/app/Console/Commands/UserAssignSku.php
rename to src/app/Console/Commands/User/AssignSkuCommand.php
--- a/src/app/Console/Commands/UserAssignSku.php
+++ b/src/app/Console/Commands/User/AssignSkuCommand.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
use App\Console\Command;
-class UserAssignSku extends Command
+class AssignSkuCommand extends Command
{
/**
* The name and signature of the console command.
@@ -30,7 +30,7 @@
$user = $this->getUser($this->argument('user'));
if (!$user) {
- $this->error("Unable to find the user {$this->argument('user')}.");
+ $this->error("User not found.");
return 1;
}
diff --git a/src/app/Console/Commands/UserDomains.php b/src/app/Console/Commands/User/DomainsCommand.php
rename from src/app/Console/Commands/UserDomains.php
rename to src/app/Console/Commands/User/DomainsCommand.php
--- a/src/app/Console/Commands/UserDomains.php
+++ b/src/app/Console/Commands/User/DomainsCommand.php
@@ -1,24 +1,24 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
use App\Console\Command;
-class UserDomains extends Command
+class DomainsCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
- protected $signature = 'user:domains {userid}';
+ protected $signature = 'user:domains {user}';
/**
* The console command description.
*
* @var string
*/
- protected $description = 'Command description';
+ protected $description = "List a user's domains.";
/**
* Execute the console command.
@@ -27,14 +27,15 @@
*/
public function handle()
{
- $user = $this->getUser($this->argument('userid'));
+ $user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
foreach ($user->domains() as $domain) {
- $this->info("{$domain->namespace}");
+ $this->info($domain->namespace);
}
}
}
diff --git a/src/app/Console/Commands/UserEntitlements.php b/src/app/Console/Commands/User/EntitlementsCommand.php
rename from src/app/Console/Commands/UserEntitlements.php
rename to src/app/Console/Commands/User/EntitlementsCommand.php
--- a/src/app/Console/Commands/UserEntitlements.php
+++ b/src/app/Console/Commands/User/EntitlementsCommand.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
use App\Console\Command;
-class UserEntitlements extends Command
+class EntitlementsCommand extends Command
{
/**
* The name and signature of the console command.
@@ -30,11 +30,10 @@
$user = $this->getUser($this->argument('userid'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
- $this->info("Found user: {$user->id}");
-
$skus_counted = [];
foreach ($user->entitlements as $entitlement) {
@@ -47,7 +46,7 @@
foreach ($skus_counted as $id => $qty) {
$sku = \App\Sku::find($id);
- $this->info("SKU: {$sku->title} ({$qty})");
+ $this->info("{$sku->title}: {$qty}");
}
}
}
diff --git a/src/app/Console/Commands/UserForceDelete.php b/src/app/Console/Commands/User/ForceDeleteCommand.php
rename from src/app/Console/Commands/UserForceDelete.php
rename to src/app/Console/Commands/User/ForceDeleteCommand.php
--- a/src/app/Console/Commands/UserForceDelete.php
+++ b/src/app/Console/Commands/User/ForceDeleteCommand.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
use App\Console\Command;
use Illuminate\Support\Facades\DB;
-class UserForceDelete extends Command
+class ForceDeleteCommand extends Command
{
/**
* The name and signature of the console command.
@@ -31,11 +31,12 @@
$user = $this->getUser($this->argument('user'), true);
if (!$user) {
+ $this->error("User not found.");
return 1;
}
if (!$user->trashed()) {
- $this->error('The user is not yet deleted');
+ $this->error("The user is not yet deleted.");
return 1;
}
diff --git a/src/app/Console/Commands/User/GreylistCommand.php b/src/app/Console/Commands/User/GreylistCommand.php
--- a/src/app/Console/Commands/User/GreylistCommand.php
+++ b/src/app/Console/Commands/User/GreylistCommand.php
@@ -21,16 +21,6 @@
protected $description = 'List currently greylisted delivery attempts for the user.';
/**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
* Execute the console command.
*
* @return mixed
diff --git a/src/app/Console/Commands/UserRestore.php b/src/app/Console/Commands/User/RestoreCommand.php
rename from src/app/Console/Commands/UserRestore.php
rename to src/app/Console/Commands/User/RestoreCommand.php
--- a/src/app/Console/Commands/UserRestore.php
+++ b/src/app/Console/Commands/User/RestoreCommand.php
@@ -1,11 +1,11 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
use App\Console\Command;
use Illuminate\Support\Facades\DB;
-class UserRestore extends Command
+class RestoreCommand extends Command
{
/**
* The name and signature of the console command.
@@ -31,12 +31,12 @@
$user = $this->getUser($this->argument('user'), true);
if (!$user) {
- $this->error('User not found.');
+ $this->error("User not found.");
return 1;
}
if (!$user->trashed()) {
- $this->error('The user is not yet deleted.');
+ $this->error("The user is not deleted.");
return 1;
}
diff --git a/src/app/Console/Commands/UserDiscount.php b/src/app/Console/Commands/User/SetDiscountCommand.php
rename from src/app/Console/Commands/UserDiscount.php
rename to src/app/Console/Commands/User/SetDiscountCommand.php
--- a/src/app/Console/Commands/UserDiscount.php
+++ b/src/app/Console/Commands/User/SetDiscountCommand.php
@@ -1,17 +1,17 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
use App\Console\Command;
-class UserDiscount extends Command
+class SetDiscountCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
- protected $signature = 'user:discount {user} {discount}';
+ protected $signature = 'user:set-discount {user} {discount}';
/**
* The console command description.
@@ -30,17 +30,17 @@
$user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
- $this->info("Found user {$user->id}");
-
if ($this->argument('discount') === '0') {
$discount = null;
} else {
$discount = $this->getObject(\App\Discount::class, $this->argument('discount'));
if (!$discount) {
+ $this->error("Discount not found.");
return 1;
}
}
diff --git a/src/app/Console/Commands/User/StatusCommand.php b/src/app/Console/Commands/User/StatusCommand.php
--- a/src/app/Console/Commands/User/StatusCommand.php
+++ b/src/app/Console/Commands/User/StatusCommand.php
@@ -2,7 +2,8 @@
namespace App\Console\Commands\User;
-use Illuminate\Console\Command;
+use App\Console\Command;
+use App\User;
class StatusCommand extends Command
{
@@ -21,40 +22,26 @@
protected $description = "Show a user's status.";
/**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
-
- /**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
- $user = \App\User::withTrashed()->withEnvTenantContext()->where('email', $this->argument('user'))->first();
-
- if (!$user) {
- $user = \App\User::withTrashed()->withEnvTenantContext()->where('id', $this->argument('user'))->first();
- }
+ $user = $this->getUser($this->argument('user'), true);
if (!$user) {
- $this->error("No such user '" . $this->argument('user') . "' within this tenant context.");
- $this->info("Try ./artisan scalpel:user:read --attr=email --attr=tenant_id " . $this->argument('user'));
+ $this->error("User not found.");
+ $this->error("Try ./artisan scalpel:user:read --attr=email --attr=tenant_id " . $this->argument('user'));
return 1;
}
$statuses = [
- 'active' => \App\User::STATUS_ACTIVE,
- 'suspended' => \App\User::STATUS_SUSPENDED,
- 'deleted' => \App\User::STATUS_DELETED,
- 'ldapReady' => \App\User::STATUS_LDAP_READY,
- 'imapReady' => \App\User::STATUS_IMAP_READY,
+ 'active' => User::STATUS_ACTIVE,
+ 'suspended' => User::STATUS_SUSPENDED,
+ 'deleted' => User::STATUS_DELETED,
+ 'ldapReady' => User::STATUS_LDAP_READY,
+ 'imapReady' => User::STATUS_IMAP_READY,
];
$user_state = [];
diff --git a/src/app/Console/Commands/UserSuspend.php b/src/app/Console/Commands/User/SuspendCommand.php
rename from src/app/Console/Commands/UserSuspend.php
rename to src/app/Console/Commands/User/SuspendCommand.php
--- a/src/app/Console/Commands/UserSuspend.php
+++ b/src/app/Console/Commands/User/SuspendCommand.php
@@ -1,11 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
-use App\User;
use App\Console\Command;
-class UserSuspend extends Command
+class SuspendCommand extends Command
{
/**
* The name and signature of the console command.
@@ -31,11 +30,10 @@
$user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
- $this->info("Found user: {$user->id}");
-
$user->suspend();
}
}
diff --git a/src/app/Console/Commands/UserUnsuspend.php b/src/app/Console/Commands/User/UnsuspendCommand.php
rename from src/app/Console/Commands/UserUnsuspend.php
rename to src/app/Console/Commands/User/UnsuspendCommand.php
--- a/src/app/Console/Commands/UserUnsuspend.php
+++ b/src/app/Console/Commands/User/UnsuspendCommand.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
use App\Console\Command;
-class UserUnsuspend extends Command
+class UnsuspendCommand extends Command
{
/**
* The name and signature of the console command.
@@ -18,7 +18,7 @@
*
* @var string
*/
- protected $description = 'Remove a user suspension';
+ protected $description = 'Unsuspend a user.';
/**
* Execute the console command.
@@ -30,11 +30,10 @@
$user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
- $this->info("Found user {$user->id}");
-
$user->unsuspend();
}
}
diff --git a/src/app/Console/Commands/UserVerify.php b/src/app/Console/Commands/User/VerifyCommand.php
rename from src/app/Console/Commands/UserVerify.php
rename to src/app/Console/Commands/User/VerifyCommand.php
--- a/src/app/Console/Commands/UserVerify.php
+++ b/src/app/Console/Commands/User/VerifyCommand.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
use App\Console\Command;
-class UserVerify extends Command
+class VerifyCommand extends Command
{
/**
* The name and signature of the console command.
@@ -30,12 +30,13 @@
$user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
- $this->info("Found user: {$user->id}");
-
$job = new \App\Jobs\User\VerifyJob($user->id);
$job->handle();
+
+ // TODO: We should check the job result and print an error on failure
}
}
diff --git a/src/app/Console/Commands/UserWallets.php b/src/app/Console/Commands/User/WalletsCommand.php
rename from src/app/Console/Commands/UserWallets.php
rename to src/app/Console/Commands/User/WalletsCommand.php
--- a/src/app/Console/Commands/UserWallets.php
+++ b/src/app/Console/Commands/User/WalletsCommand.php
@@ -1,10 +1,10 @@
<?php
-namespace App\Console\Commands;
+namespace App\Console\Commands\User;
use App\Console\Command;
-class UserWallets extends Command
+class WalletsCommand extends Command
{
/**
* The name and signature of the console command.
@@ -18,7 +18,7 @@
*
* @var string
*/
- protected $description = 'List wallets for a user';
+ protected $description = "List a user's wallets.";
/**
* Execute the console command.
@@ -30,6 +30,7 @@
$user = $this->getUser($this->argument('user'));
if (!$user) {
+ $this->error("User not found.");
return 1;
}
diff --git a/src/app/Console/Commands/UserDelete.php b/src/app/Console/Commands/UserDelete.php
deleted file mode 100644
--- a/src/app/Console/Commands/UserDelete.php
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-
-namespace App\Console\Commands;
-
-use App\Console\Command;
-
-class UserDelete extends Command
-{
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'user:delete {user}';
-
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Delete a user';
-
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- $user = $this->getUser($this->argument('user'));
-
- if (!$user) {
- return 1;
- }
-
- $user->delete();
- }
-}
diff --git a/src/tests/Feature/Console/DomainsTest.php b/src/tests/Feature/Console/DomainsTest.php
--- a/src/tests/Feature/Console/DomainsTest.php
+++ b/src/tests/Feature/Console/DomainsTest.php
@@ -1,6 +1,6 @@
<?php
-namespace Tests\Feature\Console\Domain;
+namespace Tests\Feature\Console;
use Tests\TestCase;
@@ -23,5 +23,6 @@
// TODO: Test --deleted argument
// TODO: Test output format and other attributes
// TODO: Test tenant context
+ $this->markTestIncomplete();
}
}
diff --git a/src/tests/Feature/Console/UserRestoreTest.php b/src/tests/Feature/Console/User/AddAliasTest.php
rename from src/tests/Feature/Console/UserRestoreTest.php
rename to src/tests/Feature/Console/User/AddAliasTest.php
--- a/src/tests/Feature/Console/UserRestoreTest.php
+++ b/src/tests/Feature/Console/User/AddAliasTest.php
@@ -1,11 +1,10 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
-use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
-class UserRestoreTest extends TestCase
+class AddAliasTest extends TestCase
{
/**
* {@inheritDoc}
@@ -34,15 +33,13 @@
*/
public function testHandle(): void
{
- Queue::fake();
-
// Non-existing user
- $code = \Artisan::call("user:restore unknown@unknown.org");
+ $code = \Artisan::call("user:add-alias unknown unknown");
$output = trim(\Artisan::output());
+
$this->assertSame(1, $code);
$this->assertSame("User not found.", $output);
- // Create a user account for delete
$user = $this->getTestUser('user@force-delete.com');
$domain = $this->getTestDomain('force-delete.com', [
'status' => \App\Domain::STATUS_NEW,
@@ -52,29 +49,29 @@
$package_domain = \App\Package::withEnvTenantContext()->where('title', 'domain-hosting')->first();
$user->assignPackage($package_kolab);
$domain->assignPackage($package_domain, $user);
- $wallet = $user->wallets()->first();
- $entitlements = $wallet->entitlements->pluck('id')->all();
-
- $this->assertCount(8, $entitlements);
- // Non-deleted user
- $code = \Artisan::call("user:restore {$user->email}");
+ // Invalid alias
+ $code = \Artisan::call("user:add-alias {$user->email} invalid");
$output = trim(\Artisan::output());
- $this->assertSame(1, $code);
- $this->assertSame("The user is not yet deleted.", $output);
-
- $user->delete();
- $this->assertTrue($user->trashed());
- $this->assertTrue($domain->fresh()->trashed());
+ $this->assertSame(1, $code);
+ $this->assertSame("The specified alias is invalid.", $output);
- // Deleted user
- $code = \Artisan::call("user:restore {$user->email}");
+ // Test success
+ $code = \Artisan::call("user:add-alias {$user->email} test@force-delete.com");
$output = trim(\Artisan::output());
+
$this->assertSame(0, $code);
$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());
- $this->assertFalse($domain->fresh()->trashed());
+ // TODO: test --force option
}
}
diff --git a/src/tests/Feature/Console/UserAssignSkuTest.php b/src/tests/Feature/Console/User/AssignSkuTest.php
rename from src/tests/Feature/Console/UserAssignSkuTest.php
rename to src/tests/Feature/Console/User/AssignSkuTest.php
--- a/src/tests/Feature/Console/UserAssignSkuTest.php
+++ b/src/tests/Feature/Console/User/AssignSkuTest.php
@@ -1,10 +1,10 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
use Tests\TestCase;
-class UserAssignSkuTest extends TestCase
+class AssignSkuTest extends TestCase
{
/**
* {@inheritDoc}
@@ -36,7 +36,7 @@
$this->artisan('user:assign-sku unknown@unknown.org ' . $sku->id)
->assertExitCode(1)
- ->expectsOutput("Unable to find the user unknown@unknown.org.");
+ ->expectsOutput("User not found.");
$this->artisan('user:assign-sku ' . $user->email . ' unknownsku')
->assertExitCode(1)
diff --git a/src/tests/Feature/Console/User/DeleteTest.php b/src/tests/Feature/Console/User/DeleteTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/User/DeleteTest.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Tests\Feature\Console\User;
+
+use Tests\TestCase;
+
+class DeleteTest extends TestCase
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+
+ $this->deleteTestUser('user@force-delete.com');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function tearDown(): void
+ {
+ $this->deleteTestUser('user@force-delete.com');
+
+ parent::tearDown();
+ }
+
+ /**
+ * Test the command
+ */
+ public function testHandle(): void
+ {
+ // Non-existing user
+ $code = \Artisan::call("user:delete unknown");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(1, $code);
+ $this->assertSame("No such user unknown", $output);
+
+ $user = $this->getTestUser('user@force-delete.com');
+
+ // Test success
+ $code = \Artisan::call("user:delete {$user->email}");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertSame("", $output);
+ $this->assertTrue($user->fresh()->trashed());
+
+ // User already deleted
+ $code = \Artisan::call("user:delete {$user->email}");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(1, $code);
+ $this->assertSame("No such user user@force-delete.com", $output);
+ }
+}
diff --git a/src/tests/Feature/Console/User/DomainsTest.php b/src/tests/Feature/Console/User/DomainsTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/User/DomainsTest.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Tests\Feature\Console\User;
+
+use Tests\TestCase;
+
+class DomainsTest extends TestCase
+{
+ /**
+ * Test command runs
+ */
+ public function testHandle(): void
+ {
+ $code = \Artisan::call("user:domains unknown");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(1, $code);
+ $this->assertSame("User not found.", $output);
+
+ $code = \Artisan::call("user:domains john@kolab.org");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertTrue(strpos($output, "kolab.org") !== false);
+ $this->assertTrue(strpos($output, \config('app.domain')) !== false);
+ }
+}
diff --git a/src/tests/Feature/Console/User/EntitlementsTest.php b/src/tests/Feature/Console/User/EntitlementsTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/User/EntitlementsTest.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace Tests\Feature\Console\User;
+
+use Tests\TestCase;
+
+class EntitlementsTest extends TestCase
+{
+ /**
+ * Test command runs
+ */
+ public function testHandle(): void
+ {
+ $code = \Artisan::call("user:entitlements unknown");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(1, $code);
+ $this->assertSame("User not found.", $output);
+
+ $code = \Artisan::call("user:entitlements john@kolab.org");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertTrue(strpos($output, "storage: 5") !== false);
+ $this->assertTrue(strpos($output, "mailbox: 1") !== false);
+ $this->assertTrue(strpos($output, "groupware: 1") !== false);
+ }
+}
diff --git a/src/tests/Feature/Console/UserForceDeleteTest.php b/src/tests/Feature/Console/User/ForceDeleteTest.php
rename from src/tests/Feature/Console/UserForceDeleteTest.php
rename to src/tests/Feature/Console/User/ForceDeleteTest.php
--- a/src/tests/Feature/Console/UserForceDeleteTest.php
+++ b/src/tests/Feature/Console/User/ForceDeleteTest.php
@@ -1,11 +1,11 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
-class UserForceDeleteTest extends TestCase
+class ForceDeleteTest extends TestCase
{
/**
* {@inheritDoc}
diff --git a/src/tests/Feature/Console/UserDiscountTest.php b/src/tests/Feature/Console/User/GreylistTest.php
rename from src/tests/Feature/Console/UserDiscountTest.php
rename to src/tests/Feature/Console/User/GreylistTest.php
--- a/src/tests/Feature/Console/UserDiscountTest.php
+++ b/src/tests/Feature/Console/User/GreylistTest.php
@@ -1,11 +1,14 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
use Tests\TestCase;
-class UserDiscountTest extends TestCase
+class GreylistTest extends TestCase
{
+ /**
+ * Test command runs
+ */
public function testHandle(): void
{
$this->markTestIncomplete();
diff --git a/src/tests/Feature/Console/UserRestoreTest.php b/src/tests/Feature/Console/User/RestoreTest.php
rename from src/tests/Feature/Console/UserRestoreTest.php
rename to src/tests/Feature/Console/User/RestoreTest.php
--- a/src/tests/Feature/Console/UserRestoreTest.php
+++ b/src/tests/Feature/Console/User/RestoreTest.php
@@ -1,11 +1,11 @@
<?php
-namespace Tests\Feature\Console;
+namespace Tests\Feature\Console\User;
use Illuminate\Support\Facades\Queue;
use Tests\TestCase;
-class UserRestoreTest extends TestCase
+class RestoreTest extends TestCase
{
/**
* {@inheritDoc}
@@ -61,7 +61,7 @@
$code = \Artisan::call("user:restore {$user->email}");
$output = trim(\Artisan::output());
$this->assertSame(1, $code);
- $this->assertSame("The user is not yet deleted.", $output);
+ $this->assertSame("The user is not deleted.", $output);
$user->delete();
diff --git a/src/tests/Feature/Console/User/SetDiscountTest.php b/src/tests/Feature/Console/User/SetDiscountTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/User/SetDiscountTest.php
@@ -0,0 +1,64 @@
+<?php
+
+namespace Tests\Feature\Console\User;
+
+use Tests\TestCase;
+
+class SetDiscountTest extends TestCase
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+
+ $this->deleteTestUser('wallets-controller@kolabnow.com');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function tearDown(): void
+ {
+ $this->deleteTestUser('wallets-controller@kolabnow.com');
+
+ parent::tearDown();
+ }
+
+ /**
+ * Test command runs
+ */
+ public function testHandle(): void
+ {
+ $user = $this->getTestUser('wallets-controller@kolabnow.com');
+ $wallet = $user->wallets()->first();
+ $discount = \App\Discount::withObjectTenantContext($user)->where('discount', 100)->first();
+
+ // Invalid user id
+ $code = \Artisan::call("user:set-discount 123 123");
+ $output = trim(\Artisan::output());
+ $this->assertSame(1, $code);
+ $this->assertSame("User not found.", $output);
+
+ // Invalid discount id
+ $code = \Artisan::call("user:set-discount {$user->id} 123");
+ $output = trim(\Artisan::output());
+ $this->assertSame(1, $code);
+ $this->assertSame("Discount not found.", $output);
+
+ // Assign a discount
+ $code = \Artisan::call("user:set-discount {$user->id} {$discount->id}");
+ $output = trim(\Artisan::output());
+ $this->assertSame(0, $code);
+ $this->assertSame("", $output);
+ $this->assertSame($discount->id, $wallet->fresh()->discount_id);
+
+ // Remove the discount
+ $code = \Artisan::call("user:set-discount {$user->id} 0");
+ $output = trim(\Artisan::output());
+ $this->assertSame(0, $code);
+ $this->assertSame("", $output);
+ $this->assertNull($wallet->fresh()->discount_id);
+ }
+}
diff --git a/src/tests/Feature/Console/User/StatusTest.php b/src/tests/Feature/Console/User/StatusTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/User/StatusTest.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Tests\Feature\Console\User;
+
+use Tests\TestCase;
+
+class StatusTest extends TestCase
+{
+ /**
+ * Test command runs
+ */
+ public function testHandle(): void
+ {
+ $code = \Artisan::call("user:status unknown");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(1, $code);
+ $this->assertSame(
+ "User not found.\nTry ./artisan scalpel:user:read --attr=email --attr=tenant_id unknown",
+ $output
+ );
+
+ $code = \Artisan::call("user:status john@kolab.org");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertSame("Status: active,ldapReady,imapReady", $output);
+ }
+}
diff --git a/src/tests/Feature/Console/User/SuspendTest.php b/src/tests/Feature/Console/User/SuspendTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/User/SuspendTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Tests\Feature\Console\User;
+
+use Illuminate\Support\Facades\Queue;
+use Tests\TestCase;
+
+class SuspendTest extends TestCase
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+
+ $this->deleteTestUser('user@force-delete.com');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function tearDown(): void
+ {
+ $this->deleteTestUser('user@force-delete.com');
+
+ parent::tearDown();
+ }
+
+ /**
+ * Test the command
+ */
+ public function testHandle(): void
+ {
+ Queue::fake();
+
+ // Non-existing user
+ $code = \Artisan::call("user:suspend unknown");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(1, $code);
+ $this->assertSame("User not found.", $output);
+
+ $user = $this->getTestUser('user@force-delete.com');
+
+ // Test success
+ $code = \Artisan::call("user:suspend {$user->email}");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertSame("", $output);
+ $this->assertTrue($user->fresh()->isSuspended());
+ }
+}
diff --git a/src/tests/Feature/Console/User/UnsuspendTest.php b/src/tests/Feature/Console/User/UnsuspendTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/User/UnsuspendTest.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace Tests\Feature\Console\User;
+
+use Illuminate\Support\Facades\Queue;
+use Tests\TestCase;
+
+class UnsuspendTest extends TestCase
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+
+ $this->deleteTestUser('user@force-delete.com');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function tearDown(): void
+ {
+ $this->deleteTestUser('user@force-delete.com');
+
+ parent::tearDown();
+ }
+
+ /**
+ * Test the command
+ */
+ public function testHandle(): void
+ {
+ Queue::fake();
+
+ // Non-existing user
+ $code = \Artisan::call("user:unsuspend unknown");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(1, $code);
+ $this->assertSame("User not found.", $output);
+
+ $user = $this->getTestUser('user@force-delete.com');
+ $user->suspend();
+
+ // Test success
+ $code = \Artisan::call("user:unsuspend {$user->email}");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertSame("", $output);
+ $this->assertFalse($user->fresh()->isSuspended());
+ }
+}
diff --git a/src/tests/Feature/Console/User/VerifyTest.php b/src/tests/Feature/Console/User/VerifyTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/User/VerifyTest.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace Tests\Feature\Console\User;
+
+use Illuminate\Support\Facades\Queue;
+use Tests\TestCase;
+
+class VerifyTest extends TestCase
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function setUp(): void
+ {
+ parent::setUp();
+
+ $this->deleteTestUser('user@force-delete.com');
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function tearDown(): void
+ {
+ $this->deleteTestUser('user@force-delete.com');
+
+ parent::tearDown();
+ }
+
+ /**
+ * Test the command
+ */
+ public function testHandle(): void
+ {
+ Queue::fake();
+
+ // Non-existing user
+ $code = \Artisan::call("user:verify unknown");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(1, $code);
+ $this->assertSame("User not found.", $output);
+
+ $user = $this->getTestUser('user@force-delete.com');
+
+ // Test success
+ $code = \Artisan::call("user:verify {$user->email}");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertSame("", $output);
+
+ // TODO: Test the verification utility error conditions
+ }
+}
diff --git a/src/tests/Feature/Console/User/WalletsTest.php b/src/tests/Feature/Console/User/WalletsTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/User/WalletsTest.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Tests\Feature\Console\User;
+
+use Tests\TestCase;
+
+class WalletsTest extends TestCase
+{
+ /**
+ * Test command runs
+ */
+ public function testHandle(): void
+ {
+ $code = \Artisan::call("user:wallets unknown");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(1, $code);
+ $this->assertSame("User not found.", $output);
+
+ $user = $this->getTestUser('john@kolab.org');
+ $wallet = $user->wallets()->first();
+
+ $code = \Artisan::call("user:wallets john@kolab.org");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertSame(trim("{$wallet->id} {$wallet->description}"), $output);
+ }
+}
diff --git a/src/tests/Feature/Console/UserDomainsTest.php b/src/tests/Feature/Console/UserDomainsTest.php
deleted file mode 100644
--- a/src/tests/Feature/Console/UserDomainsTest.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-
-namespace Tests\Feature\Console;
-
-use Tests\TestCase;
-
-class UserDomainsTest extends TestCase
-{
- public function testHandle(): void
- {
- $this->artisan('user:domains john@kolab.org')
- ->assertExitCode(0);
-
- $this->markTestIncomplete();
- }
-}
diff --git a/src/tests/Feature/Console/UserEntitlementsTest.php b/src/tests/Feature/Console/UserEntitlementsTest.php
deleted file mode 100644
--- a/src/tests/Feature/Console/UserEntitlementsTest.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-
-namespace Tests\Feature\Console;
-
-use Tests\TestCase;
-
-class UserEntitlementsTest extends TestCase
-{
- public function testHandle(): void
- {
- $this->artisan('user:entitlements john@kolab.org')
- ->assertExitCode(0);
-
- $this->markTestIncomplete();
- }
-}
diff --git a/src/tests/Feature/Console/UserSettingsTest.php b/src/tests/Feature/Console/UserSettingsTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/UserSettingsTest.php
@@ -0,0 +1,22 @@
+<?php
+
+namespace Tests\Feature\Console;
+
+use Tests\TestCase;
+
+class UserSettingsTest extends TestCase
+{
+ /**
+ * Test command runs
+ */
+ public function testHandle(): void
+ {
+ $code = \Artisan::call("user-settings");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+
+ // Test the output and extra arguments
+ $this->markTestIncomplete();
+ }
+}
diff --git a/src/tests/Feature/Console/UserWalletsTest.php b/src/tests/Feature/Console/UserWalletsTest.php
deleted file mode 100644
--- a/src/tests/Feature/Console/UserWalletsTest.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-
-namespace Tests\Feature\Console;
-
-use Tests\TestCase;
-
-class UserWalletsTest extends TestCase
-{
- public function testHandle(): void
- {
- $this->artisan('user:wallets john@kolab.org')
- ->assertExitCode(0);
-
- $this->markTestIncomplete();
- }
-}
diff --git a/src/tests/Feature/Console/DomainsTest.php b/src/tests/Feature/Console/UsersTest.php
copy from src/tests/Feature/Console/DomainsTest.php
copy to src/tests/Feature/Console/UsersTest.php
--- a/src/tests/Feature/Console/DomainsTest.php
+++ b/src/tests/Feature/Console/UsersTest.php
@@ -1,27 +1,28 @@
<?php
-namespace Tests\Feature\Console\Domain;
+namespace Tests\Feature\Console;
use Tests\TestCase;
-class DomainsTest extends TestCase
+class UsersTest extends TestCase
{
/**
* Test the command
*/
public function testHandle(): void
{
- $domain = \App\Domain::where('namespace', 'kolab.org')->first();
+ $john = $this->getTestUser('john@kolab.org');
// Existing domain
- $code = \Artisan::call("domains");
+ $code = \Artisan::call("users");
$output = trim(\Artisan::output());
$this->assertSame(0, $code);
- $this->assertTrue(strpos($output, (string) $domain->id) !== false);
+ $this->assertTrue(strpos($output, (string) $john->id) !== false);
// TODO: Test --deleted argument
// TODO: Test output format and other attributes
// TODO: Test tenant context
+ $this->markTestIncomplete();
}
}

File Metadata

Mime Type
text/plain
Expires
Tue, Apr 7, 2:45 PM (16 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18836489
Default Alt Text
D2936.1775573107.diff (36 KB)

Event Timeline