mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-06 04:09:40 -06:00
[tests-only][full-ci] removing the setresponse in given/then step in AppConfigurationContext and AuthContext (#7186)
* removing setting response in the given steps * use response interface * use the returned response * check success response * changed to inline variable * changed variable response_xml to responseXml
This commit is contained in:
@@ -29,6 +29,7 @@ use TestHelpers\AppConfigHelper;
|
||||
use TestHelpers\OcsApiHelper;
|
||||
use Behat\Gherkin\Node\TableNode;
|
||||
use Behat\Behat\Context\Context;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* AppConfiguration trait
|
||||
@@ -110,7 +111,7 @@ class AppConfigurationContext implements Context {
|
||||
*/
|
||||
public function userRetrievesCapabilities(string $username): void {
|
||||
$user = $this->featureContext->getActualUsername($username);
|
||||
$this->userGetsCapabilities($user, true);
|
||||
$this->featureContext->setResponse($this->userGetsCapabilities($user, true));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,24 +119,22 @@ class AppConfigurationContext implements Context {
|
||||
* @param string $username
|
||||
* @param boolean $formatJson // if true then formats the response in json
|
||||
*
|
||||
* @return void
|
||||
* @return ResponseInterface
|
||||
* @throws GuzzleException
|
||||
* @throws JsonException
|
||||
*/
|
||||
public function userGetsCapabilities(string $username, ?bool $formatJson = false):void {
|
||||
public function userGetsCapabilities(string $username, ?bool $formatJson = false):ResponseInterface {
|
||||
$user = $this->featureContext->getActualUsername($username);
|
||||
$password = $this->featureContext->getPasswordForUser($user);
|
||||
$this->featureContext->setResponse(
|
||||
OcsApiHelper::sendRequest(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$password,
|
||||
'GET',
|
||||
'/cloud/capabilities' . ($formatJson ? '?format=json' : ''),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
[],
|
||||
$this->featureContext->getOcsApiVersion()
|
||||
)
|
||||
return OcsApiHelper::sendRequest(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$password,
|
||||
'GET',
|
||||
'/cloud/capabilities' . ($formatJson ? '?format=json' : ''),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
[],
|
||||
$this->featureContext->getOcsApiVersion()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -148,14 +147,7 @@ class AppConfigurationContext implements Context {
|
||||
* @throws Exception
|
||||
*/
|
||||
public function userGetsCapabilitiesCheckResponse(string $username):void {
|
||||
$this->userGetsCapabilities($username);
|
||||
$statusCode = $this->featureContext->getResponse()->getStatusCode();
|
||||
if ($statusCode !== 200) {
|
||||
throw new \Exception(
|
||||
__METHOD__
|
||||
. " user $username returned unexpected status $statusCode"
|
||||
);
|
||||
}
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(200, '', $this->userGetsCapabilities($username));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,7 +156,7 @@ class AppConfigurationContext implements Context {
|
||||
* @return void
|
||||
*/
|
||||
public function theUserGetsCapabilities():void {
|
||||
$this->userGetsCapabilities($this->featureContext->getCurrentUser());
|
||||
$this->featureContext->setResponse($this->userGetsCapabilities($this->featureContext->getCurrentUser()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -205,7 +197,7 @@ class AppConfigurationContext implements Context {
|
||||
*/
|
||||
public function theAdministratorGetsCapabilities():void {
|
||||
$user = $this->getAdminUsernameForCapabilitiesCheck();
|
||||
$this->userGetsCapabilities($user, true);
|
||||
$this->featureContext->setResponse($this->userGetsCapabilities($user, true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,7 @@ use TestHelpers\HttpRequestHelper;
|
||||
use Behat\Gherkin\Node\TableNode;
|
||||
use Behat\Behat\Context\Context;
|
||||
use TestHelpers\SetupHelper;
|
||||
use \Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
* Authentication functions
|
||||
@@ -98,7 +99,7 @@ class AuthContext implements Context {
|
||||
* @return void
|
||||
*/
|
||||
public function userRequestsURLWith(string $url, string $method):void {
|
||||
$this->sendRequest($url, $method);
|
||||
$this->featureContext->setResponse($this->sendRequest($url, $method));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,7 +115,7 @@ class AuthContext implements Context {
|
||||
public function userRequestsURLWithNoAuth(string $user, string $url, string $method):void {
|
||||
$userRenamed = $this->featureContext->getActualUsername($user);
|
||||
$url = $this->featureContext->substituteInLineCodes($url, $userRenamed);
|
||||
$this->sendRequest($url, $method);
|
||||
$this->featureContext->setResponse($this->sendRequest($url, $method));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,8 +127,7 @@ class AuthContext implements Context {
|
||||
* @return void
|
||||
*/
|
||||
public function userHasRequestedURLWith(string $url, string $method):void {
|
||||
$this->sendRequest($url, $method);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBeSuccess();
|
||||
$this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $this->sendRequest($url, $method));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,7 +174,7 @@ class AuthContext implements Context {
|
||||
$row['endpoint'],
|
||||
$ofUser
|
||||
);
|
||||
$this->sendRequest($row['endpoint'], $method, null, false, $body);
|
||||
$this->featureContext->setResponse($this->sendRequest($row['endpoint'], $method, null, false, $body));
|
||||
$this->featureContext->pushToLastStatusCodesArrays();
|
||||
}
|
||||
}
|
||||
@@ -212,7 +212,7 @@ class AuthContext implements Context {
|
||||
$this->featureContext->emptyLastOCSStatusCodesArray();
|
||||
$this->featureContext->emptyLastHTTPStatusCodesArray();
|
||||
foreach ($table->getHash() as $row) {
|
||||
$this->sendRequest($row['endpoint'], $method);
|
||||
$this->featureContext->setResponse($this->sendRequest($row['endpoint'], $method));
|
||||
$this->featureContext->pushToLastStatusCodesArrays();
|
||||
}
|
||||
}
|
||||
@@ -578,7 +578,7 @@ class AuthContext implements Context {
|
||||
* @param string|null $body
|
||||
* @param array|null $headers
|
||||
*
|
||||
* @return void
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function sendRequest(
|
||||
string $url,
|
||||
@@ -587,7 +587,7 @@ class AuthContext implements Context {
|
||||
bool $useCookies = false,
|
||||
?string $body = null,
|
||||
?array $headers = []
|
||||
):void {
|
||||
):ResponseInterface {
|
||||
// reset responseXml
|
||||
$this->featureContext->setResponseXml([]);
|
||||
|
||||
@@ -605,18 +605,16 @@ class AuthContext implements Context {
|
||||
if (isset($this->requestToken)) {
|
||||
$headers['requesttoken'] = $this->featureContext->getRequestToken();
|
||||
}
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::sendRequest(
|
||||
$fullUrl,
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$method,
|
||||
null,
|
||||
null,
|
||||
$headers,
|
||||
$body,
|
||||
null,
|
||||
$cookies
|
||||
)
|
||||
return HttpRequestHelper::sendRequest(
|
||||
$fullUrl,
|
||||
$this->featureContext->getStepLineRef(),
|
||||
$method,
|
||||
null,
|
||||
null,
|
||||
$headers,
|
||||
$body,
|
||||
null,
|
||||
$cookies
|
||||
);
|
||||
}
|
||||
|
||||
@@ -781,13 +779,15 @@ class AuthContext implements Context {
|
||||
} else {
|
||||
$authString = $userRenamed . ":" . $this->featureContext->getActualPassword($password);
|
||||
}
|
||||
$this->sendRequest(
|
||||
$url,
|
||||
$method,
|
||||
'basic ' . \base64_encode($authString),
|
||||
false,
|
||||
$body,
|
||||
$header
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendRequest(
|
||||
$url,
|
||||
$method,
|
||||
'basic ' . \base64_encode($authString),
|
||||
false,
|
||||
$body,
|
||||
$header
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -817,13 +817,15 @@ class AuthContext implements Context {
|
||||
foreach ($headersTable as $row) {
|
||||
$headers[$row['header']] = $row ['value'];
|
||||
}
|
||||
$this->sendRequest(
|
||||
$url,
|
||||
$method,
|
||||
'basic ' . \base64_encode($authString),
|
||||
false,
|
||||
null,
|
||||
$headers
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendRequest(
|
||||
$url,
|
||||
$method,
|
||||
'basic ' . \base64_encode($authString),
|
||||
false,
|
||||
null,
|
||||
$headers
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -884,10 +886,12 @@ class AuthContext implements Context {
|
||||
*/
|
||||
public function userRequestsURLWithUsingBasicTokenAuth(string $user, string $url, string $method):void {
|
||||
$user = $this->featureContext->getActualUsername($user);
|
||||
$this->sendRequest(
|
||||
$url,
|
||||
$method,
|
||||
'basic ' . \base64_encode("$user:" . $this->clientToken)
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendRequest(
|
||||
$url,
|
||||
$method,
|
||||
'basic ' . \base64_encode("$user:" . $this->clientToken)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -914,7 +918,7 @@ class AuthContext implements Context {
|
||||
* @return void
|
||||
*/
|
||||
public function userRequestsURLWithUsingAClientToken(string $url, string $method):void {
|
||||
$this->sendRequest($url, $method, 'token ' . $this->clientToken);
|
||||
$this->featureContext->setResponse($this->sendRequest($url, $method, 'token ' . $this->clientToken));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -939,7 +943,7 @@ class AuthContext implements Context {
|
||||
* @return void
|
||||
*/
|
||||
public function userRequestsURLWithUsingAppPassword(string $url, string $method):void {
|
||||
$this->sendRequest($url, $method, 'token ' . $this->appToken);
|
||||
$this->featureContext->setResponse($this->sendRequest($url, $method, 'token ' . $this->appToken));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -952,7 +956,7 @@ class AuthContext implements Context {
|
||||
* @return void
|
||||
*/
|
||||
public function theUserRequestsWithUsingAppPasswordNamed(string $url, string $method, string $tokenName):void {
|
||||
$this->sendRequest($url, $method, 'token ' . $this->appTokens[$tokenName]['token']);
|
||||
$this->featureContext->setResponse($this->sendRequest($url, $method, 'token ' . $this->appTokens[$tokenName]['token']));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -977,7 +981,7 @@ class AuthContext implements Context {
|
||||
* @return void
|
||||
*/
|
||||
public function userRequestsURLWithBrowserSession(string $url, string $method):void {
|
||||
$this->sendRequest($url, $method, null, true);
|
||||
$this->featureContext->setResponse($this->sendRequest($url, $method, null, true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2302,9 +2302,11 @@ class FeatureContext extends BehatVariablesContext {
|
||||
$jsonExpectedDecoded = \json_decode($jsonExpected->getRaw(), true);
|
||||
$jsonRespondedDecoded = $this->getJsonDecodedResponse();
|
||||
|
||||
$this->appConfigurationContext->theAdministratorGetsCapabilitiesCheckResponse();
|
||||
$response = $this->appConfigurationContext->userGetsCapabilities($this->appConfigurationContext->getAdminUsernameForCapabilitiesCheck());
|
||||
$this->theHTTPStatusCodeShouldBe(200, '', $response);
|
||||
$responseXml = $this->getResponseXml($response)->data->capabilities;
|
||||
$edition = $this->appConfigurationContext->getParameterValueFromXml(
|
||||
$this->appConfigurationContext->getCapabilitiesXml(__METHOD__),
|
||||
$responseXml,
|
||||
'core',
|
||||
'status@@@edition'
|
||||
);
|
||||
@@ -2316,7 +2318,7 @@ class FeatureContext extends BehatVariablesContext {
|
||||
}
|
||||
|
||||
$product = $this->appConfigurationContext->getParameterValueFromXml(
|
||||
$this->appConfigurationContext->getCapabilitiesXml(__METHOD__),
|
||||
$responseXml,
|
||||
'core',
|
||||
'status@@@product'
|
||||
);
|
||||
@@ -2327,7 +2329,7 @@ class FeatureContext extends BehatVariablesContext {
|
||||
}
|
||||
|
||||
$productName = $this->appConfigurationContext->getParameterValueFromXml(
|
||||
$this->appConfigurationContext->getCapabilitiesXml(__METHOD__),
|
||||
$responseXml,
|
||||
'core',
|
||||
'status@@@productname'
|
||||
);
|
||||
@@ -2345,7 +2347,7 @@ class FeatureContext extends BehatVariablesContext {
|
||||
// We are on oCIS or reva or some other implementation. We cannot do "occ status".
|
||||
// So get the expected version values by looking in the capabilities response.
|
||||
$version = $this->appConfigurationContext->getParameterValueFromXml(
|
||||
$this->appConfigurationContext->getCapabilitiesXml(__METHOD__),
|
||||
$responseXml,
|
||||
'core',
|
||||
'status@@@version'
|
||||
);
|
||||
@@ -2357,7 +2359,7 @@ class FeatureContext extends BehatVariablesContext {
|
||||
}
|
||||
|
||||
$versionString = $this->appConfigurationContext->getParameterValueFromXml(
|
||||
$this->appConfigurationContext->getCapabilitiesXml(__METHOD__),
|
||||
$responseXml,
|
||||
'core',
|
||||
'status@@@versionstring'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user