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] removing the setresponse in given/when/then step in ocs and webdavlocking context #7347

Merged
merged 5 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
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
76 changes: 43 additions & 33 deletions tests/acceptance/features/bootstrap/OCSContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -140,7 +142,7 @@ public function userSendsHTTPMethodToOcsApiEndpointWithBody(
$user = null;
$password = null;
}
$response = OcsApiHelper::sendRequest(
return OcsApiHelper::sendRequest(
$this->featureContext->getBaseUrl(),
$user,
$password,
Expand All @@ -151,23 +153,22 @@ public function userSendsHTTPMethodToOcsApiEndpointWithBody(
$this->featureContext->getOcsApiVersion(),
$headers
);
$this->featureContext->setResponse($response);
}

/**
* @param string $verb
* @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,
Expand All @@ -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,
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -399,11 +401,12 @@ public function theAdministratorSendsHttpMethodToOcsApiEndpointWithBody(
string $url,
?TableNode $body
):void {
$this->adminSendsHttpMethodToOcsApiEndpointWithBody(
$response = $this->adminSendsHttpMethodToOcsApiEndpointWithBody(
$verb,
$url,
$body
);
$this->featureContext->setResponse($response);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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 === "") {
Expand Down Expand Up @@ -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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/acceptance/features/bootstrap/ShareesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Loading