Skip to content

Commit ad37bca

Browse files
authored
Merge pull request #10994 from owncloud/store-share-invite-response
[tests-only][full-ci] Store share invite response
2 parents 58af87d + e6fee4a commit ad37bca

File tree

3 files changed

+87
-30
lines changed

3 files changed

+87
-30
lines changed

tests/acceptance/bootstrap/Sharing.php

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ public function addToCreatedPublicShares(SimpleXMLElement $shareData): void {
116116
* @return void
117117
*/
118118
public function shareNgAddToCreatedLinkShares(ResponseInterface $response): void {
119-
$this->shareNgCreatedLinkShares[] = $response;
119+
$this->shareNgCreatedLinkShares[] = $this->getJsonDecodedResponse($response);
120120
}
121121

122122
/**
123-
* @return ResponseInterface|null
123+
* @return array|null
124124
*/
125-
public function shareNgGetLastCreatedLinkShare(): ?ResponseInterface {
125+
public function shareNgGetLastCreatedLinkShare(): ?array {
126126
return \end($this->shareNgCreatedLinkShares);
127127
}
128128

@@ -132,13 +132,13 @@ public function shareNgGetLastCreatedLinkShare(): ?ResponseInterface {
132132
* @return void
133133
*/
134134
public function shareNgAddToCreatedUserGroupShares(ResponseInterface $response): void {
135-
$this->shareNgCreatedUserGroupShares[] = $response;
135+
$this->shareNgCreatedUserGroupShares[] = $this->getJsonDecodedResponse($response);
136136
}
137137

138138
/**
139-
* @return ResponseInterface|null
139+
* @return array|null
140140
*/
141-
public function shareNgGetLastCreatedUserGroupShare(): ?ResponseInterface {
141+
public function shareNgGetLastCreatedUserGroupShare(): ?array {
142142
return \end($this->shareNgCreatedUserGroupShares);
143143
}
144144

@@ -201,37 +201,68 @@ public function getSharesEndpointPath(?string $postfix = ''): string {
201201
*/
202202
public function shareNgGetLastCreatedLinkShareID(): string {
203203
$lastResponse = $this->shareNgGetLastCreatedLinkShare();
204-
if (!isset($this->getJsonDecodedResponse($lastResponse)['id'])) {
204+
if (!isset($lastResponse['id'])) {
205205
throw new Error('Response did not contain share id for the created public link');
206206
}
207-
return $this->getJsonDecodedResponse($lastResponse)['id'];
207+
return $lastResponse['id'];
208208
}
209209

210210
/**
211211
* @return string
212212
*/
213213
public function shareNgGetLastCreatedLinkShareToken(): string {
214214
$lastResponse = $this->shareNgGetLastCreatedLinkShare();
215-
if (!isset($this->getJsonDecodedResponse($lastResponse)['link']['webUrl'])) {
215+
if (!isset($lastResponse['link']['webUrl'])) {
216216
throw new Error(
217217
'Response did not contain share id '
218-
. $this->getJsonDecodedResponse($lastResponse)['link']['webUrl']
218+
. $lastResponse['link']['webUrl']
219219
. ' for the created public link'
220220
);
221221
}
222-
$last_created_link_webURL = $this->getJsonDecodedResponse($lastResponse)['link']['webUrl'];
223-
return substr(strrchr($last_created_link_webURL, "/"), 1);
222+
return substr(strrchr($lastResponse['link']['webUrl'], "/"), 1);
223+
}
224+
225+
/**
226+
* @param string $permissionId
227+
* @param ResponseInterface $response
228+
*
229+
* @return void
230+
*/
231+
public function shareNgUpdatedCreatedLinkShare(string $permissionId, ResponseInterface $response): void {
232+
foreach ($this->shareNgCreatedLinkShares as $key => $share) {
233+
if ($share['id'] === $permissionId) {
234+
$decodedResponse = $this->getJsonDecodedResponse($response);
235+
$this->shareNgCreatedLinkShares[$key] = $decodedResponse;
236+
return;
237+
}
238+
}
224239
}
225240

226241
/**
227242
* @return string
228243
*/
229244
public function shareNgGetLastCreatedUserGroupShareID(): string {
230245
$lastResponse = $this->shareNgGetLastCreatedUserGroupShare();
231-
if (!isset($this->getJsonDecodedResponse($lastResponse)['value'][0]['id'])) {
246+
if (!isset($lastResponse['value'][0]['id'])) {
232247
throw new Error('Response did not contain share id for the last created share.');
233248
}
234-
return $this->getJsonDecodedResponse($lastResponse)['value'][0]['id'];
249+
return $lastResponse['value'][0]['id'];
250+
}
251+
252+
/**
253+
* @param string $permissionId
254+
* @param ResponseInterface $response
255+
*
256+
* @return void
257+
*/
258+
public function shareNgUpdateCreatedUserGroupShare(string $permissionId, ResponseInterface $response): void {
259+
foreach ($this->shareNgCreatedUserGroupShares as $key => $share) {
260+
if ($share['value'][0]['id'] === $permissionId) {
261+
$decodedResponse = $this->getJsonDecodedResponse($response);
262+
$this->shareNgCreatedUserGroupShares[$key]['value'] = $decodedResponse;
263+
return;
264+
};
265+
}
235266
}
236267

237268
/**

tests/acceptance/bootstrap/SharingNgContext.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function createLinkShare(string $user, TableNode $body): ResponseInterfac
101101
'password' => $this->featureContext->getActualPassword($bodyRows['password'])
102102
];
103103

104-
return GraphHelper::createLinkShare(
104+
$response = GraphHelper::createLinkShare(
105105
$this->featureContext->getBaseUrl(),
106106
$this->featureContext->getStepLineRef(),
107107
$user,
@@ -110,6 +110,12 @@ public function createLinkShare(string $user, TableNode $body): ResponseInterfac
110110
$itemId,
111111
\json_encode($body)
112112
);
113+
114+
if ($response->getStatusCode() == 200) {
115+
$this->featureContext->shareNgAddToCreatedLinkShares($response);
116+
}
117+
118+
return $response;
113119
}
114120

115121
/**
@@ -681,7 +687,7 @@ public function updateResourceShare(string $user, TableNode $body, string $perm
681687
? null : $bodyRows['expirationDateTime'];
682688
}
683689

684-
return GraphHelper::updateShare(
690+
$response = GraphHelper::updateShare(
685691
$this->featureContext->getBaseUrl(),
686692
$this->featureContext->getStepLineRef(),
687693
$user,
@@ -691,6 +697,12 @@ public function updateResourceShare(string $user, TableNode $body, string $perm
691697
\json_encode($body),
692698
$permissionID
693699
);
700+
701+
if ($response->getStatusCode() === 200) {
702+
$this->featureContext->shareNgUpdateCreatedUserGroupShare($permissionID, $response);
703+
}
704+
705+
return $response;
694706
}
695707

696708
/**
@@ -763,7 +775,6 @@ public function userHasCreatedTheFollowingResourceLinkShare(string $user, TableN
763775
);
764776
$response = $this->createLinkShare($user, $body);
765777
$this->featureContext->theHTTPStatusCodeShouldBe(200, "Failed while creating public share link!", $response);
766-
$this->featureContext->shareNgAddToCreatedLinkShares($response);
767778
}
768779

769780
/**
@@ -859,7 +870,7 @@ public function updateLinkShare(string $user, TableNode $body, string $permissi
859870
$body['displayName'] = $bodyRows['displayName'];
860871
}
861872

862-
return GraphHelper::updateShare(
873+
$response = GraphHelper::updateShare(
863874
$this->featureContext->getBaseUrl(),
864875
$this->featureContext->getStepLineRef(),
865876
$user,
@@ -869,6 +880,12 @@ public function updateLinkShare(string $user, TableNode $body, string $permissi
869880
\json_encode($body),
870881
$permissionID
871882
);
883+
884+
if ($response->getStatusCode() === 200) {
885+
$this->featureContext->shareNgUpdatedCreatedLinkShare($permissionID, $response);
886+
}
887+
888+
return $response;
872889
}
873890

874891
/**
@@ -894,7 +911,7 @@ public function setLinkSharePassword(string $user, TableNode $body, string $per
894911
throw new Error('Password is missing to set for share link!');
895912
}
896913

897-
return GraphHelper::setLinkSharePassword(
914+
$response = GraphHelper::setLinkSharePassword(
898915
$this->featureContext->getBaseUrl(),
899916
$this->featureContext->getStepLineRef(),
900917
$user,
@@ -904,6 +921,11 @@ public function setLinkSharePassword(string $user, TableNode $body, string $per
904921
\json_encode($body),
905922
$permissionID
906923
);
924+
925+
if ($response->getStatusCode() === 200) {
926+
$this->featureContext->shareNgUpdatedCreatedLinkShare($permissionID, $response);
927+
}
928+
return $response;
907929
}
908930

909931
/**

tests/acceptance/bootstrap/SpacesContext.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,18 +2666,22 @@ public function userExpiresTheLastShareOfResourceInsideOfTheSpace(
26662666
$itemId = $this->getResourceId($user, $spaceName, $resource);
26672667
$body['expirationDateTime'] = $rows['expireDate'];
26682668
$permissionID = $this->featureContext->shareNgGetLastCreatedUserGroupShareID();
2669-
$this->featureContext->setResponse(
2670-
GraphHelper::updateShare(
2671-
$this->featureContext->getBaseUrl(),
2672-
$this->featureContext->getStepLineRef(),
2673-
$user,
2674-
$this->featureContext->getPasswordForUser($user),
2675-
$space["id"],
2676-
$itemId,
2677-
\json_encode($body),
2678-
$permissionID
2679-
)
2669+
$response = GraphHelper::updateShare(
2670+
$this->featureContext->getBaseUrl(),
2671+
$this->featureContext->getStepLineRef(),
2672+
$user,
2673+
$this->featureContext->getPasswordForUser($user),
2674+
$space["id"],
2675+
$itemId,
2676+
\json_encode($body),
2677+
$permissionID
26802678
);
2679+
2680+
if ($response->getStatusCode() === 200) {
2681+
$this->featureContext->shareNgAddToCreatedUserGroupShares($response);
2682+
}
2683+
$this->featureContext->setResponse($response);
2684+
26812685
} else {
26822686
$rows['permissions'] = (string)$this->featureContext->getLastCreatedUserGroupShare()->permissions;
26832687
$this->featureContext->setResponse($this->updateSharedResource($user, $rows));

0 commit comments

Comments
 (0)