summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2018-09-05 17:50:55 +0200
committerRobin Appelman <robin@icewind.nl>2018-09-20 17:03:50 +0200
commit8491c9bdc63a1582163b17927eacc3fc9c27c606 (patch)
tree9d7fbb04978d4d4119fac886dded25a29550e20f /build
parent26e2957aeaa984ac5e94f27d3a0c08af456b78e2 (diff)
downloadnextcloud-server-8491c9bdc63a1582163b17927eacc3fc9c27c606.tar.gz
nextcloud-server-8491c9bdc63a1582163b17927eacc3fc9c27c606.zip
fix trashbin integration tests and add a few more
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'build')
-rw-r--r--build/integration/features/bootstrap/Trashbin.php122
-rw-r--r--build/integration/features/bootstrap/WebDav.php8
-rw-r--r--build/integration/features/trashbin.feature21
3 files changed, 85 insertions, 66 deletions
diff --git a/build/integration/features/bootstrap/Trashbin.php b/build/integration/features/bootstrap/Trashbin.php
index 81725e940d5..2d7f93b6f66 100644
--- a/build/integration/features/bootstrap/Trashbin.php
+++ b/build/integration/features/bootstrap/Trashbin.php
@@ -30,16 +30,16 @@ require __DIR__ . '/../../vendor/autoload.php';
* Trashbin functions
*/
trait Trashbin {
+ use WebDav;
/**
* @When User :user empties trashbin
* @param string $user user
*/
public function emptyTrashbin($user) {
- $this->asAn($user);
- $body = new \Behat\Gherkin\Node\TableNode([['allfiles', 'true'], ['dir', '%2F']]);
- $this->sendingToWithDirectUrl('POST', "/index.php/apps/files_trashbin/ajax/delete.php", $body);
- $this->theHTTPStatusCodeShouldBe('200');
+ $client = $this->getSabreClient($user);
+ $response = $client->request('DELETE', $this->makeSabrePath($user, 'trash', 'trashbin'));
+ Assert::assertEquals(204, $response['statusCode']);
}
/**
@@ -49,78 +49,76 @@ trait Trashbin {
* @param string $path path
* @return array response
*/
- public function listTrashbinFolder($user, $path){
- $this->asAn($user);
- $this->sendingToWithDirectUrl('PROPFIND', "/remote.php/dav/trashbin/$user/$path", null);
- $this->theHTTPStatusCodeShouldBe('200');
-
- $body = $this->response->getBody();
- if($body && substr($body, 0, 1) === '<') {
- $reader = new Sabre\Xml\Reader();
- $reader->xml($body);
- return $reader->parse();
- } else {
- return [];
- }
+ public function listTrashbinFolder($user, $path) {
+ $client = $this->getSabreClient($user);
+
+ return $client->propfind($this->makeSabrePath($user, 'trash' . $path, 'trashbin'), [
+ '{http://nextcloud.org/ns}trashbin-filename',
+ '{http://nextcloud.org/ns}trashbin-original-location',
+ '{http://nextcloud.org/ns}trashbin-deletion-time'
+ ], 1);
}
/**
- * @Then /^as "([^"]*)" the (file|folder|entry) "([^"]*)" exists in trash$/
+ * @Then /^user "([^"]*)" in trash folder "([^"]*)" should have the following elements$/
* @param string $user
- * @param string $entryText
- * @param string $path
+ * @param string $folder
+ * @param \Behat\Gherkin\Node\TableNode|null $expectedElements
*/
- public function asTheFileOrFolderExistsInTrash($user, $entryText, $path) {
- $path = trim($path, '/');
- $sections = explode('/', $path, 2);
-
- $firstEntry = $this->findFirstTrashedEntry($user, trim($sections[0], '/'));
-
- Assert::assertNotNull($firstEntry);
-
- // query was on the main element ?
- if (count($sections) === 1) {
- // already found, return
- return;
- }
-
- $subdir = trim(dirname($sections[1]), '/');
- if ($subdir !== '' && $subdir !== '.') {
- $subdir = $firstEntry . '/' . $subdir;
- } else {
- $subdir = $firstEntry;
- }
-
- $listing = $this->listTrashbinFolder($user, $subdir);
- $checkedName = basename($path);
-
- $found = false;
- foreach ($listing as $entry) {
- if ($entry['name'] === $checkedName) {
- $found = true;
- break;
+ public function checkTrashContents($user, $folder, $expectedElements) {
+ $elementList = $this->listTrashbinFolder($user, $folder);
+ $trashContent = array_filter(array_map(function(array $item) {
+ return $item['{http://nextcloud.org/ns}trashbin-filename'];
+ }, $elementList));
+ if ($expectedElements instanceof \Behat\Gherkin\Node\TableNode) {
+ $elementRows = $expectedElements->getRows();
+ $elementsSimplified = $this->simplifyArray($elementRows);
+ foreach ($elementsSimplified as $expectedElement) {
+ $expectedElement = ltrim($expectedElement, '/');
+ if (array_search($expectedElement, $trashContent) === false) {
+ Assert::fail("$expectedElement" . " is not in trash listing");
+ }
}
}
-
- Assert::assertTrue($found);
}
/**
- * Finds the first trashed entry matching the given name
- *
- * @param string $name
- * @return string|null real entry name with timestamp suffix or null if not found
+ * @Then /^user "([^"]*)" in trash folder "([^"]*)" should have (\d+) elements?$/
+ * @param string $user
+ * @param string $folder
+ * @param \Behat\Gherkin\Node\TableNode|null $expectedElements
*/
- private function findFirstTrashedEntry($user, $name) {
- $listing = $this->listTrashbinFolder($user, '/');
+ public function checkTrashSize($user, $folder, $expectedCount) {
+ $elementList = $this->listTrashbinFolder($user, $folder);
+ // first item is listed folder
+ Assert::assertEquals($expectedCount, count($elementList) - 1);
+ }
- foreach ($listing as $entry) {
- if ($entry['name'] === $name) {
- return $entry['name'] . '.d' . ((int)$entry['mtime'] / 1000);
+ /**
+ * @When /^user "([^"]*)" in restores "([^"]*)" from trash$/
+ * @param string $user
+ * @param string $file
+ */
+ public function restoreFromTrash($user, $file) {
+ // find the full name in trashbin
+ $file = ltrim($file, '/');
+ $parent = dirname($file);
+ if ($parent === '.') {
+ $parent = '';
+ }
+ $elementList = $this->listTrashbinFolder($user, $parent);
+ $name = basename($file);
+ foreach($elementList as $href => $item) {
+ if ($item['{http://nextcloud.org/ns}trashbin-filename'] === $name) {
+ $client = $this->getSabreClient($user);
+ $response = $client->request('MOVE', $href, null, [
+ 'Destination' => $this->makeSabrePath($user, 'restore/' . $name, 'trashbin'),
+ ]);
+ Assert::assertEquals(201, $response['statusCode']);
+ return;
}
}
-
- return null;
+ Assert::fail("$file" . " is not in trash listing");
}
}
diff --git a/build/integration/features/bootstrap/WebDav.php b/build/integration/features/bootstrap/WebDav.php
index 37a398e2aae..b36cdfaea68 100644
--- a/build/integration/features/bootstrap/WebDav.php
+++ b/build/integration/features/bootstrap/WebDav.php
@@ -423,8 +423,12 @@ trait WebDav {
return $parsedResponse;
}
- public function makeSabrePath($user, $path) {
- return $this->encodePath($this->getDavFilesPath($user) . $path);
+ public function makeSabrePath($user, $path, $type = 'files') {
+ if ($type === 'files') {
+ return $this->encodePath($this->getDavFilesPath($user) . $path);
+ } else {
+ return $this->encodePath($this->davPath . '/' . $type . '/' . $user . '/' . $path);
+ }
}
public function getSabreClient($user) {
diff --git a/build/integration/features/trashbin.feature b/build/integration/features/trashbin.feature
index adb73f2b5ea..0b8bf3a81c4 100644
--- a/build/integration/features/trashbin.feature
+++ b/build/integration/features/trashbin.feature
@@ -1,7 +1,7 @@
Feature: trashbin
Background:
Given using api version "1"
- And using old dav path
+ And using new dav path
And As an "admin"
And app "files_trashbin" is enabled
@@ -9,5 +9,22 @@ Feature: trashbin
Given As an "admin"
And user "user0" exists
When User "user0" deletes file "/textfile0.txt"
- Then as "user0" the file "/textfile0.txt" exists in trash
+ Then user "user0" in trash folder "/" should have 1 element
+ And user "user0" in trash folder "/" should have the following elements
+ | /textfile0.txt |
+
+ Scenario: clearing the trashbin
+ Given As an "admin"
+ And user "user0" exists
+ When User "user0" deletes file "/textfile0.txt"
+ And User "user0" empties trashbin
+ Then user "user0" in trash folder "/" should have 0 elements
+
+ Scenario: restoring file from trashbin
+ Given As an "admin"
+ And user "user0" exists
+ When User "user0" deletes file "/textfile0.txt"
+ And user "user0" in restores "/textfile0.txt" from trash
+ Then user "user0" in trash folder "/" should have 0 elements
+ And as "user0" the file "/textfile0.txt" exists