Skip to content

Commit f8c104c

Browse files
committed
test: add tests for invalid group name to addgroup/removegroup command
1 parent 60f1ae3 commit f8c104c

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/Commands/UserTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,24 @@ public function testAddgroup(): void
595595
$this->assertTrue($user->inGroup('admin'));
596596
}
597597

598+
public function testAddgroupWithInvalidGroup(): void
599+
{
600+
$this->createUser([
601+
'username' => 'user10',
602+
'email' => 'user10@example.com',
603+
'password' => 'secret123',
604+
]);
605+
606+
$this->setMockIo(['y']);
607+
608+
command('shield:user addgroup -n user10 -g invalid');
609+
610+
$this->assertStringContainsString(
611+
'Invalid group: "invalid"',
612+
$this->io->getLastOutput()
613+
);
614+
}
615+
598616
public function testAddgroupCancel(): void
599617
{
600618
$this->createUser([
@@ -643,6 +661,32 @@ public function testRemovegroup(): void
643661
$this->assertFalse($user->inGroup('admin'));
644662
}
645663

664+
public function testRemovegroupWithInvalidGroup(): void
665+
{
666+
$this->createUser([
667+
'username' => 'user11',
668+
'email' => 'user11@example.com',
669+
'password' => 'secret123',
670+
]);
671+
$users = model(UserModel::class);
672+
$user = $users->findByCredentials(['email' => 'user11@example.com']);
673+
$user->addGroup('admin');
674+
$this->assertTrue($user->inGroup('admin'));
675+
676+
$this->setMockIo(['y']);
677+
678+
command('shield:user removegroup -n user11 -g invalid');
679+
680+
$this->assertStringContainsString(
681+
'Invalid group: "invalid"',
682+
$this->io->getLastOutput()
683+
);
684+
685+
$users = model(UserModel::class);
686+
$user = $users->findByCredentials(['email' => 'user11@example.com']);
687+
$this->assertTrue($user->inGroup('admin'));
688+
}
689+
646690
public function testRemovegroupCancel(): void
647691
{
648692
$this->createUser([

0 commit comments

Comments
 (0)