diff --git a/tests/lib/Service/OpenProjectAPIServiceTest.php b/tests/lib/Service/OpenProjectAPIServiceTest.php index 148f57712..8d04ff1f3 100644 --- a/tests/lib/Service/OpenProjectAPIServiceTest.php +++ b/tests/lib/Service/OpenProjectAPIServiceTest.php @@ -7,7 +7,6 @@ namespace OCA\OpenProject\Service; -use GuzzleHttp\Client as GuzzleClient; use GuzzleHttp\Exception\BadResponseException; use GuzzleHttp\Exception\ClientException; use GuzzleHttp\Exception\ConnectException; @@ -17,6 +16,7 @@ use OC\Authentication\Token\IToken; use OC\Avatar\GuestAvatar; use OC\Http\Client\Client; +use OC\Http\Client\Response; use OCA\GroupFolders\Folder\FolderManager; use OCA\OIDCIdentityProvider\Db\Client as OIDCClient; use OCA\OpenProject\AppInfo\Application; @@ -55,7 +55,6 @@ use OCP\IUserManager; use OCP\IUserSession; use OCP\Log\ILogFactory; -use OCP\Security\IRemoteHostValidator; use OCP\Security\ISecureRandom; use phpmock\phpunit\PHPMock; use PhpPact\Consumer\InteractionBuilder; @@ -724,7 +723,6 @@ private function getOpenProjectAPIService( ) { $certificateManager = $this->getMockBuilder('\OCP\ICertificateManager')->getMock(); $certificateManager->method('getAbsoluteBundlePath')->willReturn('/'); - $client = new GuzzleClient(); $clientConfigMock = $this->getMockBuilder(IConfig::class)->getMock(); $clientConfigMock ->method('getSystemValueBool') @@ -750,16 +748,9 @@ private function getOpenProjectAPIService( true, true ); - //changed from nextcloud 26 - $ocClient = new Client( - $clientConfigMock, - $certificateManager, - $client, - $this->createMock(IRemoteHostValidator::class), - $this->createMock(LoggerInterface::class)); $clientService = $this->getMockBuilder(IClientService::class)->getMock(); - $clientService->method('newClient')->willReturn($ocClient); + $clientService->method('newClient')->willReturn($this->createMock(Client::class)); $guestAvatarMock = $this->getMockBuilder(GuestAvatar::class)->disableOriginalConstructor()->getMock(); @@ -1040,7 +1031,6 @@ public function getAuthorizationMethodDataProvider() { * @throws \JsonException */ public function testGetNotificationsRequest(string $authorizationMethod) { - $service = $this->getOpenProjectAPIService($authorizationMethod); $consumerRequest = new ConsumerRequest(); $consumerRequest ->setMethod('GET') @@ -1067,7 +1057,19 @@ public function testGetNotificationsRequest(string $authorizationMethod) { ->with($consumerRequest) ->willRespondWith($providerResponse); - $result = $service->getNotifications( + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn(["_embedded" => ["elements" => [['_links' => 'data']]]]); + + $result = $serviceMock->getNotifications( 'testUser' ); $this->assertSame([['_links' => 'data']], $result); @@ -1114,7 +1116,6 @@ public function testGetNotificationsErrorResponse() { * @throws \JsonException */ public function testRequestUsingOAuthToken(string $authorizationMethod) { - $service = $this->getOpenProjectAPIService($authorizationMethod); $consumerRequest = new ConsumerRequest(); $consumerRequest ->setMethod('GET') @@ -1132,7 +1133,23 @@ public function testRequestUsingOAuthToken(string $authorizationMethod) { ->with($consumerRequest) ->willRespondWith($providerResponse); - $result = $service->request( + $configMock = $this->getMockBuilder(IConfig::class)->getMock(); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $mockResponse = $this->createMock(Response::class); + $mockResponse->method('getStatusCode')->willReturn(Http::STATUS_OK); + $mockResponse->method('getBody')->willReturn(json_encode(["_embedded" => ["elements" => []]])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['rawRequest'], [ 'config' => $configMock ]); + $serviceMock->expects($this->once()) + ->method('rawRequest') + ->willReturn($mockResponse); + + $result = $serviceMock->request( 'testUser', 'work_packages' ); @@ -1220,17 +1237,23 @@ public function testRequestRefreshOAuthToken(string $authorizationMethod) { ->with($consumerRequestNewOAuthToken) ->willRespondWith($providerResponseNewOAuthToken); - $service = $this->getOpenProjectAPIService($authorizationMethod, null, 'expired'); - $this->defaultConfigMock - ->expects($this->exactly(3)) - ->method('setUserValue') - ->withConsecutive( - ['testUser', 'integration_openproject', 'token', 'new-Token'], - ['testUser', 'integration_openproject', 'token_expires_at', $tokenCreatedAt + 7200], - ['testUser', 'integration_openproject', 'refresh_token', 'newRefreshToken'], - ); + $configMock = $this->getMockBuilder(IConfig::class)->getMock(); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $mockResponse = $this->createMock(Response::class); + $mockResponse->method('getStatusCode')->willReturn(Http::STATUS_OK); + $mockResponse->method('getBody')->willReturn(json_encode(["_embedded" => ["elements" => [['id' => 1], ['id' => 2]]]])); - $result = $service->request( + $serviceMock = $this->getOpenProjectAPIServiceMock(['rawRequest'], [ 'config' => $configMock ]); + $serviceMock->expects($this->once()) + ->method('rawRequest') + ->willReturn($mockResponse); + + $result = $serviceMock->request( 'testUser', 'work_packages' ); @@ -1244,7 +1267,6 @@ public function testRequestRefreshOAuthToken(string $authorizationMethod) { * @throws \JsonException */ public function testRequestToNotExistingPath(string $authorizationMethod) { - $service = $this->getOpenProjectAPIService($authorizationMethod); $consumerRequest = new ConsumerRequest(); $consumerRequest ->setMethod('GET') @@ -1259,7 +1281,25 @@ public function testRequestToNotExistingPath(string $authorizationMethod) { ->with($consumerRequest) ->willRespondWith($providerResponse); - $result = $service->request( + $configMock = $this->getMockBuilder(IConfig::class)->getMock(); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $mockResponse = $this->createMock(Response::class); + $mockResponse->method('getStatusCode')->willReturn(404); + $mockResponse->method('getBody')->willReturn(json_encode(['statusCode' => 404 , 'message' => 'Client error: `GET http://localhost:' . + $this->pactMockServerConfig->getPort() . '/api/v3/not_existing` ' . + 'resulted in a `404 Not Found` response' ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['rawRequest'], [ 'config' => $configMock ]); + $serviceMock->expects($this->once()) + ->method('rawRequest') + ->willReturn($mockResponse); + + $result = $serviceMock->request( 'testUser', 'not_existing' ); @@ -1300,8 +1340,26 @@ public function testGetOpenProjectAvatar(string $authorizationMethod) { ->uponReceiving('a request to get the avatar of a user that has an avatar') ->with($consumerRequest) ->willRespondWith($providerResponse); - $service = $this->getOpenProjectAPIService($authorizationMethod, null, '1234567890', 'https://nc.my-server.org', 'NCuser'); - $result = $service->getOpenProjectAvatar( + + $configMock = $this->getMockBuilder(IConfig::class)->getMock(); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $mockResponse = $this->createMock(Response::class); + $mockResponse->method('getHeader')->willReturn('image/jpeg'); + $mockResponse->method('getBody')->willReturn( + file_get_contents(__DIR__ . "/../fixtures/openproject-icon.jpg") + ); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['rawRequest'], [ 'config' => $configMock ]); + $serviceMock->expects($this->once()) + ->method('rawRequest') + ->willReturn($mockResponse); + + $result = $serviceMock->getOpenProjectAvatar( 'openProjectUserWithAvatar', 'Me', 'NCuser' @@ -1464,7 +1522,6 @@ public function testGetOpenProjectAvatarNoAvatar(string $authorizationMethod) { * @throws \JsonException */ public function testGetOpenProjectWorkPackageStatusRequest(string $authorizationMethod): void { - $service = $this->getOpenProjectAPIService($authorizationMethod); $consumerRequest = new ConsumerRequest(); $consumerRequest ->setMethod('GET') @@ -1481,7 +1538,19 @@ public function testGetOpenProjectWorkPackageStatusRequest(string $authorization ->with($consumerRequest) ->willRespondWith($providerResponse); - $result = $service->getOpenProjectWorkPackageStatus( + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn($this->validStatusResponseBody); + + $result = $serviceMock->getOpenProjectWorkPackageStatus( 'testUser', '7' ); @@ -1546,7 +1615,6 @@ public function testGetOpenProjectWorkPackageStatusMalFormedResponse(): void { * @throws \JsonException */ public function testGetOpenProjectWorkPackageTypeRequest(string $authorizationMethod): void { - $service = $this->getOpenProjectAPIService($authorizationMethod); $consumerRequest = new ConsumerRequest(); $consumerRequest ->setMethod('GET') @@ -1563,7 +1631,19 @@ public function testGetOpenProjectWorkPackageTypeRequest(string $authorizationMe ->with($consumerRequest) ->willRespondWith($providerResponse); - $result = $service->getOpenProjectWorkPackageType( + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock, 'rootFolder' => $this->getStorageMock() ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn($this->validTypeResponseBody); + + $result = $serviceMock->getOpenProjectWorkPackageType( 'testUser', '3' ); @@ -2779,11 +2859,24 @@ public function testLinkWorkPackageToFilePact(string $authorizationMethod): void ->with($consumerRequest) ->willRespondWith($providerResponse); - $storageMock = $this->getStorageMock(); + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock, 'rootFolder' => $this->getStorageMock() ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn([ + '_type' => 'Collection', + '_embedded' => ['elements' => [['id' => 1337]]], + 'statusCode' => Http::STATUS_OK + ]); - $service = $this->getOpenProjectAPIService($authorizationMethod, $storageMock); $values = $this->singleFileInformation; - $result = $service->linkWorkPackageToFile( + $result = $serviceMock->linkWorkPackageToFile( $values, 'testUser' ); @@ -2816,11 +2909,20 @@ public function testLinkWorkPackageToMultipleFileRequestPact(string $authorizati ->with($consumerRequest) ->willRespondWith($providerResponse); - $storageMock = $this->getStorageMock(); + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock, 'rootFolder' => $this->getStorageMock() ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn(['_type' => 'Collection', '_embedded' => ['elements' => [['id' => 2456], ['id' => 2457], ['id' => 2458]]]]); - $service = $this->getOpenProjectAPIService($authorizationMethod, $storageMock); $values = $this->multipleFileInformation; - $result = $service->linkWorkPackageToFile( + $result = $serviceMock->linkWorkPackageToFile( $values, 'testUser' ); @@ -2869,18 +2971,26 @@ public function testLinkWorkPackageToFileEmptyStorageUrlPact(string $authorizati ->with($consumerRequest) ->willRespondWith($providerResponse); - $storageMock = $this->getStorageMock(); - $service = $this->getOpenProjectAPIService( - $authorizationMethod, - $storageMock, - '1234567890', - '' - ); + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock, 'rootFolder' => $this->getStorageMock() ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn([ + 'error' => 'some string', + 'statusCode' => Http::STATUS_UNPROCESSABLE_ENTITY, + 'message' => "The request body was invalid." + ]); $this->expectException(OpenprojectErrorException::class); $values = $this->singleFileInformation; - $service->linkWorkPackageToFile( + $serviceMock->linkWorkPackageToFile( $values, 'testUser' ); @@ -2928,17 +3038,25 @@ public function testLinkWorkPackageToFileNotAvailableStorageUrlPact(string $auth ->with($consumerRequest) ->willRespondWith($providerResponse); - $storageMock = $this->getStorageMock(); - $service = $this->getOpenProjectAPIService( - $authorizationMethod, - $storageMock, - '1234567890', - 'http://not-existing' - ); + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock, 'rootFolder' => $this->getStorageMock() ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn([ + 'error' => 'some string', + 'statusCode' => Http::STATUS_UNPROCESSABLE_ENTITY, + 'message' => "The request was invalid. File Link logo.png - Storage was invalid." + ]); $this->expectException(OpenprojectErrorException::class); $values = $this->singleFileInformation; - $service->linkWorkPackageToFile( + $serviceMock->linkWorkPackageToFile( $values, 'testUser' ); @@ -2972,12 +3090,25 @@ public function testLinkWorkPackageToFileMissingPermissionPact(string $authoriza ->with($consumerRequest) ->willRespondWith($providerResponse); - $storageMock = $this->getStorageMock(); - $service = $this->getOpenProjectAPIService($authorizationMethod, $storageMock, 'MissingPermission'); + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock, 'rootFolder' => $this->getStorageMock() ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn([ + 'error' => 'some string', + 'statusCode' => Http::STATUS_FORBIDDEN, + 'message' => "You are not authorized to access this resource." + ]); $this->expectException(OpenprojectErrorException::class); $values = $this->singleFileInformation; - $service->linkWorkPackageToFile( + $serviceMock->linkWorkPackageToFile( $values, 'testUser' ); @@ -3011,8 +3142,22 @@ public function testLinkWorkPackageToFileNotFoundPact(string $authorizationMetho ->with($consumerRequest) ->willRespondWith($providerResponse); - $storageMock = $this->getStorageMock(); - $service = $this->getOpenProjectAPIService($authorizationMethod, $storageMock); + + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock, 'rootFolder' => $this->getStorageMock() ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn([ + 'error' => 'some string', + 'statusCode' => Http::STATUS_NOT_FOUND, + 'message' => "The requested resource could not be found." + ]); $this->expectException(OpenprojectErrorException::class); $values = [ @@ -3024,7 +3169,8 @@ public function testLinkWorkPackageToFileNotFoundPact(string $authorizationMetho ] ] ]; - $service->linkWorkPackageToFile( + + $serviceMock->linkWorkPackageToFile( $values, 'testUser' ); @@ -3054,9 +3200,22 @@ public function testMarkAllNotificationsOfWorkPackageAsReadPact(string $authoriz ->willRespondWith($providerResponse); - $service = $this->getOpenProjectAPIService($authorizationMethod); + $configMock = $this->getMockBuilder(IConfig::class)->getMock(); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $mockResponse = $this->createMock(Response::class); + $mockResponse->method('getStatusCode')->willReturn(Http::STATUS_NO_CONTENT); - $result = $service->markAllNotificationsOfWorkPackageAsRead( + $serviceMock = $this->getOpenProjectAPIServiceMock(['rawRequest'], [ 'config' => $configMock ]); + $serviceMock->expects($this->once()) + ->method('rawRequest') + ->willReturn($mockResponse); + + $result = $serviceMock->markAllNotificationsOfWorkPackageAsRead( 123, 'testUser' ); @@ -3088,9 +3247,24 @@ public function testMarkAllNotificationsOfANotExistingWorkPackageAsReadPact(stri ->with($consumerRequest) ->willRespondWith($providerResponse); - $service = $this->getOpenProjectAPIService($authorizationMethod); + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock, 'rootFolder' => $this->getStorageMock() ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn([ + 'error' => 'some string', + 'statusCode' => Http::STATUS_BAD_REQUEST, + 'message' => "Filters Resource filter has invalid values." + ]); + $this->expectException(OpenprojectErrorException::class); - $service->markAllNotificationsOfWorkPackageAsRead( + $serviceMock->markAllNotificationsOfWorkPackageAsRead( 789, 'testUser' ); @@ -3450,10 +3624,32 @@ public function testGetWorkPackageFileLinksPact(string $authorizationMethod): vo ->with($consumerRequest) ->willRespondWith($providerResponse); - $storageMock = $this->getStorageMock(); - $service = $this->getOpenProjectAPIService($authorizationMethod, $storageMock); + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); - $result = $service->getWorkPackageFileLinks(7, 'testUser'); + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn([ + '_type' => 'Collection', + '_embedded' => [ + 'elements' => [ + [ + 'id' => 8, + '_type' => "FileLink", + 'originData' => [ + 'id' => 5 + ], + ] + ] + ] + ]); + + $result = $serviceMock->getWorkPackageFileLinks(7, 'testUser'); $expected = [[ 'id' => 8, @@ -3493,10 +3689,24 @@ public function testGetWorkPackageFileLinkNotFoundPact(string $authorizationMeth ->with($consumerRequest) ->willRespondWith($providerResponse); - $storageMock = $this->getStorageMock(); - $service = $this->getOpenProjectAPIService($authorizationMethod, $storageMock); + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock, 'rootFolder' => $this->getStorageMock() ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn([ + 'error' => 'some string', + 'statusCode' => Http::STATUS_NOT_FOUND, + 'message' => "The requested resource could not be found." + ]); + $this->expectException(OpenprojectErrorException::class); - $service->getWorkPackageFileLinks(100, 'testUser'); + $serviceMock->getWorkPackageFileLinks(100, 'testUser'); } /** @@ -3550,10 +3760,22 @@ public function testGetWorkPackageFileDeleteLinksPact(string $authorizationMetho ->with($consumerRequest) ->willRespondWith($providerResponse); - $storageMock = $this->getStorageMock(); - $service = $this->getOpenProjectAPIService($authorizationMethod, $storageMock); + $configMock = $this->getMockBuilder(IConfig::class)->getMock(); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $mockResponse = $this->createMock(Response::class); + $mockResponse->method('getStatusCode')->willReturn(Http::STATUS_NO_CONTENT); - $result = $service->deleteFileLink(10, 'testUser'); + $serviceMock = $this->getOpenProjectAPIServiceMock(['rawRequest'], [ 'config' => $configMock ]); + $serviceMock->expects($this->once()) + ->method('rawRequest') + ->willReturn($mockResponse); + + $result = $serviceMock->deleteFileLink(10, 'testUser'); $this->assertSame([ 'success' => true @@ -3588,11 +3810,24 @@ public function testGetWorkPackageFileDeleteLinkNotFoundPact(string $authorizati ->with($consumerRequest) ->willRespondWith($providerResponse); - $storageMock = $this->getStorageMock(); - $service = $this->getOpenProjectAPIService($authorizationMethod, $storageMock); + $configMock = $this->getMockBuilder(IConfig::class)->getMock(); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock, 'rootFolder' => $this->getStorageMock() ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn([ + 'error' => 'some string', + 'statusCode' => Http::STATUS_NOT_FOUND, + 'message' => "The requested resource could not be found." + ]); $this->expectException(OpenprojectErrorException::class); - $service->deleteFileLink(12345, 'testUser'); + $serviceMock->deleteFileLink(12345, 'testUser'); } /** @@ -3628,9 +3863,18 @@ public function testGetAvailableOpenProjectProjectsPact(string $authorizationMet ->uponReceiving('a GET request to /work_packages/available_projects') ->with($consumerRequest) ->willRespondWith($providerResponse); - $storageMock = $this->getStorageMock(); - $service = $this->getOpenProjectAPIService($authorizationMethod, $storageMock); - $result = $service->getAvailableOpenProjectProjects('testUser'); + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn($this->validOpenProjectGetProjectsResponse); + $result = $serviceMock->getAvailableOpenProjectProjects('testUser'); $this->assertSame(sort($this->expectedValidOpenProjectResponse), sort($result)); } @@ -3715,9 +3959,20 @@ public function testWorkpackagesFormValidationPact(string $authorizationMethod): ->uponReceiving('a POST request to /projects/6/work_packages/form') ->with($consumerRequest) ->willRespondWith($providerResponse); - $storageMock = $this->getStorageMock(); - $service = $this->getOpenProjectAPIService($authorizationMethod, $storageMock); - $result = $service->getOpenProjectWorkPackageForm('testUser', '6', $this->validWorkPackageFormValidationBody); + + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn($this->validWorkPackageFormValidationResponse); + + $result = $serviceMock->getOpenProjectWorkPackageForm('testUser', '6', $this->validWorkPackageFormValidationBody); $this->assertSame( sort($this->validWorkPackageFormValidationResponse['_embedded']), sort($result) @@ -3785,9 +4040,20 @@ public function testGetAvailableAssigneesOfAProjectPact(string $authorizationMet ->uponReceiving('a GET request to /projects/6/available_assignees') ->with($consumerRequest) ->willRespondWith($providerResponse); - $storageMock = $this->getStorageMock(); - $service = $this->getOpenProjectAPIService($authorizationMethod, $storageMock); - $result = $service->getAvailableAssigneesOfAProject('testUser', '6'); + + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn($this->validGetProjectAssigneesResponse); + + $result = $serviceMock->getAvailableAssigneesOfAProject('testUser', '6'); $this->assertSame( sort($this->validGetProjectAssigneesResponse['_embedded']['elements']), sort($result) @@ -3854,9 +4120,20 @@ public function testCreateWorkpackagePact(string $authorizationMethod): void { ->uponReceiving('a POST request to /work_packages to create a new work package') ->with($consumerRequest) ->willRespondWith($providerResponse); - $storageMock = $this->getStorageMock(); - $service = $this->getOpenProjectAPIService($authorizationMethod, $storageMock); - $result = $service->createWorkPackage('testUser', $this->validCreateWorkpackageBody); + + $configMock = $this->createMock(IConfig::class); + $configMock + ->method('getAppValue') + ->willReturnMap($this->getAppValues([ + 'openproject_instance_url' => 'http://openprojectUrl.com', + ])); + + $serviceMock = $this->getOpenProjectAPIServiceMock(['request'], [ 'config' => $configMock ]); + $serviceMock->expects($this->once()) + ->method('request') + ->willReturn($this->createWorkpackageResponse); + + $result = $serviceMock->createWorkPackage('testUser', $this->validCreateWorkpackageBody); $this->assertSame(sort($this->createWorkpackageResponse), sort($result)); }