summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-09-28 16:03:24 +0200
committerGitHub <noreply@github.com>2018-09-28 16:03:24 +0200
commitd867f9f091933ebc134cc50ba1ed835dbd39d36d (patch)
treeed0d4f75fb529d0bf323dcee9937989f6e7bfe58 /build
parenta23d5240987392f4eb140eefbb81882ef6ae6a5a (diff)
parentc5f77de3e270f3e6ad25e662ab77e1d68eaee67b (diff)
downloadnextcloud-server-d867f9f091933ebc134cc50ba1ed835dbd39d36d.tar.gz
nextcloud-server-d867f9f091933ebc134cc50ba1ed835dbd39d36d.zip
Merge pull request #11037 from nextcloud/trash-webui-dav
Use trashbin dav endpoint to list trash in webui
Diffstat (limited to 'build')
-rw-r--r--build/integration/config/behat.yml20
-rw-r--r--build/integration/features/bootstrap/Trashbin.php166
-rw-r--r--build/integration/features/bootstrap/WebDav.php8
-rw-r--r--build/integration/features/sharing-v1-part3.feature6
-rw-r--r--build/integration/features/trashbin.feature72
5 files changed, 195 insertions, 77 deletions
diff --git a/build/integration/config/behat.yml b/build/integration/config/behat.yml
index 428d4d45b78..7fd3686b8bb 100644
--- a/build/integration/config/behat.yml
+++ b/build/integration/config/behat.yml
@@ -1,10 +1,10 @@
default:
autoload:
- '': %paths.base%/../features/bootstrap
+ '': "%paths.base%/../features/bootstrap"
suites:
default:
paths:
- - %paths.base%/../features
+ - "%paths.base%/../features"
contexts:
- FeatureContext:
baseUrl: http://localhost:8080/ocs/
@@ -27,7 +27,7 @@ default:
ocPath: ../../
federation:
paths:
- - %paths.base%/../federation_features
+ - "%paths.base%/../federation_features"
contexts:
- FederationContext:
baseUrl: http://localhost:8080/ocs/
@@ -37,7 +37,7 @@ default:
regular_user_password: 123456
capabilities:
paths:
- - %paths.base%/../capabilities_features
+ - "%paths.base%/../capabilities_features"
contexts:
- CapabilitiesContext:
baseUrl: http://localhost:8080/ocs/
@@ -47,7 +47,7 @@ default:
regular_user_password: 123456
sharees:
paths:
- - %paths.base%/../sharees_features
+ - "%paths.base%/../sharees_features"
contexts:
- ShareesContext:
baseUrl: http://localhost:8080/ocs/
@@ -57,7 +57,7 @@ default:
regular_user_password: 123456
setup:
paths:
- - %paths.base%/../setup_features
+ - "%paths.base%/../setup_features"
contexts:
- SetupContext:
baseUrl: http://localhost:8080/ocs/
@@ -67,7 +67,7 @@ default:
regular_user_password: 123456
filesdrop:
paths:
- - %paths.base%/../filesdrop_features
+ - "%paths.base%/../filesdrop_features"
contexts:
- FilesDropContext:
baseUrl: http://localhost:8080
@@ -77,7 +77,7 @@ default:
regular_user_password: 123456
ldap:
paths:
- - %paths.base%/../ldap_features
+ - "%paths.base%/../ldap_features"
contexts:
- LDAPContext:
baseUrl: http://localhost:8080
@@ -87,7 +87,7 @@ default:
regular_user_password: what_for
remoteapi:
paths:
- - %paths.base%/../remoteapi_features
+ - "%paths.base%/../remoteapi_features"
contexts:
- FeatureContext:
baseUrl: http://localhost:8080/ocs/
@@ -100,4 +100,4 @@ default:
extensions:
jarnaiz\JUnitFormatter\JUnitFormatterExtension:
filename: report.xml
- outputDir: %paths.base%/../output/
+ outputDir: "%paths.base%/../output/"
diff --git a/build/integration/features/bootstrap/Trashbin.php b/build/integration/features/bootstrap/Trashbin.php
index 49d547a5edc..8e4d0892bc8 100644
--- a/build/integration/features/bootstrap/Trashbin.php
+++ b/build/integration/features/bootstrap/Trashbin.php
@@ -20,8 +20,6 @@
*
*/
-use GuzzleHttp\Client;
-use GuzzleHttp\Message\ResponseInterface;
use PHPUnit\Framework\Assert;
require __DIR__ . '/../../vendor/autoload.php';
@@ -30,16 +28,46 @@ 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']);
+ }
+
+ private function findFullTrashname($user, $name) {
+ $rootListing = $this->listTrashbinFolder($user, '/');
+
+ foreach ($rootListing as $href => $rootItem) {
+ if ($rootItem['{http://nextcloud.org/ns}trashbin-filename'] === $name) {
+ return basename($href);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Get the full /startofpath.dxxxx/rest/of/path from /startofpath/rest/of/path
+ */
+ private function getFullTrashPath($user, $path) {
+ if ($path !== '' && $path !== '/') {
+ $parts = explode('/', $path);
+ $fullName = $this->findFullTrashname($user, $parts[1]);
+ if ($fullName === null) {
+ Assert::fail("cant find $path in trash");
+ return '/dummy_full_path_not_found';
+ }
+ $parts[1] = $fullName;
+
+ $path = implode('/', $parts);
+ }
+ return $path;
}
/**
@@ -49,74 +77,92 @@ trait Trashbin {
* @param string $path path
* @return array response
*/
- public function listTrashbinFolder($user, $path){
- $this->asAn($user);
- $params = '?dir=' . rawurlencode('/' . trim($path, '/'));
- $this->sendingToWithDirectUrl('GET', '/index.php/apps/files_trashbin/ajax/list.php' . $params, null);
- $this->theHTTPStatusCodeShouldBe('200');
-
- $response = json_decode($this->response->getBody(), true);
-
- return $response['data']['files'];
+ public function listTrashbinFolder($user, $path) {
+ $path = $this->getFullTrashPath($user, $path);
+ $client = $this->getSabreClient($user);
+
+ $results = $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);
+ $results = array_filter($results, function (array $item) {
+ return isset($item['{http://nextcloud.org/ns}trashbin-filename']);
+ });
+ if ($path !== '' && $path !== '/') {
+ array_shift($results);
+ }
+ return $results;
}
/**
- * @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;
+ 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");
+ }
+ }
}
+ }
- $listing = $this->listTrashbinFolder($user, $subdir);
- $checkedName = basename($path);
-
- $found = false;
- foreach ($listing as $entry) {
- if ($entry['name'] === $checkedName) {
- $found = true;
- break;
- }
+ /**
+ * @Then /^as "([^"]*)" the (file|folder) "([^"]*)" exists in trash$/
+ * @param string $user
+ * @param string $type
+ * @param string $file
+ */
+ public function checkTrashContains($user, $type, $file) {
+ $parent = dirname($file);
+ if ($parent === '.') {
+ $parent = '/';
}
+ $name = basename($file);
+ $elementList = $this->listTrashbinFolder($user, $parent);
+ $trashContent = array_filter(array_map(function (array $item) {
+ return $item['{http://nextcloud.org/ns}trashbin-filename'];
+ }, $elementList));
- Assert::assertTrue($found);
+ Assert::assertArraySubset([$name], array_values($trashContent));
}
/**
- * 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, '/');
-
- foreach ($listing as $entry) {
- if ($entry['name'] === $name) {
- return $entry['name'] . '.d' . ((int)$entry['mtime'] / 1000);
- }
- }
+ public function checkTrashSize($user, $folder, $expectedCount) {
+ $elementList = $this->listTrashbinFolder($user, $folder);
+ Assert::assertEquals($expectedCount, count($elementList));
+ }
- return null;
+ /**
+ * @When /^user "([^"]*)" in restores "([^"]*)" from trash$/
+ * @param string $user
+ * @param string $file
+ */
+ public function restoreFromTrash($user, $file) {
+ $file = $this->getFullTrashPath($user, $file);
+ $url = $this->makeSabrePath($user, 'trash' . $file, 'trashbin');
+ $client = $this->getSabreClient($user);
+ $response = $client->request('MOVE', $url, null, [
+ 'Destination' => $this->makeSabrePath($user, 'restore/' . basename($file), 'trashbin'),
+ ]);
+ Assert::assertEquals(201, $response['statusCode']);
+ return;
}
}
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/sharing-v1-part3.feature b/build/integration/features/sharing-v1-part3.feature
index 44a41341a02..6ab7cfdf9a0 100644
--- a/build/integration/features/sharing-v1-part3.feature
+++ b/build/integration/features/sharing-v1-part3.feature
@@ -1,7 +1,7 @@
Feature: sharing
Background:
Given using api version "1"
- Given using old dav path
+ Given using new dav path
# See sharing-v1-part2.feature
@@ -295,7 +295,7 @@ Feature: sharing
And user "user0" exists
And User "user0" deletes file "/textfile0.txt"
When User "user0" empties trashbin
- Then the HTTP status code should be "200"
+ Then the HTTP status code should be "204"
Scenario: orphaned shares
Given As an "admin"
@@ -392,4 +392,4 @@ Feature: sharing
And folder "/shared" of user "user0" is shared with user "user1"
When User "user1" moved file "/textfile0.txt" to "/shared/shared_file.txt"
Then as "user1" the file "/shared/shared_file.txt" exists
- And as "user0" the file "/shared/shared_file.txt" exists \ No newline at end of file
+ And as "user0" the file "/shared/shared_file.txt" exists
diff --git a/build/integration/features/trashbin.feature b/build/integration/features/trashbin.feature
index adb73f2b5ea..3a9c29f7cb8 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,73 @@ 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
+
+ Scenario: deleting and restoring a folder
+ Given As an "admin"
+ And user "user0" exists
+ When User "user0" created a folder "/testfolder"
+ And User "user0" moves file "/textfile0.txt" to "/testfolder/textfile0.txt"
+ And as "user0" the file "/testfolder/textfile0.txt" exists
+ And User "user0" deletes file "/testfolder"
+ And user "user0" in trash folder "/" should have 1 element
+ And user "user0" in trash folder "/" should have the following elements
+ | testfolder |
+ And user "user0" in trash folder "/testfolder" should have 1 element
+ And user "user0" in trash folder "/testfolder" should have the following elements
+ | textfile0.txt |
+ And user "user0" in restores "/testfolder" from trash
+ Then user "user0" in trash folder "/" should have 0 elements
+ And as "user0" the file "/testfolder/textfile0.txt" exists
+
+ Scenario: deleting a file from a subfolder and restoring it moves it back to the subfolder
+ Given As an "admin"
+ And user "user0" exists
+ When User "user0" created a folder "/testfolder"
+ And User "user0" moves file "/textfile0.txt" to "/testfolder/textfile0.txt"
+ And as "user0" the file "/testfolder/textfile0.txt" exists
+ And User "user0" deletes file "/testfolder/textfile0.txt"
+ And user "user0" in trash folder "/" should have 1 element
+ And user "user0" in trash folder "/" should have the following elements
+ | 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" does not exist
+ And as "user0" the file "/testfolder/textfile0.txt" exists
+
+ Scenario: deleting and a folder and restoring a file inside it
+ Given As an "admin"
+ And user "user0" exists
+ When User "user0" created a folder "/testfolder"
+ And User "user0" moves file "/textfile0.txt" to "/testfolder/textfile0.txt"
+ And as "user0" the file "/testfolder/textfile0.txt" exists
+ And User "user0" deletes file "/testfolder"
+ And user "user0" in trash folder "/" should have 1 element
+ And user "user0" in trash folder "/" should have the following elements
+ | testfolder |
+ And user "user0" in trash folder "/testfolder" should have 1 element
+ And user "user0" in trash folder "/testfolder" should have the following elements
+ | textfile0.txt |
+ And user "user0" in restores "/testfolder/textfile0.txt" from trash
+ Then user "user0" in trash folder "/" should have 1 elements
+ And user "user0" in trash folder "/testfolder" should have 0 element
+ And as "user0" the file "/textfile0.txt" exists
+