Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
d4087811
Unverified
Commit
d4087811
authored
6 years ago
by
Robin Appelman
Browse files
Options
Downloads
Patches
Plain Diff
more trashbin integration tests
Signed-off-by:
Robin Appelman
<
robin@icewind.nl
>
parent
8491c9bd
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
build/integration/features/bootstrap/Trashbin.php
+49
-25
49 additions, 25 deletions
build/integration/features/bootstrap/Trashbin.php
build/integration/features/trashbin.feature
+52
-1
52 additions, 1 deletion
build/integration/features/trashbin.feature
with
101 additions
and
26 deletions
build/integration/features/bootstrap/Trashbin.php
+
49
−
25
View file @
d4087811
...
@@ -20,8 +20,6 @@
...
@@ -20,8 +20,6 @@
*
*
*/
*/
use
GuzzleHttp\Client
;
use
GuzzleHttp\Message\ResponseInterface
;
use
PHPUnit\Framework\Assert
;
use
PHPUnit\Framework\Assert
;
require
__DIR__
.
'/../../vendor/autoload.php'
;
require
__DIR__
.
'/../../vendor/autoload.php'
;
...
@@ -42,6 +40,36 @@ trait Trashbin {
...
@@ -42,6 +40,36 @@ trait Trashbin {
Assert
::
assertEquals
(
204
,
$response
[
'statusCode'
]);
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
;
}
/**
/**
* List trashbin folder
* List trashbin folder
*
*
...
@@ -50,13 +78,21 @@ trait Trashbin {
...
@@ -50,13 +78,21 @@ trait Trashbin {
* @return array response
* @return array response
*/
*/
public
function
listTrashbinFolder
(
$user
,
$path
)
{
public
function
listTrashbinFolder
(
$user
,
$path
)
{
$path
=
$this
->
getFullTrashPath
(
$user
,
$path
);
$client
=
$this
->
getSabreClient
(
$user
);
$client
=
$this
->
getSabreClient
(
$user
);
re
turn
$client
->
propfind
(
$this
->
makeSabrePath
(
$user
,
'trash'
.
$path
,
'trashbin'
),
[
$
re
sults
=
$client
->
propfind
(
$this
->
makeSabrePath
(
$user
,
'trash'
.
$path
,
'trashbin'
),
[
'{http://nextcloud.org/ns}trashbin-filename'
,
'{http://nextcloud.org/ns}trashbin-filename'
,
'{http://nextcloud.org/ns}trashbin-original-location'
,
'{http://nextcloud.org/ns}trashbin-original-location'
,
'{http://nextcloud.org/ns}trashbin-deletion-time'
'{http://nextcloud.org/ns}trashbin-deletion-time'
],
1
);
],
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
;
}
}
/**
/**
...
@@ -67,7 +103,7 @@ trait Trashbin {
...
@@ -67,7 +103,7 @@ trait Trashbin {
*/
*/
public
function
checkTrashContents
(
$user
,
$folder
,
$expectedElements
)
{
public
function
checkTrashContents
(
$user
,
$folder
,
$expectedElements
)
{
$elementList
=
$this
->
listTrashbinFolder
(
$user
,
$folder
);
$elementList
=
$this
->
listTrashbinFolder
(
$user
,
$folder
);
$trashContent
=
array_filter
(
array_map
(
function
(
array
$item
)
{
$trashContent
=
array_filter
(
array_map
(
function
(
array
$item
)
{
return
$item
[
'{http://nextcloud.org/ns}trashbin-filename'
];
return
$item
[
'{http://nextcloud.org/ns}trashbin-filename'
];
},
$elementList
));
},
$elementList
));
if
(
$expectedElements
instanceof
\Behat\Gherkin\Node\TableNode
)
{
if
(
$expectedElements
instanceof
\Behat\Gherkin\Node\TableNode
)
{
...
@@ -90,8 +126,7 @@ trait Trashbin {
...
@@ -90,8 +126,7 @@ trait Trashbin {
*/
*/
public
function
checkTrashSize
(
$user
,
$folder
,
$expectedCount
)
{
public
function
checkTrashSize
(
$user
,
$folder
,
$expectedCount
)
{
$elementList
=
$this
->
listTrashbinFolder
(
$user
,
$folder
);
$elementList
=
$this
->
listTrashbinFolder
(
$user
,
$folder
);
// first item is listed folder
Assert
::
assertEquals
(
$expectedCount
,
count
(
$elementList
));
Assert
::
assertEquals
(
$expectedCount
,
count
(
$elementList
)
-
1
);
}
}
/**
/**
...
@@ -100,25 +135,14 @@ trait Trashbin {
...
@@ -100,25 +135,14 @@ trait Trashbin {
* @param string $file
* @param string $file
*/
*/
public
function
restoreFromTrash
(
$user
,
$file
)
{
public
function
restoreFromTrash
(
$user
,
$file
)
{
// find the full name in trashbin
$file
=
$this
->
getFullTrashPath
(
$user
,
$file
);
$file
=
ltrim
(
$file
,
'/'
);
$url
=
$this
->
makeSabrePath
(
$user
,
'trash'
.
$file
,
'trashbin'
);
$parent
=
dirname
(
$file
);
$client
=
$this
->
getSabreClient
(
$user
);
if
(
$parent
===
'.'
)
{
$response
=
$client
->
request
(
'MOVE'
,
$url
,
null
,
[
$parent
=
''
;
'Destination'
=>
$this
->
makeSabrePath
(
$user
,
'restore/'
.
basename
(
$file
),
'trashbin'
),
}
]);
$elementList
=
$this
->
listTrashbinFolder
(
$user
,
$parent
);
Assert
::
assertEquals
(
201
,
$response
[
'statusCode'
]);
$name
=
basename
(
$file
);
return
;
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
;
}
}
Assert
::
fail
(
"
$file
"
.
" is not in trash listing"
);
}
}
}
}
This diff is collapsed.
Click to expand it.
build/integration/features/trashbin.feature
+
52
−
1
View file @
d4087811
...
@@ -11,7 +11,7 @@ Feature: trashbin
...
@@ -11,7 +11,7 @@ Feature: trashbin
When
User
"user0"
deletes file
"/textfile0.txt"
When
User
"user0"
deletes file
"/textfile0.txt"
Then
user
"user0"
in trash folder
"/"
should have 1 element
Then
user
"user0"
in trash folder
"/"
should have 1 element
And
user
"user0"
in trash folder
"/"
should have the following elements
And
user
"user0"
in trash folder
"/"
should have the following elements
|
/
textfile0.txt
|
|
textfile0.txt
|
Scenario
:
clearing the trashbin
Scenario
:
clearing the trashbin
Given
As an
"admin"
Given
As an
"admin"
...
@@ -28,3 +28,54 @@ Feature: trashbin
...
@@ -28,3 +28,54 @@ Feature: trashbin
Then
user
"user0"
in trash folder
"/"
should have 0 elements
Then
user
"user0"
in trash folder
"/"
should have 0 elements
And
as
"user0"
the file
"/textfile0.txt"
exists
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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment