fix trashbin integration tests and add a few more
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
26e2957aea
commit
8491c9bdc6
|
@ -30,16 +30,16 @@ require __DIR__ . '/../../vendor/autoload.php';
|
||||||
* Trashbin functions
|
* Trashbin functions
|
||||||
*/
|
*/
|
||||||
trait Trashbin {
|
trait Trashbin {
|
||||||
|
use WebDav;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @When User :user empties trashbin
|
* @When User :user empties trashbin
|
||||||
* @param string $user user
|
* @param string $user user
|
||||||
*/
|
*/
|
||||||
public function emptyTrashbin($user) {
|
public function emptyTrashbin($user) {
|
||||||
$this->asAn($user);
|
$client = $this->getSabreClient($user);
|
||||||
$body = new \Behat\Gherkin\Node\TableNode([['allfiles', 'true'], ['dir', '%2F']]);
|
$response = $client->request('DELETE', $this->makeSabrePath($user, 'trash', 'trashbin'));
|
||||||
$this->sendingToWithDirectUrl('POST', "/index.php/apps/files_trashbin/ajax/delete.php", $body);
|
Assert::assertEquals(204, $response['statusCode']);
|
||||||
$this->theHTTPStatusCodeShouldBe('200');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,78 +49,76 @@ trait Trashbin {
|
||||||
* @param string $path path
|
* @param string $path path
|
||||||
* @return array response
|
* @return array response
|
||||||
*/
|
*/
|
||||||
public function listTrashbinFolder($user, $path){
|
public function listTrashbinFolder($user, $path) {
|
||||||
$this->asAn($user);
|
$client = $this->getSabreClient($user);
|
||||||
$this->sendingToWithDirectUrl('PROPFIND', "/remote.php/dav/trashbin/$user/$path", null);
|
|
||||||
$this->theHTTPStatusCodeShouldBe('200');
|
|
||||||
|
|
||||||
$body = $this->response->getBody();
|
return $client->propfind($this->makeSabrePath($user, 'trash' . $path, 'trashbin'), [
|
||||||
if($body && substr($body, 0, 1) === '<') {
|
'{http://nextcloud.org/ns}trashbin-filename',
|
||||||
$reader = new Sabre\Xml\Reader();
|
'{http://nextcloud.org/ns}trashbin-original-location',
|
||||||
$reader->xml($body);
|
'{http://nextcloud.org/ns}trashbin-deletion-time'
|
||||||
return $reader->parse();
|
], 1);
|
||||||
} else {
|
}
|
||||||
return [];
|
|
||||||
|
/**
|
||||||
|
* @Then /^user "([^"]*)" in trash folder "([^"]*)" should have the following elements$/
|
||||||
|
* @param string $user
|
||||||
|
* @param string $folder
|
||||||
|
* @param \Behat\Gherkin\Node\TableNode|null $expectedElements
|
||||||
|
*/
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Then /^as "([^"]*)" the (file|folder|entry) "([^"]*)" exists in trash$/
|
* @Then /^user "([^"]*)" in trash folder "([^"]*)" should have (\d+) elements?$/
|
||||||
* @param string $user
|
* @param string $user
|
||||||
* @param string $entryText
|
* @param string $folder
|
||||||
* @param string $path
|
* @param \Behat\Gherkin\Node\TableNode|null $expectedElements
|
||||||
*/
|
*/
|
||||||
public function asTheFileOrFolderExistsInTrash($user, $entryText, $path) {
|
public function checkTrashSize($user, $folder, $expectedCount) {
|
||||||
$path = trim($path, '/');
|
$elementList = $this->listTrashbinFolder($user, $folder);
|
||||||
$sections = explode('/', $path, 2);
|
// first item is listed folder
|
||||||
|
Assert::assertEquals($expectedCount, count($elementList) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
$firstEntry = $this->findFirstTrashedEntry($user, trim($sections[0], '/'));
|
/**
|
||||||
|
* @When /^user "([^"]*)" in restores "([^"]*)" from trash$/
|
||||||
Assert::assertNotNull($firstEntry);
|
* @param string $user
|
||||||
|
* @param string $file
|
||||||
// query was on the main element ?
|
*/
|
||||||
if (count($sections) === 1) {
|
public function restoreFromTrash($user, $file) {
|
||||||
// already found, return
|
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
$subdir = trim(dirname($sections[1]), '/');
|
|
||||||
if ($subdir !== '' && $subdir !== '.') {
|
|
||||||
$subdir = $firstEntry . '/' . $subdir;
|
|
||||||
} else {
|
|
||||||
$subdir = $firstEntry;
|
|
||||||
}
|
}
|
||||||
|
Assert::fail("$file" . " 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
*/
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -423,8 +423,12 @@ trait WebDav {
|
||||||
return $parsedResponse;
|
return $parsedResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function makeSabrePath($user, $path) {
|
public function makeSabrePath($user, $path, $type = 'files') {
|
||||||
|
if ($type === 'files') {
|
||||||
return $this->encodePath($this->getDavFilesPath($user) . $path);
|
return $this->encodePath($this->getDavFilesPath($user) . $path);
|
||||||
|
} else {
|
||||||
|
return $this->encodePath($this->davPath . '/' . $type . '/' . $user . '/' . $path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSabreClient($user) {
|
public function getSabreClient($user) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
Feature: trashbin
|
Feature: trashbin
|
||||||
Background:
|
Background:
|
||||||
Given using api version "1"
|
Given using api version "1"
|
||||||
And using old dav path
|
And using new dav path
|
||||||
And As an "admin"
|
And As an "admin"
|
||||||
And app "files_trashbin" is enabled
|
And app "files_trashbin" is enabled
|
||||||
|
|
||||||
|
@ -9,5 +9,22 @@ Feature: trashbin
|
||||||
Given As an "admin"
|
Given As an "admin"
|
||||||
And user "user0" exists
|
And user "user0" exists
|
||||||
When User "user0" deletes file "/textfile0.txt"
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue