[tests-only] ApiTest. Share space via link (#4241)
* add test share space via link * Bump core commit
This commit is contained in:
@@ -125,6 +125,11 @@ class SpacesContext implements Context {
|
||||
*/
|
||||
private array $availableSpaces;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private array $lastPublicLinkData = [];
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -502,6 +507,7 @@ class SpacesContext implements Context {
|
||||
* @param string $password
|
||||
* @param string $xRequestId
|
||||
* @param array $headers
|
||||
* @param mixed $body
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
@@ -512,9 +518,10 @@ class SpacesContext implements Context {
|
||||
string $user,
|
||||
string $password,
|
||||
string $xRequestId = '',
|
||||
array $headers = []
|
||||
array $headers = [],
|
||||
$body = null
|
||||
): ResponseInterface {
|
||||
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'PROPFIND', $user, $password, $headers);
|
||||
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'PROPFIND', $user, $password, $headers, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -542,6 +549,57 @@ class SpacesContext implements Context {
|
||||
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, 'PUT', $user, $password, $headers, $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send POST Request to url
|
||||
*
|
||||
* @param string $fullUrl
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param mixed $body
|
||||
* @param string $xRequestId
|
||||
* @param array $headers
|
||||
*
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function sendPostRequestToUrl(
|
||||
string $fullUrl,
|
||||
string $user,
|
||||
string $password,
|
||||
$body,
|
||||
string $xRequestId = '',
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
return HttpRequestHelper::post($fullUrl, $xRequestId, $user, $password, $headers, $body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Graph Create Folder Request
|
||||
*
|
||||
* @param string $fullUrl
|
||||
* @param string $method
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $xRequestId
|
||||
* @param array $headers
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function sendCreateFolderRequest(
|
||||
string $fullUrl,
|
||||
string $method,
|
||||
string $user,
|
||||
string $password,
|
||||
string $xRequestId = '',
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, $method, $user, $password, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^user "([^"]*)" lists all available spaces via the GraphApi$/
|
||||
* @When /^user "([^"]*)" lists all available spaces via the GraphApi with query "([^"]*)"$/
|
||||
@@ -683,13 +741,13 @@ class SpacesContext implements Context {
|
||||
public function theAdministratorGivesUserTheRole(string $user, string $role): void {
|
||||
$admin = $this->featureContext->getAdminUsername();
|
||||
$password = $this->featureContext->getAdminPassword();
|
||||
$headers = [];
|
||||
$bundles = [];
|
||||
$assignment = [];
|
||||
|
||||
// get the roles list first
|
||||
$fullUrl = $this->baseUrl . "/api/v0/settings/roles-list";
|
||||
$this->featureContext->setResponse(HttpRequestHelper::post($fullUrl, "", $admin, $password, $headers, "{}"));
|
||||
$this->featureContext->setResponse($this->sendPostRequestToUrl($fullUrl, $admin, $password, "{}"));
|
||||
|
||||
if ($this->featureContext->getResponse()) {
|
||||
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
|
||||
if (isset(\json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["bundles"])) {
|
||||
@@ -727,7 +785,7 @@ class SpacesContext implements Context {
|
||||
$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));
|
||||
$this->featureContext->setResponse($this->sendPostRequestToUrl($fullUrl, $admin, $password, $body));
|
||||
if ($this->featureContext->getResponse()) {
|
||||
$rawBody = $this->featureContext->getResponse()->getBody()->getContents();
|
||||
if (isset(\json_decode($rawBody, true, 512, JSON_THROW_ON_ERROR)["assignment"])) {
|
||||
@@ -787,8 +845,8 @@ class SpacesContext implements Context {
|
||||
$spaceWebDavUrl . '/' . $foldersPath,
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
"",
|
||||
$headers,
|
||||
'',
|
||||
$headers
|
||||
)
|
||||
);
|
||||
$this->setResponseSpaceId($spaceId);
|
||||
@@ -1410,31 +1468,6 @@ class SpacesContext implements Context {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Graph Create Folder Request
|
||||
*
|
||||
* @param string $fullUrl
|
||||
* @param string $method
|
||||
* @param string $user
|
||||
* @param string $password
|
||||
* @param string $xRequestId
|
||||
* @param array $headers
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function sendCreateFolderRequest(
|
||||
string $fullUrl,
|
||||
string $method,
|
||||
string $user,
|
||||
string $password,
|
||||
string $xRequestId = '',
|
||||
array $headers = []
|
||||
): ResponseInterface {
|
||||
return HttpRequestHelper::sendRequest($fullUrl, $xRequestId, $method, $user, $password, $headers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^user "([^"]*)" changes the name of the "([^"]*)" space to "([^"]*)"$/
|
||||
*
|
||||
@@ -1842,12 +1875,10 @@ class SpacesContext implements Context {
|
||||
$fullUrl = $this->baseUrl . $this->ocsApiUrl;
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::post(
|
||||
$this->sendPostRequestToUrl(
|
||||
$fullUrl,
|
||||
"",
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
[],
|
||||
$body
|
||||
)
|
||||
);
|
||||
@@ -1883,12 +1914,10 @@ class SpacesContext implements Context {
|
||||
$fullUrl = $this->baseUrl . $this->ocsApiUrl;
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::post(
|
||||
$this->sendPostRequestToUrl(
|
||||
$fullUrl,
|
||||
"",
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
[],
|
||||
$body
|
||||
)
|
||||
);
|
||||
@@ -1931,12 +1960,10 @@ class SpacesContext implements Context {
|
||||
$fullUrl = $this->baseUrl . $this->ocsApiUrl;
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::post(
|
||||
$this->sendPostRequestToUrl(
|
||||
$fullUrl,
|
||||
"",
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
[],
|
||||
$body
|
||||
)
|
||||
);
|
||||
@@ -2211,14 +2238,10 @@ class SpacesContext implements Context {
|
||||
$space = $this->getSpaceByName($user, $spaceName);
|
||||
$fullUrl = $this->baseUrl . $this->davSpacesUrl . "trash-bin/" . $space["id"];
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::sendRequest(
|
||||
$this->sendPropfindRequestToUrl(
|
||||
$fullUrl,
|
||||
"",
|
||||
'PROPFIND',
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
[],
|
||||
""
|
||||
$this->featureContext->getPasswordForUser($user)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -2469,14 +2492,10 @@ class SpacesContext implements Context {
|
||||
$fullUrl = $this->baseUrl . '/remote.php/dav/meta/' . $fileId . '/v';
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
HttpRequestHelper::sendRequest(
|
||||
$this->sendPropfindRequestToUrl(
|
||||
$fullUrl,
|
||||
"",
|
||||
'PROPFIND',
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
[],
|
||||
""
|
||||
$this->featureContext->getPasswordForUser($user)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -2499,12 +2518,11 @@ class SpacesContext implements Context {
|
||||
$space = $this->getSpaceByName($user, $space);
|
||||
|
||||
$fullUrl = $space['root']['webDavUrl'] . '/' . ltrim($path, '/');
|
||||
$response = HttpRequestHelper::sendRequest(
|
||||
$response = $this->sendPropfindRequestToUrl(
|
||||
$fullUrl,
|
||||
$this->featureContext->getStepLineRef(),
|
||||
'PROPFIND',
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$this->featureContext->getStepLineRef(),
|
||||
[],
|
||||
$this->etagPropfindBody
|
||||
);
|
||||
@@ -2653,4 +2671,52 @@ class SpacesContext implements Context {
|
||||
throw new Exception("Expected stored etag to be some string but found null!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @When /^user "([^"]*)" creates a public link share of the space "([^"]*)" with settings:$/
|
||||
*
|
||||
* @param string $user
|
||||
* @param string $spaceName
|
||||
* @param TableNode|null $table
|
||||
*
|
||||
* @return void
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function sendShareSpaceViaLinkRequest(
|
||||
string $user,
|
||||
string $spaceName,
|
||||
?TableNode $table
|
||||
): void {
|
||||
$space = $this->getSpaceByName($user, $spaceName);
|
||||
$rows = $table->getRowsHash();
|
||||
|
||||
$rows["shareType"] = \array_key_exists("shareType", $rows) ? $rows["shareType"] : 3;
|
||||
$rows["permissions"] = \array_key_exists("permissions", $rows) ? $rows["permissions"] : null;
|
||||
$rows["password"] = \array_key_exists("password", $rows) ? $rows["password"] : null;
|
||||
$rows["name"] = \array_key_exists("name", $rows) ? $rows["name"] : null;
|
||||
$rows["expireDate"] = \array_key_exists("expireDate", $rows) ? $rows["expireDate"] : null;
|
||||
|
||||
$body = [
|
||||
"space_ref" => $space['id'],
|
||||
"shareType" => $rows["shareType"],
|
||||
"permissions" => $rows["permissions"],
|
||||
"password" => $rows["password"],
|
||||
"name" => $rows["name"],
|
||||
"expireDate" => $rows["expireDate"]
|
||||
];
|
||||
|
||||
$fullUrl = $this->baseUrl . $this->ocsApiUrl;
|
||||
|
||||
$this->featureContext->setResponse(
|
||||
$this->sendPostRequestToUrl(
|
||||
$fullUrl,
|
||||
$user,
|
||||
$this->featureContext->getPasswordForUser($user),
|
||||
$body
|
||||
)
|
||||
);
|
||||
|
||||
// set last response as PublicShareData. using method from core
|
||||
$this->featureContext->setLastPublicShareData($this->featureContext->getResponseXml(null, __METHOD__));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user