removing usage of a stepdefination inside another stepdefination in OCSContext.php (#9013)
This commit is contained in:
@@ -50,19 +50,6 @@ class OCSContext implements Context {
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^the user has sent HTTP method "([^"]*)" to OCS API endpoint "([^"]*)"$/
|
||||
*
|
||||
* @param string $verb
|
||||
* @param string $url
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theUserHasSentToOcsApiEndpoint(string $verb, string $url):void {
|
||||
$response = $this->theUserSendsToOcsApiEndpointWithBody($verb, $url);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^user "([^"]*)" sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)"$/
|
||||
* @When /^user "([^"]*)" sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" using password "([^"]*)"$/
|
||||
@@ -75,7 +62,7 @@ class OCSContext implements Context {
|
||||
* @return void
|
||||
*/
|
||||
public function userSendsToOcsApiEndpoint(string $user, string $verb, string $url, ?string $password = null):void {
|
||||
$response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$response = $this->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
$verb,
|
||||
$url,
|
||||
@@ -85,27 +72,6 @@ class OCSContext implements Context {
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^user "([^"]*)" has sent HTTP method "([^"]*)" to API endpoint "([^"]*)"$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $verb
|
||||
* @param string $url
|
||||
* @param string|null $password
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function userHasSentToOcsApiEndpoint(string $user, string $verb, string $url, ?string $password = null):void {
|
||||
$response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$user,
|
||||
$verb,
|
||||
$url,
|
||||
null,
|
||||
$password
|
||||
);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $user
|
||||
* @param string $verb
|
||||
@@ -116,7 +82,7 @@ class OCSContext implements Context {
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
public function sendRequestToOcsEndpoint(
|
||||
string $user,
|
||||
string $verb,
|
||||
string $url,
|
||||
@@ -168,7 +134,7 @@ class OCSContext implements Context {
|
||||
?TableNode $body
|
||||
):ResponseInterface {
|
||||
$admin = $this->featureContext->getAdminUsername();
|
||||
return $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
return $this->sendRequestToOcsEndpoint(
|
||||
$admin,
|
||||
$verb,
|
||||
$url,
|
||||
@@ -184,7 +150,7 @@ class OCSContext implements Context {
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function theUserSendsToOcsApiEndpointWithBody(string $verb, string $url, ?TableNode $body = null):ResponseInterface {
|
||||
return $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
return $this->sendRequestToOcsEndpoint(
|
||||
$this->featureContext->getCurrentUser(),
|
||||
$verb,
|
||||
$url,
|
||||
@@ -210,7 +176,7 @@ class OCSContext implements Context {
|
||||
?TableNode $body = null,
|
||||
?string $password = null
|
||||
):void {
|
||||
$response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$response = $this->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
$verb,
|
||||
$url,
|
||||
@@ -220,34 +186,6 @@ class OCSContext implements Context {
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^user "([^"]*)" has sent HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with body$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $verb
|
||||
* @param string $url
|
||||
* @param TableNode|null $body
|
||||
* @param string|null $password
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function userHasSentHTTPMethodToOcsApiEndpointWithBody(
|
||||
string $user,
|
||||
string $verb,
|
||||
string $url,
|
||||
?TableNode $body = null,
|
||||
?string $password = null
|
||||
):void {
|
||||
$response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$user,
|
||||
$verb,
|
||||
$url,
|
||||
$body,
|
||||
$password
|
||||
);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the administrator sends HTTP method :verb to OCS API endpoint :url
|
||||
* @When the administrator sends HTTP method :verb to OCS API endpoint :url using password :password
|
||||
@@ -263,8 +201,15 @@ class OCSContext implements Context {
|
||||
string $url,
|
||||
?string $password = null
|
||||
):void {
|
||||
$admin = $this->featureContext->getAdminUsername();
|
||||
$this->userSendsToOcsApiEndpoint($admin, $verb, $url, $password);
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendRequestToOcsEndpoint(
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$verb,
|
||||
$url,
|
||||
null,
|
||||
$password
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,12 +231,15 @@ class OCSContext implements Context {
|
||||
):void {
|
||||
$user = $this->featureContext->getActualUsername($user);
|
||||
$password = $this->featureContext->getPasswordForUser($user);
|
||||
$this->userSendsToOcsApiEndpointWithHeadersAndPassword(
|
||||
$user,
|
||||
$verb,
|
||||
$url,
|
||||
$password,
|
||||
$headersTable
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
$verb,
|
||||
$url,
|
||||
null,
|
||||
$password,
|
||||
$headersTable->getRowsHash()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -310,57 +258,20 @@ class OCSContext implements Context {
|
||||
string $url,
|
||||
TableNode $headersTable
|
||||
):void {
|
||||
$this->userSendsToOcsApiEndpointWithHeaders(
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$verb,
|
||||
$url,
|
||||
$headersTable
|
||||
$user = $this->featureContext->getAdminUsername();
|
||||
$password = $this->featureContext->getPasswordForUser($user);
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
$verb,
|
||||
$url,
|
||||
null,
|
||||
$password,
|
||||
$headersTable->getRowsHash()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^user "([^"]*)" sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with headers using password "([^"]*)"$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $verb
|
||||
* @param string $url
|
||||
* @param string $password
|
||||
* @param TableNode $headersTable
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function userSendsToOcsApiEndpointWithHeadersAndPassword(
|
||||
string $user,
|
||||
string $verb,
|
||||
string $url,
|
||||
string $password,
|
||||
TableNode $headersTable
|
||||
):void {
|
||||
$this->featureContext->verifyTableNodeColumns(
|
||||
$headersTable,
|
||||
['header', 'value']
|
||||
);
|
||||
$user = $this->featureContext->getActualUsername($user);
|
||||
$headers = [];
|
||||
foreach ($headersTable as $row) {
|
||||
$headers[$row['header']] = $row ['value'];
|
||||
}
|
||||
|
||||
$response = OcsApiHelper::sendRequest(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$password,
|
||||
$verb,
|
||||
$url,
|
||||
$this->featureContext->getStepLineRef(),
|
||||
[],
|
||||
$this->featureContext->getOcsApiVersion(),
|
||||
$headers
|
||||
);
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^the administrator sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with headers using password "([^"]*)"$/
|
||||
*
|
||||
@@ -378,12 +289,15 @@ class OCSContext implements Context {
|
||||
string $password,
|
||||
TableNode $headersTable
|
||||
):void {
|
||||
$this->userSendsToOcsApiEndpointWithHeadersAndPassword(
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$verb,
|
||||
$url,
|
||||
$password,
|
||||
$headersTable
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendRequestToOcsEndpoint(
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$verb,
|
||||
$url,
|
||||
null,
|
||||
$password,
|
||||
$headersTable->getRowsHash()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -409,28 +323,6 @@ class OCSContext implements Context {
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given the administrator has sent HTTP method :verb to OCS API endpoint :url with body
|
||||
*
|
||||
* @param string $verb
|
||||
* @param string $url
|
||||
* @param TableNode|null $body
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theAdministratorHasSentHttpMethodToOcsApiEndpointWithBody(
|
||||
string $verb,
|
||||
string $url,
|
||||
?TableNode $body
|
||||
):void {
|
||||
$response = $this->adminSendsHttpMethodToOcsApiEndpointWithBody(
|
||||
$verb,
|
||||
$url,
|
||||
$body
|
||||
);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^the user sends HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with body$/
|
||||
*
|
||||
@@ -449,24 +341,6 @@ class OCSContext implements Context {
|
||||
$this->featureContext->setResponse($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Given /^the user has sent HTTP method "([^"]*)" to OCS API endpoint "([^"]*)" with body$/
|
||||
*
|
||||
* @param string $verb
|
||||
* @param string $url
|
||||
* @param TableNode $body
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function theUserHasSentHTTPMethodToOcsApiEndpointWithBody(string $verb, string $url, TableNode $body):void {
|
||||
$response = $this->theUserSendsToOcsApiEndpointWithBody(
|
||||
$verb,
|
||||
$url,
|
||||
$body
|
||||
);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBeBetween(200, 299, $response);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When the administrator sends HTTP method :verb to OCS API endpoint :url with body using password :password
|
||||
*
|
||||
@@ -484,7 +358,7 @@ class OCSContext implements Context {
|
||||
TableNode $body
|
||||
):void {
|
||||
$admin = $this->featureContext->getAdminUsername();
|
||||
$response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$response = $this->sendRequestToOcsEndpoint(
|
||||
$admin,
|
||||
$verb,
|
||||
$url,
|
||||
@@ -512,7 +386,7 @@ class OCSContext implements Context {
|
||||
string $password,
|
||||
TableNode $body
|
||||
):void {
|
||||
$response = $this->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$response = $this->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
$verb,
|
||||
$url,
|
||||
@@ -571,9 +445,17 @@ class OCSContext implements Context {
|
||||
* @throws Exception
|
||||
*/
|
||||
public function theOcsStatusCodeShouldBeOr(string $statusCode1, string $statusCode2):void {
|
||||
$this->theOCSStatusCodeShouldBe(
|
||||
$statusCode1 . "," . $statusCode2
|
||||
$statusCodes = [$statusCode1,$statusCode1];
|
||||
$response = $this->featureContext->getResponse();
|
||||
$responseStatusCode = $this->getOCSResponseStatusCode(
|
||||
$response
|
||||
);
|
||||
Assert::assertContainsEquals(
|
||||
$responseStatusCode,
|
||||
$statusCodes,
|
||||
"OCS status code is not any of the expected values " . \implode(",", $statusCodes) . " got " . $responseStatusCode
|
||||
);
|
||||
$this->featureContext->emptyLastOCSStatusCodesArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -748,7 +748,7 @@ trait Provisioning {
|
||||
);
|
||||
$this->emptyLastHTTPStatusCodesArray();
|
||||
$this->emptyLastOCSStatusCodesArray();
|
||||
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$this->ocsContext->sendRequestToOcsEndpoint(
|
||||
$this->getAdminUsername(),
|
||||
"POST",
|
||||
"/cloud/users",
|
||||
@@ -817,7 +817,7 @@ trait Provisioning {
|
||||
public function userTriesToResetUserPasswordUsingTheProvisioningApi(?string $user, ?string $username, ?string $password):void {
|
||||
$password = $this->getActualPassword($password);
|
||||
$bodyTable = new TableNode([['key', 'password'], ['value', $password]]);
|
||||
$this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$this->ocsContext->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
"PUT",
|
||||
"/cloud/users/$username",
|
||||
|
||||
@@ -72,7 +72,7 @@ class ShareesContext implements Context {
|
||||
$url .= '?' . \implode('&', $parameters);
|
||||
}
|
||||
|
||||
$response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$response = $this->ocsContext->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
'GET',
|
||||
$url
|
||||
|
||||
@@ -1696,7 +1696,7 @@ trait Sharing {
|
||||
}
|
||||
}
|
||||
$url = $this->getSharesEndpointPath("/$shareId");
|
||||
return $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
return $this->ocsContext->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
"DELETE",
|
||||
$url
|
||||
@@ -1899,7 +1899,7 @@ trait Sharing {
|
||||
if ($language !== null) {
|
||||
$headers['Accept-Language'] = $language;
|
||||
}
|
||||
return $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
return $this->ocsContext->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
"GET",
|
||||
$url,
|
||||
@@ -1919,7 +1919,7 @@ trait Sharing {
|
||||
public function userGetsAllTheSharesSharedWithHimUsingTheSharingApi(string $user):void {
|
||||
$user = $this->getActualUsername($user);
|
||||
$url = "/apps/files_sharing/api/v1/shares?shared_with_me=true";
|
||||
$response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$response = $this->ocsContext->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
'GET',
|
||||
$url
|
||||
@@ -1966,7 +1966,7 @@ trait Sharing {
|
||||
} else {
|
||||
$rawShareTypes = SharingHelper::SHARE_TYPES[$shareType];
|
||||
}
|
||||
$response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$response = $this->ocsContext->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
'GET',
|
||||
$this->getSharesEndpointPath(
|
||||
@@ -1988,7 +1988,7 @@ trait Sharing {
|
||||
$user = $this->getActualUsername($user);
|
||||
$url = "/apps/files_sharing/api/"
|
||||
. "v$this->sharingApiVersion/shares?shared_with_me=true&path=$path";
|
||||
$response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$response = $this->ocsContext->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
'GET',
|
||||
$url
|
||||
@@ -2765,7 +2765,7 @@ trait Sharing {
|
||||
$user = $this->getActualUsername($user);
|
||||
$share_id = $this->getPublicShareIDByName($user, $path, $name);
|
||||
$url = $this->getSharesEndpointPath("/$share_id");
|
||||
return $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
return $this->ocsContext->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
"DELETE",
|
||||
$url
|
||||
@@ -2871,7 +2871,7 @@ trait Sharing {
|
||||
$httpRequestMethod = "POST";
|
||||
}
|
||||
|
||||
$response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$response = $this->ocsContext->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
$httpRequestMethod,
|
||||
$url
|
||||
@@ -2930,7 +2930,7 @@ trait Sharing {
|
||||
$httpRequestMethod = "POST";
|
||||
}
|
||||
|
||||
$response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$response = $this->ocsContext->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
$httpRequestMethod,
|
||||
$url
|
||||
@@ -3123,7 +3123,7 @@ trait Sharing {
|
||||
__METHOD__ . " could not find share, offered by $sharer to $sharee"
|
||||
);
|
||||
|
||||
$response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$response = $this->ocsContext->sendRequestToOcsEndpoint(
|
||||
$sharer,
|
||||
'DELETE',
|
||||
'/apps/files_sharing/api/v' . $this->sharingApiVersion . '/shares/' . $shareId
|
||||
@@ -3198,7 +3198,7 @@ trait Sharing {
|
||||
);
|
||||
}
|
||||
$url = $this->getSharesEndpointPath("?format=json&shared_with_me=true&state=$stateCode");
|
||||
$response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$response = $this->ocsContext->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
"GET",
|
||||
$url
|
||||
|
||||
@@ -2456,7 +2456,13 @@ class SpacesContext implements Context {
|
||||
$response
|
||||
);
|
||||
$expectedOCSStatus = "200";
|
||||
$this->ocsContext->theOCSStatusCodeShouldBe($expectedOCSStatus, "Expected OCS response status code $expectedOCSStatus", $response);
|
||||
Assert::assertEquals(
|
||||
$expectedOCSStatus,
|
||||
$this->ocsContext->getOCSResponseStatusCode(
|
||||
$response
|
||||
),
|
||||
"Expected OCS response status code $expectedOCSStatus"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3431,7 +3437,7 @@ class SpacesContext implements Context {
|
||||
|
||||
$url = "/apps/files_sharing/api/v1/shares?reshares=true&space_ref=" . $body;
|
||||
|
||||
$response = $this->ocsContext->userSendsHTTPMethodToOcsApiEndpointWithBody(
|
||||
$response = $this->ocsContext->sendRequestToOcsEndpoint(
|
||||
$user,
|
||||
'GET',
|
||||
$url,
|
||||
@@ -4011,6 +4017,14 @@ class SpacesContext implements Context {
|
||||
$resource_id
|
||||
);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(200, "", $response);
|
||||
$this->ocsContext->theOCSStatusCodeShouldBe("100,200", "", $response);
|
||||
$responseStatusCode = $this->ocsContext->getOCSResponseStatusCode(
|
||||
$response
|
||||
);
|
||||
$statusCodes = ["100", "200"];
|
||||
Assert::assertContainsEquals(
|
||||
$responseStatusCode,
|
||||
$statusCodes,
|
||||
"OCS status code is not any of the expected values " . \implode(",", $statusCodes) . " got " . $responseStatusCode
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user