Page MenuHomePhorge

D5772.1775263479.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D5772.1775263479.diff

diff --git a/src/app/Console/Commands/User/DelegateCommand.php b/src/app/Console/Commands/User/DelegateCommand.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/User/DelegateCommand.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace App\Console\Commands\User;
+
+use App\Console\Command;
+use App\Delegation;
+use Carbon\Carbon;
+
+class DelegateCommand extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'user:delegate {delegator} {delegatee}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Create delegation for user.';
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $delegator = $this->getUser($this->argument('delegator'));
+ $delegatee = $this->getUser($this->argument('delegatee'));
+
+ if (!$delegator || !$delegatee) {
+ $this->error("User not found.");
+ return 1;
+ }
+
+ $delegation = new Delegation();
+ $delegation->user_id = $delegator->id;
+ $delegation->delegatee_id = $delegatee->id;
+ $delegation->save();
+ }
+}
diff --git a/src/tests/Feature/Console/User/DelegateTest.php b/src/tests/Feature/Console/User/DelegateTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/User/DelegateTest.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace Tests\Feature\Console\User;
+
+use Illuminate\Support\Facades\Queue;
+use Tests\TestCase;
+use App\Delegation;
+
+class DelegateTest extends TestCase
+{
+ protected function setUp(): void
+ {
+ parent::setUp();
+
+ $this->deleteTestUser('delegator@kolabnow.com');
+ $this->deleteTestUser('delegatee@kolabnow.com');
+ }
+
+ protected function tearDown(): void
+ {
+ $this->deleteTestUser('delegator@kolabnow.com');
+ $this->deleteTestUser('delegatee@kolabnow.com');
+
+ parent::tearDown();
+ }
+
+ /**
+ * Test the command
+ */
+ public function testHandle(): void
+ {
+ Queue::fake();
+
+ // Non-existing user
+ $code = \Artisan::call("user:delegate unknown@unknown.org unknown@unknown.org");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(1, $code);
+ $this->assertSame("User not found.", $output);
+
+ $delegator = $this->getTestUser('delegator@kolabnow.com');
+ $delegatee = $this->getTestUser('delegatee@kolabnow.com');
+
+ $code = \Artisan::call("user:delegate {$delegator->email} {$delegatee->email}");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame($delegatee->email, $delegator->delegatees()->first()->email);
+ $this->assertSame('', $output);
+ $this->assertSame(0, $code);
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Apr 4, 12:44 AM (1 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18823153
Default Alt Text
D5772.1775263479.diff (2 KB)

Event Timeline