Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
7aeda7c9
Commit
7aeda7c9
authored
Nov 11, 2015
by
Sergio Bertolin
Browse files
Added a test and logic for checking answer of public shares
parent
5dd59b4b
Changes
2
Hide whitespace changes
Inline
Side-by-side
build/integration/features/bootstrap/FeatureContext.php
View file @
7aeda7c9
...
...
@@ -562,7 +562,30 @@ class FeatureContext implements Context, SnippetAcceptingContext {
* @param \Behat\Gherkin\Node\TableNode|null $formData
*/
public
function
createPublicShare
(
$body
)
{
$this
->
sendingToWith
(
"POST"
,
"/apps/files_sharing/api/v1/shares"
,
$body
);
$fullUrl
=
$this
->
baseUrl
.
"v
{
$this
->
apiVersion
}
.php/apps/files_sharing/api/v1/shares"
;
$client
=
new
Client
();
$options
=
[];
if
(
$this
->
currentUser
===
'admin'
)
{
$options
[
'auth'
]
=
$this
->
adminUser
;
}
else
{
$options
[
'auth'
]
=
[
$this
->
currentUser
,
$this
->
regularUser
];
}
if
(
$body
instanceof
\
Behat\Gherkin\Node\TableNode
)
{
$fd
=
$body
->
getRowsHash
();
if
(
array_key_exists
(
'expireDate'
,
$fd
)){
$dateModification
=
$fd
[
'expireDate'
];
$fd
[
'expireDate'
]
=
date
(
'Y-m-d'
,
strtotime
(
$dateModification
));
}
$options
[
'body'
]
=
$fd
;
}
try
{
$this
->
response
=
$client
->
send
(
$client
->
createRequest
(
"POST"
,
$fullUrl
,
$options
));
}
catch
(
\
GuzzleHttp\Exception\ClientException
$ex
)
{
$this
->
response
=
$ex
->
getResponse
();
}
$this
->
lastShareData
=
$this
->
response
->
xml
();
}
...
...
@@ -669,17 +692,48 @@ class FeatureContext implements Context, SnippetAcceptingContext {
}
public
function
isFieldInResponse
(
$field
,
$content_expected
){
public
function
isExpectedUrl
(
$possibleUrl
,
$finalPart
){
$baseUrlChopped
=
substr
(
$this
->
baseUrl
,
0
,
-
4
);
$endCharacter
=
strlen
(
$baseUrlChopped
)
+
strlen
(
$finalPart
);
return
(
substr
(
$possibleUrl
,
0
,
$endCharacter
)
==
"
$baseUrlChopped
"
.
"
$finalPart
"
);
}
public
function
isFieldInResponse
(
$field
,
$contentExpected
){
$data
=
$this
->
response
->
xml
()
->
data
[
0
];
foreach
(
$data
as
$element
)
{
if
(
$content_expected
==
"A_NUMBER"
){
return
is_numeric
((
string
)
$element
->
$field
);
}
elseif
(
$element
->
$field
==
$content_expected
){
return
True
;
if
((
string
)
$field
==
'expiration'
){
$contentExpected
=
date
(
'Y-m-d'
,
strtotime
(
$contentExpected
))
.
" 00:00:00"
;
}
if
(
count
(
$data
->
element
)
>
0
){
foreach
(
$data
as
$element
)
{
if
(
$contentExpected
==
"A_TOKEN"
){
return
(
strlen
((
string
)
$element
->
$field
)
==
15
);
}
elseif
(
$contentExpected
==
"A_NUMBER"
){
return
is_numeric
((
string
)
$element
->
$field
);
}
elseif
(
$contentExpected
==
"AN_URL"
){
return
$this
->
isExpectedUrl
((
string
)
$element
->
$field
,
"index.php/s/"
);
}
elseif
(
$element
->
$field
==
$contentExpected
){
return
True
;
}
}
return
False
;
}
else
{
if
(
$contentExpected
==
"A_TOKEN"
){
return
(
strlen
((
string
)
$data
->
$field
)
==
15
);
}
elseif
(
$contentExpected
==
"A_NUMBER"
){
return
is_numeric
((
string
)
$data
->
$field
);
}
elseif
(
$contentExpected
==
"AN_URL"
){
return
$this
->
isExpectedUrl
((
string
)
$data
->
$field
,
"index.php/s/"
);
}
elseif
(
$data
->
$field
==
$contentExpected
){
return
True
;
}
return
False
;
}
return
False
;
}
/**
...
...
@@ -786,6 +840,9 @@ class FeatureContext implements Context, SnippetAcceptingContext {
for
(
$i
=
0
;
$i
<
5
;
$i
++
){
file_put_contents
(
"../../core/skeleton/"
.
"textfile"
.
"
$i
"
.
".txt"
,
"ownCloud test text file
\n
"
);
}
if
(
!
file_exists
(
"../../core/skeleton/FOLDER"
))
{
mkdir
(
"../../core/skeleton/FOLDER"
,
0777
,
true
);
}
}
...
...
@@ -796,6 +853,9 @@ class FeatureContext implements Context, SnippetAcceptingContext {
for
(
$i
=
0
;
$i
<
5
;
$i
++
){
self
::
removeFile
(
"../../core/skeleton/"
,
"textfile"
.
"
$i
"
.
".txt"
);
}
if
(
!
is_dir
(
"../../core/skeleton/FOLDER"
))
{
rmdir
(
"../../core/skeleton/FOLDER"
);
}
}
/**
...
...
build/integration/features/sharing-v1.feature
View file @
7aeda7c9
...
...
@@ -46,6 +46,25 @@ Feature: sharing
And
the HTTP status code should be
"200"
And
Public shared file
"welcome.txt"
with password
"publicpw"
can be downloaded
Scenario
:
Creating a new public share of a folder
Given
user
"user0"
exists
And
As an
"user0"
When
creating a public share with
|
path
|
FOLDER
|
|
shareType
|
3
|
|
password
|
publicpw
|
|
expireDate
|
+3
days
|
|
publicUpload
|
true
|
|
permissions
|
7
|
Then
the OCS status code should be
"100"
And
the HTTP status code should be
"200"
And
Share fields of last share match with
|
id
|
A_NUMBER
|
|
permissions
|
7
|
|
expiration
|
+3
days
|
|
url
|
AN_URL
|
|
token
|
A_TOKEN
|
Scenario
:
Creating a new public share with password and adding an expiration date
Given
user
"user0"
exists
And
As an
"user0"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment