Skip to content

Commit

Permalink
make listFolder function in WebDav.php to use Guzzle
Browse files Browse the repository at this point in the history
  • Loading branch information
individual-it committed Jan 3, 2019
1 parent fb4b70c commit 5ff595c
Show file tree
Hide file tree
Showing 7 changed files with 177 additions and 128 deletions.
65 changes: 63 additions & 2 deletions tests/TestHelpers/WebDavHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use GuzzleHttp\Stream\StreamInterface;
use InvalidArgumentException;
use Sabre\DAV\Client as SClient;
use SimpleXMLElement;

/**
* Helper to make WebDav Requests
Expand Down Expand Up @@ -71,12 +72,20 @@ public static function getFileIdForPath(
}

/**
* sends a PROPFIND request
* with these registered namespaces:
* | prefix | namespace |
* | d | DAV: |
* | oc | http://owncloud.org/ns |
* | ocs | http://open-collaboration-services.org/ns |
*
* @param string $baseUrl
* @param string $user
* @param string $password
* @param string $path
* @param string[] $properties
* string can contain namespace prefix,
* if no prefix is given 'd:' is used as prefix
* @param int $folderDepth
* @param string $type
* @param int $davPathVersionToUse
Expand All @@ -97,10 +106,17 @@ public static function propfind(
) {
$headers = ['Depth' => $folderDepth];
$body = '<?xml version="1.0"?>
<d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
<d:propfind
xmlns:d="DAV:"
xmlns:oc="http://owncloud.org/ns"
xmlns:ocs="http://open-collaboration-services.org/ns">
<d:prop>';
foreach ($properties as $property) {
$body .= "<d:$property/>";
//if no namespace is given in the property add the default one
if (\strpos($property, ":") === false) {
$property = "d:$property";
}
$body .= "<$property/>";
}

$body .= '</d:prop></d:propfind>';
Expand All @@ -112,6 +128,51 @@ public static function propfind(
return $response;
}

/**
* returns the result parsed into an SimpleXMLElement
* with these registered namespaces:
* | prefix | namespace |
* | d | DAV: |
* | oc | http://owncloud.org/ns |
* | ocs | http://open-collaboration-services.org/ns |
*
* @param string $baseUrl
* @param string $user
* @param string $password
* @param string $path
* @param int $folderDepth
* @param string[] $properties
* @param string $type
* @param int $davPathVersionToUse
*
* @return SimpleXMLElement
*/
public static function listFolder(
$baseUrl,
$user,
$password,
$path,
$folderDepth,
$properties = null,
$type = "files",
$davPathVersionToUse = 2
) {
if (!$properties) {
$properties = [
'getetag'
];
}
$response = self::propfind(
$baseUrl,
$user, $password, $path, $properties, $folderDepth, $type, $davPathVersionToUse
);
$responseXml = HttpRequestHelper::getResponseXml($response);
$responseXml->registerXPathNamespace('d', 'DAV:');
$responseXml->registerXPathNamespace('oc', 'http://owncloud.org/ns');
$responseXml->registerXPathNamespace('ocs', 'http://open-collaboration-services.org/ns');
return $responseXml;
}

