2016-12-29 05:26:49 -05:00
|
|
|
<?php
|
|
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2016-12-29 05:26:49 -05:00
|
|
|
*/
|
2019-11-22 14:52:10 -05:00
|
|
|
|
2016-12-29 05:26:49 -05:00
|
|
|
namespace Test\Core\Command\Group;
|
|
|
|
|
|
|
|
|
|
use OC\Core\Command\Group\AddUser;
|
|
|
|
|
use OCP\IGroup;
|
|
|
|
|
use OCP\IGroupManager;
|
|
|
|
|
use OCP\IUser;
|
|
|
|
|
use OCP\IUserManager;
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
|
|
class AddUserTest extends TestCase {
|
2020-08-11 15:32:18 -04:00
|
|
|
/** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject */
|
2016-12-29 05:26:49 -05:00
|
|
|
private $groupManager;
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
/** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
|
2016-12-29 05:26:49 -05:00
|
|
|
private $userManager;
|
|
|
|
|
|
|
|
|
|
/** @var AddUser */
|
|
|
|
|
private $command;
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
/** @var InputInterface|\PHPUnit\Framework\MockObject\MockObject */
|
2016-12-29 05:26:49 -05:00
|
|
|
private $input;
|
|
|
|
|
|
2020-08-11 15:32:18 -04:00
|
|
|
/** @var OutputInterface|\PHPUnit\Framework\MockObject\MockObject */
|
2016-12-29 05:26:49 -05:00
|
|
|
private $output;
|
|
|
|
|
|
2019-11-27 09:27:18 -05:00
|
|
|
protected function setUp(): void {
|
2016-12-29 05:26:49 -05:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
2020-10-05 09:12:57 -04:00
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
2016-12-29 05:26:49 -05:00
|
|
|
$this->command = new AddUser($this->userManager, $this->groupManager);
|
|
|
|
|
|
|
|
|
|
$this->input = $this->createMock(InputInterface::class);
|
|
|
|
|
$this->input->method('getArgument')
|
2020-04-09 07:53:40 -04:00
|
|
|
->willReturnCallback(function ($arg) {
|
2016-12-29 05:26:49 -05:00
|
|
|
if ($arg === 'group') {
|
|
|
|
|
return 'myGroup';
|
2020-04-10 04:35:09 -04:00
|
|
|
} elseif ($arg === 'user') {
|
2016-12-29 05:26:49 -05:00
|
|
|
return 'myUser';
|
|
|
|
|
}
|
|
|
|
|
throw new \Exception();
|
|
|
|
|
});
|
|
|
|
|
$this->output = $this->createMock(OutputInterface::class);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testNoGroup() {
|
|
|
|
|
$this->groupManager->method('get')
|
|
|
|
|
->with('myGroup')
|
|
|
|
|
->willReturn(null);
|
|
|
|
|
|
|
|
|
|
$this->output->expects($this->once())
|
|
|
|
|
->method('writeln')
|
|
|
|
|
->with('<error>group not found</error>');
|
|
|
|
|
|
|
|
|
|
$this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testNoUser() {
|
|
|
|
|
$group = $this->createMock(IGroup::class);
|
|
|
|
|
$this->groupManager->method('get')
|
|
|
|
|
->with('myGroup')
|
|
|
|
|
->willReturn($group);
|
|
|
|
|
|
|
|
|
|
$this->userManager->method('get')
|
|
|
|
|
->with('myUser')
|
|
|
|
|
->willReturn(null);
|
|
|
|
|
|
|
|
|
|
$this->output->expects($this->once())
|
|
|
|
|
->method('writeln')
|
|
|
|
|
->with('<error>user not found</error>');
|
|
|
|
|
|
|
|
|
|
$this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testAdd() {
|
|
|
|
|
$group = $this->createMock(IGroup::class);
|
|
|
|
|
$this->groupManager->method('get')
|
|
|
|
|
->with('myGroup')
|
|
|
|
|
->willReturn($group);
|
|
|
|
|
|
|
|
|
|
$user = $this->createMock(IUser::class);
|
|
|
|
|
$this->userManager->method('get')
|
|
|
|
|
->with('myUser')
|
|
|
|
|
->willReturn($user);
|
|
|
|
|
|
|
|
|
|
$group->expects($this->once())
|
|
|
|
|
->method('addUser')
|
|
|
|
|
->with($user);
|
|
|
|
|
|
|
|
|
|
$this->invokePrivate($this->command, 'execute', [$this->input, $this->output]);
|
|
|
|
|
}
|
|
|
|
|
}
|