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 4, 2019
1 parent fb4b70c commit baef349
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 207 deletions.
39 changes: 11 additions & 28 deletions tests/TestHelpers/Asserts/WebDav.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
namespace TestHelpers\Asserts;

use PHPUnit_Framework_Assert;
use SimpleXMLElement;
use Behat\Gherkin\Node\TableNode;
use \Sabre\HTTP\ResponseInterface as SabreResponseInterface;

/**
* WebDAV related asserts
Expand Down Expand Up @@ -60,38 +60,21 @@ public static function assertDavResponseElementIs(

/**
*
* @param SabreResponseInterface $response
* @param SimpleXMLElement $responseXmlObject
* @param TableNode $expectedShareTypes
*
* @return bool
*
* @throws \Exception
* @return void
*/
public static function assertSabreResponseContainsShareTypes(
$response, $expectedShareTypes
public static function assertResponseContainsShareTypes(
$responseXmlObject, $expectedShareTypes
) {
if (!\array_key_exists('{http://owncloud.org/ns}share-types', $response)) {
throw new \Exception(
"Cannot find property \"{http://owncloud.org/ns}share-types\""
foreach ($expectedShareTypes->getRows() as $row) {
$xmlPart = $responseXmlObject->xpath(
"//d:prop/oc:share-types/oc:share-type[.=" . $row[0] . "]"
);
PHPUnit_Framework_Assert::assertNotEmpty(
$xmlPart, "cannot find share-type '" . $row[0] . "'"
);
}

$foundTypes = [];
$data = $response['{http://owncloud.org/ns}share-types'];
foreach ($data as $item) {
if ($item['name'] !== '{http://owncloud.org/ns}share-type') {
throw new \Exception(
"Invalid property found: '{$item['name']}'"
);
}

//make the multi dimensional array so it looks like TableNode::getRows()
$foundTypes[] = [$item['value']];
}
PHPUnit_Framework_Assert::assertSame(
$expectedShareTypes->getRows(), $foundTypes,
"expected share types do not match the received share types"
);
return true;
}
}
67 changes: 65 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,53 @@ public static function propfind(
return $response;
}

/**
* returns the result parsed into a 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
);
$responseXmlObject = HttpRequestHelper::getResponseXml($response);
$responseXmlObject->registerXPathNamespace('d', 'DAV:');
$responseXmlObject->registerXPathNamespace('oc', 'http://owncloud.org/ns');
$responseXmlObject->registerXPathNamespace(
'ocs', 'http://open-collaboration-services.org/ns'
);
return $responseXmlObject;
}

/**
*
* @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
Loading

0 comments on commit baef349

Please sign in to comment.