[tests-only] ApiTest: set space image/description to space (#3289)

* add tests: set space image/description to space

* php style fix. add checking that file exists
This commit is contained in:
Viktor Scharf
2022-03-10 09:29:26 +01:00
committed by GitHub
parent f0954b2197
commit 3e2d1582a3
2 changed files with 229 additions and 45 deletions
@@ -33,3 +33,44 @@ Feature: Change data of space
| key | value |
| name | Project Earth |
| quota@@@total | 100 |
Scenario: An user set readme file as description of the space via the Graph API
Given user "Alice" has created a space "add special section" with the default quota using the GraphApi
And user "Alice" has created a folder ".space" in space "add special section"
And user "Alice" has uploaded a file inside space "add special section" with content "space description" to ".space/readme.md"
When user "Alice" sets the file ".space/readme.md" as a description in a special section of the "add special section" space
Then the HTTP status code should be "200"
When user "Alice" lists all available spaces via the GraphApi
Then the json responded should contain a space "add special section" owned by "Alice" with description file ".space/readme.md" with these key and value pairs:
| key | value |
| name | add special section |
| special@@@0@@@size | 17 |
| special@@@0@@@name | readme.md |
| special@@@0@@@specialFolder@@@name | readme |
| special@@@0@@@file@@@mimeType | text/markdown |
| special@@@0@@@id | %file_id% |
| special@@@0@@@eTag | %eTag% |
Scenario Outline: An user set image file as space image of the space via the Graph API
Given user "Alice" has created a space "add special section" with the default quota using the GraphApi
And user "Alice" has created a folder ".space" in space "add special section"
And user "Alice" has uploaded a file inside space "add special section" with content "" to "<fileName>"
When user "Alice" sets the file "<fileName>" as a space image in a special section of the "add special section" space
Then the HTTP status code should be "200"
When user "Alice" lists all available spaces via the GraphApi
Then the json responded should contain a space "add special section" owned by "Alice" with description file "<fileName>" with these key and value pairs:
| key | value |
| name | add special section |
| special@@@0@@@size | 0 |
| special@@@0@@@name | <nameInResponse> |
| special@@@0@@@specialFolder@@@name | image |
| special@@@0@@@file@@@mimeType | <mimeType> |
| special@@@0@@@id | %file_id% |
| special@@@0@@@eTag | %eTag% |
Examples:
| fileName | nameInResponse | mimeType |
| .space/spaceImage.jpeg | spaceImage.jpeg | image/jpeg |
| .space/spaceImage.png | spaceImage.png | image/png |
| .space/spaceImage.gif | spaceImage.gif | image/gif |
@@ -205,6 +205,65 @@ class SpacesContext implements Context {
return $spaces[$spaceName];
}
/**
* The method finds file by fileName and spaceName and returns data of file wich contains in responseHeader
* fileName contains the path, if the file is in the folder
*
* @param string $user
* @param string $spaceName
* @param string $fileName
*
* @return array
*/
public function getFileData(string $user, string $spaceName, string $fileName): array {
$space = $this->getSpaceByName($user, $spaceName);
$fullUrl = $this->baseUrl . "/remote.php/dav/spaces/" . $space["id"] . "/" . $fileName;
$this->featureContext->setResponse(
HttpRequestHelper::get(
$fullUrl,
"",
$user,
$this->featureContext->getPasswordForUser($user),
[],
"{}"
)
);
$this->featureContext->theHTTPStatusCodeShouldBe(
200,
"file $fileName not found"
);
return $this->featureContext->getResponse()->getHeaders();
}
/**
* The method returns fileId
*
* @param string $user
* @param string $spaceName
* @param string $fileName
*
* @return string
*/
public function getFileId(string $user, string $spaceName, string $fileName): string {
$fileData = $this->getFileData($user, $spaceName, $fileName);
return $fileData["Oc-Fileid"][0];
}
/**
* The method returns eTag
*
* @param string $user
* @param string $spaceName
* @param string $fileName
*
* @return string
*/
public function getETag(string $user, string $spaceName, string $fileName): string {
$fileData = $this->getFileData($user, $spaceName, $fileName);
return $fileData["Etag"][0];
}
/**
* The method returns userId
*
@@ -213,7 +272,6 @@ class SpacesContext implements Context {
* @return string
*/
public function getUserIdByUserName(string $userName): string {
$fullUrl = $this->baseUrl . "/api/v0/accounts/accounts-list";
$this->featureContext->setResponse(
HttpRequestHelper::post(
@@ -430,7 +488,7 @@ class SpacesContext implements Context {
$this->listMySpacesRequest(
$user,
$this->featureContext->getPasswordForUser($user),
"?". $query
"?" . $query
)
);
}
@@ -755,7 +813,7 @@ class SpacesContext implements Context {
}
/**
* @Then /^the json responded should contain a space "([^"]*)" (?:|(?:owned by|granted to) "([^"]*)" )with these key and value pairs:$/
* @Then /^the json responded should contain a space "([^"]*)" (?:|(?:owned by|granted to) "([^"]*)" )(?:|(?:with description file|with space image) "([^"]*)" )with these key and value pairs:$/
*
* @param string $spaceName
* @param string $userName
@@ -767,6 +825,7 @@ class SpacesContext implements Context {
public function jsonRespondedShouldContain(
string $spaceName,
string $userName = '',
string $fileName = '',
TableNode $table
): void {
$this->featureContext->verifyTableNodeColumns($table, ['key', 'value']);
@@ -791,6 +850,18 @@ class SpacesContext implements Context {
[$this, "getUserIdByUserName"],
"parameter" => [$userName]
],
[
"code" => "%file_id%",
"function" =>
[$this, "getFileId"],
"parameter" => [$userName, $spaceName, $fileName]
],
[
"code" => "%eTag%",
"function" =>
[$this, "getETag"],
"parameter" => [$userName, $spaceName, $fileName]
],
]
);
$segments = explode("@@@", $row["key"]);
@@ -830,10 +901,11 @@ class SpacesContext implements Context {
$userRole = "";
foreach ($permissions as $permission) {
foreach ($permission["grantedTo"] as $grantedTo)
if ($grantedTo["user"]["id"] === $userId) {
$userRole = $permission["roles"][0];
}
foreach ($permission["grantedTo"] as $grantedTo) {
if ($grantedTo["user"]["id"] === $userId) {
$userRole = $permission["roles"][0];
}
}
}
Assert::assertEquals($userRole, $role, "the user $userName with the role $role could not be found");
}
@@ -875,18 +947,18 @@ class SpacesContext implements Context {
)
);
$matches = [];
foreach($spaces["value"] as $space) {
if($onlyOrNot === "not") {
foreach ($spaces["value"] as $space) {
if ($onlyOrNot === "not") {
Assert::assertNotEquals($space["driveType"], $type);
}
if($onlyOrNot === "only") {
if ($onlyOrNot === "only") {
Assert::assertEquals($space["driveType"], $type);
}
if($onlyOrNot === "" && $space["driveType"] === $type) {
if ($onlyOrNot === "" && $space["driveType"] === $type) {
$matches[] = $space;
}
}
if($onlyOrNot === "") {
if ($onlyOrNot === "") {
Assert::assertNotEmpty($matches);
}
}
@@ -1031,7 +1103,7 @@ class SpacesContext implements Context {
): void {
$exploded = explode('/', $folder);
$path = '';
for ($i = 0; $i < count($exploded); $i++) {
for ($i = 0; $i < \count($exploded); $i++) {
$path = $path . $exploded[$i] . '/';
$this->theUserCreatesAFolderToAnotherOwnerSpaceUsingTheGraphApi($user, $path, $spaceName);
};
@@ -1225,36 +1297,36 @@ class SpacesContext implements Context {
}
/**
* @When /^user "([^"]*)" changes the description of the "([^"]*)" space to "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $newName
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function updateSpaceDescription(
string $user,
string $spaceName,
string $newDescription
): void {
$space = $this->getSpaceByName($user, $spaceName);
$spaceId = $space["id"];
* @When /^user "([^"]*)" changes the description of the "([^"]*)" space to "([^"]*)"$/
*
* @param string $user
* @param string $spaceName
* @param string $newName
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function updateSpaceDescription(
string $user,
string $spaceName,
string $newDescription
): void {
$space = $this->getSpaceByName($user, $spaceName);
$spaceId = $space["id"];
$bodyData = ["description" => $newDescription];
$body = json_encode($bodyData, JSON_THROW_ON_ERROR);
$bodyData = ["description" => $newDescription];
$body = json_encode($bodyData, JSON_THROW_ON_ERROR);
$this->featureContext->setResponse(
$this->sendUpdateSpaceRequest(
$user,
$this->featureContext->getPasswordForUser($user),
$body,
$spaceId
)
);
}
$this->featureContext->setResponse(
$this->sendUpdateSpaceRequest(
$user,
$this->featureContext->getPasswordForUser($user),
$body,
$spaceId
)
);
}
/**
* @When /^user "([^"]*)" changes the quota of the "([^"]*)" space to "([^"]*)"$/
@@ -1288,6 +1360,47 @@ class SpacesContext implements Context {
);
}
/**
* @When /^user "([^"]*)" sets the file "([^"]*)" as a (description|space image)\s? in a special section of the "([^"]*)" space$/
*
* @param string $user
* @param string $file
* @param string $type
* @param string $spaceName
*
* @return void
* @throws GuzzleException
* @throws Exception
*/
public function updateSpaceSpecialSection(
string $user,
string $file,
string $type,
string $spaceName
): void {
$space = $this->getSpaceByName($user, $spaceName);
$spaceId = $space["id"];
$fileId = $this->getFileId($user, $spaceName, $file);
if ($type === "description") {
$type = "readme";
} else {
$type = "image";
}
$bodyData = ["special" => [["specialFolder" => ["name" => "$type"], "id" => "$fileId"]]];
$body = json_encode($bodyData, JSON_THROW_ON_ERROR);
$this->featureContext->setResponse(
$this->sendUpdateSpaceRequest(
$user,
$this->featureContext->getPasswordForUser($user),
$body,
$spaceId
)
);
}
/**
* Send Graph Update Space Request
*
@@ -1347,6 +1460,36 @@ class SpacesContext implements Context {
);
}
/**
* @When /^user "([^"]*)" has created a space "([^"]*)" with the default quota using the GraphApi$/
*
* @param string $user
* @param string $spaceName
*
* @return void
*
* @throws GuzzleException
* @throws Exception
*/
public function theUserHasCreatedASpaceByDefaultUsingTheGraphApi(
string $user,
string $spaceName
): void {
$space = ["Name" => $spaceName];
$body = json_encode($space, JSON_THROW_ON_ERROR);
$this->featureContext->setResponse(
$this->sendCreateSpaceRequest(
$user,
$this->featureContext->getPasswordForUser($user),
$body
)
);
$this->featureContext->theHTTPStatusCodeShouldBe(
201,
"Expected response status code should be 201 (Created)"
);
}
/**
* @Given /^user "([^"]*)" has uploaded a file inside space "([^"]*)" with content "([^"]*)" to "([^"]*)"$/
*
@@ -1443,10 +1586,10 @@ class SpacesContext implements Context {
$expectedHTTPStatus = "200";
$this->featureContext->theHTTPStatusCodeShouldBe(
$expectedHTTPStatus,
$expectedHTTPStatus,
"Expected response status code should be $expectedHTTPStatus"
);
$expectedOCSStatus = "200";
$expectedOCSStatus = "200";
$this->ocsContext->theOCSStatusCodeShouldBe($expectedOCSStatus, "Expected OCS response status code $expectedOCSStatus");
}
@@ -1546,7 +1689,7 @@ class SpacesContext implements Context {
$this->sendDisableSpaceRequest($user, $spaceName);
$expectedHTTPStatus = "204";
$this->featureContext->theHTTPStatusCodeShouldBe(
$expectedHTTPStatus,
$expectedHTTPStatus,
"Expected response status code should be $expectedHTTPStatus"
);
}
@@ -1647,7 +1790,7 @@ class SpacesContext implements Context {
$this->sendRestoreSpaceRequest($user, $spaceName);
$expectedHTTPStatus = "200";
$this->featureContext->theHTTPStatusCodeShouldBe(
$expectedHTTPStatus,
$expectedHTTPStatus,
"Expected response status code should be $expectedHTTPStatus"
);
}