[tests-only] removing the setresponse in given/when/then step in ocs and webdavlocking context (#7347)

* refactor given and when steps in ocs and webdav locking context

* use the returned response

* use of returned response from helper function

* made changes to the affected test steps

* deleted vardump line
This commit is contained in:
Karun Atreya
2023-10-02 17:00:04 +05:45
committed by GitHub
parent eb1aa4502e
commit 87f1235562
5 changed files with 213 additions and 138 deletions
@@ -46,7 +46,8 @@ class OCSContext implements Context {
* @return void * @return void
*/ */
public function theUserSendsToOcsApiEndpoint(string $verb, string $url):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 @@ class OCSContext implements Context {
* @return void * @return void
*/ */
public function theUserHasSentToOcsApiEndpoint(string $verb, string $url):void { public function theUserHasSentToOcsApiEndpoint(string $verb, string $url):void {
$this->theUserSendsToOcsApiEndpointWithBody($verb, $url); $response = $this->theUserSendsToOcsApiEndpointWithBody($verb, $url);
$this->featureContext->theHTTPStatusCodeShouldBeSuccess(); $this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
} }
/** /**
@@ -74,13 +75,14 @@ class OCSContext implements Context {
* @return void * @return void
*/ */
public function userSendsToOcsApiEndpoint(string $user, string $verb, string $url, ?string $password = null):void { public function userSendsToOcsApiEndpoint(string $user, string $verb, string $url, ?string $password = null):void {
$this->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
$verb, $verb,
$url, $url,
null, null,
$password $password
); );
$this->featureContext->setResponse($response);
} }
/** /**
@@ -94,14 +96,14 @@ class OCSContext implements Context {
* @return void * @return void
*/ */
public function userHasSentToOcsApiEndpoint(string $user, string $verb, string $url, ?string $password = null):void { public function userHasSentToOcsApiEndpoint(string $user, string $verb, string $url, ?string $password = null):void {
$this->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
$verb, $verb,
$url, $url,
null, null,
$password $password
); );
$this->featureContext->theHTTPStatusCodeShouldBeSuccess(); $this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
} }
/** /**
@@ -112,7 +114,7 @@ class OCSContext implements Context {
* @param string|null $password * @param string|null $password
* @param array|null $headers * @param array|null $headers
* *
* @return void * @return ResponseInterface
*/ */
public function userSendsHTTPMethodToOcsApiEndpointWithBody( public function userSendsHTTPMethodToOcsApiEndpointWithBody(
string $user, string $user,
@@ -121,7 +123,7 @@ class OCSContext implements Context {
?TableNode $body = null, ?TableNode $body = null,
?string $password = null, ?string $password = null,
?array $headers = null ?array $headers = null
):void { ):ResponseInterface {
/** /**
* array of the data to be sent in the body. * array of the data to be sent in the body.
* contains $body data converted to an array * contains $body data converted to an array
@@ -140,7 +142,7 @@ class OCSContext implements Context {
$user = null; $user = null;
$password = null; $password = null;
} }
$response = OcsApiHelper::sendRequest( return OcsApiHelper::sendRequest(
$this->featureContext->getBaseUrl(), $this->featureContext->getBaseUrl(),
$user, $user,
$password, $password,
@@ -151,7 +153,6 @@ class OCSContext implements Context {
$this->featureContext->getOcsApiVersion(), $this->featureContext->getOcsApiVersion(),
$headers $headers
); );
$this->featureContext->setResponse($response);
} }
/** /**
@@ -159,15 +160,15 @@ class OCSContext implements Context {
* @param string $url * @param string $url
* @param TableNode|null $body * @param TableNode|null $body
* *
* @return void * @return ResponseInterface
*/ */
public function adminSendsHttpMethodToOcsApiEndpointWithBody( public function adminSendsHttpMethodToOcsApiEndpointWithBody(
string $verb, string $verb,
string $url, string $url,
?TableNode $body ?TableNode $body
):void { ):ResponseInterface {
$admin = $this->featureContext->getAdminUsername(); $admin = $this->featureContext->getAdminUsername();
$this->userSendsHTTPMethodToOcsApiEndpointWithBody( return $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
$admin, $admin,
$verb, $verb,
$url, $url,
@@ -180,10 +181,10 @@ class OCSContext implements Context {
* @param string $url * @param string $url
* @param TableNode|null $body * @param TableNode|null $body
* *
* @return void * @return ResponseInterface
*/ */
public function theUserSendsToOcsApiEndpointWithBody(string $verb, string $url, ?TableNode $body = null):void { public function theUserSendsToOcsApiEndpointWithBody(string $verb, string $url, ?TableNode $body = null):ResponseInterface {
$this->userSendsHTTPMethodToOcsApiEndpointWithBody( return $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
$this->featureContext->getCurrentUser(), $this->featureContext->getCurrentUser(),
$verb, $verb,
$url, $url,
@@ -209,13 +210,14 @@ class OCSContext implements Context {
?TableNode $body = null, ?TableNode $body = null,
?string $password = null ?string $password = null
):void { ):void {
$this->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
$verb, $verb,
$url, $url,
$body, $body,
$password $password
); );
$this->featureContext->setResponse($response);
} }
/** /**
@@ -236,14 +238,14 @@ class OCSContext implements Context {
?TableNode $body = null, ?TableNode $body = null,
?string $password = null ?string $password = null
):void { ):void {
$this->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
$verb, $verb,
$url, $url,
$body, $body,
$password $password
); );
$this->featureContext->theHTTPStatusCodeShouldBeSuccess(); $this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
} }
/** /**
@@ -399,11 +401,12 @@ class OCSContext implements Context {
string $url, string $url,
?TableNode $body ?TableNode $body
):void { ):void {
$this->adminSendsHttpMethodToOcsApiEndpointWithBody( $response = $this->adminSendsHttpMethodToOcsApiEndpointWithBody(
$verb, $verb,
$url, $url,
$body $body
); );
$this->featureContext->setResponse($response);
} }
/** /**
@@ -420,12 +423,12 @@ class OCSContext implements Context {
string $url, string $url,
?TableNode $body ?TableNode $body
):void { ):void {
$this->adminSendsHttpMethodToOcsApiEndpointWithBody( $response = $this->adminSendsHttpMethodToOcsApiEndpointWithBody(
$verb, $verb,
$url, $url,
$body $body
); );
$this->featureContext->theHTTPStatusCodeShouldBeSuccess(); $this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
} }
/** /**
@@ -438,11 +441,12 @@ class OCSContext implements Context {
* @return void * @return void
*/ */
public function theUserSendsHTTPMethodToOcsApiEndpointWithBody(string $verb, string $url, TableNode $body):void { public function theUserSendsHTTPMethodToOcsApiEndpointWithBody(string $verb, string $url, TableNode $body):void {
$this->theUserSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->theUserSendsToOcsApiEndpointWithBody(
$verb, $verb,
$url, $url,
$body $body
); );
$this->featureContext->setResponse($response);
} }
/** /**
@@ -455,12 +459,12 @@ class OCSContext implements Context {
* @return void * @return void
*/ */
public function theUserHasSentHTTPMethodToOcsApiEndpointWithBody(string $verb, string $url, TableNode $body):void { public function theUserHasSentHTTPMethodToOcsApiEndpointWithBody(string $verb, string $url, TableNode $body):void {
$this->theUserSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->theUserSendsToOcsApiEndpointWithBody(
$verb, $verb,
$url, $url,
$body $body
); );
$this->featureContext->theHTTPStatusCodeShouldBeSuccess(); $this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
} }
/** /**
@@ -480,13 +484,14 @@ class OCSContext implements Context {
TableNode $body TableNode $body
):void { ):void {
$admin = $this->featureContext->getAdminUsername(); $admin = $this->featureContext->getAdminUsername();
$this->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
$admin, $admin,
$verb, $verb,
$url, $url,
$body, $body,
$password $password
); );
$this->featureContext->setResponse($response);
} }
/** /**
@@ -507,13 +512,14 @@ class OCSContext implements Context {
string $password, string $password,
TableNode $body TableNode $body
):void { ):void {
$this->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
$verb, $verb,
$url, $url,
$body, $body,
$password $password
); );
$this->featureContext->setResponse($response);
} }
/** /**
@@ -781,14 +787,16 @@ class OCSContext implements Context {
* *
* @param string $statusCode * @param string $statusCode
* @param string $message * @param string $message
* @param ResponseInterface|null $response
* *
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
public function theOCSStatusCodeShouldBe(string $statusCode, string $message = ""):void { public function theOCSStatusCodeShouldBe(string $statusCode, string $message = "", ?ResponseInterface $response = null):void {
$statusCodes = explode(",", $statusCode); $statusCodes = explode(",", $statusCode);
$response = $response ?? $this->featureContext->getResponse();
$responseStatusCode = $this->getOCSResponseStatusCode( $responseStatusCode = $this->getOCSResponseStatusCode(
$this->featureContext->getResponse() $response
); );
if (\is_array($statusCodes)) { if (\is_array($statusCodes)) {
if ($message === "") { if ($message === "") {
@@ -994,16 +1002,18 @@ class OCSContext implements Context {
* this function is aware of the currently used OCS version * this function is aware of the currently used OCS version
* *
* @param string|null $message * @param string|null $message
* @param ResponseInterface|null $response
* *
* @return void * @return void
* @throws Exception * @throws Exception
*/ */
public function assertOCSResponseIndicatesSuccess(?string $message = ""):void { public function assertOCSResponseIndicatesSuccess(?string $message = "", ?ResponseInterface $response = null):void {
$this->featureContext->theHTTPStatusCodeShouldBe('200', $message); $response = $response ?? $this->featureContext->getResponse();
$this->featureContext->theHTTPStatusCodeShouldBe('200', $message, $response);
if ($this->featureContext->getOcsApiVersion() === 1) { if ($this->featureContext->getOcsApiVersion() === 1) {
$this->theOCSStatusCodeShouldBe('100', $message); $this->theOCSStatusCodeShouldBe('100', $message, $response);
} else { } else {
$this->theOCSStatusCodeShouldBe('200', $message); $this->theOCSStatusCodeShouldBe('200', $message, $response);
} }
} }
@@ -72,11 +72,12 @@ class ShareesContext implements Context {
$url .= '?' . \implode('&', $parameters); $url .= '?' . \implode('&', $parameters);
} }
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
'GET', 'GET',
$url $url
); );
$this->featureContext->setResponse($response);
} }
/** /**
+56 -45
View File
@@ -1846,7 +1846,7 @@ trait Sharing {
* @return void * @return void
*/ */
public function theUserDeletesLastShareUsingTheSharingAPI():void { public function theUserDeletesLastShareUsingTheSharingAPI():void {
$this->deleteLastShareUsingSharingApiByCurrentUser(); $this->setResponse($this->deleteLastShareUsingSharingApiByCurrentUser());
} }
/** /**
@@ -1855,8 +1855,8 @@ trait Sharing {
* @return void * @return void
*/ */
public function theUserHasDeletedLastShareUsingTheSharingAPI():void { public function theUserHasDeletedLastShareUsingTheSharingAPI():void {
$this->deleteLastShareUsingSharingApiByCurrentUser(); $response = $this->deleteLastShareUsingSharingApiByCurrentUser();
$this->theHTTPStatusCodeShouldBeSuccess(); $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
} }
/** /**
@@ -1864,9 +1864,9 @@ trait Sharing {
* @param string|null $sharer the specific user whose share will be deleted (if specified) * @param string|null $sharer the specific user whose share will be deleted (if specified)
* @param bool $deleteLastPublicLink * @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); $user = $this->getActualUsername($user);
if ($deleteLastPublicLink) { if ($deleteLastPublicLink) {
$shareId = (string) $this->getLastCreatedPublicShare()->id; $shareId = (string) $this->getLastCreatedPublicShare()->id;
@@ -1878,7 +1878,7 @@ trait Sharing {
} }
} }
$url = $this->getSharesEndpointPath("/$shareId"); $url = $this->getSharesEndpointPath("/$shareId");
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( return $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
"DELETE", "DELETE",
$url $url
@@ -1886,10 +1886,10 @@ trait Sharing {
} }
/** /**
* @return void * @return ResponseInterface
*/ */
public function deleteLastShareUsingSharingApiByCurrentUser():void { public function deleteLastShareUsingSharingApiByCurrentUser():ResponseInterface {
$this->deleteLastShareUsingSharingApi($this->currentUser); return $this->deleteLastShareUsingSharingApi($this->currentUser);
} }
/** /**
@@ -1901,7 +1901,7 @@ trait Sharing {
* @return void * @return void
*/ */
public function userDeletesLastShareUsingTheSharingApi(string $user):void { public function userDeletesLastShareUsingTheSharingApi(string $user):void {
$this->deleteLastShareUsingSharingApi($user); $this->setResponse($this->deleteLastShareUsingSharingApi($user));
$this->pushToLastStatusCodesArrays(); $this->pushToLastStatusCodesArrays();
} }
@@ -1914,7 +1914,7 @@ trait Sharing {
* @return void * @return void
*/ */
public function userDeletesLastPublicLinkShareUsingTheSharingApi(string $user):void { public function userDeletesLastPublicLinkShareUsingTheSharingApi(string $user):void {
$this->deleteLastShareUsingSharingApi($user, null, true); $this->setResponse($this->deleteLastShareUsingSharingApi($user, null, true));
$this->pushToLastStatusCodesArrays(); $this->pushToLastStatusCodesArrays();
} }
@@ -1928,7 +1928,7 @@ trait Sharing {
* @return void * @return void
*/ */
public function userDeletesLastShareOfUserUsingTheSharingApi(string $user, string $sharer):void { public function userDeletesLastShareOfUserUsingTheSharingApi(string $user, string $sharer):void {
$this->deleteLastShareUsingSharingApi($user, $sharer); $this->setResponse($this->deleteLastShareUsingSharingApi($user, $sharer));
$this->pushToLastStatusCodesArrays(); $this->pushToLastStatusCodesArrays();
} }
@@ -1940,8 +1940,8 @@ trait Sharing {
* @return void * @return void
*/ */
public function userHasDeletedLastShareUsingTheSharingApi(string $user):void { public function userHasDeletedLastShareUsingTheSharingApi(string $user):void {
$this->deleteLastShareUsingSharingApi($user); $response = $this->deleteLastShareUsingSharingApi($user);
$this->theHTTPStatusCodeShouldBeSuccess(); $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
} }
/** /**
@@ -1967,7 +1967,7 @@ trait Sharing {
public function userGetsInfoOfLastShareUsingTheSharingApi(string $user, ?string $language = null):void { public function userGetsInfoOfLastShareUsingTheSharingApi(string $user, ?string $language = null):void {
$shareId = $this->getLastCreatedUserGroupShareId(); $shareId = $this->getLastCreatedUserGroupShareId();
$language = TranslationHelper::getLanguage($language); $language = TranslationHelper::getLanguage($language);
$this->getShareData($user, $shareId, $language); $this->setResponse($this->getShareData($user, $shareId, $language));
$this->pushToLastStatusCodesArrays(); $this->pushToLastStatusCodesArrays();
} }
@@ -2000,7 +2000,7 @@ trait Sharing {
); );
} }
$language = TranslationHelper::getLanguage($language); $language = TranslationHelper::getLanguage($language);
$this->getShareData($user, $shareId, $language); $this->setResponse($this->getShareData($user, $shareId, $language));
$this->pushToLastStatusCodesArrays(); $this->pushToLastStatusCodesArrays();
} }
@@ -2073,16 +2073,16 @@ trait Sharing {
* @param string $share_id * @param string $share_id
* @param string|null $language * @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); $user = $this->getActualUsername($user);
$url = $this->getSharesEndpointPath("/$share_id"); $url = $this->getSharesEndpointPath("/$share_id");
$headers = []; $headers = [];
if ($language !== null) { if ($language !== null) {
$headers['Accept-Language'] = $language; $headers['Accept-Language'] = $language;
} }
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( return $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
"GET", "GET",
$url, $url,
@@ -2102,11 +2102,12 @@ trait Sharing {
public function userGetsAllTheSharesSharedWithHimUsingTheSharingApi(string $user):void { public function userGetsAllTheSharesSharedWithHimUsingTheSharingApi(string $user):void {
$user = $this->getActualUsername($user); $user = $this->getActualUsername($user);
$url = "/apps/files_sharing/api/v1/shares?shared_with_me=true"; $url = "/apps/files_sharing/api/v1/shares?shared_with_me=true";
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
'GET', 'GET',
$url $url
); );
$this->setResponse($response);
} }
/** /**
@@ -2120,8 +2121,8 @@ trait Sharing {
public function userGetsTheLastShareSharedWithHimUsingTheSharingApi(string $user, TableNode $table):void { public function userGetsTheLastShareSharedWithHimUsingTheSharingApi(string $user, TableNode $table):void {
$user = $this->getActualUsername($user); $user = $this->getActualUsername($user);
$shareId = (string) $this->getLastCreatedPublicShare()->id; $shareId = (string) $this->getLastCreatedPublicShare()->id;
$this->getShareData($user, $shareId); $response = $this->getShareData($user, $shareId);
$this->checkFields($user, $table); $this->checkFields($user, $table, $response);
} }
/** /**
@@ -2148,13 +2149,14 @@ trait Sharing {
} else { } else {
$rawShareTypes = SharingHelper::SHARE_TYPES[$shareType]; $rawShareTypes = SharingHelper::SHARE_TYPES[$shareType];
} }
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
'GET', 'GET',
$this->getSharesEndpointPath( $this->getSharesEndpointPath(
"?shared_with_me=true" . $pendingClause . "&share_types=" . $rawShareTypes "?shared_with_me=true" . $pendingClause . "&share_types=" . $rawShareTypes
) )
); );
$this->setResponse($response);
} }
/** /**
@@ -2169,11 +2171,12 @@ trait Sharing {
$user = $this->getActualUsername($user); $user = $this->getActualUsername($user);
$url = "/apps/files_sharing/api/" $url = "/apps/files_sharing/api/"
. "v$this->sharingApiVersion/shares?shared_with_me=true&path=$path"; . "v$this->sharingApiVersion/shares?shared_with_me=true&path=$path";
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
'GET', 'GET',
$url $url
); );
$this->setResponse($response);
} }
/** /**
@@ -2295,19 +2298,21 @@ trait Sharing {
):void { ):void {
$user = $this->getActualUsername($user); $user = $this->getActualUsername($user);
$this->verifyTableNodeRows($body, [], $this->shareResponseFields); $this->verifyTableNodeRows($body, [], $this->shareResponseFields);
$this->getShareData($user, $this->getLastCreatedUserGroupShareId()); $response = $this->getShareData($user, $this->getLastCreatedUserGroupShareId());
$this->theHTTPStatusCodeShouldBe( $this->theHTTPStatusCodeShouldBe(
200, 200,
"Error getting info of last share for user $user" "Error getting info of last share for user $user",
$response
); );
$this->ocsContext->assertOCSResponseIndicatesSuccess( $this->ocsContext->assertOCSResponseIndicatesSuccess(
__METHOD__ . __METHOD__ .
' Error getting info of last share for user $user\n' . ' Error getting info of last share for user $user\n' .
$this->ocsContext->getOCSResponseStatusMessage( $this->ocsContext->getOCSResponseStatusMessage(
$this->getResponse() $response
) . '"' ) . '"',
$response
); );
$this->checkFields($user, $body); $this->checkFields($user, $body, $response);
} }
/** /**
@@ -2543,11 +2548,14 @@ trait Sharing {
* *
* @param string $user * @param string $user
* @param TableNode|null $body * @param TableNode|null $body
* @param ResponseInterface|null $response
* *
* @return void * @return void
* @throws Exception * @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); $this->verifyTableNodeColumnsCount($body, 2);
$bodyRows = $body->getRowsHash(); $bodyRows = $body->getRowsHash();
$userRelatedFieldNames = [ $userRelatedFieldNames = [
@@ -2568,8 +2576,8 @@ trait Sharing {
$value = $this->getActualUsername($value); $value = $this->getActualUsername($value);
$value = $this->replaceValuesFromTable($field, $value); $value = $this->replaceValuesFromTable($field, $value);
Assert::assertTrue( Assert::assertTrue(
$this->isFieldInResponse($field, $value), $this->isFieldInResponse($field, $value, true, $data),
"$field doesn't have value '$value'" "$field doesn't have value '$value'",
); );
} }
} }
@@ -3022,17 +3030,17 @@ trait Sharing {
* @param string $name * @param string $name
* @param string $path * @param string $path
* *
* @return void * @return ResponseInterface
*/ */
public function deletePublicLinkShareUsingTheSharingApi( public function deletePublicLinkShareUsingTheSharingApi(
string $user, string $user,
string $name, string $name,
string $path string $path
):void { ):ResponseInterface {
$user = $this->getActualUsername($user); $user = $this->getActualUsername($user);
$share_id = $this->getPublicShareIDByName($user, $path, $name); $share_id = $this->getPublicShareIDByName($user, $path, $name);
$url = $this->getSharesEndpointPath("/$share_id"); $url = $this->getSharesEndpointPath("/$share_id");
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( return $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
"DELETE", "DELETE",
$url $url
@@ -3053,11 +3061,12 @@ trait Sharing {
string $name, string $name,
string $path string $path
):void { ):void {
$this->deletePublicLinkShareUsingTheSharingApi( $response = $this->deletePublicLinkShareUsingTheSharingApi(
$user, $user,
$name, $name,
$path $path
); );
$this->setResponse($response);
} }
/** /**
@@ -3074,12 +3083,12 @@ trait Sharing {
string $name, string $name,
string $path string $path
):void { ):void {
$this->deletePublicLinkShareUsingTheSharingApi( $response = $this->deletePublicLinkShareUsingTheSharingApi(
$user, $user,
$name, $name,
$path $path
); );
$this->theHTTPStatusCodeShouldBeSuccess(); $this->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
} }
/** /**
@@ -3137,11 +3146,12 @@ trait Sharing {
$httpRequestMethod = "POST"; $httpRequestMethod = "POST";
} }
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
$httpRequestMethod, $httpRequestMethod,
$url $url
); );
$this->setResponse($response);
$this->pushToLastStatusCodesArrays(); $this->pushToLastStatusCodesArrays();
} }
@@ -3195,11 +3205,12 @@ trait Sharing {
$httpRequestMethod = "POST"; $httpRequestMethod = "POST";
} }
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
$httpRequestMethod, $httpRequestMethod,
$url $url
); );
$this->setResponse($response);
} }
/** /**
@@ -3387,11 +3398,12 @@ trait Sharing {
__METHOD__ . " could not find share, offered by $sharer to $sharee" __METHOD__ . " could not find share, offered by $sharer to $sharee"
); );
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$sharer, $sharer,
'DELETE', 'DELETE',
'/apps/files_sharing/api/v' . $this->sharingApiVersion . '/shares/' . $shareId '/apps/files_sharing/api/v' . $this->sharingApiVersion . '/shares/' . $shareId
); );
$this->setResponse($response);
} }
/** /**
@@ -3460,19 +3472,18 @@ trait Sharing {
__METHOD__ . ' invalid "state" given' __METHOD__ . ' invalid "state" given'
); );
} }
$url = $this->getSharesEndpointPath("?format=json&shared_with_me=true&state=$stateCode"); $url = $this->getSharesEndpointPath("?format=json&shared_with_me=true&state=$stateCode");
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
"GET", "GET",
$url $url
); );
if ($this->response->getStatusCode() !== 200) { if ($response->getStatusCode() !== 200) {
throw new Exception( throw new Exception(
__METHOD__ . " could not retrieve information about shares" __METHOD__ . " could not retrieve information about shares"
); );
} }
$result = $this->response->getBody()->getContents(); $result = $response->getBody()->getContents();
$usersShares = \json_decode($result, true); $usersShares = \json_decode($result, true);
if (!\is_array($usersShares)) { if (!\is_array($usersShares)) {
throw new Exception( throw new Exception(
@@ -2970,14 +2970,14 @@ class SpacesContext implements Context {
$url = "/apps/files_sharing/api/v1/shares?reshares=true&space_ref=" . $body; $url = "/apps/files_sharing/api/v1/shares?reshares=true&space_ref=" . $body;
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody( $response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
$user, $user,
'GET', 'GET',
$url, $url,
); );
$should = ($shouldOrNot !== "not"); $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) { if ($should) {
Assert::assertNotEmpty($responseArray, __METHOD__ . ' Response should contain a link, but it is empty'); Assert::assertNotEmpty($responseArray, __METHOD__ . ' Response should contain a link, but it is empty');
@@ -29,6 +29,7 @@ use PHPUnit\Framework\Assert;
use TestHelpers\HttpRequestHelper; use TestHelpers\HttpRequestHelper;
use TestHelpers\OcsApiHelper; use TestHelpers\OcsApiHelper;
use TestHelpers\WebDavHelper; use TestHelpers\WebDavHelper;
use Psr\Http\Message\ResponseInterface;
require_once 'bootstrap.php'; require_once 'bootstrap.php';
@@ -61,7 +62,7 @@ class WebDavLockingContext implements Context {
TableNode $properties, TableNode $properties,
bool $public = false, bool $public = false,
bool $expectToSucceed = true bool $expectToSucceed = true
) { ):ResponseInterface {
$user = $this->featureContext->getActualUsername($user); $user = $this->featureContext->getActualUsername($user);
$baseUrl = $this->featureContext->getBaseUrl(); $baseUrl = $this->featureContext->getBaseUrl();
if ($public === true) { if ($public === true) {
@@ -99,10 +100,7 @@ class WebDavLockingContext implements Context {
$this->featureContext->getDavPathVersion(), $this->featureContext->getDavPathVersion(),
$type $type
); );
$responseXml = $this->featureContext->getResponseXml($response, __METHOD__);
$this->featureContext->setResponse($response);
$responseXml = $this->featureContext->getResponseXml(null, __METHOD__);
$this->featureContext->setResponseXmlObject($responseXml);
$xmlPart = $responseXml->xpath("//d:locktoken/d:href"); $xmlPart = $responseXml->xpath("//d:locktoken/d:href");
if (isset($xmlPart[0])) { if (isset($xmlPart[0])) {
$this->tokenOfLastLock[$user][$file] = (string) $xmlPart[0]; $this->tokenOfLastLock[$user][$file] = (string) $xmlPart[0];
@@ -111,6 +109,7 @@ class WebDavLockingContext implements Context {
Assert::fail("could not find lock token after trying to lock '$file'"); Assert::fail("could not find lock token after trying to lock '$file'");
} }
} }
return $response;
} }
/** /**
@@ -123,7 +122,8 @@ class WebDavLockingContext implements Context {
* @return void * @return void
*/ */
public function lockFileUsingWebDavAPI(string $user, string $file, TableNode $properties) { 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 @@ class WebDavLockingContext implements Context {
* @return void * @return void
*/ */
public function userHasLockedFile(string $user, string $file, TableNode $properties) { 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 @@ class WebDavLockingContext implements Context {
* @return void * @return void
*/ */
public function publicHasLockedLastSharedFile(TableNode $properties) { public function publicHasLockedLastSharedFile(TableNode $properties) {
$this->lockFile( $response = $this->lockFile(
$this->featureContext->getLastCreatedPublicShareToken(), $this->featureContext->getLastCreatedPublicShareToken(),
"/", "/",
$properties, $properties,
true true
); );
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
} }
/** /**
@@ -163,13 +165,14 @@ class WebDavLockingContext implements Context {
* @return void * @return void
*/ */
public function publicLocksLastSharedFile(TableNode $properties) { public function publicLocksLastSharedFile(TableNode $properties) {
$this->lockFile( $response = $this->lockFile(
$this->featureContext->getLastCreatedPublicShareToken(), $this->featureContext->getLastCreatedPublicShareToken(),
"/", "/",
$properties, $properties,
true, true,
false false
); );
$this->featureContext->setResponse($response);
} }
/** /**
@@ -184,12 +187,13 @@ class WebDavLockingContext implements Context {
string $file, string $file,
TableNode $properties TableNode $properties
) { ) {
$this->lockFile( $response = $this->lockFile(
$this->featureContext->getLastCreatedPublicShareToken(), $this->featureContext->getLastCreatedPublicShareToken(),
$file, $file,
$properties, $properties,
true true
); );
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $response);
} }
/** /**
@@ -206,13 +210,14 @@ class WebDavLockingContext implements Context {
string $publicWebDAVAPIVersion, string $publicWebDAVAPIVersion,
TableNode $properties TableNode $properties
) { ) {
$this->lockFile( $response = $this->lockFile(
$this->featureContext->getLastCreatedPublicShareToken(), $this->featureContext->getLastCreatedPublicShareToken(),
$file, $file,
$properties, $properties,
true, true,
false false
); );
$this->featureContext->setResponse($response);
} }
/** /**
@@ -224,12 +229,13 @@ class WebDavLockingContext implements Context {
* @return void * @return void
*/ */
public function unlockLastLockUsingWebDavAPI(string $user, string $file) { public function unlockLastLockUsingWebDavAPI(string $user, string $file) {
$this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( $response = $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI(
$user, $user,
$file, $file,
$user, $user,
$file $file
); );
$this->featureContext->setResponse($response);
} }
/** /**
@@ -246,12 +252,13 @@ class WebDavLockingContext implements Context {
string $itemToUnlock, string $itemToUnlock,
string $itemToUseLockOf string $itemToUseLockOf
) { ) {
$this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( $response = $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI(
$user, $user,
$itemToUnlock, $itemToUnlock,
$user, $user,
$itemToUseLockOf $itemToUseLockOf
); );
$this->featureContext->setResponse($response);
} }
/** /**
@@ -269,12 +276,13 @@ class WebDavLockingContext implements Context {
string $itemToUseLockOf string $itemToUseLockOf
) { ) {
$lockOwner = $this->featureContext->getLastCreatedPublicShareToken(); $lockOwner = $this->featureContext->getLastCreatedPublicShareToken();
$this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( $response = $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI(
$user, $user,
$itemToUnlock, $itemToUnlock,
$lockOwner, $lockOwner,
$itemToUseLockOf $itemToUseLockOf
); );
$this->featureContext->setResponse($response);
} }
/** /**
@@ -339,28 +347,26 @@ class WebDavLockingContext implements Context {
) { ) {
$lockCount = $this->countLockOfResources($user, $itemToUnlock); $lockCount = $this->countLockOfResources($user, $itemToUnlock);
$this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( $response = $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI(
$user, $user,
$itemToUnlock, $itemToUnlock,
$lockOwner, $lockOwner,
$itemToUseLockOf, $itemToUseLockOf,
$public $public
); );
$this->featureContext->theHTTPStatusCodeShouldBe(204); $this->featureContext->theHTTPStatusCodeShouldBe(204, "", $response);
$this->numberOfLockShouldBeReported($lockCount - 1, $itemToUnlock, $user); $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 $user
* @param string $itemToUnlock * @param string $itemToUnlock
* @param string $lockOwner * @param string $lockOwner
* @param string $itemToUseLockOf * @param string $itemToUseLockOf
* @param boolean $public * @param boolean $public
* *
* @return void * @return ResponseInterface
*/ */
public function unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( public function unlockItemWithLastLockOfUserAndItemUsingWebDavAPI(
string $user, string $user,
@@ -368,7 +374,7 @@ class WebDavLockingContext implements Context {
string $lockOwner, string $lockOwner,
string $itemToUseLockOf, string $itemToUseLockOf,
bool $public = false bool $public = false
) { ):ResponseInterface {
$user = $this->featureContext->getActualUsername($user); $user = $this->featureContext->getActualUsername($user);
$lockOwner = $this->featureContext->getActualUsername($lockOwner); $lockOwner = $this->featureContext->getActualUsername($lockOwner);
if ($public === true) { if ($public === true) {
@@ -388,21 +394,43 @@ class WebDavLockingContext implements Context {
$headers = [ $headers = [
"Lock-Token" => $this->tokenOfLastLock[$lockOwner][$itemToUseLockOf] "Lock-Token" => $this->tokenOfLastLock[$lockOwner][$itemToUseLockOf]
]; ];
$this->featureContext->setResponse( return WebDavHelper::makeDavRequest(
WebDavHelper::makeDavRequest( $baseUrl,
$baseUrl, $user,
$user, $password,
$password, "UNLOCK",
"UNLOCK", $itemToUnlock,
$itemToUnlock, $headers,
$headers, $this->featureContext->getStepLineRef(),
$this->featureContext->getStepLineRef(), null,
null, $this->featureContext->getDavPathVersion(),
$this->featureContext->getDavPathVersion(), $type
$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 @@ class WebDavLockingContext implements Context {
string $itemToUseLockOf string $itemToUseLockOf
) { ) {
$user = $this->featureContext->getLastCreatedPublicShareToken(); $user = $this->featureContext->getLastCreatedPublicShareToken();
$this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( $response = $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI(
$user, $user,
$itemToUnlock, $itemToUnlock,
$lockOwner, $lockOwner,
$itemToUseLockOf, $itemToUseLockOf,
true true
); );
$this->featureContext->setResponse($response);
} }
/** /**
@@ -438,13 +467,14 @@ class WebDavLockingContext implements Context {
*/ */
public function unlockItemAsPublicUsingWebDavAPI(string $itemToUnlock) { public function unlockItemAsPublicUsingWebDavAPI(string $itemToUnlock) {
$user = $this->featureContext->getLastCreatedPublicShareToken(); $user = $this->featureContext->getLastCreatedPublicShareToken();
$this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI( $response = $this->unlockItemWithLastLockOfUserAndItemUsingWebDavAPI(
$user, $user,
$itemToUnlock, $itemToUnlock,
$user, $user,
$itemToUnlock, $itemToUnlock,
true true
); );
$this->featureContext->setResponse($response);
} }
/** /**
@@ -463,13 +493,49 @@ class WebDavLockingContext implements Context {
string $fileDestination, string $fileDestination,
string $itemToUseLockOf string $itemToUseLockOf
) { ) {
$this->moveItemSendingLockTokenOfUser( $response = $this->moveItemSendingLockTokenOfUser(
$user, $user,
$fileSource, $fileSource,
$fileDestination, $fileDestination,
$itemToUseLockOf, $itemToUseLockOf,
$user $user
); );
$this->featureContext->setResponse($response);
}
/**
* @param string $user
* @param string $fileSource
* @param string $fileDestination
* @param string $itemToUseLockOf
* @param string $lockOwner
*
* @return ResponseInterface
*/
public function moveItemSendingLockTokenOfUser(
string $user,
string $fileSource,
string $fileDestination,
string $itemToUseLockOf,
string $lockOwner
):ResponseInterface {
$user = $this->featureContext->getActualUsername($user);
$lockOwner = $this->featureContext->getActualUsername($lockOwner);
$destination = $this->featureContext->destinationHeaderValue(
$user,
$fileDestination
);
$token = $this->tokenOfLastLock[$lockOwner][$itemToUseLockOf];
$headers = [
"Destination" => $destination,
"If" => "(<$token>)"
];
return $this->featureContext->makeDavRequest(
$user,
"MOVE",
$fileSource,
$headers
);
} }
/** /**
@@ -483,34 +549,21 @@ class WebDavLockingContext implements Context {
* *
* @return void * @return void
*/ */
public function moveItemSendingLockTokenOfUser( public function userMovesItemSendingLockTokenOfUser(
string $user, string $user,
string $fileSource, string $fileSource,
string $fileDestination, string $fileDestination,
string $itemToUseLockOf, string $itemToUseLockOf,
string $lockOwner string $lockOwner
) { ) {
$user = $this->featureContext->getActualUsername($user); $response = $this->moveItemSendingLockTokenOfUser(
$lockOwner = $this->featureContext->getActualUsername($lockOwner);
$destination = $this->featureContext->destinationHeaderValue(
$user, $user,
$fileDestination $fileSource,
$fileDestination,
$itemToUseLockOf,
$lockOwner
); );
$token = $this->tokenOfLastLock[$lockOwner][$itemToUseLockOf]; $this->featureContext->setResponse($response);
$headers = [
"Destination" => $destination,
"If" => "(<$token>)"
];
try {
$response = $this->featureContext->makeDavRequest(
$user,
"MOVE",
$fileSource,
$headers
);
$this->featureContext->setResponse($response);
} catch (ConnectException $e) {
}
} }
/** /**