aboutsummaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/provisioning_api/tests/Controller/GroupsControllerTest.php')
-rw-r--r--apps/provisioning_api/tests/Controller/GroupsControllerTest.php165
1 files changed, 65 insertions, 100 deletions
diff --git a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
index 5d16d58fc0a..85e5d733b1f 100644
--- a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
+++ b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php
@@ -1,70 +1,43 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- * @author Julius Härtl <jus@bitgrid.net>
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Tom Needham <tom@owncloud.com>
- *
- * @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/>
- *
+ * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace OCA\Provisioning_API\Tests\Controller;
use OC\Group\Manager;
-use OC\SubAdmin;
use OC\User\NoUserException;
use OCA\Provisioning_API\Controller\GroupsController;
use OCP\Accounts\IAccountManager;
+use OCP\AppFramework\OCS\OCSException;
+use OCP\Files\IRootFolder;
+use OCP\Group\ISubAdmin;
use OCP\IConfig;
+use OCP\IGroup;
use OCP\IRequest;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\UserInterface;
+use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
class GroupsControllerTest extends \Test\TestCase {
- /** @var IRequest|\PHPUnit\Framework\MockObject\MockObject */
- protected $request;
- /** @var IUserManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $userManager;
- /** @var IConfig|\PHPUnit\Framework\MockObject\MockObject */
- protected $config;
- /** @var Manager|\PHPUnit\Framework\MockObject\MockObject */
- protected $groupManager;
- /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */
- protected $userSession;
- /** @var IAccountManager|\PHPUnit\Framework\MockObject\MockObject */
- protected $accountManager;
- /** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
- protected $l10nFactory;
- /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */
- protected $logger;
- /** @var SubAdmin|\PHPUnit\Framework\MockObject\MockObject */
- protected $subAdminManager;
-
- /** @var GroupsController|\PHPUnit\Framework\MockObject\MockObject */
- protected $api;
+ protected IRequest&MockObject $request;
+ protected IUserManager&MockObject $userManager;
+ protected IConfig&MockObject $config;
+ protected Manager&MockObject $groupManager;
+ protected IUserSession&MockObject $userSession;
+ protected IAccountManager&MockObject $accountManager;
+ protected ISubAdmin&MockObject $subAdminManager;
+ protected IFactory&MockObject $l10nFactory;
+ protected LoggerInterface&MockObject $logger;
+ protected GroupsController&MockObject $api;
+
+ private IRootFolder $rootFolder;
protected function setUp(): void {
@@ -76,14 +49,14 @@ class GroupsControllerTest extends \Test\TestCase {
$this->groupManager = $this->createMock(Manager::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->accountManager = $this->createMock(IAccountManager::class);
+ $this->subAdminManager = $this->createMock(ISubAdmin::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->logger = $this->createMock(LoggerInterface::class);
-
- $this->subAdminManager = $this->createMock(SubAdmin::class);
+ $this->rootFolder = $this->createMock(IRootFolder::class);
$this->groupManager
- ->method('getSubAdmin')
- ->willReturn($this->subAdminManager);
+ ->method('getSubAdmin')
+ ->willReturn($this->subAdminManager);
$this->api = $this->getMockBuilder(GroupsController::class)
->setConstructorArgs([
@@ -94,25 +67,23 @@ class GroupsControllerTest extends \Test\TestCase {
$this->groupManager,
$this->userSession,
$this->accountManager,
+ $this->subAdminManager,
$this->l10nFactory,
+ $this->rootFolder,
$this->logger
])
- ->setMethods(['fillStorageInfo'])
+ ->onlyMethods(['fillStorageInfo'])
->getMock();
}
- /**
- * @param string $gid
- * @return \OCP\IGroup|\PHPUnit\Framework\MockObject\MockObject
- */
- private function createGroup($gid) {
- $group = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock();
+ private function createGroup(string $gid): IGroup&MockObject {
+ $group = $this->createMock(IGroup::class);
$group
->method('getGID')
->willReturn($gid);
$group
->method('getDisplayName')
- ->willReturn($gid.'-name');
+ ->willReturn($gid . '-name');
$group
->method('count')
->willReturn(123);
@@ -131,7 +102,7 @@ class GroupsControllerTest extends \Test\TestCase {
/**
* @param string $uid
- * @return \OCP\IUser|\PHPUnit\Framework\MockObject\MockObject
+ * @return IUser&MockObject
*/
private function createUser($uid) {
$user = $this->getMockBuilder(IUser::class)->disableOriginalConstructor()->getMock();
@@ -180,7 +151,7 @@ class GroupsControllerTest extends \Test\TestCase {
});
}
- public function dataGetGroups() {
+ public static function dataGetGroups(): array {
return [
[null, 0, 0],
['foo', 0, 0],
@@ -190,14 +161,8 @@ class GroupsControllerTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider dataGetGroups
- *
- * @param string|null $search
- * @param int|null $limit
- * @param int|null $offset
- */
- public function testGetGroups($search, $limit, $offset) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetGroups')]
+ public function testGetGroups(?string $search, int $limit, int $offset): void {
$groups = [$this->createGroup('group1'), $this->createGroup('group2')];
$search = $search === null ? '' : $search;
@@ -213,13 +178,13 @@ class GroupsControllerTest extends \Test\TestCase {
}
/**
- * @dataProvider dataGetGroups
*
* @param string|null $search
* @param int|null $limit
* @param int|null $offset
*/
- public function testGetGroupsDetails($search, $limit, $offset) {
+ #[\PHPUnit\Framework\Attributes\DataProvider('dataGetGroups')]
+ public function testGetGroupsDetails($search, $limit, $offset): void {
$groups = [$this->createGroup('group1'), $this->createGroup('group2')];
$search = $search === null ? '' : $search;
@@ -251,7 +216,7 @@ class GroupsControllerTest extends \Test\TestCase {
]], $result->getData());
}
- public function testGetGroupAsSubadmin() {
+ public function testGetGroupAsSubadmin(): void {
$group = $this->createGroup('group');
$this->asSubAdminOfGroup($group);
@@ -276,8 +241,8 @@ class GroupsControllerTest extends \Test\TestCase {
}
- public function testGetGroupAsIrrelevantSubadmin() {
- $this->expectException(\OCP\AppFramework\OCS\OCSException::class);
+ public function testGetGroupAsIrrelevantSubadmin(): void {
+ $this->expectException(OCSException::class);
$this->expectExceptionCode(403);
$group = $this->createGroup('group');
@@ -296,7 +261,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->api->getGroup('group');
}
- public function testGetGroupAsAdmin() {
+ public function testGetGroupAsAdmin(): void {
$group = $this->createGroup('group');
$this->asAdmin();
@@ -321,8 +286,8 @@ class GroupsControllerTest extends \Test\TestCase {
}
- public function testGetGroupNonExisting() {
- $this->expectException(\OCP\AppFramework\OCS\OCSException::class);
+ public function testGetGroupNonExisting(): void {
+ $this->expectException(OCSException::class);
$this->expectExceptionMessage('The requested group could not be found');
$this->expectExceptionCode(404);
@@ -332,15 +297,15 @@ class GroupsControllerTest extends \Test\TestCase {
}
- public function testGetSubAdminsOfGroupsNotExists() {
- $this->expectException(\OCP\AppFramework\OCS\OCSException::class);
+ public function testGetSubAdminsOfGroupsNotExists(): void {
+ $this->expectException(OCSException::class);
$this->expectExceptionMessage('Group does not exist');
$this->expectExceptionCode(101);
$this->api->getSubAdminsOfGroup('NonExistingGroup');
}
- public function testGetSubAdminsOfGroup() {
+ public function testGetSubAdminsOfGroup(): void {
$group = $this->createGroup('GroupWithSubAdmins');
$this->groupManager
->method('get')
@@ -360,7 +325,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->assertEquals(['SubAdmin1', 'SubAdmin2'], $result->getData());
}
- public function testGetSubAdminsOfGroupEmptyList() {
+ public function testGetSubAdminsOfGroupEmptyList(): void {
$group = $this->createGroup('GroupWithOutSubAdmins');
$this->groupManager
->method('get')
@@ -379,8 +344,8 @@ class GroupsControllerTest extends \Test\TestCase {
}
- public function testAddGroupEmptyGroup() {
- $this->expectException(\OCP\AppFramework\OCS\OCSException::class);
+ public function testAddGroupEmptyGroup(): void {
+ $this->expectException(OCSException::class);
$this->expectExceptionMessage('Invalid group name');
$this->expectExceptionCode(101);
@@ -388,8 +353,8 @@ class GroupsControllerTest extends \Test\TestCase {
}
- public function testAddGroupExistingGroup() {
- $this->expectException(\OCP\AppFramework\OCS\OCSException::class);
+ public function testAddGroupExistingGroup(): void {
+ $this->expectException(OCSException::class);
$this->expectExceptionCode(102);
$this->groupManager
@@ -400,7 +365,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->api->addGroup('ExistingGroup');
}
- public function testAddGroup() {
+ public function testAddGroup(): void {
$this->groupManager
->method('groupExists')
->with('NewGroup')
@@ -416,7 +381,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->api->addGroup('NewGroup');
}
- public function testAddGroupWithSpecialChar() {
+ public function testAddGroupWithSpecialChar(): void {
$this->groupManager
->method('groupExists')
->with('Iñtërnâtiônàlizætiøn')
@@ -433,16 +398,16 @@ class GroupsControllerTest extends \Test\TestCase {
}
- public function testDeleteGroupNonExisting() {
- $this->expectException(\OCP\AppFramework\OCS\OCSException::class);
+ public function testDeleteGroupNonExisting(): void {
+ $this->expectException(OCSException::class);
$this->expectExceptionCode(101);
$this->api->deleteGroup('NonExistingGroup');
}
- public function testDeleteAdminGroup() {
- $this->expectException(\OCP\AppFramework\OCS\OCSException::class);
+ public function testDeleteAdminGroup(): void {
+ $this->expectException(OCSException::class);
$this->expectExceptionCode(102);
$this->groupManager
@@ -453,7 +418,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->api->deleteGroup('admin');
}
- public function testDeleteGroup() {
+ public function testDeleteGroup(): void {
$this->groupManager
->method('groupExists')
->with('ExistingGroup')
@@ -472,7 +437,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->api->deleteGroup('ExistingGroup');
}
- public function testDeleteGroupEncoding() {
+ public function testDeleteGroupEncoding(): void {
$this->groupManager
->method('groupExists')
->with('ExistingGroup A/B')
@@ -491,7 +456,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->api->deleteGroup(urlencode('ExistingGroup A/B'));
}
- public function testGetGroupUsersDetails() {
+ public function testGetGroupUsersDetails(): void {
$gid = 'ncg1';
$this->asAdmin();
@@ -507,7 +472,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->userManager->expects($this->any())
->method('get')
->willReturnCallback(function (string $uid) use ($users) {
- return isset($users[$uid]) ? $users[$uid] : null;
+ return $users[$uid] ?? null;
});
$group = $this->createGroup($gid);
@@ -524,7 +489,7 @@ class GroupsControllerTest extends \Test\TestCase {
->method('getUserGroups')
->willReturn([$group]);
- /** @var \PHPUnit\Framework\MockObject\MockObject */
+ /** @var MockObject */
$this->subAdminManager->expects($this->any())
->method('isSubAdminOfGroup')
->willReturn(false);
@@ -536,7 +501,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->api->getGroupUsersDetails($gid);
}
- public function testGetGroupUsersDetailsEncoded() {
+ public function testGetGroupUsersDetailsEncoded(): void {
$gid = 'Department A/B C/D';
$this->asAdmin();
@@ -552,7 +517,7 @@ class GroupsControllerTest extends \Test\TestCase {
$this->userManager->expects($this->any())
->method('get')
->willReturnCallback(function (string $uid) use ($users) {
- return isset($users[$uid]) ? $users[$uid] : null;
+ return $users[$uid] ?? null;
});
$group = $this->createGroup($gid);
@@ -569,7 +534,7 @@ class GroupsControllerTest extends \Test\TestCase {
->method('getUserGroups')
->willReturn([$group]);
- /** @var \PHPUnit\Framework\MockObject\MockObject */
+ /** @var MockObject */
$this->subAdminManager->expects($this->any())
->method('isSubAdminOfGroup')
->willReturn(false);