diff --git a/tests/acceptance/features/bootstrap/OCSContext.php b/tests/acceptance/features/bootstrap/OCSContext.php index 46a10c36da9..9d10c93bbae 100644 --- a/tests/acceptance/features/bootstrap/OCSContext.php +++ b/tests/acceptance/features/bootstrap/OCSContext.php @@ -46,7 +46,8 @@ class OCSContext implements Context { * @return void */ public function theUserSendsToOcsApiEndpoint(string $verb, string $url):void { - $this->theUserSendsToOcsApiEndpointWithBody($verb, $url); + $response = $this->theUserSendsToOcsApiEndpointWithBody($verb, $url); + $this->featureContext->setResponse($response); } /** @@ -58,8 +59,8 @@ public function theUserSendsToOcsApiEndpoint(string $verb, string $url):void { * @return void */ public function theUserHasSentToOcsApiEndpoint(string $verb, string $url):void { - $this->theUserSendsToOcsApiEndpointWithBody($verb, $url); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $response = $this->theUserSendsToOcsApiEndpointWithBody($verb, $url); + $this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response); } /** @@ -74,13 +75,14 @@ public function theUserHasSentToOcsApiEndpoint(string $verb, string $url):void { * @return void */ public function userSendsToOcsApiEndpoint(string $user, string $verb, string $url, ?string $password = null):void { - $this->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, $verb, $url, null, $password ); + $this->featureContext->setResponse($response); } /** @@ -94,14 +96,14 @@ public function userSendsToOcsApiEndpoint(string $user, string $verb, string $ur * @return void */ public function userHasSentToOcsApiEndpoint(string $user, string $verb, string $url, ?string $password = null):void { - $this->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, $verb, $url, null, $password ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response); } /** @@ -112,7 +114,7 @@ public function userHasSentToOcsApiEndpoint(string $user, string $verb, string $ * @param string|null $password * @param array|null $headers * - * @return void + * @return ResponseInterface */ public function userSendsHTTPMethodToOcsApiEndpointWithBody( string $user, @@ -121,7 +123,7 @@ public function userSendsHTTPMethodToOcsApiEndpointWithBody( ?TableNode $body = null, ?string $password = null, ?array $headers = null - ):void { + ):ResponseInterface { /** * array of the data to be sent in the body. * contains $body data converted to an array @@ -140,7 +142,7 @@ public function userSendsHTTPMethodToOcsApiEndpointWithBody( $user = null; $password = null; } - $response = OcsApiHelper::sendRequest( + return OcsApiHelper::sendRequest( $this->featureContext->getBaseUrl(), $user, $password, @@ -151,7 +153,6 @@ public function userSendsHTTPMethodToOcsApiEndpointWithBody( $this->featureContext->getOcsApiVersion(), $headers ); - $this->featureContext->setResponse($response); } /** @@ -159,15 +160,15 @@ public function userSendsHTTPMethodToOcsApiEndpointWithBody( * @param string $url * @param TableNode|null $body * - * @return void + * @return ResponseInterface */ public function adminSendsHttpMethodToOcsApiEndpointWithBody( string $verb, string $url, ?TableNode $body - ):void { + ):ResponseInterface { $admin = $this->featureContext->getAdminUsername(); - $this->userSendsHTTPMethodToOcsApiEndpointWithBody( + return $this->userSendsHTTPMethodToOcsApiEndpointWithBody( $admin, $verb, $url, @@ -180,10 +181,10 @@ public function adminSendsHttpMethodToOcsApiEndpointWithBody( * @param string $url * @param TableNode|null $body * - * @return void + * @return ResponseInterface */ - public function theUserSendsToOcsApiEndpointWithBody(string $verb, string $url, ?TableNode $body = null):void { - $this->userSendsHTTPMethodToOcsApiEndpointWithBody( + public function theUserSendsToOcsApiEndpointWithBody(string $verb, string $url, ?TableNode $body = null):ResponseInterface { + return $this->userSendsHTTPMethodToOcsApiEndpointWithBody( $this->featureContext->getCurrentUser(), $verb, $url, @@ -209,13 +210,14 @@ public function userSendHTTPMethodToOcsApiEndpointWithBody( ?TableNode $body = null, ?string $password = null ):void { - $this->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, $verb, $url, $body, $password ); + $this->featureContext->setResponse($response); } /** @@ -236,14 +238,14 @@ public function userHasSentHTTPMethodToOcsApiEndpointWithBody( ?TableNode $body = null, ?string $password = null ):void { - $this->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, $verb, $url, $body, $password ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response); } /** @@ -399,11 +401,12 @@ public function theAdministratorSendsHttpMethodToOcsApiEndpointWithBody( string $url, ?TableNode $body ):void { - $this->adminSendsHttpMethodToOcsApiEndpointWithBody( + $response = $this->adminSendsHttpMethodToOcsApiEndpointWithBody( $verb, $url, $body ); + $this->featureContext->setResponse($response); } /** @@ -420,12 +423,12 @@ public function theAdministratorHasSentHttpMethodToOcsApiEndpointWithBody( string $url, ?TableNode $body ):void { - $this->adminSendsHttpMethodToOcsApiEndpointWithBody( + $response = $this->adminSendsHttpMethodToOcsApiEndpointWithBody( $verb, $url, $body ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response); } /** @@ -438,11 +441,12 @@ public function theAdministratorHasSentHttpMethodToOcsApiEndpointWithBody( * @return void */ public function theUserSendsHTTPMethodToOcsApiEndpointWithBody(string $verb, string $url, TableNode $body):void { - $this->theUserSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->theUserSendsToOcsApiEndpointWithBody( $verb, $url, $body ); + $this->featureContext->setResponse($response); } /** @@ -455,12 +459,12 @@ public function theUserSendsHTTPMethodToOcsApiEndpointWithBody(string $verb, str * @return void */ public function theUserHasSentHTTPMethodToOcsApiEndpointWithBody(string $verb, string $url, TableNode $body):void { - $this->theUserSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->theUserSendsToOcsApiEndpointWithBody( $verb, $url, $body ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response); } /** @@ -480,13 +484,14 @@ public function theAdministratorSendsHttpMethodToOcsApiWithBodyAndPassword( TableNode $body ):void { $admin = $this->featureContext->getAdminUsername(); - $this->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody( $admin, $verb, $url, $body, $password ); + $this->featureContext->setResponse($response); } /** @@ -507,13 +512,14 @@ public function userSendsHTTPMethodToOcsApiEndpointWithBodyAndPassword( string $password, TableNode $body ):void { - $this->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, $verb, $url, $body, $password ); + $this->featureContext->setResponse($response); } /** @@ -781,14 +787,16 @@ public function userRequestsTheseEndpointsWithoutBodyUsingThePasswordOfUser(stri * * @param string $statusCode * @param string $message + * @param ResponseInterface|null $response * * @return void * @throws Exception */ - public function theOCSStatusCodeShouldBe(string $statusCode, string $message = ""):void { + public function theOCSStatusCodeShouldBe(string $statusCode, string $message = "", ?ResponseInterface $response = null):void { $statusCodes = explode(",", $statusCode); + $response = $response ?? $this->featureContext->getResponse(); $responseStatusCode = $this->getOCSResponseStatusCode( - $this->featureContext->getResponse() + $response ); if (\is_array($statusCodes)) { if ($message === "") { @@ -994,16 +1002,18 @@ public function getActualStatusMessage(string $statusMessage, ?string $language * this function is aware of the currently used OCS version * * @param string|null $message + * @param ResponseInterface|null $response * * @return void * @throws Exception */ - public function assertOCSResponseIndicatesSuccess(?string $message = ""):void { - $this->featureContext->theHTTPStatusCodeShouldBe('200', $message); + public function assertOCSResponseIndicatesSuccess(?string $message = "", ?ResponseInterface $response = null):void { + $response = $response ?? $this->featureContext->getResponse(); + $this->featureContext->theHTTPStatusCodeShouldBe('200', $message, $response); if ($this->featureContext->getOcsApiVersion() === 1) { - $this->theOCSStatusCodeShouldBe('100', $message); + $this->theOCSStatusCodeShouldBe('100', $message, $response); } else { - $this->theOCSStatusCodeShouldBe('200', $message); + $this->theOCSStatusCodeShouldBe('200', $message, $response); } } diff --git a/tests/acceptance/features/bootstrap/ShareesContext.php b/tests/acceptance/features/bootstrap/ShareesContext.php index 2fc8cbf146a..25c31bfb9b1 100644 --- a/tests/acceptance/features/bootstrap/ShareesContext.php +++ b/tests/acceptance/features/bootstrap/ShareesContext.php @@ -72,11 +72,12 @@ public function userGetsTheShareesWithParameters(string $user, TableNode $body): $url .= '?' . \implode('&', $parameters); } - $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, 'GET', $url ); + $this->featureContext->setResponse($response); } /** diff --git a/tests/acceptance/features/bootstrap/Sharing.php b/tests/acceptance/features/bootstrap/Sharing.php index 84cdc753936..5122e423363 100644 --- a/tests/acceptance/features/bootstrap/Sharing.php +++ b/tests/acceptance/features/bootstrap/Sharing.php @@ -1846,7 +1846,7 @@ public function userShouldBeAbleToShareUsingTheSharingApi( * @return void */ public function theUserDeletesLastShareUsingTheSharingAPI():void { - $this->deleteLastShareUsingSharingApiByCurrentUser(); + $this->setResponse($this->deleteLastShareUsingSharingApiByCurrentUser()); } /** @@ -1855,8 +1855,8 @@ public function theUserDeletesLastShareUsingTheSharingAPI():void { * @return void */ public function theUserHasDeletedLastShareUsingTheSharingAPI():void { - $this->deleteLastShareUsingSharingApiByCurrentUser(); - $this->theHTTPStatusCodeShouldBeSuccess(); + $response = $this->deleteLastShareUsingSharingApiByCurrentUser(); + $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); } /** @@ -1864,9 +1864,9 @@ public function theUserHasDeletedLastShareUsingTheSharingAPI():void { * @param string|null $sharer the specific user whose share will be deleted (if specified) * @param bool $deleteLastPublicLink * - * @return void + * @return ResponseInterface */ - public function deleteLastShareUsingSharingApi(string $user, string $sharer = null, bool $deleteLastPublicLink = false):void { + public function deleteLastShareUsingSharingApi(string $user, string $sharer = null, bool $deleteLastPublicLink = false):ResponseInterface { $user = $this->getActualUsername($user); if ($deleteLastPublicLink) { $shareId = (string) $this->getLastCreatedPublicShare()->id; @@ -1878,7 +1878,7 @@ public function deleteLastShareUsingSharingApi(string $user, string $sharer = nu } } $url = $this->getSharesEndpointPath("/$shareId"); - $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + return $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, "DELETE", $url @@ -1886,10 +1886,10 @@ public function deleteLastShareUsingSharingApi(string $user, string $sharer = nu } /** - * @return void + * @return ResponseInterface */ - public function deleteLastShareUsingSharingApiByCurrentUser():void { - $this->deleteLastShareUsingSharingApi($this->currentUser); + public function deleteLastShareUsingSharingApiByCurrentUser():ResponseInterface { + return $this->deleteLastShareUsingSharingApi($this->currentUser); } /** @@ -1901,7 +1901,7 @@ public function deleteLastShareUsingSharingApiByCurrentUser():void { * @return void */ public function userDeletesLastShareUsingTheSharingApi(string $user):void { - $this->deleteLastShareUsingSharingApi($user); + $this->setResponse($this->deleteLastShareUsingSharingApi($user)); $this->pushToLastStatusCodesArrays(); } @@ -1914,7 +1914,7 @@ public function userDeletesLastShareUsingTheSharingApi(string $user):void { * @return void */ public function userDeletesLastPublicLinkShareUsingTheSharingApi(string $user):void { - $this->deleteLastShareUsingSharingApi($user, null, true); + $this->setResponse($this->deleteLastShareUsingSharingApi($user, null, true)); $this->pushToLastStatusCodesArrays(); } @@ -1928,7 +1928,7 @@ public function userDeletesLastPublicLinkShareUsingTheSharingApi(string $user):v * @return void */ public function userDeletesLastShareOfUserUsingTheSharingApi(string $user, string $sharer):void { - $this->deleteLastShareUsingSharingApi($user, $sharer); + $this->setResponse($this->deleteLastShareUsingSharingApi($user, $sharer)); $this->pushToLastStatusCodesArrays(); } @@ -1940,8 +1940,8 @@ public function userDeletesLastShareOfUserUsingTheSharingApi(string $user, strin * @return void */ public function userHasDeletedLastShareUsingTheSharingApi(string $user):void { - $this->deleteLastShareUsingSharingApi($user); - $this->theHTTPStatusCodeShouldBeSuccess(); + $response = $this->deleteLastShareUsingSharingApi($user); + $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); } /** @@ -1967,7 +1967,7 @@ public function theUserGetsInfoOfLastShareUsingTheSharingApi():void { public function userGetsInfoOfLastShareUsingTheSharingApi(string $user, ?string $language = null):void { $shareId = $this->getLastCreatedUserGroupShareId(); $language = TranslationHelper::getLanguage($language); - $this->getShareData($user, $shareId, $language); + $this->setResponse($this->getShareData($user, $shareId, $language)); $this->pushToLastStatusCodesArrays(); } @@ -2000,7 +2000,7 @@ public function userGetsInfoOfLastPublicLinkShareUsingTheSharingApi(string $user ); } $language = TranslationHelper::getLanguage($language); - $this->getShareData($user, $shareId, $language); + $this->setResponse($this->getShareData($user, $shareId, $language)); $this->pushToLastStatusCodesArrays(); } @@ -2073,16 +2073,16 @@ public function getListOfShares(string $user):ResponseInterface { * @param string $share_id * @param string|null $language * - * @return void + * @return ResponseInterface */ - public function getShareData(string $user, string $share_id, ?string $language = null):void { + public function getShareData(string $user, string $share_id, ?string $language = null):ResponseInterface { $user = $this->getActualUsername($user); $url = $this->getSharesEndpointPath("/$share_id"); $headers = []; if ($language !== null) { $headers['Accept-Language'] = $language; } - $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + return $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, "GET", $url, @@ -2102,11 +2102,12 @@ public function getShareData(string $user, string $share_id, ?string $language = public function userGetsAllTheSharesSharedWithHimUsingTheSharingApi(string $user):void { $user = $this->getActualUsername($user); $url = "/apps/files_sharing/api/v1/shares?shared_with_me=true"; - $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, 'GET', $url ); + $this->setResponse($response); } /** @@ -2120,8 +2121,8 @@ public function userGetsAllTheSharesSharedWithHimUsingTheSharingApi(string $user public function userGetsTheLastShareSharedWithHimUsingTheSharingApi(string $user, TableNode $table):void { $user = $this->getActualUsername($user); $shareId = (string) $this->getLastCreatedPublicShare()->id; - $this->getShareData($user, $shareId); - $this->checkFields($user, $table); + $response = $this->getShareData($user, $shareId); + $this->checkFields($user, $table, $response); } /** @@ -2148,13 +2149,14 @@ public function userGetsFilteredSharesSharedWithHimUsingTheSharingApi(string $us } else { $rawShareTypes = SharingHelper::SHARE_TYPES[$shareType]; } - $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, 'GET', $this->getSharesEndpointPath( "?shared_with_me=true" . $pendingClause . "&share_types=" . $rawShareTypes ) ); + $this->setResponse($response); } /** @@ -2169,11 +2171,12 @@ public function userGetsAllSharesSharedWithHimFromFileOrFolderUsingTheProvisioni $user = $this->getActualUsername($user); $url = "/apps/files_sharing/api/" . "v$this->sharingApiVersion/shares?shared_with_me=true&path=$path"; - $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, 'GET', $url ); + $this->setResponse($response); } /** @@ -2295,19 +2298,21 @@ public function theResponseWhenUserGetsInfoOfLastShareShouldInclude( ):void { $user = $this->getActualUsername($user); $this->verifyTableNodeRows($body, [], $this->shareResponseFields); - $this->getShareData($user, $this->getLastCreatedUserGroupShareId()); + $response = $this->getShareData($user, $this->getLastCreatedUserGroupShareId()); $this->theHTTPStatusCodeShouldBe( 200, - "Error getting info of last share for user $user" + "Error getting info of last share for user $user", + $response ); $this->ocsContext->assertOCSResponseIndicatesSuccess( __METHOD__ . ' Error getting info of last share for user $user\n' . $this->ocsContext->getOCSResponseStatusMessage( - $this->getResponse() - ) . '"' + $response + ) . '"', + $response ); - $this->checkFields($user, $body); + $this->checkFields($user, $body, $response); } /** @@ -2543,11 +2548,14 @@ public function checkingTheResponseEntriesCount(int $count):void { * * @param string $user * @param TableNode|null $body + * @param ResponseInterface|null $response * * @return void * @throws Exception */ - public function checkFields(string $user, ?TableNode $body):void { + public function checkFields(string $user, ?TableNode $body, ?ResponseInterface $response = null):void { + $response = $response ?? $this->getResponse(); + $data = $this->getResponseXml($response, __METHOD__)->data[0]; $this->verifyTableNodeColumnsCount($body, 2); $bodyRows = $body->getRowsHash(); $userRelatedFieldNames = [ @@ -2568,8 +2576,8 @@ public function checkFields(string $user, ?TableNode $body):void { $value = $this->getActualUsername($value); $value = $this->replaceValuesFromTable($field, $value); Assert::assertTrue( - $this->isFieldInResponse($field, $value), - "$field doesn't have value '$value'" + $this->isFieldInResponse($field, $value, true, $data), + "$field doesn't have value '$value'", ); } } @@ -3022,17 +3030,17 @@ public function getPublicShareIDByName(string $user, string $path, string $name) * @param string $name * @param string $path * - * @return void + * @return ResponseInterface */ public function deletePublicLinkShareUsingTheSharingApi( string $user, string $name, string $path - ):void { + ):ResponseInterface { $user = $this->getActualUsername($user); $share_id = $this->getPublicShareIDByName($user, $path, $name); $url = $this->getSharesEndpointPath("/$share_id"); - $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + return $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, "DELETE", $url @@ -3053,11 +3061,12 @@ public function userDeletesPublicLinkShareNamedUsingTheSharingApi( string $name, string $path ):void { - $this->deletePublicLinkShareUsingTheSharingApi( + $response = $this->deletePublicLinkShareUsingTheSharingApi( $user, $name, $path ); + $this->setResponse($response); } /** @@ -3074,12 +3083,12 @@ public function userHasDeletedPublicLinkShareNamedUsingTheSharingApi( string $name, string $path ):void { - $this->deletePublicLinkShareUsingTheSharingApi( + $response = $this->deletePublicLinkShareUsingTheSharingApi( $user, $name, $path ); - $this->theHTTPStatusCodeShouldBeSuccess(); + $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response); } /** @@ -3137,11 +3146,12 @@ public function userReactsToShareOfferedBy(string $user, string $action, string $httpRequestMethod = "POST"; } - $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, $httpRequestMethod, $url ); + $this->setResponse($response); $this->pushToLastStatusCodesArrays(); } @@ -3195,11 +3205,12 @@ public function userReactsToShareWithShareIDOfferedBy(string $user, string $acti $httpRequestMethod = "POST"; } - $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, $httpRequestMethod, $url ); + $this->setResponse($response); } /** @@ -3387,11 +3398,12 @@ public function userUnsharesResourceSharedTo(string $sharer, string $path, strin __METHOD__ . " could not find share, offered by $sharer to $sharee" ); - $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $sharer, 'DELETE', '/apps/files_sharing/api/v' . $this->sharingApiVersion . '/shares/' . $shareId ); + $this->setResponse($response); } /** @@ -3460,19 +3472,18 @@ private function getAllSharesSharedWithUser(string $user, ?string $state = "all" __METHOD__ . ' invalid "state" given' ); } - $url = $this->getSharesEndpointPath("?format=json&shared_with_me=true&state=$stateCode"); - $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, "GET", $url ); - if ($this->response->getStatusCode() !== 200) { + if ($response->getStatusCode() !== 200) { throw new Exception( __METHOD__ . " could not retrieve information about shares" ); } - $result = $this->response->getBody()->getContents(); + $result = $response->getBody()->getContents(); $usersShares = \json_decode($result, true); if (!\is_array($usersShares)) { throw new Exception( diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index f446a0f71c1..cda4db794f1 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -2970,14 +2970,14 @@ public function forUserSpaceShouldContainLinks( $url = "/apps/files_sharing/api/v1/shares?reshares=true&space_ref=" . $body; - $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( + $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $user, 'GET', $url, ); $should = ($shouldOrNot !== "not"); - $responseArray = json_decode(json_encode($this->featureContext->getResponseXml()->data), true, 512, JSON_THROW_ON_ERROR); + $responseArray = json_decode(json_encode($this->featureContext->getResponseXml($response)->data), true, 512, JSON_THROW_ON_ERROR); if ($should) { Assert::assertNotEmpty($responseArray, __METHOD__ . ' Response should contain a link, but it is empty'); diff --git a/tests/acceptance/features/bootstrap/WebDavLockingContext.php b/tests/acceptance/features/bootstrap/WebDavLockingContext.php index 85a91cf5297..18d29a990a6 100644 --- a/tests/acceptance/features/bootstrap/WebDavLockingContext.php +++ b/tests/acceptance/features/bootstrap/WebDavLockingContext.php @@ -29,6 +29,7 @@ use TestHelpers\HttpRequestHelper; use TestHelpers\OcsApiHelper; use TestHelpers\WebDavHelper; +use Psr\Http\Message\ResponseInterface; require_once 'bootstrap.php'; @@ -61,7 +62,7 @@ private function lockFile( TableNode $properties, bool $public = false, bool $expectToSucceed = true - ) { + ):ResponseInterface { $user = $this->featureContext->getActualUsername($user); $baseUrl = $this->featureContext->getBaseUrl(); if ($public === true) { @@ -99,10 +100,7 @@ private function lockFile( $this->featureContext->getDavPathVersion(), $type ); - - $this->featureContext->setResponse($response); - $responseXml = $this->featureContext->getResponseXml(null, __METHOD__); - $this->featureContext->setResponseXmlObject($responseXml); + $responseXml = $this->featureContext->getResponseXml($response, __METHOD__); $xmlPart = $responseXml->xpath("//d:locktoken/d:href"); if (isset($xmlPart[0])) { $this->tokenOfLastLock[$user][$file] = (string) $xmlPart[0]; @@ -111,6 +109,7 @@ private function lockFile( Assert::fail("could not find lock token after trying to lock '$file'"); } } + return $response; } /** @@ -123,7 +122,8 @@ private function lockFile( * @return void */ public function lockFileUsingWebDavAPI(string $user, string $file, TableNode $properties) { - $this->lockFile($user, $file, $properties, false, false); + $response = $this->lockFile($user, $file, $properties, false, false); + $this->featureContext->setResponse($response); } /** @@ -136,7 +136,8 @@ public function lockFileUsingWebDavAPI(string $user, string $file, TableNode $pr * @return void */ public function userHasLockedFile(string $user, string $file, TableNode $properties) { - $this->lockFile($user, $file, $properties); + $response = $this->lockFile($user, $file, $properties); + $this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response); } /** @@ -147,12 +148,13 @@ public function userHasLockedFile(string $user, string $file, TableNode $propert * @return void */ public function publicHasLockedLastSharedFile(TableNode $properties) { - $this->lockFile( + $response = $this->lockFile( $this->featureContext->getLastCreatedPublicShareToken(), "/", $properties, true ); + $this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response); } /** @@ -163,13 +165,14 @@ public function publicHasLockedLastSharedFile(TableNode $properties) { * @return void */ public function publicLocksLastSharedFile(TableNode $properties) { - $this->lockFile( + $response = $this->lockFile( $this->featureContext->getLastCreatedPublicShareToken(), "/", $properties, true, false ); + $this->featureContext->setResponse($response); } /** @@ -184,12 +187,13 @@ public function publicHasLockedFileLastSharedFolder( string $file, TableNode $properties ) { - $this->lockFile( + $response = $this->lockFile( $this->featureContext->getLastCreatedPublicShareToken(), $file, $properties, true ); + $this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response); } /** @@ -206,13 +210,14 @@ public function publicLocksFileLastSharedFolder( string $publicWebDAVAPIVersion, TableNode $properties ) { - $this->lockFile( + $response = $this->lockFile( $this->featureContext->getLastCreatedPublicShareToken(), $file, $properties, true, false ); + $this->featureContext->setResponse($response); } /** @@ -224,12 +229,13 @@ public function publicLocksFileLastSharedFolder( * @return void */ public function unlockLastLockUsingWebDavAPI(string $user, string $file) { - $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( + $response = $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( $user, $file, $user, $file ); + $this->featureContext->setResponse($response); } /** @@ -246,12 +252,13 @@ public function unlockItemWithLastLockOfOtherItemUsingWebDavAPI( string $itemToUnlock, string $itemToUseLockOf ) { - $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( + $response = $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( $user, $itemToUnlock, $user, $itemToUseLockOf ); + $this->featureContext->setResponse($response); } /** @@ -269,12 +276,13 @@ public function unlockItemWithLastPublicLockOfOtherItemUsingWebDavAPI( string $itemToUseLockOf ) { $lockOwner = $this->featureContext->getLastCreatedPublicShareToken(); - $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( + $response = $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( $user, $itemToUnlock, $lockOwner, $itemToUseLockOf ); + $this->featureContext->setResponse($response); } /** @@ -339,28 +347,26 @@ public function hasUnlockItemWithTheLastCreatedLock( ) { $lockCount = $this->countLockOfResources($user, $itemToUnlock); - $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( + $response = $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( $user, $itemToUnlock, $lockOwner, $itemToUseLockOf, $public ); - $this->featureContext->theHTTPStatusCodeShouldBe(204); + $this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response); $this->numberOfLockShouldBeReported($lockCount - 1, $itemToUnlock, $user); } /** - * @When user :user unlocks file/folder :itemToUnlock with the last created lock of file/folder :itemToUseLockOf of user :lockOwner using the WebDAV API - * * @param string $user * @param string $itemToUnlock * @param string $lockOwner * @param string $itemToUseLockOf * @param boolean $public * - * @return void + * @return ResponseInterface */ public function unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( string $user, @@ -368,7 +374,7 @@ public function unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( string $lockOwner, string $itemToUseLockOf, bool $public = false - ) { + ):ResponseInterface { $user = $this->featureContext->getActualUsername($user); $lockOwner = $this->featureContext->getActualUsername($lockOwner); if ($public === true) { @@ -388,21 +394,43 @@ public function unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( $headers = [ "Lock-Token" => $this->tokenOfLastLock[$lockOwner][$itemToUseLockOf] ]; - $this->featureContext->setResponse( - WebDavHelper::makeDavRequest( - $baseUrl, - $user, - $password, - "UNLOCK", - $itemToUnlock, - $headers, - $this->featureContext->getStepLineRef(), - null, - $this->featureContext->getDavPathVersion(), - $type - ) + return WebDavHelper::makeDavRequest( + $baseUrl, + $user, + $password, + "UNLOCK", + $itemToUnlock, + $headers, + $this->featureContext->getStepLineRef(), + null, + $this->featureContext->getDavPathVersion(), + $type ); - $this->featureContext->pushToLastStatusCodesArrays(); + } + + /** + * @When user :user unlocks file/folder :itemToUnlock with the last created lock of file/folder :itemToUseLockOf of user :lockOwner using the WebDAV API + * + * @param string $user + * @param string $itemToUnlock + * @param string $lockOwner + * @param string $itemToUseLockOf + * + * @return void + */ + public function userUnlocksItemWithLastLockOfUserAndItemUsingWebDavAPI( + string $user, + string $itemToUnlock, + string $lockOwner, + string $itemToUseLockOf + ) { + $response = $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( + $user, + $itemToUnlock, + $lockOwner, + $itemToUseLockOf + ); + $this->featureContext->setResponse($response); } /** @@ -420,13 +448,14 @@ public function unlockItemAsPublicWithLastLockOfUserAndItemUsingWebDavAPI( string $itemToUseLockOf ) { $user = $this->featureContext->getLastCreatedPublicShareToken(); - $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( + $response = $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( $user, $itemToUnlock, $lockOwner, $itemToUseLockOf, true ); + $this->featureContext->setResponse($response); } /** @@ -438,13 +467,14 @@ public function unlockItemAsPublicWithLastLockOfUserAndItemUsingWebDavAPI( */ public function unlockItemAsPublicUsingWebDavAPI(string $itemToUnlock) { $user = $this->featureContext->getLastCreatedPublicShareToken(); - $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( + $response = $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( $user, $itemToUnlock, $user, $itemToUnlock, true ); + $this->featureContext->setResponse($response); } /** @@ -463,25 +493,24 @@ public function moveItemSendingLockToken( string $fileDestination, string $itemToUseLockOf ) { - $this->moveItemSendingLockTokenOfUser( + $response = $this->moveItemSendingLockTokenOfUser( $user, $fileSource, $fileDestination, $itemToUseLockOf, $user ); + $this->featureContext->setResponse($response); } /** - * @When /^user "([^"]*)" moves (?:file|folder|entry) "([^"]*)" to "([^"]*)" sending the locktoken of (?:file|folder|entry) "([^"]*)" of user "([^"]*)" using the WebDAV API$/ - * * @param string $user * @param string $fileSource * @param string $fileDestination * @param string $itemToUseLockOf * @param string $lockOwner * - * @return void + * @return ResponseInterface */ public function moveItemSendingLockTokenOfUser( string $user, @@ -489,7 +518,7 @@ public function moveItemSendingLockTokenOfUser( string $fileDestination, string $itemToUseLockOf, string $lockOwner - ) { + ):ResponseInterface { $user = $this->featureContext->getActualUsername($user); $lockOwner = $this->featureContext->getActualUsername($lockOwner); $destination = $this->featureContext->destinationHeaderValue( @@ -501,16 +530,40 @@ public function moveItemSendingLockTokenOfUser( "Destination" => $destination, "If" => "(<$token>)" ]; - try { - $response = $this->featureContext->makeDavRequest( - $user, - "MOVE", - $fileSource, - $headers - ); - $this->featureContext->setResponse($response); - } catch (ConnectException $e) { - } + return $this->featureContext->makeDavRequest( + $user, + "MOVE", + $fileSource, + $headers + ); + } + + /** + * @When /^user "([^"]*)" moves (?:file|folder|entry) "([^"]*)" to "([^"]*)" sending the locktoken of (?:file|folder|entry) "([^"]*)" of user "([^"]*)" using the WebDAV API$/ + * + * @param string $user + * @param string $fileSource + * @param string $fileDestination + * @param string $itemToUseLockOf + * @param string $lockOwner + * + * @return void + */ + public function userMovesItemSendingLockTokenOfUser( + string $user, + string $fileSource, + string $fileDestination, + string $itemToUseLockOf, + string $lockOwner + ) { + $response = $this->moveItemSendingLockTokenOfUser( + $user, + $fileSource, + $fileDestination, + $itemToUseLockOf, + $lockOwner + ); + $this->featureContext->setResponse($response); } /**