public function testRemoveFromGroupSuccessful() { $loggedInUser = $this->getMock('\\OCP\\IUser'); $loggedInUser->expects($this->any())->method('getUID')->will($this->returnValue('admin')); $targetUser = $this->getMock('\\OCP\\IUser'); $targetGroup = $this->getMock('\\OCP\\IGroup'); $this->userSession->expects($this->once())->method('getUser')->will($this->returnValue($loggedInUser)); $this->groupManager->expects($this->once())->method('get')->with('admin')->will($this->returnValue($targetGroup)); $this->userManager->expects($this->once())->method('get')->with('AnotherUser')->will($this->returnValue($targetUser)); $subAdminManager = $this->getMockBuilder('\\OC\\Subadmin')->disableOriginalConstructor()->getMock(); $this->groupManager->expects($this->once())->method('getSubAdmin')->will($this->returnValue($subAdminManager)); $this->groupManager->expects($this->any())->method('isAdmin')->with('admin')->will($this->returnValue(true)); $targetGroup->expects($this->once())->method('removeUser')->with($targetUser); $expected = new \OC_OCS_Result(null, 100); $this->assertEquals($expected, $this->api->removeFromGroup(['userid' => 'AnotherUser', '_delete' => ['groupid' => 'admin']])); }
public function testRemoveFromGroupAsIrelevantSubAdmin() { $user1 = $this->generateUsers(); self::loginAsUser($user1); $user2 = $this->generateUsers(); $group1 = $this->getUniqueID(); $group2 = $this->getUniqueID(); \OC_Group::createGroup($group1); \OC_Group::createGroup($group2); \OC_Group::addToGroup($user1, $group1); \OC_Group::addToGroup($user2, $group2); \OC_SubAdmin::createSubAdmin($user1, $group1); $result = \OCA\provisioning_api\Users::removeFromGroup(array('userid' => $user2, '_delete' => array('groupid' => $group2))); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertFalse($result->succeeded()); $this->assertTrue(\OC_Group::inGroup($user2, $group2)); \OC_Group::deleteGroup($group1); \OC_Group::deleteGroup($group2); }