Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <[email protected]>
  • Loading branch information
skjnldsv committed Mar 23, 2018
1 parent d597478 commit ab64d0f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
10 changes: 6 additions & 4 deletions apps/provisioning_api/lib/Controller/GroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCSController;
use OCP\IGroup;
use OCP\IGroupManager;
Expand Down Expand Up @@ -106,7 +108,7 @@ public function getGroups(string $search = '', int $limit = null, int $offset =
* @param int $offset
* @return DataResponse
*/
public function getGroupsDetails(string $search = '', int $limit = null, int $offset = null): DataResponse {
public function getGroupsDetails(string $search = '', int $limit = null, int $offset = 0): DataResponse {
$groups = $this->groupManager->search($search, $limit, $offset);
$groups = array_map(function($group) {
/** @var IGroup $group */
Expand All @@ -126,7 +128,7 @@ public function getGroupsDetails(string $search = '', int $limit = null, int $of
* @deprecated 14 Use getGroupUsers
*/
public function getGroup(string $groupId): DataResponse {
return $this->getGroup($groupId);
return $this->getGroupUsers($groupId);
}

/**
Expand All @@ -147,7 +149,7 @@ public function getGroupUsers(string $groupId): DataResponse {
if ($group !== null) {
$isSubadminOfGroup =$this->groupManager->getSubAdmin()->isSubAdminOfGroup($user, $group);
} else {
throw new OCSException('The requested group could not be found', \OCP\API::RESPOND_NOT_FOUND);
throw new OCSNotFoundException('The requested group could not be found');
}

// Check subadmin has access to this group
Expand All @@ -162,7 +164,7 @@ public function getGroupUsers(string $groupId): DataResponse {
return new DataResponse(['users' => $users]);
}

throw new OCSException('User does not have access to specified group', \OCP\API::RESPOND_UNAUTHORISED);
throw new OCSForbiddenException();
}

/**
Expand Down
21 changes: 14 additions & 7 deletions apps/provisioning_api/tests/Controller/GroupsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class GroupsControllerTest extends \Test\TestCase {
protected $userSession;
/** @var \OC\SubAdmin|\PHPUnit_Framework_MockObject_MockObject */
protected $subAdminManager;
/** @var OCA\Provisioning_API\Controller\UsersController|\PHPUnit_Framework_MockObject_MockObject */
protected $userController;

/** @var GroupsController */
protected $api;
Expand Down Expand Up @@ -67,12 +69,17 @@ protected function setUp() {

$logger = $this->createMock(ILogger::class);

$this->userController = $this->getMockBuilder('OCA\Provisioning_API\Controller\UsersController')
->disableOriginalConstructor()
->getMock();

$this->api = new GroupsController(
'provisioning_api',
$request,
$this->groupManager,
$this->userSession,
$logger
$logger,
$this->userController
);
}

Expand Down Expand Up @@ -141,10 +148,10 @@ private function asSubAdminOfGroup($group) {

public function dataGetGroups() {
return [
[null, null, null],
['foo', null, null],
[null, 1, null],
[null, null, 2],
[null, 0, 0],
['foo', 0, 0],
[null, 1, 0],
[null, 0, 2],
['foo', 1, 2],
];
}
Expand Down Expand Up @@ -224,7 +231,7 @@ public function testGetGroupAsSubadmin() {

/**
* @expectedException \OCP\AppFramework\OCS\OCSException
* @expectedExceptionCode 997
* @expectedExceptionCode 403
*/
public function testGetGroupAsIrrelevantSubadmin() {
$group = $this->createGroup('group');
Expand Down Expand Up @@ -269,7 +276,7 @@ public function testGetGroupAsAdmin() {

/**
* @expectedException \OCP\AppFramework\OCS\OCSException
* @expectedExceptionCode 998
* @expectedExceptionCode 404
* @expectedExceptionMessage The requested group could not be found
*/
public function testGetGroupNonExisting() {
Expand Down

0 comments on commit ab64d0f

Please sign in to comment.