diff options
author | Johannes Leuker <j.leuker@hosting.de> | 2021-02-09 14:50:38 +0100 |
---|---|---|
committer | Johannes Leuker <j.leuker@hosting.de> | 2021-03-01 16:02:08 +0100 |
commit | 2796ef80ff53684c6b276b054bb2d3b6039a4ef6 (patch) | |
tree | 29336019d1ad40fedae19f39ca67da5455ae2266 /tests/Core | |
parent | 9fd72b0d3a4ebfad2291a18aefc51e999fbb0744 (diff) | |
download | nextcloud-server-2796ef80ff53684c6b276b054bb2d3b6039a4ef6.tar.gz nextcloud-server-2796ef80ff53684c6b276b054bb2d3b6039a4ef6.zip |
Show group backends in occ group:list --info and group:info
Signed-off-by: Johannes Leuker <j.leuker@hosting.de>
Diffstat (limited to 'tests/Core')
-rw-r--r-- | tests/Core/Command/Group/InfoTest.php | 115 | ||||
-rw-r--r-- | tests/Core/Command/Group/ListCommandTest.php | 99 |
2 files changed, 207 insertions, 7 deletions
diff --git a/tests/Core/Command/Group/InfoTest.php b/tests/Core/Command/Group/InfoTest.php new file mode 100644 index 00000000000..40b0f78f5ab --- /dev/null +++ b/tests/Core/Command/Group/InfoTest.php @@ -0,0 +1,115 @@ +<?php +/** + * @copyright 2021, hosting.de, Johannes Leuker <j.leuker@hosting.de> + * + * @author Johannes Leuker <j.leuker@hosting.de> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Afferoq General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace Test\Core\Command\Group; + +use OC\Core\Command\Group\Info; +use OCP\IGroup; +use OCP\IGroupManager; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Test\TestCase; + +class InfoTest extends TestCase { + + /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */ + private $groupManager; + + /** @var Info|\PHPUnit\Framework\MockObject\MockObject */ + private $command; + + /** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */ + private $input; + + /** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */ + private $output; + + protected function setUp(): void { + parent::setUp(); + + $this->groupManager = $this->createMock(IGroupManager::class); + $this->command = $this->getMockBuilder(Info::class) + ->setConstructorArgs([$this->groupManager]) + ->setMethods(['writeArrayInOutputFormat']) + ->getMock(); + + $this->input = $this->createMock(InputInterface::class); + $this->output = $this->createMock(OutputInterface::class); + } + + public function testDoesNotExists() { + $gid = 'myGroup'; + $this->input->method('getArgument') + ->willReturnCallback(function ($arg) use ($gid) { + if ($arg === 'groupid') { + return $gid; + } + throw new \Exception(); + }); + $this->groupManager->method('get') + ->with($gid) + ->willReturn(null); + + $this->output->expects($this->once()) + ->method('writeln') + ->with($this->equalTo('<error>Group "' . $gid . '" does not exist.</error>')); + + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + } + + public function testInfo() { + $gid = 'myGroup'; + $this->input->method('getArgument') + ->willReturnCallback(function ($arg) use ($gid) { + if ($arg === 'groupid') { + return $gid; + } + throw new \Exception(); + }); + + $group = $this->createMock(IGroup::class); + $group->method('getGID')->willReturn($gid); + $group->method('getDisplayName') + ->willReturn('My Group'); + $group->method('getBackendNames') + ->willReturn(['Database']); + + $this->groupManager->method('get') + ->with($gid) + ->willReturn($group); + + $this->command->expects($this->once()) + ->method('writeArrayInOutputFormat') + ->with( + $this->equalTo($this->input), + $this->equalTo($this->output), + [ + 'groupID' => 'myGroup', + 'displayName' => 'My Group', + 'backends' => ['Database'], + ] + ); + + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); + } +} diff --git a/tests/Core/Command/Group/ListCommandTest.php b/tests/Core/Command/Group/ListCommandTest.php index 1c1dd3c95eb..ed454a796a6 100644 --- a/tests/Core/Command/Group/ListCommandTest.php +++ b/tests/Core/Command/Group/ListCommandTest.php @@ -55,21 +55,77 @@ class ListCommandTest extends TestCase { ->getMock(); $this->input = $this->createMock(InputInterface::class); + $this->output = $this->createMock(OutputInterface::class); + } + + public function testExecute() { + $group1 = $this->createMock(IGroup::class); + $group1->method('getGID')->willReturn('group1'); + $group2 = $this->createMock(IGroup::class); + $group2->method('getGID')->willReturn('group2'); + $group3 = $this->createMock(IGroup::class); + $group3->method('getGID')->willReturn('group3'); + + $user = $this->createMock(IUser::class); + + $this->groupManager->method('search') + ->with( + '', + 100, + 42, + )->willReturn([$group1, $group2, $group3]); + + $group1->method('getUsers') + ->willReturn([ + 'user1' => $user, + 'user2' => $user, + ]); + + $group2->method('getUsers') + ->willReturn([ + ]); + + $group3->method('getUsers') + ->willReturn([ + 'user1' => $user, + 'user3' => $user, + ]); + $this->input->method('getOption') ->willReturnCallback(function ($arg) { if ($arg === 'limit') { return '100'; } elseif ($arg === 'offset') { return '42'; + } elseif ($arg === 'info') { + return null; } throw new \Exception(); }); + $this->command->expects($this->once()) + ->method('writeArrayInOutputFormat') + ->with( + $this->equalTo($this->input), + $this->equalTo($this->output), + [ + 'group1' => [ + 'user1', + 'user2', + ], + 'group2' => [ + ], + 'group3' => [ + 'user1', + 'user3', + ] + ] + ); - $this->output = $this->createMock(OutputInterface::class); + $this->invokePrivate($this->command, 'execute', [$this->input, $this->output]); } - public function testExecute() { + public function testInfo() { $group1 = $this->createMock(IGroup::class); $group1->method('getGID')->willReturn('group1'); $group2 = $this->createMock(IGroup::class); @@ -83,7 +139,7 @@ class ListCommandTest extends TestCase { ->with( '', 100, - 42 + 42, )->willReturn([$group1, $group2, $group3]); $group1->method('getUsers') @@ -92,16 +148,37 @@ class ListCommandTest extends TestCase { 'user2' => $user, ]); + $group1->method('getBackendNames') + ->willReturn(['Database']); + $group2->method('getUsers') ->willReturn([ ]); + $group2->method('getBackendNames') + ->willReturn(['Database']); + $group3->method('getUsers') ->willReturn([ 'user1' => $user, 'user3' => $user, ]); + $group3->method('getBackendNames') + ->willReturn(['LDAP']); + + $this->input->method('getOption') + ->willReturnCallback(function ($arg) { + if ($arg === 'limit') { + return '100'; + } elseif ($arg === 'offset') { + return '42'; + } elseif ($arg === 'info') { + return true; + } + throw new \Exception(); + }); + $this->command->expects($this->once()) ->method('writeArrayInOutputFormat') ->with( @@ -109,14 +186,22 @@ class ListCommandTest extends TestCase { $this->equalTo($this->output), [ 'group1' => [ - 'user1', - 'user2', + 'backends' => ['Database'], + 'users' => [ + 'user1', + 'user2', + ], ], 'group2' => [ + 'backends' => ['Database'], + 'users' => [], ], 'group3' => [ - 'user1', - 'user3', + 'backends' => ['LDAP'], + 'users' => [ + 'user1', + 'user3', + ], ] ] ); |