From f8c104c5abbefdab75ad0831311a9feed0379521 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 21 Aug 2024 16:55:44 +0900 Subject: [PATCH] test: add tests for invalid group name to `addgroup`/`removegroup` command --- tests/Commands/UserTest.php | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/Commands/UserTest.php b/tests/Commands/UserTest.php index b28cd0ae6..3823d8314 100644 --- a/tests/Commands/UserTest.php +++ b/tests/Commands/UserTest.php @@ -595,6 +595,24 @@ public function testAddgroup(): void $this->assertTrue($user->inGroup('admin')); } + public function testAddgroupWithInvalidGroup(): void + { + $this->createUser([ + 'username' => 'user10', + 'email' => 'user10@example.com', + '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([ @@ -643,6 +661,32 @@ public function testRemovegroup(): void $this->assertFalse($user->inGroup('admin')); } + public function testRemovegroupWithInvalidGroup(): void + { + $this->createUser([ + 'username' => 'user11', + 'email' => 'user11@example.com', + 'password' => 'secret123', + ]); + $users = model(UserModel::class); + $user = $users->findByCredentials(['email' => 'user11@example.com']); + $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' => 'user11@example.com']); + $this->assertTrue($user->inGroup('admin')); + } + public function testRemovegroupCancel(): void { $this->createUser([