Skip to content

Commit af42ca2

Browse files
Merge pull request #3905 from nextcloud/downstream-27069
Add integration test for trashbin
2 parents 53787a2 + 749046a commit af42ca2

File tree

5 files changed

+174
-10
lines changed

5 files changed

+174
-10
lines changed

.drone.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,15 @@ pipeline:
457457
when:
458458
matrix:
459459
TESTS: integration-ldap-features
460+
integration-trashbin:
461+
image: nextcloudci/integration-php7.0:integration-php7.0-3
462+
commands:
463+
- ./occ maintenance:install --admin-pass=admin
464+
- cd build/integration
465+
- ./run.sh features/trashbin.feature
466+
when:
467+
matrix:
468+
TESTS: integration-trashbin
460469
nodb-codecov:
461470
image: nextcloudci/php7.0:php7.0-7
462471
commands:
@@ -528,6 +537,7 @@ matrix:
528537
- TESTS: integration-filesdrop-features
529538
- TESTS: integration-transfer-ownership-features
530539
- TESTS: integration-ldap-features
540+
- TESTS: integration-trashbin
531541
- TESTS: jsunit
532542
- TESTS: check-autoloader
533543
- TESTS: check-mergejs

build/integration/features/bootstrap/BasicStructure.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
trait BasicStructure {
3636

3737
use Auth;
38+
use Trashbin;
3839

3940
/** @var string */
4041
private $currentUser = '';
@@ -377,16 +378,6 @@ public function fileIsCreatedInLocalStorageWithText($filename, $text) {
377378
$this->createFileWithText("local_storage/$filename", $text);
378379
}
379380

380-
/**
381-
* @When User :user empties trashbin
382-
* @param string $user
383-
*/
384-
public function emptyTrashbin($user) {
385-
$body = new \Behat\Gherkin\Node\TableNode([['allfiles', 'true'], ['dir', '%2F']]);
386-
$this->sendingToWithDirectUrl('POST', "/index.php/apps/files_trashbin/ajax/delete.php", $body);
387-
$this->theHTTPStatusCodeShouldBe('200');
388-
}
389-
390381
/**
391382
* @When Sleep for :seconds seconds
392383
* @param int $seconds
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
/**
3+
* @author Vincent Petry <[email protected]>
4+
*
5+
* @copyright Copyright (c) 2017, ownCloud GmbH.
6+
* @license AGPL-3.0
7+
*
8+
* This code is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License, version 3,
10+
* as published by the Free Software Foundation.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU Affero General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Affero General Public License, version 3,
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>
19+
*
20+
*/
21+
22+
use GuzzleHttp\Client;
23+
use GuzzleHttp\Message\ResponseInterface;
24+
25+
require __DIR__ . '/../../vendor/autoload.php';
26+
27+
/**
28+
* Trashbin functions
29+
*/
30+
trait Trashbin {
31+
32+
/**
33+
* @When User :user empties trashbin
34+
* @param string $user user
35+
*/
36+
public function emptyTrashbin($user) {
37+
$this->asAn($user);
38+
$body = new \Behat\Gherkin\Node\TableNode([['allfiles', 'true'], ['dir', '%2F']]);
39+
$this->sendingToWithDirectUrl('POST', "/index.php/apps/files_trashbin/ajax/delete.php", $body);
40+
$this->theHTTPStatusCodeShouldBe('200');
41+
}
42+
43+
/**
44+
* List trashbin folder
45+
*
46+
* @param string $user user
47+
* @param string $path path
48+
* @return array response
49+
*/
50+
public function listTrashbinFolder($user, $path){
51+
$this->asAn($user);
52+
$params = '?dir=' . rawurlencode('/' . trim($path, '/'));
53+
$this->sendingToWithDirectUrl('GET', '/index.php/apps/files_trashbin/ajax/list.php' . $params, null);
54+
$this->theHTTPStatusCodeShouldBe('200');
55+
56+
$response = json_decode($this->response->getBody(), true);
57+
58+
return $response['data']['files'];
59+
}
60+
61+
/**
62+
* @Then /^as "([^"]*)" the (file|folder|entry) "([^"]*)" exists in trash$/
63+
* @param string $user
64+
* @param string $entryText
65+
* @param string $path
66+
*/
67+
public function asTheFileOrFolderExistsInTrash($user, $entryText, $path) {
68+
$path = trim($path, '/');
69+
$sections = explode('/', $path, 2);
70+
71+
$firstEntry = $this->findFirstTrashedEntry($user, trim($sections[0], '/'));
72+
73+
PHPUnit_Framework_Assert::assertNotNull($firstEntry);
74+
75+
// query was on the main element ?
76+
if (count($sections) === 1) {
77+
// already found, return
78+
return;
79+
}
80+
81+
$subdir = trim(dirname($sections[1]), '/');
82+
if ($subdir !== '' && $subdir !== '.') {
83+
$subdir = $firstEntry . '/' . $subdir;
84+
} else {
85+
$subdir = $firstEntry;
86+
}
87+
88+
$listing = $this->listTrashbinFolder($user, $subdir);
89+
$checkedName = basename($path);
90+
91+
$found = false;
92+
foreach ($listing as $entry) {
93+
if ($entry['name'] === $checkedName) {
94+
$found = true;
95+
break;
96+
}
97+
}
98+
99+
PHPUnit_Framework_Assert::assertTrue($found);
100+
}
101+
102+
/**
103+
* Finds the first trashed entry matching the given name
104+
*
105+
* @param string $name
106+
* @return string|null real entry name with timestamp suffix or null if not found
107+
*/
108+
private function findFirstTrashedEntry($user, $name) {
109+
$listing = $this->listTrashbinFolder($user, '/');
110+
111+
foreach ($listing as $entry) {
112+
if ($entry['name'] === $name) {
113+
return $entry['name'] . '.d' . ((int)$entry['mtime'] / 1000);
114+
}
115+
}
116+
117+
return null;
118+
}
119+
}
120+

build/integration/features/sharing-v1-part2.feature

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,36 @@ Feature: sharing
705705
And Updating last share with
706706
| publicUpload | true |
707707
Then the OCS status code should be "404"
708+
And the HTTP status code should be "200"
709+
710+
Scenario: deleting file out of a share as recipient creates a backup for the owner
711+
Given As an "admin"
712+
And user "user0" exists
713+
And user "user1" exists
714+
And user "user0" created a folder "/shared"
715+
And User "user0" moved file "/textfile0.txt" to "/shared/shared_file.txt"
716+
And folder "/shared" of user "user0" is shared with user "user1"
717+
When User "user1" deletes file "/shared/shared_file.txt"
718+
Then as "user1" the file "/shared/shared_file.txt" does not exist
719+
And as "user0" the file "/shared/shared_file.txt" does not exist
720+
And as "user0" the file "/shared_file.txt" exists in trash
721+
And as "user1" the file "/shared_file.txt" exists in trash
722+
723+
Scenario: deleting folder out of a share as recipient creates a backup for the owner
724+
Given As an "admin"
725+
And user "user0" exists
726+
And user "user1" exists
727+
And user "user0" created a folder "/shared"
728+
And user "user0" created a folder "/shared/sub"
729+
And User "user0" moved file "/textfile0.txt" to "/shared/sub/shared_file.txt"
730+
And folder "/shared" of user "user0" is shared with user "user1"
731+
When User "user1" deletes folder "/shared/sub"
732+
Then as "user1" the folder "/shared/sub" does not exist
733+
And as "user0" the folder "/shared/sub" does not exist
734+
And as "user0" the folder "/sub" exists in trash
735+
And as "user0" the file "/sub/shared_file.txt" exists in trash
736+
And as "user1" the folder "/sub" exists in trash
737+
And as "user1" the file "/sub/shared_file.txt" exists in trash
708738

709739
Scenario: moving a file into a share as recipient
710740
Given As an "admin"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Feature: trashbin
2+
Background:
3+
Given using api version "1"
4+
And using old dav path
5+
And As an "admin"
6+
And app "files_trashbin" is enabled
7+
8+
Scenario: deleting a file moves it to trashbin
9+
Given As an "admin"
10+
And user "user0" exists
11+
When User "user0" deletes file "/textfile0.txt"
12+
Then as "user0" the file "/textfile0.txt" exists in trash
13+

0 commit comments

Comments
 (0)