Exemplo n.º 1
0
 public function testGetUsers()
 {
     $result = \OCA\provisioning_API\Users::getUsers(array());
     $this->assertInstanceOf('OC_OCS_Result', $result);
     $this->assertTrue($result->succeeded());
     $count = $result->getData();
     $count = count($count['users']);
     $this->assertEquals(count(\OC_User::getUsers()), $count);
     $user = $this->generateUsers();
     $_GET['search'] = $user;
     $result = \OCA\provisioning_API\Users::getUsers(array());
     $this->assertInstanceOf('OC_OCS_Result', $result);
     $this->assertTrue($result->succeeded());
     $data = $result->getData();
     $this->assertEquals($user, reset($data['users']));
     // Add several users
     $this->generateUsers(10);
     $this->resetParams();
     $_GET['limit'] = 2;
     $result = \OCA\provisioning_API\Users::getUsers(array());
     $this->assertInstanceOf('OC_OCS_Result', $result);
     $this->assertTrue($result->succeeded());
     $count = $result->getData();
     $count = count($count['users']);
     $this->assertEquals(2, $count);
     $this->resetParams();
     $_GET['limit'] = 1;
     $_GET['offset'] = 1;
     $result = \OCA\provisioning_API\Users::getUsers(array());
     $this->assertInstanceOf('OC_OCS_Result', $result);
     $this->assertTrue($result->succeeded());
     $data = $result->getData();
     $this->assertEquals(\OC_User::getUsers('', 1, 1), $data['users']);
 }
Exemplo n.º 2
0
 public function testGetUsersAsRegularUser()
 {
     $_GET['search'] = 'MyCustomSearch';
     $loggedInUser = $this->getMock('\\OCP\\IUser');
     $loggedInUser->expects($this->once())->method('getUID')->will($this->returnValue('regularUser'));
     $this->userSession->expects($this->once())->method('getUser')->will($this->returnValue($loggedInUser));
     $this->groupManager->expects($this->once())->method('isAdmin')->will($this->returnValue(false));
     $subAdminManager = $this->getMockBuilder('\\OC\\Subadmin')->disableOriginalConstructor()->getMock();
     $subAdminManager->expects($this->once())->method('isSubAdmin')->with($loggedInUser)->will($this->returnValue(false));
     $this->groupManager->expects($this->once())->method('getSubAdmin')->will($this->returnValue($subAdminManager));
     $expected = new \OC_OCS_Result(null, \OCP\API::RESPOND_UNAUTHORISED);
     $this->assertEquals($expected, $this->api->getUsers());
 }