mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-24 05:48:36 -05:00
Merge pull request #2911 from owncloud/refactor-spaces-tests-20211222
[tests-only] Refactor SpacesContext
This commit is contained in:
@@ -46,6 +46,11 @@ class SpacesContext implements Context {
|
||||
*/
|
||||
private OCSContext $ocsContext;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private string $baseUrl;
|
||||
|
||||
/**
|
||||
* @var array key is space name and value is the username that created the space
|
||||
*/
|
||||
@@ -217,10 +222,11 @@ class SpacesContext implements Context {
|
||||
$this->ocsContext = $environment->getContext('OCSContext');
|
||||
// Run the BeforeScenario function in OCSContext to set it up correctly
|
||||
$this->ocsContext->before($scope);
|
||||
$this->baseUrl = \trim($this->featureContext->getBaseUrl(), "/");
|
||||
SetupHelper::init(
|
||||
$this->featureContext->getAdminUsername(),
|
||||
$this->featureContext->getAdminPassword(),
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$this->baseUrl,
|
||||
$this->featureContext->getOcPath()
|
||||
);
|
||||
}
|
||||
@@ -228,7 +234,6 @@ class SpacesContext implements Context {
|
||||
/**
|
||||
* Send Graph List Spaces Request
|
||||
*
|
||||
* @param string $baseUrl
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $urlArguments
|
||||
@@ -241,19 +246,14 @@ class SpacesContext implements Context {
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function listSpacesRequest(
|
||||
string $baseUrl,
|
||||
string $user,
|
||||
string $password,
|
||||
string $urlArguments,
|
||||
string $urlArguments = '',
|
||||
string $xRequestId = '',
|
||||
array $body = [],
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
$fullUrl = $baseUrl;
|
||||
if (!str_ends_with($fullUrl, '/')) {
|
||||
$fullUrl .= '/';
|
||||
}
|
||||
$fullUrl .= "graph/v1.0/me/drives/" . $urlArguments;
|
||||
$fullUrl = $this->baseUrl . "/graph/v1.0/me/drives/" . $urlArguments;
|
||||
|
||||
return HttpRequestHelper::get($fullUrl, $xRequestId, $user, $password, $headers, $body);
|
||||
}
|
||||
@@ -261,7 +261,6 @@ class SpacesContext implements Context {
|
||||
/**
|
||||
* Send Graph Create Space Request
|
||||
*
|
||||
* @param string $baseUrl
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $body
|
||||
@@ -273,18 +272,13 @@ class SpacesContext implements Context {
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function sendCreateSpaceRequest(
|
||||
string $baseUrl,
|
||||
string $user,
|
||||
string $password,
|
||||
string $body,
|
||||
string $xRequestId = '',
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
$fullUrl = $baseUrl;
|
||||
if (!str_ends_with($fullUrl, '/')) {
|
||||
$fullUrl .= '/';
|
||||
}
|
||||
$fullUrl .= "graph/v1.0/drives/";
|
||||
$fullUrl = $this->baseUrl . "/graph/v1.0/drives/";
|
||||
|
||||
return HttpRequestHelper::post($fullUrl, $xRequestId, $user, $password, $headers, $body);
|
||||
}
|
||||
@@ -349,11 +343,8 @@ class SpacesContext implements Context {
|
||||
public function theUserListsAllHisAvailableSpacesUsingTheGraphApi(string $user): void {
|
||||
$this->featureContext->setResponse(
|
||||
$this->listSpacesRequest(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
"",
|
||||
""
|
||||
$this->featureContext->getPasswordForUser($user)
|
||||
)
|
||||
);
|
||||
$this->rememberTheAvailableSpaces();
|
||||
@@ -380,11 +371,9 @@ class SpacesContext implements Context {
|
||||
$body = json_encode($space, JSON_THROW_ON_ERROR);
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendCreateSpaceRequest(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body,
|
||||
""
|
||||
$body
|
||||
)
|
||||
);
|
||||
$this->setSpaceCreator($spaceName, $user);
|
||||
@@ -413,11 +402,9 @@ class SpacesContext implements Context {
|
||||
$body = json_encode($space);
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendCreateSpaceRequest(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body,
|
||||
""
|
||||
$body
|
||||
)
|
||||
);
|
||||
$this->setSpaceCreator($spaceName, $user);
|
||||
@@ -442,12 +429,8 @@ class SpacesContext implements Context {
|
||||
$accounts = [];
|
||||
$assignment = [];
|
||||
|
||||
$baseUrl = $this->featureContext->getBaseUrl();
|
||||
if (!str_ends_with($baseUrl, '/')) {
|
||||
$baseUrl .= '/';
|
||||
}
|
||||
// get the roles list first
|
||||
$fullUrl = $baseUrl . "api/v0/settings/roles-list";
|
||||
$fullUrl = $this->baseUrl . "/api/v0/settings/roles-list";
|
||||
$this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, "{}"));
|
||||
if ($this->featureContext->getResponse()) {
|
||||
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
|
||||
@@ -465,7 +448,7 @@ class SpacesContext implements Context {
|
||||
Assert::assertNotEmpty($roleToAssign, "The selected role $role could not be found");
|
||||
|
||||
// get the accounts list first
|
||||
$fullUrl = $baseUrl . "api/v0/accounts/accounts-list";
|
||||
$fullUrl = $this->baseUrl . "/api/v0/accounts/accounts-list";
|
||||
$this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, "{}"));
|
||||
if ($this->featureContext->getResponse()) {
|
||||
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
|
||||
@@ -483,7 +466,7 @@ class SpacesContext implements Context {
|
||||
Assert::assertNotEmpty($accountToChange, "The selected account $user does not exist");
|
||||
|
||||
// set the new role
|
||||
$fullUrl = $baseUrl . "api/v0/settings/assignments-add";
|
||||
$fullUrl = $this->baseUrl . "/api/v0/settings/assignments-add";
|
||||
$body = json_encode(["account_uuid" => $accountToChange["id"], "role_id" => $roleToAssign["id"]], JSON_THROW_ON_ERROR);
|
||||
|
||||
$this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, $body));
|
||||
@@ -874,11 +857,7 @@ class SpacesContext implements Context {
|
||||
|
||||
$space = $this->getSpaceByName($ownerUser, $spaceName);
|
||||
|
||||
$baseUrl = $this->featureContext->getBaseUrl();
|
||||
if (!str_ends_with($baseUrl, '/')) {
|
||||
$baseUrl .= '/';
|
||||
}
|
||||
$fullUrl = $baseUrl . "dav/spaces/" . $space['id'] . '/' . $folder;
|
||||
$fullUrl = $this->baseUrl . "/dav/spaces/" . $space['id'] . '/' . $folder;
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendCreateFolderRequest(
|
||||
@@ -1009,7 +988,6 @@ class SpacesContext implements Context {
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendUpdateSpaceRequest(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body,
|
||||
@@ -1042,7 +1020,6 @@ class SpacesContext implements Context {
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendUpdateSpaceRequest(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body,
|
||||
@@ -1054,7 +1031,6 @@ class SpacesContext implements Context {
|
||||
/**
|
||||
* Send Graph Update Space Request
|
||||
*
|
||||
* @param string $baseUrl
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param mixed $body
|
||||
@@ -1067,7 +1043,6 @@ class SpacesContext implements Context {
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function sendUpdateSpaceRequest(
|
||||
string $baseUrl,
|
||||
string $user,
|
||||
string $password,
|
||||
$body,
|
||||
@@ -1075,11 +1050,7 @@ class SpacesContext implements Context {
|
||||
string $xRequestId = '',
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
$fullUrl = $baseUrl;
|
||||
if (!str_ends_with($fullUrl, '/')) {
|
||||
$fullUrl .= '/';
|
||||
}
|
||||
$fullUrl .= "graph/v1.0/drives/$spaceId";
|
||||
$fullUrl = $this->baseUrl . "/graph/v1.0/drives/$spaceId";
|
||||
$method = 'PATCH';
|
||||
|
||||
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, $method, $user, $password, $headers, $body);
|
||||
@@ -1105,11 +1076,9 @@ class SpacesContext implements Context {
|
||||
$body = json_encode($space);
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendCreateSpaceRequest(
|
||||
$this->featureContext->getBaseUrl(),
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body,
|
||||
""
|
||||
$body
|
||||
)
|
||||
);
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(
|
||||
@@ -1172,11 +1141,7 @@ class SpacesContext implements Context {
|
||||
$space = $this->getSpaceByName($user, $spaceName);
|
||||
$body = ["space_ref" => $space['id'], "shareType" => 7, "shareWith" => $userRecipient];
|
||||
|
||||
$baseUrl = $this->featureContext->getBaseUrl();
|
||||
if (!str_ends_with($baseUrl, '/')) {
|
||||
$baseUrl .= '/';
|
||||
}
|
||||
$fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares";
|
||||
$fullUrl = $this->baseUrl . "/ocs/v2.php/apps/files_sharing/api/v1/shares";
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::post(
|
||||
@@ -1205,27 +1170,9 @@ class SpacesContext implements Context {
|
||||
string $spaceName,
|
||||
string $userRecipient
|
||||
): void {
|
||||
$space = $this->getSpaceByName($user, $spaceName);
|
||||
$body = ["space_ref" => $space['id'], "shareType" => 7, "shareWith" => $userRecipient];
|
||||
$this->sendShareSpaceRequest($user, $spaceName, $userRecipient);
|
||||
|
||||
$baseUrl = $this->featureContext->getBaseUrl();
|
||||
if (!str_ends_with($baseUrl, '/')) {
|
||||
$baseUrl .= '/';
|
||||
}
|
||||
$fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares";
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::post(
|
||||
$fullUrl,
|
||||
"",
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
[],
|
||||
$body
|
||||
)
|
||||
);
|
||||
|
||||
$expectedHTTPStatus = "200";
|
||||
$expectedHTTPStatus = "200";
|
||||
$this->featureContext->theHTTPStatusCodeShouldBe(
|
||||
$expectedHTTPStatus,
|
||||
"Expected response status code should be $expectedHTTPStatus"
|
||||
@@ -1250,11 +1197,7 @@ class SpacesContext implements Context {
|
||||
string $userRecipient
|
||||
): void {
|
||||
$space = $this->getSpaceByName($user, $spaceName);
|
||||
$baseUrl = $this->featureContext->getBaseUrl();
|
||||
if (!str_ends_with($baseUrl, '/')) {
|
||||
$baseUrl .= '/';
|
||||
}
|
||||
$fullUrl = $baseUrl . "ocs/v2.php/apps/files_sharing/api/v1/shares/" . $space['id'] . "?shareWith=" . $userRecipient;
|
||||
$fullUrl = $this->baseUrl . "/ocs/v2.php/apps/files_sharing/api/v1/shares/" . $space['id'] . "?shareWith=" . $userRecipient;
|
||||
|
||||
HttpRequestHelper::delete($fullUrl, "", $user, $this->featureContext->getPasswordForUser($user));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user