/**
*
* @param string $baseUrl
Expand Down
12 changes: 6 additions & 6 deletions tests/acceptance/features/apiComments/comments.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Feature: Comments
And the user should have the following comments on file "/myFileToComment.txt"
| user0 | My first comment |
When the user gets the following properties of folder "/myFileToComment.txt" using the WebDAV API
| {http://owncloud.org/ns}comments-href |
| {http://owncloud.org/ns}comments-count |
| {http://owncloud.org/ns}comments-unread |
Then the single response should contain a property "{http://owncloud.org/ns}comments-count" with value "1"
And the single response should contain a property "{http://owncloud.org/ns}comments-unread" with value "0"
And the single response should contain a property "{http://owncloud.org/ns}comments-href" with value "a_comment_url"
| oc:comments-href |
| oc:comments-count |
| oc:comments-unread |
Then the single response should contain a property "oc:comments-count" with value "1"
And the single response should contain a property "oc:comments-unread" with value "0"
And the single response should contain a property "oc:comments-href" with value "a_comment_url"
12 changes: 6 additions & 6 deletions tests/acceptance/features/apiShareManagement/mergeShare.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Feature: sharing
Given user "user0" has created folder "/merge-test-outside-perms"
When user "user0" shares folder "/merge-test-outside-perms" with group "grp1" with permissions 1 using the sharing API
And user "user0" shares folder "/merge-test-outside-perms" with user "user1" with permissions 31 using the sharing API
Then as user "user1" folder "/merge-test-outside-perms" should contain a property "{http://owncloud.org/ns}permissions" with value "SRDNVCK"
Then as user "user1" folder "/merge-test-outside-perms" should contain a property "oc:permissions" with value "SRDNVCK"
And as "user1" folder "/merge-test-outside-perms (2)" should not exist

Scenario: Merging shares for recipient when shared from outside with two groups
Expand All @@ -39,7 +39,7 @@ Feature: sharing
And user "user0" has created folder "/merge-test-outside-twogroups-perms"
When user "user0" shares folder "/merge-test-outside-twogroups-perms" with group "grp1" with permissions 1 using the sharing API
And user "user0" shares folder "/merge-test-outside-twogroups-perms" with group "grp4" with permissions 31 using the sharing API
Then as user "user1" folder "/merge-test-outside-twogroups-perms" should contain a property "{http://owncloud.org/ns}permissions" with value "SRDNVCK"
Then as user "user1" folder "/merge-test-outside-twogroups-perms" should contain a property "oc:permissions" with value "SRDNVCK"
And as "user1" folder "/merge-test-outside-twogroups-perms (2)" should not exist

Scenario: Merging shares for recipient when shared from outside with two groups and member
Expand All @@ -49,7 +49,7 @@ Feature: sharing
When user "user0" shares folder "/merge-test-outside-twogroups-member-perms" with group "grp1" with permissions 1 using the sharing API
And user "user0" shares folder "/merge-test-outside-twogroups-member-perms" with group "grp4" with permissions 31 using the sharing API
And user "user0" shares folder "/merge-test-outside-twogroups-member-perms" with user "user1" with permissions 1 using the sharing API
Then as user "user1" folder "/merge-test-outside-twogroups-member-perms" should contain a property "{http://owncloud.org/ns}permissions" with value "SRDNVCK"
Then as user "user1" folder "/merge-test-outside-twogroups-member-perms" should contain a property "oc:permissions" with value "SRDNVCK"
And as "user1" folder "/merge-test-outside-twogroups-member-perms (2)" should not exist

Scenario: Merging shares for recipient when shared from inside with group
Expand All @@ -74,7 +74,7 @@ Feature: sharing
And user "user1" has created folder "/merge-test-inside-twogroups-perms"
When user "user1" shares folder "/merge-test-inside-twogroups-perms" with group "grp1" using the sharing API
And user "user1" shares folder "/merge-test-inside-twogroups-perms" with group "grp4" using the sharing API
Then as user "user1" folder "/merge-test-inside-twogroups-perms" should contain a property "{http://owncloud.org/ns}permissions" with value "RDNVCK" or with value "RMDNVCK"
Then as user "user1" folder "/merge-test-inside-twogroups-perms" should contain a property "oc:permissions" with value "RDNVCK" or with value "RMDNVCK"
And as "user1" folder "/merge-test-inside-twogroups-perms (2)" should not exist
And as "user1" folder "/merge-test-inside-twogroups-perms (3)" should not exist

Expand All @@ -84,7 +84,7 @@ Feature: sharing
When user "user0" shares folder "/merge-test-outside-groups-renamebeforesecondshare" with group "grp1" using the sharing API
And user "user1" moves folder "/merge-test-outside-groups-renamebeforesecondshare" to "/merge-test-outside-groups-renamebeforesecondshare-renamed" using the WebDAV API
And user "user0" shares folder "/merge-test-outside-groups-renamebeforesecondshare" with user "user1" using the sharing API
Then as user "user1" folder "/merge-test-outside-groups-renamebeforesecondshare-renamed" should contain a property "{http://owncloud.org/ns}permissions" with value "SRDNVCK"
Then as user "user1" folder "/merge-test-outside-groups-renamebeforesecondshare-renamed" should contain a property "oc:permissions" with value "SRDNVCK"
And as "user1" folder "/merge-test-outside-groups-renamebeforesecondshare" should not exist

@skipOnLDAP @user_ldap-issue-274
Expand All @@ -93,5 +93,5 @@ Feature: sharing
When user "user0" shares folder "/merge-test-outside-groups-renamebeforesecondshare" with user "user1" using the sharing API
And user "user1" moves folder "/merge-test-outside-groups-renamebeforesecondshare" to "/merge-test-outside-groups-renamebeforesecondshare-renamed" using the WebDAV API
And user "user0" shares folder "/merge-test-outside-groups-renamebeforesecondshare" with group "grp1" using the sharing API
Then as user "user1" folder "/merge-test-outside-groups-renamebeforesecondshare-renamed" should contain a property "{http://owncloud.org/ns}permissions" with value "SRDNVCK"
Then as user "user1" folder "/merge-test-outside-groups-renamebeforesecondshare-renamed" should contain a property "oc:permissions" with value "SRDNVCK"
And as "user1" folder "/merge-test-outside-groups-renamebeforesecondshare" should not exist
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Feature: sharing
Given using <dav-path> DAV path
And user "user0" has uploaded file with content "foo" to "/tmp.txt"
When user "user0" gets the following properties of file "/tmp.txt" using the WebDAV API
| {http://open-collaboration-services.org/ns}share-permissions |
Then the single response should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "19"
| ocs:share-permissions |
Then the single response should contain a property "ocs:share-permissions" with value "19"
Examples:
| dav-path |
| old |
Expand All @@ -23,8 +23,8 @@ Feature: sharing
And user "user0" has uploaded file with content "foo" to "/tmp.txt"
And user "user0" has shared file "/tmp.txt" with user "user1"
When user "user1" gets the following properties of file "/tmp.txt" using the WebDAV API
| {http://open-collaboration-services.org/ns}share-permissions |
Then the single response should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "19"
| ocs:share-permissions |
Then the single response should contain a property "ocs:share-permissions" with value "19"
Examples:
| dav-path |
| old |
Expand All @@ -41,8 +41,8 @@ Feature: sharing
| permissions | 19 |
| shareWith | grp1 |
When user "user1" gets the following properties of file "/tmp.txt" using the WebDAV API
| {http://open-collaboration-services.org/ns}share-permissions |
Then the single response should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "19"
| ocs:share-permissions |
Then the single response should contain a property "ocs:share-permissions" with value "19"
Examples:
| dav-path |
| old |
Expand All @@ -54,7 +54,7 @@ Feature: sharing
And user "user0" has shared file "tmp.txt" with user "user1"
When user "user0" updates the last share using the sharing API with
| permissions | 3 |
Then as user "user1" file "/tmp.txt" should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "3"
Then as user "user1" file "/tmp.txt" should contain a property "ocs:share-permissions" with value "3"
Examples:
| dav-path |
| old |
Expand All @@ -71,8 +71,8 @@ Feature: sharing
| permissions | 3 |
| shareWith | grp1 |
When user "user1" gets the following properties of file "/tmp.txt" using the WebDAV API
| {http://open-collaboration-services.org/ns}share-permissions |
Then the single response should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "3"
| ocs:share-permissions |
Then the single response should contain a property "ocs:share-permissions" with value "3"
Examples:
| dav-path |
| old |
Expand All @@ -84,7 +84,7 @@ Feature: sharing
And user "user0" has shared file "tmp.txt" with user "user1"
When user "user0" updates the last share using the sharing API with
| permissions | 17 |
Then as user "user1" file "/tmp.txt" should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "17"
Then as user "user1" file "/tmp.txt" should contain a property "ocs:share-permissions" with value "17"
Examples:
| dav-path |
| old |
Expand All @@ -101,8 +101,8 @@ Feature: sharing
| permissions | 17 |
| shareWith | grp1 |
When user "user1" gets the following properties of file "/tmp.txt" using the WebDAV API
| {http://open-collaboration-services.org/ns}share-permissions |
Then the single response should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "17"
| ocs:share-permissions |
Then the single response should contain a property "ocs:share-permissions" with value "17"
Examples:
| dav-path |
| old |
Expand All @@ -112,8 +112,8 @@ Feature: sharing
Given using <dav-path> DAV path
And user "user0" has created folder "/tmp"
When user "user0" gets the following properties of folder "/" using the WebDAV API
| {http://open-collaboration-services.org/ns}share-permissions |
Then the single response should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "31"
| ocs:share-permissions |
Then the single response should contain a property "ocs:share-permissions" with value "31"
Examples:
| dav-path |
| old |
Expand All @@ -124,8 +124,8 @@ Feature: sharing
And user "user0" has created folder "/tmp"
And user "user0" has shared file "/tmp" with user "user1"
When user "user1" gets the following properties of folder "/tmp" using the WebDAV API
| {http://open-collaboration-services.org/ns}share-permissions |
Then the single response should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "31"
| ocs:share-permissions |
Then the single response should contain a property "ocs:share-permissions" with value "31"
Examples:
| dav-path |
| old |
Expand All @@ -141,8 +141,8 @@ Feature: sharing
| shareType | 1 |
| shareWith | grp1 |
When user "user1" gets the following properties of folder "/tmp" using the WebDAV API
| {http://open-collaboration-services.org/ns}share-permissions |
Then the single response should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "31"
| ocs:share-permissions |
Then the single response should contain a property "ocs:share-permissions" with value "31"
Examples:
| dav-path |
| old |
Expand All @@ -154,7 +154,7 @@ Feature: sharing
And user "user0" has shared file "/tmp" with user "user1"
When user "user0" updates the last share using the sharing API with
| permissions | 29 |
Then as user "user1" folder "/tmp" should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "29"
Then as user "user1" folder "/tmp" should contain a property "ocs:share-permissions" with value "29"
Examples:
| dav-path |
| old |
Expand All @@ -171,8 +171,8 @@ Feature: sharing
| shareWith | grp1 |
| permissions | 29 |
When user "user1" gets the following properties of folder "/tmp" using the WebDAV API
| {http://open-collaboration-services.org/ns}share-permissions |
Then the single response should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "29"
| ocs:share-permissions |
Then the single response should contain a property "ocs:share-permissions" with value "29"
Examples:
| dav-path |
| old |
Expand All @@ -184,7 +184,7 @@ Feature: sharing
And user "user0" has shared file "/tmp" with user "user1"
When user "user0" updates the last share using the sharing API with
| permissions | 27 |
Then as user "user1" folder "/tmp" should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "27"
Then as user "user1" folder "/tmp" should contain a property "ocs:share-permissions" with value "27"
Examples:
| dav-path |
| old |
Expand All @@ -201,8 +201,8 @@ Feature: sharing
| shareWith | grp1 |
| permissions | 27 |
When user "user1" gets the following properties of folder "/tmp" using the WebDAV API
| {http://open-collaboration-services.org/ns}share-permissions |
Then the single response should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "27"
| ocs:share-permissions |
Then the single response should contain a property "ocs:share-permissions" with value "27"
Examples:
| dav-path |
| old |
Expand All @@ -214,7 +214,7 @@ Feature: sharing
And user "user0" has shared file "/tmp" with user "user1"
When user "user0" updates the last share using the sharing API with
| permissions | 23 |
Then as user "user1" folder "/tmp" should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "23"
Then as user "user1" folder "/tmp" should contain a property "ocs:share-permissions" with value "23"
Examples:
| dav-path |
| old |
Expand All @@ -231,8 +231,8 @@ Feature: sharing
| shareWith | grp1 |
| permissions | 23 |
When user "user1" gets the following properties of folder "/tmp" using the WebDAV API
| {http://open-collaboration-services.org/ns}share-permissions |
Then the single response should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "23"
| ocs:share-permissions |
Then the single response should contain a property "ocs:share-permissions" with value "23"
Examples:
| dav-path |
| old |
Expand All @@ -244,7 +244,7 @@ Feature: sharing
And user "user0" has shared file "/tmp" with user "user1"
When user "user0" updates the last share using the sharing API with
| permissions | 15 |
Then as user "user1" folder "/tmp" should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "15"
Then as user "user1" folder "/tmp" should contain a property "ocs:share-permissions" with value "15"
Examples:
| dav-path |
| old |
Expand All @@ -261,8 +261,8 @@ Feature: sharing
| shareWith | grp1 |
| permissions | 15 |
When user "user1" gets the following properties of folder "/tmp" using the WebDAV API
| {http://open-collaboration-services.org/ns}share-permissions |
Then the single response should contain a property "{http://open-collaboration-services.org/ns}share-permissions" with value "15"
| ocs:share-permissions |
Then the single response should contain a property "ocs:share-permissions" with value "15"
Examples:
| dav-path |
| old |
Expand Down
Loading

0 comments on commit 5ff595c

Please sign in to comment.