Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tests-only][full-ci] removing the setResponse() and $this->response in given/then step in Sharing file #7889

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 37 additions & 130 deletions tests/acceptance/features/bootstrap/Sharing.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -610,11 +610,11 @@ public function shouldNotBeAbleToCreatePublicLinkShare(string $sharer, string $e
/**
* @param TableNode|null $body
*
* @return void
* @return ResponseInterface
* @throws Exception
*/
public function updateLastShareByCurrentUser(?TableNode $body):void {
$this->updateLastShareWithSettings($this->currentUser, $body);
public function updateLastShareByCurrentUser(?TableNode $body):ResponseInterface {
return $this->updateLastShareWithSettings($this->currentUser, $body);
}

/**
Expand All @@ -626,7 +626,7 @@ public function updateLastShareByCurrentUser(?TableNode $body):void {
* @throws Exception
*/
public function theUserUpdatesTheLastShareWith(?TableNode $body):void {
$this->updateLastShareByCurrentUser($body);
$this->setResponse($this->updateLastShareByCurrentUser($body));
}

/**
Expand All @@ -638,8 +638,8 @@ public function theUserUpdatesTheLastShareWith(?TableNode $body):void {
* @throws Exception
*/
public function theUserHasUpdatedTheLastShareWith(?TableNode $body):void {
$this->updateLastShareByCurrentUser($body);
$this->theHTTPStatusCodeShouldBeSuccess();
$response = $this->updateLastShareByCurrentUser($body);
$this->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
}

/**
Expand Down Expand Up @@ -667,15 +667,15 @@ public function getLastCreatedUserGroupShareId(?string $user = null): string {
* @param string|null $shareOwner
* @param bool $updateLastPublicLink
*
* @return void
* @return ResponseInterface
* @throws Exception
*/
public function updateLastShareWithSettings(
string $user,
?TableNode $body,
?string $shareOwner = null,
?bool $updateLastPublicLink = false
):void {
):ResponseInterface {
$user = $this->getActualUsername($user);

if ($updateLastPublicLink) {
Expand Down Expand Up @@ -706,7 +706,7 @@ public function updateLastShareWithSettings(
$bodyRows['permissions'] = SharingHelper::getPermissionSum($bodyRows['permissions']);
}
}
$this->response = OcsApiHelper::sendRequest(
return OcsApiHelper::sendRequest(
$this->getBaseUrl(),
$user,
$this->getPasswordForUser($user),
Expand All @@ -728,7 +728,7 @@ public function updateLastShareWithSettings(
* @throws Exception
*/
public function userUpdatesTheLastShareWith(string $user, ?TableNode $body):void {
$this->updateLastShareWithSettings($user, $body);
$this->setResponse($this->updateLastShareWithSettings($user, $body));
$this->pushToLastStatusCodesArrays();
}

Expand All @@ -742,7 +742,7 @@ public function userUpdatesTheLastShareWith(string $user, ?TableNode $body):void
* @throws Exception
*/
public function userUpdatesTheLastPublicLinkShareWith(string $user, ?TableNode $body):void {
$this->updateLastShareWithSettings($user, $body, null, true);
$this->response = $this->updateLastShareWithSettings($user, $body, null, true);
$this->pushToLastStatusCodesArrays();
}

Expand All @@ -756,8 +756,8 @@ public function userUpdatesTheLastPublicLinkShareWith(string $user, ?TableNode $
* @throws Exception
*/
public function userHasUpdatedTheLastShareWith(string $user, ?TableNode $body):void {
$this->updateLastShareWithSettings($user, $body);
$this->theHTTPStatusCodeShouldBeSuccess();
$response = $this->updateLastShareWithSettings($user, $body);
$this->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
}

/**
Expand All @@ -770,8 +770,8 @@ public function userHasUpdatedTheLastShareWith(string $user, ?TableNode $body):v
* @throws Exception
*/
public function userHasUpdatedTheLastPublicLinkShareWith(string $user, ?TableNode $body):void {
$this->updateLastShareWithSettings($user, $body, null, true);
$this->theHTTPStatusCodeShouldBeSuccess();
$response = $this->updateLastShareWithSettings($user, $body, null, true);
$this->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
}

/**
Expand All @@ -785,12 +785,12 @@ public function userHasUpdatedTheLastPublicLinkShareWith(string $user, ?TableNod
* @throws Exception
*/
public function userHasUpdatedTheLastShareOfWith(string $user, string $shareOwner, ?TableNode $body):void {
$this->updateLastShareWithSettings($user, $body, $shareOwner);
$this->theHTTPStatusCodeShouldBeSuccess();
$response = $this->updateLastShareWithSettings($user, $body, $shareOwner);
$this->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
if ($this->ocsApiVersion == 1) {
$this->ocsContext->theOCSStatusCodeShouldBe("100");
$this->ocsContext->theOCSStatusCodeShouldBe("100", "", $response);
} elseif ($this->ocsApiVersion === 2) {
$this->ocsContext->theOCSStatusCodeShouldBe("200");
$this->ocsContext->theOCSStatusCodeShouldBe("200", "", $response);
} else {
throw new Exception('Invalid ocs api version used');
}
Expand Down Expand Up @@ -1492,7 +1492,7 @@ public function userHasSharedFileWithGroupUsingTheSharingApi(
* @throws Exception
*/
public function userTriesToUpdateTheLastShareUsingTheSharingApiWith(string $user, ?TableNode $body):void {
$this->updateLastShareWithSettings($user, $body);
$this->response = $this->updateLastShareWithSettings($user, $body);
}

/**
Expand All @@ -1505,7 +1505,7 @@ public function userTriesToUpdateTheLastShareUsingTheSharingApiWith(string $user
* @throws Exception
*/
public function userTriesToUpdateTheLastPublicLinkShareUsingTheSharingApiWith(string $user, ?TableNode $body):void {
$this->updateLastShareWithSettings($user, $body, null, true);
$this->response = $this->updateLastShareWithSettings($user, $body, null, true);
}

/**
Expand Down Expand Up @@ -1800,7 +1800,7 @@ public function theInfoAboutTheLastShareByUserWithUserShouldInclude(
*/
public function getListOfShares(string $user):ResponseInterface {
$user = $this->getActualUsername($user);
$this->response = OcsApiHelper::sendRequest(
return OcsApiHelper::sendRequest(
$this->getBaseUrl(),
$user,
$this->getPasswordForUser($user),
Expand All @@ -1810,7 +1810,6 @@ public function getListOfShares(string $user):ResponseInterface {
[],
$this->ocsApiVersion
);
return $this->response;
}

/**
Expand Down Expand Up @@ -2560,97 +2559,6 @@ public function checkFieldsNotInResponse(?TableNode $body):void {
}
}

/**
* @param string $user
* @param string $fileName
*
* @return void
* @throws Exception
*/
public function removeAllSharesFromResource(string $user, string $fileName):void {
$headers = ['Content-Type' => 'application/json'];
$res = OcsApiHelper::sendRequest(
$this->getBaseUrl(),
$user,
$this->getPasswordForUser($user),
"GET",
$this->getSharesEndpointPath("?format=json"),
$this->getStepLineRef(),
[],
$this->ocsApiVersion,
$headers
);

$this->setResponse($res);
$this->theHTTPStatusCodeShouldBeSuccess();

$json = \json_decode($res->getBody()->getContents(), true);
$deleted = false;
foreach ($json['ocs']['data'] as $data) {
if (\stripslashes($data['path']) === $fileName) {
$id = $data['id'];
$response = OcsApiHelper::sendRequest(
$this->getBaseUrl(),
$user,
$this->getPasswordForUser($user),
"DELETE",
$this->getSharesEndpointPath("/$id"),
$this->getStepLineRef(),
[],
$this->ocsApiVersion
);

$this->setResponse($response);
$this->theHTTPStatusCodeShouldBeSuccess();

$deleted = true;
}
}

if ($deleted === false) {
throw new Exception(
"Could not delete shares for user $user file $fileName"
);
}
}

/**
* @When user :user removes all shares from the file named :fileName using the sharing API
*
* @param string $user
* @param string $fileName
*
* @return void
* @throws Exception
*/
public function userRemovesAllSharesFromTheFileNamed(string $user, string $fileName):void {
$user = $this->getActualUsername($user);
$this->removeAllSharesFromResource($user, $fileName);
}

/**
* @Given user :user has removed all shares from the file named :fileName
*
* @param string $user
* @param string $fileName
*
* @return void
* @throws Exception
*/
public function userHasRemovedAllSharesFromTheFileNamed(string $user, string $fileName):void {
$user = $this->getActualUsername($user);
$this->removeAllSharesFromResource($user, $fileName);
$response = $this->getShares($user, $fileName);
Assert::assertEquals(
0,
\count($response),
__METHOD__
. " Expected all shares to be removed from '$fileName' but got '"
. \count($response)
. "' shares still present"
);
}

/**
* Returns shares of a file or folder as a SimpleXMLElement
*
Expand All @@ -2667,7 +2575,7 @@ public function userHasRemovedAllSharesFromTheFileNamed(string $user, string $fi
* @return SimpleXMLElement
*/
public function getShares(string $user, string $path):SimpleXMLElement {
$this->response = OcsApiHelper::sendRequest(
$response = OcsApiHelper::sendRequest(
$this->getBaseUrl(),
$user,
$this->getPasswordForUser($user),
Expand All @@ -2677,7 +2585,7 @@ public function getShares(string $user, string $path):SimpleXMLElement {
[],
$this->ocsApiVersion
);
return $this->getResponseXml(null, __METHOD__)->data->element;
return $this->getResponseXml($response, __METHOD__)->data->element;
}

/**
Expand Down Expand Up @@ -3297,13 +3205,13 @@ public function thePublicAccessesThePreviewOfTheFollowingSharedFileUsingTheShari
* @param string $shareServer
* @param string|null $password
*
* @return void
* @return ResponseInterface
*/
public function saveLastSharedPublicLinkShare(
string $user,
string $shareServer,
?string $password = ""
):void {
):ResponseInterface {
$user = $this->getActualUsername($user);
$userPassword = $this->getPasswordForUser($user);

Expand Down Expand Up @@ -3342,7 +3250,7 @@ public function saveLastSharedPublicLinkShare(
null,
$body
);
$this->setResponse($response);
return $response;
}

/**
Expand Down Expand Up @@ -3432,8 +3340,7 @@ public function theUserHasCreatedAReadOnlyPublicLinkForFileFolder(string $user,
null,
$requestPayload
);
$this->setResponse($response);
$this->theHTTPStatusCodeShouldBe(200);
$this->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
}

/**
Expand All @@ -3445,29 +3352,29 @@ public function theUserHasCreatedAReadOnlyPublicLinkForFileFolder(string $user,
* @return void
*/
public function userAddsPublicShareCreatedByUser(string $user, string $shareServer):void {
$this->saveLastSharedPublicLinkShare($user, $shareServer);
$this->setResponse($this->saveLastSharedPublicLinkShare($user, $shareServer));
}

/**
* Expires last created public link share using the testing API
*
* @return void
* @throws GuzzleException
* @throws ResponseInterface
*/
public function expireLastCreatedPublicLinkShare():void {
public function expireLastCreatedPublicLinkShare():ResponseInterface {
$shareId = (string) $this->getLastCreatedPublicShare()->id;
$this->expireShare($shareId);
return $this->expireShare($shareId);
}

/**
* Expires a share using the testing API
*
* @param string|null $shareId optional share id, if null then expire the last share that was created.
*
* @return void
* @return ResponseInterface
* @throws GuzzleException
*/
public function expireShare(string $shareId = null):void {
public function expireShare(string $shareId = null):ResponseInterface {
$adminUser = $this->getAdminUsername();
if ($shareId === null) {
$shareId = $this->getLastCreatedUserGroupShareId();
Expand All @@ -3482,7 +3389,7 @@ public function expireShare(string $shareId = null):void {
[],
$this->getOcsApiVersion()
);
$this->setResponse($response);
return $response;
}

/**
Expand Down Expand Up @@ -3544,7 +3451,7 @@ public function theAdministratorHasExpiredTheLastCreatedPublicLinkShare():void {
* @throws GuzzleException
*/
public function theAdministratorExpiresTheLastCreatedShare():void {
$this->expireShare();
$this->setResponse($this->expireShare());
}

/**
Expand All @@ -3554,7 +3461,7 @@ public function theAdministratorExpiresTheLastCreatedShare():void {
* @throws GuzzleException
*/
public function theAdministratorExpiresTheLastCreatedPublicLinkShare():void {
$this->expireLastCreatedPublicLinkShare();
$this->setResponse($this->expireLastCreatedPublicLinkShare());
}

/**
Expand Down