request = $this->createMock(IRequest::class); $this->collaboratorSearch = $this->createMock(ISearch::class); $this->userSession = $this->createMock(IUserSession::class); $this->userManager = $this->createMock(IUserManager::class); $this->sessionService = $this->createMock(SessionService::class); $this->userApiController = new UserApiController( 'text', $this->request, $this->sessionService, $this->collaboratorSearch, $this->userManager, $this->userSession ); } /** * @dataProvider dataTestUsersIndex */ public function testUsersIndex(int $documentId, int $sessionId, string $sessionToken, string $filter) { $session = new Session(); $session->setUserId('admin'); $this->sessionService ->expects($this->once()) ->method('isValidSession')->willReturn(true); $this->sessionService ->expects($this->once()) ->method('getAllSessions')->willReturn([[ 'userId' => 'admin', 'displayName' => 'admin', ]]); $this->sessionService ->expects($this->once()) ->method('getSession')->willReturn($session); $this->collaboratorSearch ->expects($this->once()) ->method('search')->willReturn([ [ 'exact' => [ 'users' => [] ], 'users' => [ [ 'label' => 'admin', 'subline' => '', 'icon' => 'icon-user', 'value' => [ 'shareType' => 0, 'shareWith' => 'admin' ], 'shareWithDisplayNameUnique' => 'admin', 'status' => [] ], ] ] ]); $users = $this->userApiController->index( $documentId, $sessionId, $sessionToken, $filter ); $this->assertInstanceOf(DataResponse::class, $users); } public function dataTestUsersIndex() { return [ [103, 44, 'token1', 'admin'], [103, 44, 'token2', 'admin'], [103, 44, 'token3', 'admin'], ]; } }