Skip to content

Commit

Permalink
test: add tests for invalid group name to addgroup/removegroup co…
Browse files Browse the repository at this point in the history
…mmand
  • Loading branch information
kenjis committed Aug 21, 2024
1 parent 60f1ae3 commit f8c104c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/Commands/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,24 @@ public function testAddgroup(): void
$this->assertTrue($user->inGroup('admin'));
}

public function testAddgroupWithInvalidGroup(): void
{
$this->createUser([
'username' => 'user10',
'email' => '[email protected]',
'password' => 'secret123',
]);

$this->setMockIo(['y']);

command('shield:user addgroup -n user10 -g invalid');

$this->assertStringContainsString(
'Invalid group: "invalid"',
$this->io->getLastOutput()
);
}

public function testAddgroupCancel(): void
{
$this->createUser([
Expand Down Expand Up @@ -643,6 +661,32 @@ public function testRemovegroup(): void
$this->assertFalse($user->inGroup('admin'));
}

public function testRemovegroupWithInvalidGroup(): void
{
$this->createUser([
'username' => 'user11',
'email' => '[email protected]',
'password' => 'secret123',
]);
$users = model(UserModel::class);
$user = $users->findByCredentials(['email' => '[email protected]']);
$user->addGroup('admin');
$this->assertTrue($user->inGroup('admin'));

$this->setMockIo(['y']);

command('shield:user removegroup -n user11 -g invalid');

$this->assertStringContainsString(
'Invalid group: "invalid"',
$this->io->getLastOutput()
);

$users = model(UserModel::class);
$user = $users->findByCredentials(['email' => '[email protected]']);
$this->assertTrue($user->inGroup('admin'));
}

public function testRemovegroupCancel(): void
{
$this->createUser([
Expand Down

0 comments on commit f8c104c

Please sign in to comment.