nextcloud/apps/files_external/tests/Command/ApplicableTest.php

173 lines
4.7 KiB
PHP
Raw Normal View History

2016-01-18 13:58:17 +03:00
<?php
/**
2016-07-21 17:49:16 +03:00
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
2016-07-21 19:13:36 +03:00
* @author Robin Appelman <robin@icewind.nl>
* @author Roeland Jago Douma <roeland@famdouma.nl>
2016-01-18 13:58:17 +03:00
*
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
2016-01-18 13:58:17 +03:00
*
*/
namespace OCA\Files_External\Tests\Command;
use OCA\Files_External\Command\Applicable;
2016-09-02 11:37:20 +03:00
use OCP\IGroupManager;
use OCP\IUserManager;
2016-01-18 13:58:17 +03:00
class ApplicableTest extends CommandTest {
private function getInstance($storageService) {
/** @var \OCP\IUserManager|\PHPUnit_Framework_MockObject_MockObject $userManager */
2016-09-02 11:37:20 +03:00
$userManager = $this->createMock(IUserManager::class);
2016-01-18 13:58:17 +03:00
/** @var \OCP\IGroupManager|\PHPUnit_Framework_MockObject_MockObject $groupManager */
2016-09-02 11:37:20 +03:00
$groupManager = $this->createMock(IGroupManager::class);
2016-01-18 13:58:17 +03:00
$userManager->expects($this->any())
->method('userExists')
->willReturn(true);
2016-01-18 13:58:17 +03:00
$groupManager->expects($this->any())
->method('groupExists')
->willReturn(true);
2016-01-18 13:58:17 +03:00
return new Applicable($storageService, $userManager, $groupManager);
}
public function testListEmpty() {
$mount = $this->getMount(1, '', '');
$storageService = $this->getGlobalStorageService([$mount]);
$command = $this->getInstance($storageService);
$input = $this->getInput($command, [
'mount_id' => 1
], [
'output' => 'json'
]);
$result = json_decode($this->executeCommand($command, $input), true);
$this->assertEquals(['users' => [], 'groups' => []], $result);
}
public function testList() {
$mount = $this->getMount(1, '', '', '', [], [], ['test', 'asd']);
$storageService = $this->getGlobalStorageService([$mount]);
$command = $this->getInstance($storageService);
$input = $this->getInput($command, [
'mount_id' => 1
], [
'output' => 'json'
]);
$result = json_decode($this->executeCommand($command, $input), true);
$this->assertEquals(['users' => ['test', 'asd'], 'groups' => []], $result);
}
public function testAddSingle() {
$mount = $this->getMount(1, '', '', '', [], [], []);
$storageService = $this->getGlobalStorageService([$mount]);
$command = $this->getInstance($storageService);
$input = $this->getInput($command, [
'mount_id' => 1
], [
'output' => 'json',
'add-user' => ['foo']
]);
$this->executeCommand($command, $input);
$this->assertEquals(['foo'], $mount->getApplicableUsers());
}
public function testAddDuplicate() {
$mount = $this->getMount(1, '', '', '', [], [], ['foo']);
$storageService = $this->getGlobalStorageService([$mount]);
$command = $this->getInstance($storageService);
$input = $this->getInput($command, [
'mount_id' => 1
], [
'output' => 'json',
'add-user' => ['foo', 'bar']
]);
$this->executeCommand($command, $input);
$this->assertEquals(['foo', 'bar'], $mount->getApplicableUsers());
}
public function testRemoveSingle() {
$mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']);
$storageService = $this->getGlobalStorageService([$mount]);
$command = $this->getInstance($storageService);
$input = $this->getInput($command, [
'mount_id' => 1
], [
'output' => 'json',
'remove-user' => ['bar']
]);
$this->executeCommand($command, $input);
$this->assertEquals(['foo'], $mount->getApplicableUsers());
}
public function testRemoveNonExisting() {
$mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']);
$storageService = $this->getGlobalStorageService([$mount]);
$command = $this->getInstance($storageService);
$input = $this->getInput($command, [
'mount_id' => 1
], [
'output' => 'json',
'remove-user' => ['bar', 'asd']
]);
$this->executeCommand($command, $input);
$this->assertEquals(['foo'], $mount->getApplicableUsers());
}
public function testRemoveAddRemove() {
$mount = $this->getMount(1, '', '', '', [], [], ['foo', 'bar']);
$storageService = $this->getGlobalStorageService([$mount]);
$command = $this->getInstance($storageService);
$input = $this->getInput($command, [
'mount_id' => 1
], [
'output' => 'json',
'remove-user' => ['bar', 'asd'],
'add-user' => ['test']
]);
$this->executeCommand($command, $input);
$this->assertEquals(['foo', 'test'], $mount->getApplicableUsers());
}
}