diff --git a/tests/acceptance/bootstrap/Sharing.php b/tests/acceptance/bootstrap/Sharing.php index b2250d3d522..e0715d8b102 100755 --- a/tests/acceptance/bootstrap/Sharing.php +++ b/tests/acceptance/bootstrap/Sharing.php @@ -116,13 +116,13 @@ public function addToCreatedPublicShares(SimpleXMLElement $shareData): void { * @return void */ public function shareNgAddToCreatedLinkShares(ResponseInterface $response): void { - $this->shareNgCreatedLinkShares[] = $response; + $this->shareNgCreatedLinkShares[] = $this->getJsonDecodedResponse($response); } /** - * @return ResponseInterface|null + * @return array|null */ - public function shareNgGetLastCreatedLinkShare(): ?ResponseInterface { + public function shareNgGetLastCreatedLinkShare(): ?array { return \end($this->shareNgCreatedLinkShares); } @@ -132,13 +132,13 @@ public function shareNgGetLastCreatedLinkShare(): ?ResponseInterface { * @return void */ public function shareNgAddToCreatedUserGroupShares(ResponseInterface $response): void { - $this->shareNgCreatedUserGroupShares[] = $response; + $this->shareNgCreatedUserGroupShares[] = $this->getJsonDecodedResponse($response); } /** - * @return ResponseInterface|null + * @return array|null */ - public function shareNgGetLastCreatedUserGroupShare(): ?ResponseInterface { + public function shareNgGetLastCreatedUserGroupShare(): ?array { return \end($this->shareNgCreatedUserGroupShares); } @@ -201,10 +201,10 @@ public function getSharesEndpointPath(?string $postfix = ''): string { */ public function shareNgGetLastCreatedLinkShareID(): string { $lastResponse = $this->shareNgGetLastCreatedLinkShare(); - if (!isset($this->getJsonDecodedResponse($lastResponse)['id'])) { + if (!isset($lastResponse['id'])) { throw new Error('Response did not contain share id for the created public link'); } - return $this->getJsonDecodedResponse($lastResponse)['id']; + return $lastResponse['id']; } /** @@ -212,15 +212,30 @@ public function shareNgGetLastCreatedLinkShareID(): string { */ public function shareNgGetLastCreatedLinkShareToken(): string { $lastResponse = $this->shareNgGetLastCreatedLinkShare(); - if (!isset($this->getJsonDecodedResponse($lastResponse)['link']['webUrl'])) { + if (!isset($lastResponse['link']['webUrl'])) { throw new Error( 'Response did not contain share id ' - . $this->getJsonDecodedResponse($lastResponse)['link']['webUrl'] + . $lastResponse['link']['webUrl'] . ' for the created public link' ); } - $last_created_link_webURL = $this->getJsonDecodedResponse($lastResponse)['link']['webUrl']; - return substr(strrchr($last_created_link_webURL, "/"), 1); + return substr(strrchr($lastResponse['link']['webUrl'], "/"), 1); + } + + /** + * @param string $permissionId + * @param ResponseInterface $response + * + * @return void + */ + public function shareNgUpdatedCreatedLinkShare(string $permissionId, ResponseInterface $response): void { + foreach ($this->shareNgCreatedLinkShares as $key => $share) { + if ($share['id'] === $permissionId) { + $decodedResponse = $this->getJsonDecodedResponse($response); + $this->shareNgCreatedLinkShares[$key] = $decodedResponse; + return; + } + } } /** @@ -228,10 +243,26 @@ public function shareNgGetLastCreatedLinkShareToken(): string { */ public function shareNgGetLastCreatedUserGroupShareID(): string { $lastResponse = $this->shareNgGetLastCreatedUserGroupShare(); - if (!isset($this->getJsonDecodedResponse($lastResponse)['value'][0]['id'])) { + if (!isset($lastResponse['value'][0]['id'])) { throw new Error('Response did not contain share id for the last created share.'); } - return $this->getJsonDecodedResponse($lastResponse)['value'][0]['id']; + return $lastResponse['value'][0]['id']; + } + + /** + * @param string $permissionId + * @param ResponseInterface $response + * + * @return void + */ + public function shareNgUpdateCreatedUserGroupShare(string $permissionId, ResponseInterface $response): void { + foreach ($this->shareNgCreatedUserGroupShares as $key => $share) { + if ($share['value'][0]['id'] === $permissionId) { + $decodedResponse = $this->getJsonDecodedResponse($response); + $this->shareNgCreatedUserGroupShares[$key]['value'] = $decodedResponse; + return; + }; + } } /** diff --git a/tests/acceptance/bootstrap/SharingNgContext.php b/tests/acceptance/bootstrap/SharingNgContext.php index 8515d71e8a5..33410ec7cbf 100644 --- a/tests/acceptance/bootstrap/SharingNgContext.php +++ b/tests/acceptance/bootstrap/SharingNgContext.php @@ -101,7 +101,7 @@ public function createLinkShare(string $user, TableNode $body): ResponseInterfac 'password' => $this->featureContext->getActualPassword($bodyRows['password']) ]; - return GraphHelper::createLinkShare( + $response = GraphHelper::createLinkShare( $this->featureContext->getBaseUrl(), $this->featureContext->getStepLineRef(), $user, @@ -110,6 +110,12 @@ public function createLinkShare(string $user, TableNode $body): ResponseInterfac $itemId, \json_encode($body) ); + + if ($response->getStatusCode() == 200) { + $this->featureContext->shareNgAddToCreatedLinkShares($response); + } + + return $response; } /** @@ -681,7 +687,7 @@ public function updateResourceShare(string $user, TableNode $body, string $perm ? null : $bodyRows['expirationDateTime']; } - return GraphHelper::updateShare( + $response = GraphHelper::updateShare( $this->featureContext->getBaseUrl(), $this->featureContext->getStepLineRef(), $user, @@ -691,6 +697,12 @@ public function updateResourceShare(string $user, TableNode $body, string $perm \json_encode($body), $permissionID ); + + if ($response->getStatusCode() === 200) { + $this->featureContext->shareNgUpdateCreatedUserGroupShare($permissionID, $response); + } + + return $response; } /** @@ -763,7 +775,6 @@ public function userHasCreatedTheFollowingResourceLinkShare(string $user, TableN ); $response = $this->createLinkShare($user, $body); $this->featureContext->theHTTPStatusCodeShouldBe(200, "Failed while creating public share link!", $response); - $this->featureContext->shareNgAddToCreatedLinkShares($response); } /** @@ -859,7 +870,7 @@ public function updateLinkShare(string $user, TableNode $body, string $permissi $body['displayName'] = $bodyRows['displayName']; } - return GraphHelper::updateShare( + $response = GraphHelper::updateShare( $this->featureContext->getBaseUrl(), $this->featureContext->getStepLineRef(), $user, @@ -869,6 +880,12 @@ public function updateLinkShare(string $user, TableNode $body, string $permissi \json_encode($body), $permissionID ); + + if ($response->getStatusCode() === 200) { + $this->featureContext->shareNgUpdatedCreatedLinkShare($permissionID, $response); + } + + return $response; } /** @@ -894,7 +911,7 @@ public function setLinkSharePassword(string $user, TableNode $body, string $per throw new Error('Password is missing to set for share link!'); } - return GraphHelper::setLinkSharePassword( + $response = GraphHelper::setLinkSharePassword( $this->featureContext->getBaseUrl(), $this->featureContext->getStepLineRef(), $user, @@ -904,6 +921,11 @@ public function setLinkSharePassword(string $user, TableNode $body, string $per \json_encode($body), $permissionID ); + + if ($response->getStatusCode() === 200) { + $this->featureContext->shareNgUpdatedCreatedLinkShare($permissionID, $response); + } + return $response; } /** diff --git a/tests/acceptance/bootstrap/SpacesContext.php b/tests/acceptance/bootstrap/SpacesContext.php index fb8979b2f70..781c4926fc3 100644 --- a/tests/acceptance/bootstrap/SpacesContext.php +++ b/tests/acceptance/bootstrap/SpacesContext.php @@ -2666,18 +2666,22 @@ public function userExpiresTheLastShareOfResourceInsideOfTheSpace( $itemId = $this->getResourceId($user, $spaceName, $resource); $body['expirationDateTime'] = $rows['expireDate']; $permissionID = $this->featureContext->shareNgGetLastCreatedUserGroupShareID(); - $this->featureContext->setResponse( - GraphHelper::updateShare( - $this->featureContext->getBaseUrl(), - $this->featureContext->getStepLineRef(), - $user, - $this->featureContext->getPasswordForUser($user), - $space["id"], - $itemId, - \json_encode($body), - $permissionID - ) + $response = GraphHelper::updateShare( + $this->featureContext->getBaseUrl(), + $this->featureContext->getStepLineRef(), + $user, + $this->featureContext->getPasswordForUser($user), + $space["id"], + $itemId, + \json_encode($body), + $permissionID ); + + if ($response->getStatusCode() === 200) { + $this->featureContext->shareNgAddToCreatedUserGroupShares($response); + } + $this->featureContext->setResponse($response); + } else { $rows['permissions'] = (string)$this->featureContext->getLastCreatedUserGroupShare()->permissions; $this->featureContext->setResponse($this->updateSharedResource($user, $rows));