public function testGetUsersGroupsForSubAdminUserAndUserIsInaccessible() { $loggedInUser = $this->getMock('\\OCP\\IUser'); $loggedInUser->expects($this->exactly(2))->method('getUID')->will($this->returnValue('subadmin')); $targetUser = $this->getMock('\\OCP\\IUser'); $targetUser->expects($this->once())->method('getUID')->will($this->returnValue('UserToLookup')); $this->userSession->expects($this->once())->method('getUser')->will($this->returnValue($loggedInUser)); $this->userManager->expects($this->once())->method('get')->with('UserToLookup')->will($this->returnValue($targetUser)); $this->groupManager->expects($this->once())->method('isAdmin')->with('subadmin')->will($this->returnValue(false)); $subAdminManager = $this->getMockBuilder('\\OC\\Subadmin')->disableOriginalConstructor()->getMock(); $subAdminManager->expects($this->once())->method('isUserAccessible')->with($loggedInUser, $targetUser)->will($this->returnValue(false)); $this->groupManager->expects($this->once())->method('getSubAdmin')->will($this->returnValue($subAdminManager)); $this->groupManager->expects($this->any())->method('getUserGroupIds')->with($targetUser)->will($this->returnValue(['Group1'])); $expected = new \OC_OCS_Result(null, 997); $this->assertEquals($expected, $this->api->getUsersGroups(['userid' => 'UserToLookup'])); }
public function testGetUsersGroupsOnOtherAsIrelevantSubAdmin() { $user1 = $this->generateUsers(); $user2 = $this->generateUsers(); self::loginAsUser($user1); $group1 = $this->getUniqueID(); $group2 = $this->getUniqueID(); \OC_Group::createGroup($group1); \OC_Group::createGroup($group2); \OC_Group::addToGroup($user2, $group2); \OC_Group::addToGroup($user1, $group1); \OC_SubAdmin::createSubAdmin($user1, $group1); $result = \OCA\provisioning_API\Users::getUsersGroups(array('userid' => $user2)); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertFalse($result->succeeded()); \OC_Group::deleteGroup($group1); \OC_Group::deleteGroup($group2); }