public function testAddUserAsSubAdminExistingGroups() { $_POST['userid'] = 'NewUser'; $_POST['password'] = '******'; $_POST['groups'] = ['ExistingGroup1', 'ExistingGroup2']; $this->userManager->expects($this->once())->method('userExists')->with('NewUser')->willReturn(false); $loggedInUser = $this->getMock('\\OCP\\IUser'); $loggedInUser->expects($this->once())->method('getUID')->will($this->returnValue('subAdminUser')); $this->userSession->expects($this->once())->method('getUser')->will($this->returnValue($loggedInUser)); $this->groupManager->expects($this->once())->method('isAdmin')->with('subAdminUser')->willReturn(false); $this->groupManager->expects($this->exactly(2))->method('groupExists')->withConsecutive(['ExistingGroup1'], ['ExistingGroup2'])->willReturn(true); $user = $this->getMock('\\OCP\\IUser'); $this->userManager->expects($this->once())->method('createUser')->with('NewUser', 'PasswordOfTheNewUser')->willReturn($user); $existingGroup1 = $this->getMock('\\OCP\\IGroup'); $existingGroup2 = $this->getMock('\\OCP\\IGroup'); $existingGroup1->expects($this->once())->method('addUser')->with($user); $existingGroup2->expects($this->once())->method('addUser')->with($user); $this->groupManager->expects($this->exactly(4))->method('get')->withConsecutive(['ExistingGroup1'], ['ExistingGroup2'], ['ExistingGroup1'], ['ExistingGroup2'])->will($this->returnValueMap([['ExistingGroup1', $existingGroup1], ['ExistingGroup2', $existingGroup2]])); $this->logger->expects($this->exactly(3))->method('info')->withConsecutive(['Successful addUser call with userid: NewUser', ['app' => 'ocs_api']], ['Added userid NewUser to group ExistingGroup1', ['app' => 'ocs_api']], ['Added userid NewUser to group ExistingGroup2', ['app' => 'ocs_api']]); $subAdminManager = $this->getMockBuilder('\\OC\\Subadmin')->disableOriginalConstructor()->getMock(); $this->groupManager->expects($this->once())->method('getSubAdmin')->willReturn($subAdminManager); $subAdminManager->expects($this->once())->method('isSubAdmin')->with($loggedInUser)->willReturn(true); $subAdminManager->expects($this->exactly(2))->method('isSubAdminOfGroup')->withConsecutive([$loggedInUser, $existingGroup1], [$loggedInUser, $existingGroup2])->wilLReturn(true); $expected = new \OC_OCS_Result(null, 100); $this->assertEquals($expected, $this->api->addUser()); }
public function testAddUserUnsuccessful() { $_POST['userid'] = 'NewUser'; $_POST['password'] = '******'; $this->userManager->expects($this->once())->method('userExists')->with('NewUser')->will($this->returnValue(false)); $this->userManager->expects($this->once())->method('createUser')->with('NewUser', 'PasswordOfTheNewUser')->will($this->throwException(new \Exception('User backend not found.'))); $this->logger->expects($this->once())->method('error')->with('Failed addUser attempt with exception: User backend not found.', ['app' => 'ocs_api']); $expected = new \OC_OCS_Result(null, 101, 'Bad request'); $this->assertEquals($expected, $this->api->addUser()); }
public function testAddUser() { $this->resetParams(); $_POST['userid'] = $this->getUniqueID(); $_POST['password'] = '******'; $result = \OCA\provisioning_API\Users::addUser(array()); $this->assertInstanceOf('OC_OCS_Result', $result); $this->assertTrue($result->succeeded()); $this->assertTrue(\OC_User::userExists($_POST['userid'])); $this->assertEquals($_POST['userid'], \OC_User::checkPassword($_POST['userid'], $_POST['password'])); $this->users[] = $_POST['userid']; }