diff --git a/tests/TestHelpers/WebDavHelper.php b/tests/TestHelpers/WebDavHelper.php index 7e4e0761e587..bfe4ad4eec95 100644 --- a/tests/TestHelpers/WebDavHelper.php +++ b/tests/TestHelpers/WebDavHelper.php @@ -27,6 +27,7 @@ use GuzzleHttp\Stream\StreamInterface; use InvalidArgumentException; use Sabre\DAV\Client as SClient; +use SimpleXMLElement; /** * Helper to make WebDav Requests @@ -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 @@ -97,10 +106,17 @@ public static function propfind( ) { $headers = ['Depth' => $folderDepth]; $body = ' - + '; foreach ($properties as $property) { - $body .= ""; + //if no namespace is given in the property add the default one + if (\strpos($property, ":") === false) { + $property = "d:$property"; + } + $body .= "<$property/>"; } $body .= ''; @@ -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 diff --git a/tests/acceptance/features/apiComments/comments.feature b/tests/acceptance/features/apiComments/comments.feature index 073581302de4..a79eb90651ef 100644 --- a/tests/acceptance/features/apiComments/comments.feature +++ b/tests/acceptance/features/apiComments/comments.feature @@ -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" diff --git a/tests/acceptance/features/apiShareManagement/mergeShare.feature b/tests/acceptance/features/apiShareManagement/mergeShare.feature index 058a5dfb9e7f..b34d552c1fd0 100644 --- a/tests/acceptance/features/apiShareManagement/mergeShare.feature +++ b/tests/acceptance/features/apiShareManagement/mergeShare.feature @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 \ No newline at end of file diff --git a/tests/acceptance/features/apiShareOperations/getWebDAVSharePermissions.feature b/tests/acceptance/features/apiShareOperations/getWebDAVSharePermissions.feature index 3680c9b4b4e3..32ac3037e747 100644 --- a/tests/acceptance/features/apiShareOperations/getWebDAVSharePermissions.feature +++ b/tests/acceptance/features/apiShareOperations/getWebDAVSharePermissions.feature @@ -11,8 +11,8 @@ Feature: sharing Given using 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 | @@ -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 | @@ -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 | @@ -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 | @@ -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 | @@ -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 | @@ -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 | @@ -112,8 +112,8 @@ Feature: sharing Given using 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 | @@ -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 | @@ -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 | @@ -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 | @@ -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 | @@ -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 | @@ -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 | @@ -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 | @@ -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 | @@ -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 | @@ -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 | diff --git a/tests/acceptance/features/bootstrap/CommandLine.php b/tests/acceptance/features/bootstrap/CommandLine.php index 13fd8d4a5772..5fd7d2c8f9d1 100644 --- a/tests/acceptance/features/bootstrap/CommandLine.php +++ b/tests/acceptance/features/bootstrap/CommandLine.php @@ -20,6 +20,7 @@ */ use TestHelpers\SetupHelper; +use TestHelpers\WebDavHelper; require __DIR__ . '/../../../../lib/composer/autoload.php'; @@ -502,22 +503,19 @@ public function theOccCommandJsonOutputShouldNotReturnAnyData() { */ public function findLastTransferFolderForUser($sourceUser, $targetUser) { $foundPaths = []; - $results = $this->listFolder($targetUser, '', 1); - foreach ($results as $path => $data) { - $path = \rawurldecode($path); + $responseXmlObject = $this->listFolder($targetUser, '', 1); + $transferredElements = $responseXmlObject->xpath( + "//d:response/d:href[contains(., '/transferred%20from%20$sourceUser%20on%')]" + ); + foreach ($transferredElements as $transferredElement) { + $path = \rawurldecode($transferredElement); $parts = \explode(' ', $path); - if (\basename($parts[0]) !== 'transferred') { - continue; - } - if (isset($parts[2]) && $parts[2] === $sourceUser) { - // store timestamp as key - $foundPaths[] = [ - 'date' => \strtotime(\trim($parts[4], '/')), - 'path' => $path, - ]; - } + // store timestamp as key + $foundPaths[] = [ + 'date' => \strtotime(\trim($parts[4], '/')), + 'path' => $path, + ]; } - if (empty($foundPaths)) { return null; } diff --git a/tests/acceptance/features/bootstrap/FavoritesContext.php b/tests/acceptance/features/bootstrap/FavoritesContext.php index f1535a6f78b8..2241ff9d1897 100644 --- a/tests/acceptance/features/bootstrap/FavoritesContext.php +++ b/tests/acceptance/features/bootstrap/FavoritesContext.php @@ -199,7 +199,7 @@ public function theUserUnfavoritesElement($path) { * @return void */ public function asUserTheFileOrFolderShouldBeFavorited($user, $path, $expectedValue = 1) { - $property = "{http://owncloud.org/ns}favorite"; + $property = "oc:favorite"; $this->featureContext->asUserFolderShouldContainAPropertyWithValue( $user, $path, $property, $expectedValue ); diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 8a0a0557731e..04891b3f82e8 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -87,6 +87,13 @@ trait WebDav { * @var array */ private $responseXml = []; + + /** + * response content parsed into a SimpleXMLElement + * + * @var SimpleXMLElement + */ + private $responseXmlObject; private $httpRequestTimeout = 0; @@ -955,9 +962,7 @@ public function jobStatusValuesShouldMatchRegEx($user, $table) { public function userGetsThePropertiesOfFolder( $user, $path ) { - $this->response = $this->listFolder( - $user, $path, 0, [] - ); + $this->responseXmlObject = $this->listFolder($user, $path, 0); } /** @@ -978,9 +983,7 @@ public function userGetsPropertiesOfFolder( $properties[] = $row[0]; } } - $this->response = $this->listFolder( - $user, $path, 0, $properties - ); + $this->responseXmlObject = $this->listFolder($user, $path, 0, $properties); } /** @@ -1100,7 +1103,7 @@ public function asFileOrFolderShouldNotExist($user, $entry, $path) { */ public function asFileOrFolderShouldExist($user, $entry, $path) { $path = $this->substituteInLineCodes($path); - $this->response = $this->listFolder($user, $path, 0); + $this->responseXmlObject = $this->listFolder($user, $path, 0); try { $this->thePropertiesResponseShouldContainAnEtag(); } catch (\Exception $e) { @@ -1117,7 +1120,10 @@ public function asFileOrFolderShouldExist($user, $entry, $path) { * @throws \Exception */ public function thePropertiesResponseShouldContainAnEtag() { - if (!\is_array($this->response) || !isset($this->response['{DAV:}getetag'])) { + $xmlPart = $this->responseXmlObject->xpath("//d:prop/d:getetag"); + if (!\is_array($xmlPart) + || !\preg_match("/^\"[a-f0-9]{1,32}\"$/", $xmlPart[0]->__toString()) + ) { throw new \Exception( "getetag not found in response" ); @@ -1154,36 +1160,20 @@ public function theSingleResponseShouldContainAPropertyWithValue( public function theSingleResponseShouldContainAPropertyWithValueAndAlternative( $key, $expectedValue, $altExpectedValue ) { - $keys = $this->response; - if (!\array_key_exists($key, $keys)) { - throw new \Exception( - "Cannot find property \"$key\" with \"$expectedValue\"" - ); - } - - $value = $keys[$key]; - if ($value instanceof ResourceType) { - $value = $value->getValue(); - if (empty($value)) { - $value = ''; - } else { - $value = $value[0]; - } - } + $xmlPart = $this->responseXmlObject->xpath("//d:prop/$key"); + PHPUnit_Framework_Assert::assertTrue( + isset($xmlPart[0]), "Cannot find property \"$key\"" + ); + $value = $xmlPart[0]->__toString(); if ($expectedValue === "a_comment_url") { $basePath = \ltrim($this->getBasePath() . "/", "/"); $expected = "#^/{$basePath}remote.php/dav/comments/files/([0-9]+)$#"; - if (\preg_match($expected, $value)) { - return; - } else { - throw new \Exception( - "Property \"$key\" found with value \"$value\", expected \"$expectedValue\"" - ); - } - } - - if ($value != $expectedValue && $value != $altExpectedValue) { + PHPUnit_Framework_Assert::assertRegExp( + $expected, $value, + "Property \"$key\" found with value \"$value\", expected \"$expectedValue\"" + ); + } elseif ($value != $expectedValue && $value != $altExpectedValue) { throw new \Exception( "Property \"$key\" found with value \"$value\", expected \"$expectedValue\"" ); @@ -1204,9 +1194,7 @@ public function theSingleResponseShouldContainAPropertyWithValueAndAlternative( public function asUserFolderShouldContainAPropertyWithValueOrWithValue( $user, $path, $property, $expectedValue, $altExpectedValue ) { - $this->response = $this->listFolder( - $user, $path, 0, [$property] - ); + $this->responseXmlObject = $this->listFolder($user, $path, 0, [$property]); $this->theSingleResponseShouldContainAPropertyWithValueAndAlternative( $property, $expectedValue, $altExpectedValue ); @@ -1305,24 +1293,20 @@ public function theResponseShouldContainAnEmptyProperty($property) { * @param int $folderDepth requires 1 to see elements without children * @param array|null $properties * - * @return array|\Sabre\HTTP\ResponseInterface + * @return SimpleXMLElement */ public function listFolder($user, $path, $folderDepth, $properties = null) { - $client = $this->getSabreClient($user); - if (!$properties) { - $properties = [ - '{DAV:}getetag' - ]; - } - - try { - $response = $client->propfind( - $this->makeSabrePath($user, $path), $properties, $folderDepth - ); - } catch (Sabre\HTTP\ClientHttpException $e) { - $response = $e->getResponse(); + if ($this->customDavPath !== null) { + $path = $this->customDavPath . $path; } - return $response; + + return WebDavHelper::listFolder( + $this->getBaseUrl(), + $this->getActualUsername($user), + $this->getPasswordForUser($user), + $path, $folderDepth, $properties, + "files", ($this->usingOldDavPath) ? 1 : 2 + ); } /** @@ -1395,16 +1379,22 @@ public function checkElementList( '$expectedElements has to be an instance of TableNode' ); } - $elementList = $this->listFolder($user, '/', 3); + $responseXmlObject = $this->listFolder($user, "/", 3); $elementRows = $elements->getRows(); $elementsSimplified = $this->simplifyArray($elementRows); foreach ($elementsSimplified as $expectedElement) { $webdavPath = "/" . $this->getFullDavFilesPath($user) . $expectedElement; - if (!\array_key_exists($webdavPath, $elementList) && $expectedToBeListed) { + $element = $responseXmlObject->xpath( + "//d:response/d:href[text() = \"$webdavPath\"]" + ); + if ($expectedToBeListed + && (!isset($element[0]) || $element[0]->__toString() !== $webdavPath) + ) { PHPUnit_Framework_Assert::fail( "$webdavPath is not in propfind answer but should" ); - } elseif (\array_key_exists($webdavPath, $elementList) && !$expectedToBeListed) { + } elseif (!$expectedToBeListed && isset($element[0]) + ) { PHPUnit_Framework_Assert::fail( "$webdavPath is in propfind answer but should not be" ); @@ -2290,12 +2280,12 @@ public function encodePath($path) { * @return void */ public function userStoresEtagOfElement($user, $path) { - $propertiesTable = new TableNode([['{DAV:}getetag']]); + $propertiesTable = new TableNode([['getetag']]); $this->userGetsPropertiesOfFolder( $user, $path, $propertiesTable ); - $pathETAG[$path] = $this->response['{DAV:}getetag']; - $this->storedETAG[$user] = $pathETAG; + $xmlPart = $this->responseXmlObject->xpath("//d:prop/d:getetag"); + $this->storedETAG[$user][$path] = $xmlPart[0]->__toString(); } /** @@ -2307,12 +2297,13 @@ public function userStoresEtagOfElement($user, $path) { * @return void */ public function etagOfElementOfUserShouldNotHaveChanged($path, $user) { - $propertiesTable = new TableNode([['{DAV:}getetag']]); + $propertiesTable = new TableNode([['getetag']]); $this->userGetsPropertiesOfFolder( $user, $path, $propertiesTable ); + $xmlPart = $this->responseXmlObject->xpath("//d:prop/d:getetag"); PHPUnit_Framework_Assert::assertEquals( - $this->response['{DAV:}getetag'], $this->storedETAG[$user][$path] + $xmlPart[0]->__toString(), $this->storedETAG[$user][$path] ); } @@ -2325,12 +2316,13 @@ public function etagOfElementOfUserShouldNotHaveChanged($path, $user) { * @return void */ public function etagOfElementOfUserShouldHaveChanged($path, $user) { - $propertiesTable = new TableNode([['{DAV:}getetag']]); + $propertiesTable = new TableNode([['getetag']]); $this->userGetsPropertiesOfFolder( $user, $path, $propertiesTable ); + $xmlPart = $this->responseXmlObject->xpath("//d:prop/d:getetag"); PHPUnit_Framework_Assert::assertNotEquals( - $this->response['{DAV:}getetag'], $this->storedETAG[$user][$path] + $xmlPart[0]->__toString(), $this->storedETAG[$user][$path] ); } @@ -2437,15 +2429,13 @@ public function headersShouldMatchRegularExpressions(TableNode $table) { * @return void */ public function userDeletesEverythingInFolder($user, $folder) { - $elementList = $this->listFolder($user, $folder, 1); + $responseXmlObject = $this->listFolder($user, folder, 1); + $elementList = $responseXmlObject->xpath("//d:response/d:href"); if (\is_array($elementList) && \count($elementList)) { - $elementListKeys = \array_keys($elementList); - \array_shift($elementListKeys); + \array_shift($elementList); //don't delete the folder itself $davPrefix = "/" . $this->getFullDavFilesPath($user); - foreach ($elementListKeys as $element) { - if (\substr($element, 0, \strlen($davPrefix)) == $davPrefix) { - $element = \substr($element, \strlen($davPrefix)); - } + foreach ($elementList as $element) { + $element = \substr($element, \strlen($davPrefix)); $this->userDeletesFile($user, $element); } }