2014-12-22 16:54:50 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 17:49:16 +03:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2015-03-26 13:44:34 +03:00
|
|
|
* @author Tom Needham <tom@owncloud.com>
|
2014-12-22 16:54:50 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* @license AGPL-3.0
|
2014-12-22 16:54:50 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* 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.
|
2014-12-22 16:54:50 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2014-12-22 16:54:50 +03:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-03-26 13:44:34 +03:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
2014-12-22 16:54:50 +03:00
|
|
|
*
|
2015-03-26 13:44:34 +03:00
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2014-12-22 16:54:50 +03:00
|
|
|
*
|
|
|
|
*/
|
2015-02-26 13:37:37 +03:00
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
namespace OCA\Provisioning_API\Tests\Controller;
|
2014-12-22 16:54:50 +03:00
|
|
|
|
2018-03-26 21:04:32 +03:00
|
|
|
use OC\Accounts\AccountManager;
|
|
|
|
use OC\Group\Manager;
|
|
|
|
use OC\SubAdmin;
|
2019-01-17 13:59:05 +03:00
|
|
|
use OC\User\NoUserException;
|
2016-08-11 10:46:25 +03:00
|
|
|
use OCA\Provisioning_API\Controller\GroupsController;
|
2018-03-26 21:04:32 +03:00
|
|
|
use OCP\IConfig;
|
2017-07-25 16:12:49 +03:00
|
|
|
use OCP\ILogger;
|
2017-10-24 16:26:53 +03:00
|
|
|
use OCP\IRequest;
|
|
|
|
use OCP\IUser;
|
2018-03-26 21:04:32 +03:00
|
|
|
use OCP\IUserManager;
|
2015-08-11 12:47:01 +03:00
|
|
|
use OCP\IUserSession;
|
2019-01-17 13:59:05 +03:00
|
|
|
use OCP\UserInterface;
|
2015-08-11 12:47:01 +03:00
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
class GroupsControllerTest extends \Test\TestCase {
|
2018-03-26 21:04:32 +03:00
|
|
|
|
2019-01-17 13:59:05 +03:00
|
|
|
/** @var IRequest|\PHPUnit_Framework_MockObject_MockObject */
|
2018-03-26 21:04:32 +03:00
|
|
|
protected $request;
|
2019-01-17 13:59:05 +03:00
|
|
|
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
2018-03-26 21:04:32 +03:00
|
|
|
protected $userManager;
|
2019-01-17 13:59:05 +03:00
|
|
|
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
|
2018-03-26 21:04:32 +03:00
|
|
|
protected $config;
|
2019-01-17 13:59:05 +03:00
|
|
|
/** @var Manager|\PHPUnit_Framework_MockObject_MockObject */
|
2015-08-11 12:47:01 +03:00
|
|
|
protected $groupManager;
|
2019-01-17 13:59:05 +03:00
|
|
|
/** @var IUserSession|\PHPUnit_Framework_MockObject_MockObject */
|
2015-08-11 12:47:01 +03:00
|
|
|
protected $userSession;
|
2019-01-17 13:59:05 +03:00
|
|
|
/** @var AccountManager|\PHPUnit_Framework_MockObject_MockObject */
|
2018-03-26 21:04:32 +03:00
|
|
|
protected $accountManager;
|
2019-01-17 13:59:05 +03:00
|
|
|
/** @var ILogger|\PHPUnit_Framework_MockObject_MockObject */
|
2018-03-26 21:04:32 +03:00
|
|
|
protected $logger;
|
2019-01-17 13:59:05 +03:00
|
|
|
/** @var SubAdmin|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
protected $subAdminManager;
|
2017-07-24 08:44:09 +03:00
|
|
|
|
2019-01-17 13:59:05 +03:00
|
|
|
/** @var GroupsController|\PHPUnit_Framework_MockObject_MockObject */
|
2015-10-27 16:09:45 +03:00
|
|
|
protected $api;
|
2015-08-11 12:47:01 +03:00
|
|
|
|
2019-01-17 13:59:05 +03:00
|
|
|
|
2019-11-21 18:40:38 +03:00
|
|
|
protected function setUp(): void {
|
2016-05-11 20:38:49 +03:00
|
|
|
parent::setUp();
|
2015-07-25 15:32:49 +03:00
|
|
|
|
2018-03-26 21:04:32 +03:00
|
|
|
$this->request = $this->createMock(IRequest::class);
|
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
|
|
|
$this->config = $this->createMock(IConfig::class);
|
|
|
|
$this->groupManager = $this->createMock(Manager::class);
|
|
|
|
$this->userSession = $this->createMock(IUserSession::class);
|
|
|
|
$this->accountManager = $this->createMock(AccountManager::class);
|
|
|
|
$this->logger = $this->createMock(ILogger::class);
|
2020-04-02 20:37:40 +03:00
|
|
|
|
2018-03-26 21:04:32 +03:00
|
|
|
$this->subAdminManager = $this->createMock(SubAdmin::class);
|
2016-05-11 20:38:49 +03:00
|
|
|
|
2015-11-06 16:54:31 +03:00
|
|
|
$this->groupManager
|
2018-03-26 21:04:32 +03:00
|
|
|
->method('getSubAdmin')
|
|
|
|
->willReturn($this->subAdminManager);
|
2020-04-02 20:37:40 +03:00
|
|
|
|
2018-03-26 21:04:32 +03:00
|
|
|
$this->api = $this->getMockBuilder(GroupsController::class)
|
|
|
|
->setConstructorArgs([
|
|
|
|
'provisioning_api',
|
|
|
|
$this->request,
|
|
|
|
$this->userManager,
|
|
|
|
$this->config,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->userSession,
|
|
|
|
$this->accountManager,
|
|
|
|
$this->logger
|
|
|
|
])
|
|
|
|
->setMethods(['fillStorageInfo'])
|
2016-07-12 09:38:56 +03:00
|
|
|
->getMock();
|
2015-07-25 15:32:49 +03:00
|
|
|
}
|
|
|
|
|
2015-12-07 23:08:20 +03:00
|
|
|
/**
|
|
|
|
* @param string $gid
|
2015-12-08 11:11:50 +03:00
|
|
|
* @return \OCP\IGroup|\PHPUnit_Framework_MockObject_MockObject
|
2015-12-07 23:08:20 +03:00
|
|
|
*/
|
2015-11-06 16:54:31 +03:00
|
|
|
private function createGroup($gid) {
|
2016-07-12 09:38:56 +03:00
|
|
|
$group = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
|
2015-11-06 16:54:31 +03:00
|
|
|
$group
|
|
|
|
->method('getGID')
|
|
|
|
->willReturn($gid);
|
2018-03-17 16:47:47 +03:00
|
|
|
$group
|
|
|
|
->method('getDisplayName')
|
|
|
|
->willReturn($gid.'-name');
|
2018-05-17 13:48:26 +03:00
|
|
|
$group
|
|
|
|
->method('count')
|
|
|
|
->willReturn(123);
|
|
|
|
$group
|
|
|
|
->method('countDisabled')
|
|
|
|
->willReturn(11);
|
2018-06-19 22:51:59 +03:00
|
|
|
$group
|
|
|
|
->method('canAddUser')
|
|
|
|
->willReturn(true);
|
|
|
|
$group
|
|
|
|
->method('canRemoveUser')
|
|
|
|
->willReturn(true);
|
2018-03-17 16:47:47 +03:00
|
|
|
|
2015-11-06 16:54:31 +03:00
|
|
|
return $group;
|
|
|
|
}
|
2015-08-11 12:47:01 +03:00
|
|
|
|
2015-12-07 23:08:20 +03:00
|
|
|
/**
|
|
|
|
* @param string $uid
|
2015-12-08 11:11:50 +03:00
|
|
|
* @return \OCP\IUser|\PHPUnit_Framework_MockObject_MockObject
|
2015-12-07 23:08:20 +03:00
|
|
|
*/
|
2015-11-06 16:54:31 +03:00
|
|
|
private function createUser($uid) {
|
2017-10-24 16:26:53 +03:00
|
|
|
$user = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
|
2015-11-06 16:54:31 +03:00
|
|
|
$user
|
|
|
|
->method('getUID')
|
|
|
|
->willReturn($uid);
|
2019-01-17 13:59:05 +03:00
|
|
|
$backendMock = $this->createMock(UserInterface::class);
|
|
|
|
$user
|
|
|
|
->method('getBackend')
|
|
|
|
->willReturn($backendMock);
|
2015-11-06 16:54:31 +03:00
|
|
|
return $user;
|
|
|
|
}
|
2015-08-11 12:47:01 +03:00
|
|
|
|
2015-11-06 16:54:31 +03:00
|
|
|
private function asUser() {
|
|
|
|
$user = $this->createUser('user');
|
|
|
|
$this->userSession
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn($user);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function asAdmin() {
|
|
|
|
$user = $this->createUser('admin');
|
|
|
|
$this->userSession
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn($user);
|
|
|
|
|
|
|
|
$this->groupManager
|
|
|
|
->method('isAdmin')
|
|
|
|
->with('admin')
|
|
|
|
->willReturn(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function asSubAdminOfGroup($group) {
|
|
|
|
$user = $this->createUser('subAdmin');
|
|
|
|
$this->userSession
|
|
|
|
->method('getUser')
|
|
|
|
->willReturn($user);
|
|
|
|
|
|
|
|
$this->subAdminManager
|
|
|
|
->method('isSubAdminOfGroup')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function ($_user, $_group) use ($user, $group) {
|
2015-11-06 16:54:31 +03:00
|
|
|
if ($_user === $user && $_group === $group) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2020-03-26 00:21:27 +03:00
|
|
|
});
|
2015-11-06 16:54:31 +03:00
|
|
|
}
|
|
|
|
|
2019-01-17 13:59:05 +03:00
|
|
|
private function useAccountManager() {
|
|
|
|
$this->accountManager->expects($this->any())
|
|
|
|
->method('getUser')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function (IUser $user) {
|
2019-01-17 13:59:05 +03:00
|
|
|
return [
|
|
|
|
AccountManager::PROPERTY_PHONE => ['value' => '0800-call-' . $user->getUID()],
|
|
|
|
AccountManager::PROPERTY_ADDRESS => ['value' => 'Holzweg 99, 0601 Herrera, Panama'],
|
|
|
|
AccountManager::PROPERTY_WEBSITE => ['value' => 'https://' . $user->getUid() . '.pa'],
|
|
|
|
AccountManager::PROPERTY_TWITTER => ['value' => '@' . $user->getUID()],
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-11-06 16:54:31 +03:00
|
|
|
public function dataGetGroups() {
|
|
|
|
return [
|
2018-03-23 20:24:03 +03:00
|
|
|
[null, 0, 0],
|
|
|
|
['foo', 0, 0],
|
|
|
|
[null, 1, 0],
|
|
|
|
[null, 0, 2],
|
2015-11-06 16:54:31 +03:00
|
|
|
['foo', 1, 2],
|
2015-08-11 12:47:01 +03:00
|
|
|
];
|
2015-11-06 16:54:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataGetGroups
|
2016-05-11 20:38:49 +03:00
|
|
|
*
|
|
|
|
* @param string|null $search
|
|
|
|
* @param int|null $limit
|
|
|
|
* @param int|null $offset
|
2015-11-06 16:54:31 +03:00
|
|
|
*/
|
|
|
|
public function testGetGroups($search, $limit, $offset) {
|
|
|
|
$groups = [$this->createGroup('group1'), $this->createGroup('group2')];
|
|
|
|
|
|
|
|
$search = $search === null ? '' : $search;
|
|
|
|
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with($search, $limit, $offset)
|
|
|
|
->willReturn($groups);
|
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$result = $this->api->getGroups($search, $limit, $offset);
|
|
|
|
$this->assertEquals(['groups' => ['group1', 'group2']], $result->getData());
|
2018-03-17 16:47:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataGetGroups
|
|
|
|
*
|
|
|
|
* @param string|null $search
|
|
|
|
* @param int|null $limit
|
|
|
|
* @param int|null $offset
|
|
|
|
*/
|
|
|
|
public function testGetGroupsDetails($search, $limit, $offset) {
|
|
|
|
$groups = [$this->createGroup('group1'), $this->createGroup('group2')];
|
|
|
|
|
|
|
|
$search = $search === null ? '' : $search;
|
|
|
|
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('search')
|
|
|
|
->with($search, $limit, $offset)
|
|
|
|
->willReturn($groups);
|
|
|
|
|
|
|
|
$result = $this->api->getGroupsDetails($search, $limit, $offset);
|
|
|
|
$this->assertEquals(['groups' => [
|
2020-03-26 11:30:18 +03:00
|
|
|
[
|
2018-05-17 13:48:26 +03:00
|
|
|
'id' => 'group1',
|
|
|
|
'displayname' => 'group1-name',
|
|
|
|
'usercount' => 123,
|
2018-06-19 22:51:59 +03:00
|
|
|
'disabled' => 11,
|
|
|
|
'canAdd' => true,
|
|
|
|
'canRemove' => true
|
2020-04-09 17:07:47 +03:00
|
|
|
],
|
2020-03-26 11:30:18 +03:00
|
|
|
[
|
2018-05-17 13:48:26 +03:00
|
|
|
'id' => 'group2',
|
|
|
|
'displayname' => 'group2-name',
|
|
|
|
'usercount' => 123,
|
2018-06-19 22:51:59 +03:00
|
|
|
'disabled' => 11,
|
|
|
|
'canAdd' => true,
|
|
|
|
'canRemove' => true
|
2020-04-09 10:22:29 +03:00
|
|
|
]
|
2018-03-17 16:47:47 +03:00
|
|
|
]], $result->getData());
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetGroupAsSubadmin() {
|
2015-11-06 16:54:31 +03:00
|
|
|
$group = $this->createGroup('group');
|
|
|
|
$this->asSubAdminOfGroup($group);
|
|
|
|
|
|
|
|
$this->groupManager
|
|
|
|
->method('get')
|
|
|
|
->with('group')
|
|
|
|
->willReturn($group);
|
|
|
|
$this->groupManager
|
|
|
|
->method('groupExists')
|
|
|
|
->with('group')
|
|
|
|
->willReturn(true);
|
|
|
|
$group
|
|
|
|
->method('getUsers')
|
|
|
|
->willReturn([
|
|
|
|
$this->createUser('user1'),
|
|
|
|
$this->createUser('user2')
|
|
|
|
]);
|
2014-12-22 16:54:50 +03:00
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$result = $this->api->getGroup('group');
|
2014-12-22 16:54:50 +03:00
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$this->assertEquals(['users' => ['user1', 'user2']], $result->getData());
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2020-04-02 20:37:40 +03:00
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetGroupAsIrrelevantSubadmin() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(403);
|
|
|
|
|
2015-11-06 16:54:31 +03:00
|
|
|
$group = $this->createGroup('group');
|
|
|
|
$otherGroup = $this->createGroup('otherGroup');
|
|
|
|
$this->asSubAdminOfGroup($otherGroup);
|
|
|
|
|
|
|
|
$this->groupManager
|
|
|
|
->method('get')
|
|
|
|
->with('group')
|
|
|
|
->willReturn($group);
|
|
|
|
$this->groupManager
|
|
|
|
->method('groupExists')
|
|
|
|
->with('group')
|
|
|
|
->willReturn(true);
|
2014-12-22 16:54:50 +03:00
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$this->api->getGroup('group');
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetGroupAsAdmin() {
|
2015-11-06 16:54:31 +03:00
|
|
|
$group = $this->createGroup('group');
|
|
|
|
$this->asAdmin();
|
|
|
|
|
|
|
|
$this->groupManager
|
|
|
|
->method('get')
|
|
|
|
->with('group')
|
|
|
|
->willReturn($group);
|
|
|
|
$this->groupManager
|
|
|
|
->method('groupExists')
|
|
|
|
->with('group')
|
|
|
|
->willReturn(true);
|
|
|
|
$group
|
|
|
|
->method('getUsers')
|
|
|
|
->willReturn([
|
|
|
|
$this->createUser('user1'),
|
|
|
|
$this->createUser('user2')
|
|
|
|
]);
|
2014-12-22 16:54:50 +03:00
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$result = $this->api->getGroup('group');
|
2014-12-22 16:54:50 +03:00
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$this->assertEquals(['users' => ['user1', 'user2']], $result->getData());
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
|
|
|
|
2020-04-02 20:37:40 +03:00
|
|
|
|
2015-08-11 12:47:01 +03:00
|
|
|
public function testGetGroupNonExisting() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('The requested group could not be found');
|
|
|
|
$this->expectExceptionCode(404);
|
|
|
|
|
2015-11-06 16:54:31 +03:00
|
|
|
$this->asUser();
|
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$this->api->getGroup($this->getUniqueID());
|
2015-08-11 12:47:01 +03:00
|
|
|
}
|
|
|
|
|
2020-04-02 20:37:40 +03:00
|
|
|
|
2015-11-06 16:54:31 +03:00
|
|
|
public function testGetSubAdminsOfGroupsNotExists() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Group does not exist');
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$this->api->getSubAdminsOfGroup('NonExistingGroup');
|
2015-11-06 16:54:31 +03:00
|
|
|
}
|
|
|
|
|
2015-01-07 12:34:42 +03:00
|
|
|
public function testGetSubAdminsOfGroup() {
|
2015-11-06 16:54:31 +03:00
|
|
|
$group = $this->createGroup('GroupWithSubAdmins');
|
|
|
|
$this->groupManager
|
|
|
|
->method('get')
|
|
|
|
->with('GroupWithSubAdmins')
|
|
|
|
->willReturn($group);
|
|
|
|
|
|
|
|
$this->subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getGroupsSubAdmins')
|
|
|
|
->with($group)
|
|
|
|
->willReturn([
|
|
|
|
$this->createUser('SubAdmin1'),
|
|
|
|
$this->createUser('SubAdmin2'),
|
|
|
|
]);
|
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$result = $this->api->getSubAdminsOfGroup('GroupWithSubAdmins');
|
2015-11-06 16:54:31 +03:00
|
|
|
$this->assertEquals(['SubAdmin1', 'SubAdmin2'], $result->getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetSubAdminsOfGroupEmptyList() {
|
|
|
|
$group = $this->createGroup('GroupWithOutSubAdmins');
|
|
|
|
$this->groupManager
|
|
|
|
->method('get')
|
|
|
|
->with('GroupWithOutSubAdmins')
|
|
|
|
->willReturn($group);
|
|
|
|
|
|
|
|
$this->subAdminManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('getGroupsSubAdmins')
|
|
|
|
->with($group)
|
|
|
|
->willReturn([
|
|
|
|
]);
|
2014-12-22 16:54:50 +03:00
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$result = $this->api->getSubAdminsOfGroup('GroupWithOutSubAdmins');
|
2015-11-17 00:24:53 +03:00
|
|
|
$this->assertEquals([], $result->getData());
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|
2015-08-11 12:47:01 +03:00
|
|
|
|
2020-04-02 20:37:40 +03:00
|
|
|
|
2015-08-11 12:47:01 +03:00
|
|
|
public function testAddGroupEmptyGroup() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionMessage('Invalid group name');
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$this->api->addGroup('');
|
2015-08-11 12:47:01 +03:00
|
|
|
}
|
|
|
|
|
2020-04-02 20:37:40 +03:00
|
|
|
|
2015-08-11 12:47:01 +03:00
|
|
|
public function testAddGroupExistingGroup() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(102);
|
|
|
|
|
2015-11-06 16:54:31 +03:00
|
|
|
$this->groupManager
|
|
|
|
->method('groupExists')
|
|
|
|
->with('ExistingGroup')
|
|
|
|
->willReturn(true);
|
2015-08-11 12:47:01 +03:00
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$this->api->addGroup('ExistingGroup');
|
2015-08-11 12:47:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddGroup() {
|
2015-11-06 16:54:31 +03:00
|
|
|
$this->groupManager
|
|
|
|
->method('groupExists')
|
|
|
|
->with('NewGroup')
|
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createGroup')
|
|
|
|
->with('NewGroup');
|
2015-08-11 12:47:01 +03:00
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$this->api->addGroup('NewGroup');
|
2015-08-11 12:47:01 +03:00
|
|
|
}
|
|
|
|
|
2015-12-04 16:21:24 +03:00
|
|
|
public function testAddGroupWithSpecialChar() {
|
|
|
|
$this->groupManager
|
|
|
|
->method('groupExists')
|
2015-12-23 10:31:20 +03:00
|
|
|
->with('Iñtërnâtiônàlizætiøn')
|
2015-12-04 16:21:24 +03:00
|
|
|
->willReturn(false);
|
|
|
|
|
|
|
|
$this->groupManager
|
|
|
|
->expects($this->once())
|
|
|
|
->method('createGroup')
|
|
|
|
->with('Iñtërnâtiônàlizætiøn');
|
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$this->api->addGroup('Iñtërnâtiônàlizætiøn');
|
2015-12-04 16:21:24 +03:00
|
|
|
}
|
|
|
|
|
2020-04-02 20:37:40 +03:00
|
|
|
|
2015-08-11 12:47:01 +03:00
|
|
|
public function testDeleteGroupNonExisting() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(101);
|
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$this->api->deleteGroup('NonExistingGroup');
|
2015-08-11 12:47:01 +03:00
|
|
|
}
|
|
|
|
|
2020-04-02 20:37:40 +03:00
|
|
|
|
2015-08-11 12:47:01 +03:00
|
|
|
public function testDeleteAdminGroup() {
|
2019-11-27 17:27:18 +03:00
|
|
|
$this->expectException(\OCP\AppFramework\OCS\OCSException::class);
|
|
|
|
$this->expectExceptionCode(102);
|
|
|
|
|
2015-11-06 16:54:31 +03:00
|
|
|
$this->groupManager
|
|
|
|
->method('groupExists')
|
|
|
|
->with('admin')
|
|
|
|
->willReturn('true');
|
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$this->api->deleteGroup('admin');
|
2015-08-11 12:47:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteGroup() {
|
2015-11-06 16:54:31 +03:00
|
|
|
$this->groupManager
|
|
|
|
->method('groupExists')
|
|
|
|
->with('ExistingGroup')
|
|
|
|
->willReturn('true');
|
|
|
|
|
|
|
|
$group = $this->createGroup('ExistingGroup');
|
|
|
|
$this->groupManager
|
|
|
|
->method('get')
|
|
|
|
->with('ExistingGroup')
|
|
|
|
->willReturn($group);
|
|
|
|
$group
|
|
|
|
->expects($this->once())
|
|
|
|
->method('delete')
|
|
|
|
->willReturn(true);
|
2015-08-11 12:47:01 +03:00
|
|
|
|
2016-08-11 10:46:25 +03:00
|
|
|
$this->api->deleteGroup('ExistingGroup');
|
2015-08-11 12:47:01 +03:00
|
|
|
}
|
2019-01-17 13:59:05 +03:00
|
|
|
|
2020-04-02 20:37:40 +03:00
|
|
|
public function testDeleteGroupEncoding() {
|
|
|
|
$this->groupManager
|
|
|
|
->method('groupExists')
|
|
|
|
->with('ExistingGroup A/B')
|
|
|
|
->willReturn('true');
|
|
|
|
|
|
|
|
$group = $this->createGroup('ExistingGroup');
|
|
|
|
$this->groupManager
|
|
|
|
->method('get')
|
|
|
|
->with('ExistingGroup A/B')
|
|
|
|
->willReturn($group);
|
|
|
|
$group
|
|
|
|
->expects($this->once())
|
|
|
|
->method('delete')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$this->api->deleteGroup(urlencode('ExistingGroup A/B'));
|
|
|
|
}
|
|
|
|
|
2019-01-17 13:59:05 +03:00
|
|
|
public function testGetGroupUsersDetails() {
|
|
|
|
$gid = 'ncg1';
|
|
|
|
|
|
|
|
$this->asAdmin();
|
|
|
|
$this->useAccountManager();
|
|
|
|
|
|
|
|
$users = [
|
|
|
|
'ncu1' => $this->createUser('ncu1'), # regular
|
|
|
|
'ncu2' => $this->createUser('ncu2'), # the zombie
|
|
|
|
];
|
|
|
|
$users['ncu2']->expects($this->atLeastOnce())
|
|
|
|
->method('getHome')
|
|
|
|
->willThrowException(new NoUserException());
|
|
|
|
|
|
|
|
$this->userManager->expects($this->any())
|
|
|
|
->method('get')
|
2020-04-09 14:53:40 +03:00
|
|
|
->willReturnCallback(function (string $uid) use ($users) {
|
2019-01-17 13:59:05 +03:00
|
|
|
return isset($users[$uid]) ? $users[$uid] : null;
|
|
|
|
});
|
|
|
|
|
|
|
|
$group = $this->createGroup($gid);
|
|
|
|
$group->expects($this->once())
|
|
|
|
->method('searchUsers')
|
|
|
|
->with('', null, 0)
|
|
|
|
->willReturn(array_values($users));
|
|
|
|
|
|
|
|
$this->groupManager
|
|
|
|
->method('get')
|
|
|
|
->with($gid)
|
|
|
|
->willReturn($group);
|
|
|
|
$this->groupManager->expects($this->any())
|
|
|
|
->method('getUserGroups')
|
|
|
|
->willReturn([$group]);
|
|
|
|
|
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
$this->subAdminManager->expects($this->any())
|
|
|
|
->method('isSubAdminOfGroup')
|
|
|
|
->willReturn(false);
|
|
|
|
$this->subAdminManager->expects($this->any())
|
|
|
|
->method('getSubAdminsGroups')
|
|
|
|
->willReturn([]);
|
|
|
|
|
|
|
|
|
|
|
|
$this->api->getGroupUsersDetails($gid);
|
|
|
|
}
|
2020-04-02 20:37:40 +03:00
|
|
|
|
|
|
|
public function testGetGroupUsersDetailsEncoded() {
|
|
|
|
$gid = 'Department A/B C/D';
|
|
|
|
|
|
|
|
$this->asAdmin();
|
|
|
|
$this->useAccountManager();
|
|
|
|
|
|
|
|
$users = [
|
|
|
|
'ncu1' => $this->createUser('ncu1'), # regular
|
|
|
|
'ncu2' => $this->createUser('ncu2'), # the zombie
|
|
|
|
];
|
|
|
|
$users['ncu2']->expects($this->atLeastOnce())
|
|
|
|
->method('getHome')
|
|
|
|
->willThrowException(new NoUserException());
|
|
|
|
|
|
|
|
$this->userManager->expects($this->any())
|
|
|
|
->method('get')
|
2020-04-14 18:53:44 +03:00
|
|
|
->willReturnCallback(function (string $uid) use ($users) {
|
2020-04-02 20:37:40 +03:00
|
|
|
return isset($users[$uid]) ? $users[$uid] : null;
|
|
|
|
});
|
|
|
|
|
|
|
|
$group = $this->createGroup($gid);
|
|
|
|
$group->expects($this->once())
|
|
|
|
->method('searchUsers')
|
|
|
|
->with('', null, 0)
|
|
|
|
->willReturn(array_values($users));
|
|
|
|
|
|
|
|
$this->groupManager
|
|
|
|
->method('get')
|
|
|
|
->with($gid)
|
|
|
|
->willReturn($group);
|
|
|
|
$this->groupManager->expects($this->any())
|
|
|
|
->method('getUserGroups')
|
|
|
|
->willReturn([$group]);
|
|
|
|
|
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
$this->subAdminManager->expects($this->any())
|
|
|
|
->method('isSubAdminOfGroup')
|
|
|
|
->willReturn(false);
|
|
|
|
$this->subAdminManager->expects($this->any())
|
|
|
|
->method('getSubAdminsGroups')
|
|
|
|
->willReturn([]);
|
|
|
|
|
|
|
|
|
|
|
|
$this->api->getGroupUsersDetails(urlencode($gid));
|
|
|
|
}
|
2014-12-22 16:54:50 +03:00
|
|
|
}
|