Skip to content

Commit d689596

Browse files
authored
Merge pull request #11472 from owncloud/test/check-trashbin-restore
[full-ci][tests-only] add step to try to restore trashed file
2 parents 7d6fb91 + c4d9ac2 commit d689596

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

tests/acceptance/bootstrap/SpacesContext.php

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3232,6 +3232,7 @@ public function listAllDeletedFilesFromTrash(
32323232

32333233
/**
32343234
* @When /^user "([^"]*)" lists all deleted files in the trash bin of the space "([^"]*)"$/
3235+
* @When /^user "([^"]*)" tries to list all deleted files in the trash bin of the space "([^"]*)"$/
32353236
*
32363237
* @param string $user
32373238
* @param string $spaceName
@@ -3314,6 +3315,23 @@ public function getObjectsInTrashbin(
33143315
);
33153316
}
33163317

3318+
/**
3319+
* @param string $user
3320+
* @param string $spaceName
3321+
* @param string $resource
3322+
*
3323+
* @return string
3324+
* @throws GuzzleException
3325+
*/
3326+
public function getTrashbinItemHref(string $user, string $spaceName, string $resource): string {
3327+
$items = $this->getObjectsInTrashbin($user, $spaceName);
3328+
foreach ($items as $item) {
3329+
if ($item["name"] === $resource) {
3330+
return $item["href"];
3331+
}
3332+
}
3333+
}
3334+
33173335
/**
33183336
* @Then /^as "([^"]*)" (?:file|folder|entry) "([^"]*)" should (not|)\s?exist in the trashbin of the space "([^"]*)"$/
33193337
*
@@ -3348,9 +3366,10 @@ public function checkExistenceOfObjectsInTrashbin(
33483366

33493367
/**
33503368
* @When /^user "([^"]*)" restores the (?:file|folder) "([^"]*)" from the trash of the space "([^"]*)" to "([^"]*)"$/
3369+
* @When /^user "([^"]*)" tries to restore the (?:file|folder) "([^"]*)" from the trash of the space "([^"]*)" to "([^"]*)"$/
33513370
*
33523371
* @param string $user
3353-
* @param string $object
3372+
* @param string $trashResource
33543373
* @param string $spaceName
33553374
* @param string $destination
33563375
*
@@ -3360,33 +3379,22 @@ public function checkExistenceOfObjectsInTrashbin(
33603379
*/
33613380
public function userRestoresSpaceObjectsFromTrashRequest(
33623381
string $user,
3363-
string $object,
3382+
string $trashResource,
33643383
string $spaceName,
33653384
string $destination,
33663385
): void {
3386+
$destination = \ltrim($destination, "/");
33673387
$space = $this->getSpaceByName($user, $spaceName);
3368-
3369-
// find object in trash
3370-
$objectsInTrash = $this->getObjectsInTrashbin($user, $spaceName);
3371-
$pathToDeletedObject = "";
3372-
foreach ($objectsInTrash as $objectInTrash) {
3373-
if ($objectInTrash["name"] === $object) {
3374-
$pathToDeletedObject = $objectInTrash["href"];
3375-
}
3376-
}
3377-
3378-
if ($pathToDeletedObject === "") {
3379-
throw new Exception(
3380-
__METHOD__ . " Object '$object' was not found in the trashbin of space '$spaceName' by user '$user'",
3381-
);
3382-
}
3388+
$spaceId = $space["id"];
3389+
$spaceOwner = $space["spaceCreator"];
3390+
$itemHref = $this->getTrashbinItemHref($spaceOwner, $spaceName, $trashResource);
33833391

33843392
$baseUrl = $this->featureContext->getBaseUrl();
3385-
$davPath = WebDavHelper::getDavPath(WebDavHelper::DAV_VERSION_SPACES, $space["id"]);
3393+
$davPath = WebDavHelper::getDavPath(WebDavHelper::DAV_VERSION_SPACES, $spaceId);
33863394
$destination = "$baseUrl/$davPath/$destination";
33873395
$header = ["Destination" => $destination, "Overwrite" => "F"];
33883396

3389-
$fullUrl = $baseUrl . $pathToDeletedObject;
3397+
$fullUrl = $baseUrl . $itemHref;
33903398
$this->featureContext->setResponse(
33913399
HttpRequestHelper::sendRequest(
33923400
$fullUrl,

tests/acceptance/features/apiSharingNgAdditionalShareRole/SpaceEditorWithoutTrashbin.feature

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Feature: an user shares resources
2121
| shareType | user |
2222
| permissionsRole | Space Editor Without Trashbin |
2323
And user "Brian" has removed the file "textfile.txt" from space "new-space"
24-
When user "Brian" lists all deleted files in the trash bin of the space "new-space"
24+
When user "Brian" tries to list all deleted files in the trash bin of the space "new-space"
25+
Then the HTTP status code should be "403"
26+
When user "Brian" tries to restore the file "textfile.txt" from the trash of the space "new-space" to "/textfile.txt"
2527
Then the HTTP status code should be "403"
2628
And as "Alice" file "textfile.txt" should exist in the trashbin of the space "new-space"

0 commit comments

Comments
 (0)