Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Console/Group/CreateTest.php
- This file was added.
<?php | |||||
namespace Tests\Feature\Console\Group; | |||||
use App\Group; | |||||
use Illuminate\Support\Facades\Queue; | |||||
use Tests\TestCase; | |||||
class CreateTest extends TestCase | |||||
{ | |||||
/** | |||||
* {@inheritDoc} | |||||
*/ | |||||
public function setUp(): void | |||||
{ | |||||
parent::setUp(); | |||||
$this->deleteTestGroup('group-test@kolab.org'); | |||||
$this->deleteTestGroup('group-testm@kolab.org'); | |||||
} | |||||
/** | |||||
* {@inheritDoc} | |||||
*/ | |||||
public function tearDown(): void | |||||
{ | |||||
$this->deleteTestGroup('group-test@kolab.org'); | |||||
$this->deleteTestGroup('group-testm@kolab.org'); | |||||
parent::tearDown(); | |||||
} | |||||
/** | |||||
* Test command runs | |||||
*/ | |||||
public function testHandle(): void | |||||
{ | |||||
Queue::fake(); | |||||
// Warning: We're not using artisan() here, as this will not | |||||
// allow us to test "empty output" cases | |||||
// Missing group owner argument | |||||
$code = \Artisan::call("group:create group-test@kolabnow.com"); | |||||
$output = trim(\Artisan::output()); | |||||
$this->assertSame(1, $code); | |||||
$this->assertSame("The --user option is required.", $output); | |||||
// Invalid group owner argument | |||||
$code = \Artisan::call("group:create group-test@kolabnow.com --user=nonexisting@nonexisting.org"); | |||||
$output = trim(\Artisan::output()); | |||||
$this->assertSame(1, $code); | |||||
$this->assertSame("User nonexisting@nonexisting.org does not exist.", $output); | |||||
$user = $this->getTestUser('john@kolab.org'); | |||||
// Domain not existing | |||||
$code = \Artisan::call("group:create testgroup@unknown.org --user={$user->id}"); | |||||
$output = trim(\Artisan::output()); | |||||
$this->assertSame(1, $code); | |||||
$this->assertSame("testgroup@unknown.org: The specified domain is not available.", $output); | |||||
// Domain not available to the user | |||||
$code = \Artisan::call("group:create testgroup@kolab.org --user=jack@kolab.org"); | |||||
$output = trim(\Artisan::output()); | |||||
$this->assertSame(1, $code); | |||||
$this->assertSame("testgroup@kolab.org: The specified domain is not available.", $output); | |||||
// Existing email | |||||
$code = \Artisan::call("group:create jack@kolab.org --user={$user->email}"); | |||||
$output = trim(\Artisan::output()); | |||||
$this->assertSame(1, $code); | |||||
$this->assertSame("jack@kolab.org: The specified email is not available.", $output); | |||||
// Existing email (of a user alias) | |||||
$code = \Artisan::call("group:create jack.daniels@kolab.org --user={$user->email}"); | |||||
$output = trim(\Artisan::output()); | |||||
$this->assertSame(1, $code); | |||||
$this->assertSame("jack.daniels@kolab.org: The specified email is not available.", $output); | |||||
// Public domain not allowed in the group email address | |||||
$code = \Artisan::call("group:create group-test@kolabnow.com --user={$user->email}"); | |||||
$output = trim(\Artisan::output()); | |||||
$this->assertSame(1, $code); | |||||
$this->assertSame("group-test@kolabnow.com: The specified domain is not available.", $output); | |||||
// Create a group without members | |||||
$code = \Artisan::call("group:create group-test@kolab.org --user={$user->email}"); | |||||
$output = trim(\Artisan::output()); | |||||
$group = Group::where('email', 'group-test@kolab.org')->first(); | |||||
$this->assertSame(0, $code); | |||||
$this->assertEquals($group->id, $output); | |||||
$this->assertSame([], $group->members); | |||||
$this->assertSame($user->wallets->first()->id, $group->entitlement->wallet_id); | |||||
// Existing email (of a group) | |||||
$code = \Artisan::call("group:create group-test@kolab.org --user={$user->email}"); | |||||
$output = trim(\Artisan::output()); | |||||
$this->assertSame(1, $code); | |||||
$this->assertSame("group-test@kolab.org: The specified email is not available.", $output); | |||||
// Invalid member | |||||
$code = \Artisan::call("group:create group-testm@kolab.org --user={$user->email} --member=invalid"); | |||||
$output = trim(\Artisan::output()); | |||||
$this->assertSame(1, $code); | |||||
$this->assertSame("invalid: The specified email address is invalid.", $output); | |||||
// Valid members | |||||
$code = \Artisan::call( | |||||
"group:create group-testm@kolab.org --user={$user->email}" | |||||
. " --member=member1@kolabnow.com --member=member2@gmail.com" | |||||
); | |||||
$output = trim(\Artisan::output()); | |||||
$group = Group::where('email', 'group-testm@kolab.org')->first(); | |||||
$this->assertSame(0, $code); | |||||
$this->assertEquals($group->id, $output); | |||||
$this->assertSame(['member1@kolabnow.com', 'member2@gmail.com'], $group->members); | |||||
} | |||||
} |