diff options
Diffstat (limited to 'apps/provisioning_api/tests/Controller/GroupsControllerTest.php')
-rw-r--r-- | apps/provisioning_api/tests/Controller/GroupsControllerTest.php | 131 |
1 files changed, 59 insertions, 72 deletions
diff --git a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php index 6a66df3a7d2..85e5d733b1f 100644 --- a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php +++ b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php @@ -8,41 +8,36 @@ 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 { @@ -54,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([ @@ -72,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); @@ -109,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(); @@ -158,7 +151,7 @@ class GroupsControllerTest extends \Test\TestCase { }); } - public function dataGetGroups() { + public static function dataGetGroups(): array { return [ [null, 0, 0], ['foo', 0, 0], @@ -168,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; @@ -191,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; @@ -229,7 +216,7 @@ class GroupsControllerTest extends \Test\TestCase { ]], $result->getData()); } - public function testGetGroupAsSubadmin() { + public function testGetGroupAsSubadmin(): void { $group = $this->createGroup('group'); $this->asSubAdminOfGroup($group); @@ -254,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'); @@ -274,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(); @@ -299,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); @@ -310,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') @@ -338,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') @@ -357,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); @@ -366,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 @@ -378,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') @@ -394,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') @@ -411,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 @@ -431,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') @@ -450,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') @@ -469,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(); @@ -502,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); @@ -514,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(); @@ -547,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); |