diff --git a/tests/acceptance/features/apiSpacesShares/shareOperations.feature b/tests/acceptance/features/apiSpacesShares/shareOperations.feature index c4a88e010..bcea2a2dd 100644 --- a/tests/acceptance/features/apiSpacesShares/shareOperations.feature +++ b/tests/acceptance/features/apiSpacesShares/shareOperations.feature @@ -19,7 +19,7 @@ Feature: sharing When user "Brian" gets the following properties of file "/tmp.txt" inside space "Shares" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "19" @@ -36,7 +36,7 @@ Feature: sharing When user "Brian" gets the following properties of file "/tmp.txt" inside space "Shares" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "19" @@ -63,7 +63,7 @@ Feature: sharing When user "Brian" gets the following properties of file "/tmp.txt" inside space "Shares" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "3" @@ -90,7 +90,7 @@ Feature: sharing When user "Brian" gets the following properties of file "/tmp.txt" inside space "Shares" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "17" @@ -101,7 +101,7 @@ Feature: sharing When user "Brian" gets the following properties of folder "/tmp" inside space "Shares" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "31" @@ -117,7 +117,7 @@ Feature: sharing When user "Brian" gets the following properties of folder "/tmp" inside space "Shares" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "31" @@ -144,7 +144,7 @@ Feature: sharing When user "Brian" gets the following properties of folder "/tmp" inside space "Shares" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "29" @@ -171,7 +171,7 @@ Feature: sharing When user "Brian" gets the following properties of folder "/tmp" inside space "Shares" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "27" @@ -198,7 +198,7 @@ Feature: sharing When user "Brian" gets the following properties of folder "/tmp" inside space "Shares" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "23" @@ -225,7 +225,7 @@ Feature: sharing When user "Brian" gets the following properties of folder "/tmp" inside space "Shares" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "15" diff --git a/tests/acceptance/features/bootstrap/SpacesContext.php b/tests/acceptance/features/bootstrap/SpacesContext.php index 247cdd466..32302b99f 100644 --- a/tests/acceptance/features/bootstrap/SpacesContext.php +++ b/tests/acceptance/features/bootstrap/SpacesContext.php @@ -2740,8 +2740,8 @@ class SpacesContext implements Context { */ public function userGetsEtagOfElementInASpace(string $user, string $space, string $path) { $this->setSpaceIDByName($user, $space); - $this->webDavPropertiesContext->storeEtagOfElement($user, $path); - return $this->featureContext->getEtagFromResponseXmlObject(); + $xmlObject = $this->webDavPropertiesContext->storeEtagOfElement($user, $path); + return $this->featureContext->getEtagFromResponseXmlObject($xmlObject); } /** @@ -3019,7 +3019,8 @@ class SpacesContext implements Context { TableNode $propertiesTable ):void { $this->setSpaceIDByName($user, $spaceName); - $this->webDavPropertiesContext->userGetsPropertiesOfFolder($user, $resourceName, $propertiesTable); + $response = $this->webDavPropertiesContext->getPropertiesOfFolder($user, $resourceName, $propertiesTable); + $this->featureContext->setResponse($response); } /** diff --git a/tests/acceptance/features/bootstrap/WebDav.php b/tests/acceptance/features/bootstrap/WebDav.php index 8f5b6b3c3..42c3b9e9b 100644 --- a/tests/acceptance/features/bootstrap/WebDav.php +++ b/tests/acceptance/features/bootstrap/WebDav.php @@ -148,11 +148,12 @@ trait WebDav { } /** + * @param SimpleXMLElement|null $xmlObject * * @return string the etag or an empty string if the getetag property does not exist */ - public function getEtagFromResponseXmlObject():string { - $xmlObject = $this->getResponseXmlObject(); + public function getEtagFromResponseXmlObject(?SimpleXMLElement $xmlObject = null): string { + $xmlObject = $xmlObject ?? $this->getResponseXml(); $xmlPart = $xmlObject->xpath("//d:prop/d:getetag"); if (!\is_array($xmlPart) || (\count($xmlPart) === 0)) { return ''; @@ -162,14 +163,11 @@ trait WebDav { /** * - * @param string|null $eTag if null then get eTag from response XML object + * @param string $eTag * * @return boolean */ - public function isEtagValid(?string $eTag = null):bool { - if ($eTag === null) { - $eTag = $this->getEtagFromResponseXmlObject(); - } + public function isEtagValid(string $eTag): bool { if (\preg_match("/^\"[a-f0-9:\.]{1,32}\"$/", $eTag) ) { return true; @@ -1688,7 +1686,7 @@ trait WebDav { $statusCode = $response->getStatusCode(); if ($statusCode < 401 || $statusCode > 404) { try { - $this->responseXmlObject = HttpRequestHelper::getResponseXml( + $responseXml = $this->featureContext->getResponseXml( $response, __METHOD__ ); @@ -1698,10 +1696,10 @@ trait WebDav { ); } Assert::assertTrue( - $this->isEtagValid(), + $this->isEtagValid($this->getEtagFromResponseXmlObject($responseXml)), "$entry '$path' should not exist. But API returned $statusCode without an etag in the body" ); - $isCollection = $this->getResponseXmlObject()->xpath("//d:prop/d:resourcetype/d:collection"); + $isCollection = $responseXml->xpath("//d:prop/d:resourcetype/d:collection"); if (\count($isCollection) === 0) { $actualResourceType = "file"; } else { @@ -1757,7 +1755,7 @@ trait WebDav { ):void { $user = $this->getActualUsername($user); $path = $this->substituteInLineCodes($path); - $this->responseXmlObject = $this->listFolderAndReturnResponseXml( + $responseXml = $this->listFolderAndReturnResponseXml( $user, $path, '0', @@ -1765,16 +1763,15 @@ trait WebDav { $type ); Assert::assertTrue( - $this->isEtagValid(), + $this->isEtagValid($this->getEtagFromResponseXmlObject($responseXml)), "$entry '$path' expected to exist for user $user but not found" ); - $isCollection = $this->getResponseXmlObject()->xpath("//d:prop/d:resourcetype/d:collection"); + $isCollection = $responseXml->xpath("//d:prop/d:resourcetype/d:collection"); if ($entry === "folder") { Assert::assertEquals(\count($isCollection), 1, "Unexpectedly, `$path` is not a folder"); } elseif ($entry === "file") { Assert::assertEquals(\count($isCollection), 0, "Unexpectedly, `$path` is not a file"); } - $this->emptyLastHTTPStatusCodesArray(); } /** @@ -1838,12 +1835,12 @@ trait WebDav { $numEntriesThatExist = 0; foreach ($table->getTable() as $row) { $path = $this->substituteInLineCodes($row[0]); - $this->responseXmlObject = $this->listFolderAndReturnResponseXml( + $responseXml = $this->listFolderAndReturnResponseXml( $user, $path, '0' ); - if ($this->isEtagValid()) { + if ($this->isEtagValid($this->getEtagFromResponseXmlObject($responseXml))) { $numEntriesThatExist = $numEntriesThatExist + 1; } } diff --git a/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php b/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php index 3abf131b8..eaa303738 100644 --- a/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php +++ b/tests/acceptance/features/bootstrap/WebDavPropertiesContext.php @@ -27,6 +27,7 @@ use PHPUnit\Framework\Assert; use TestHelpers\Asserts\WebDav as WebDavTest; use TestHelpers\HttpRequestHelper; use TestHelpers\WebDavHelper; +use Psr\Http\Message\ResponseInterface; require_once 'bootstrap.php'; @@ -55,13 +56,12 @@ class WebDavPropertiesContext implements Context { string $user, string $path ):void { - $this->featureContext->setResponseXmlObject( - $this->featureContext->listFolderAndReturnResponseXml( - $user, - $path, - '0' - ) + $response = $this->featureContext->listFolder( + $user, + $path, + '0' ); + $this->featureContext->setResponse($response); } /** @@ -79,12 +79,39 @@ class WebDavPropertiesContext implements Context { string $path, string $depth ):void { - $this->featureContext->setResponseXmlObject( - $this->featureContext->listFolderAndReturnResponseXml( - $user, - $path, - $depth - ) + $response = $this->featureContext->listFolder( + $user, + $path, + $depth + ); + $this->featureContext->setResponse($response); + } + + /** + * @param string $user + * @param string $path + * @param TableNode|null $propertiesTable + * + * @return ResponseInterface + * @throws Exception + */ + public function getPropertiesOfFolder( + string $user, + string $path, + TableNode $propertiesTable + ): ResponseInterface { + $user = $this->featureContext->getActualUsername($user); + $properties = null; + $this->featureContext->verifyTableNodeColumns($propertiesTable, ["propertyName"]); + $this->featureContext->verifyTableNodeColumnsCount($propertiesTable, 1); + foreach ($propertiesTable->getColumnsHash() as $row) { + $properties[] = $row["propertyName"]; + } + return $this->featureContext->listFolder( + $user, + $path, + "1", + $properties ); } @@ -98,101 +125,16 @@ class WebDavPropertiesContext implements Context { * @return void * @throws Exception */ - public function userGetsPropertiesOfFolder( + public function userGetsFollowingPropertiesOfEntryUsingWebDavApi( string $user, string $path, TableNode $propertiesTable ):void { - $user = $this->featureContext->getActualUsername($user); - $properties = null; - $this->featureContext->verifyTableNodeColumns($propertiesTable, ["propertyName"]); - $this->featureContext->verifyTableNodeColumnsCount($propertiesTable, 1); - foreach ($propertiesTable->getColumnsHash() as $row) { - $properties[] = $row["propertyName"]; - } - $depth = "1"; - $this->featureContext->setResponseXmlObject( - $this->featureContext->listFolderAndReturnResponseXml( - $user, - $path, - $depth, - $properties - ) - ); + $response = $this->getPropertiesOfFolder($user, $path, $propertiesTable); + $this->featureContext->setResponse($response); $this->featureContext->pushToLastStatusCodesArrays(); } - /** - * @param string $user - * @param string $path - * @param TableNode $propertiesTable - * @param string $depth - * - * @return void - * @throws Exception - */ - public function getFollowingCommentPropertiesOfFileUsingWebDAVPropfindApi( - string $user, - string $path, - TableNode $propertiesTable, - string $depth = "1" - ):void { - $properties = null; - $this->featureContext->verifyTableNodeColumns($propertiesTable, ["propertyName"]); - $this->featureContext->verifyTableNodeColumnsCount($propertiesTable, 1); - foreach ($propertiesTable->getColumnsHash() as $row) { - $properties[] = $row["propertyName"]; - } - - $user = $this->featureContext->getActualUsername($user); - $fileId = $this->featureContext->getFileIdForPath($user, $path); - $commentsPath = "/comments/files/$fileId/"; - $this->featureContext->setResponseXmlObject( - $this->featureContext->listFolderAndReturnResponseXml( - $user, - $commentsPath, - $depth, - $properties, - "comments" - ) - ); - } - - /** - * @When user :user gets the following comment properties of file :path using the WebDAV PROPFIND API - * - * @param string $user - * @param string $path - * @param TableNode $propertiesTable - * - * @return void - * @throws Exception - */ - public function userGetsFollowingCommentPropertiesOfFileUsingWebDAVPropfindApi(string $user, string $path, TableNode $propertiesTable) { - $this->getFollowingCommentPropertiesOfFileUsingWebDAVPropfindApi( - $user, - $path, - $propertiesTable - ); - } - - /** - * @When the user gets the following comment properties of file :arg1 using the WebDAV PROPFIND API - * - * @param string $path - * @param TableNode $propertiesTable - * - * @return void - * @throws Exception - */ - public function theUserGetsFollowingCommentPropertiesOfFileUsingWebDAVPropfindApi(string $path, TableNode $propertiesTable) { - $this->getFollowingCommentPropertiesOfFileUsingWebDAVPropfindApi( - $this->featureContext->getCurrentUser(), - $path, - $propertiesTable - ); - } - /** * @When /^the user gets the following properties of (?:file|folder|entry) "([^"]*)" using the WebDAV API$/ * @@ -203,11 +145,12 @@ class WebDavPropertiesContext implements Context { * @throws Exception */ public function theUserGetsPropertiesOfFolder(string $path, TableNode $propertiesTable) { - $this->userGetsPropertiesOfFolder( + $response = $this->getPropertiesOfFolder( $this->featureContext->getCurrentUser(), $path, $propertiesTable ); + $this->featureContext->setResponse($response); } /** @@ -229,18 +172,16 @@ class WebDavPropertiesContext implements Context { $username = $this->featureContext->getActualUsername($username); $this->featureContext->verifyTableNodeColumns($propertiesTable, ['propertyName', 'propertyValue']); $properties = $propertiesTable->getColumnsHash(); - $this->featureContext->setResponse( - WebDavHelper::proppatchWithMultipleProps( - $this->featureContext->getBaseUrl(), - $username, - $this->featureContext->getPasswordForUser($username), - $path, - $properties, - $this->featureContext->getStepLineRef(), - $this->featureContext->getDavPathVersion() - ) + $response = WebDavHelper::proppatchWithMultipleProps( + $this->featureContext->getBaseUrl(), + $username, + $this->featureContext->getPasswordForUser($username), + $path, + $properties, + $this->featureContext->getStepLineRef(), + $this->featureContext->getDavPathVersion() ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe(207, "", $response); } /** @@ -279,6 +220,28 @@ class WebDavPropertiesContext implements Context { ); } + /** + * @param string $path + * @param TableNode $propertiesTable + * + * @return ResponseInterface + * @throws Exception + */ + public function getPropertiesOfEntryFromLastLinkShare(string $path, TableNode $propertiesTable): ResponseInterface { + $user = $this->featureContext->getLastCreatedPublicShareToken(); + $properties = null; + foreach ($propertiesTable->getRows() as $row) { + $properties[] = $row[0]; + } + return $this->featureContext->listFolder( + $user, + $path, + '0', + $properties, + $this->featureContext->getDavPathVersion() === 1 ? "public-files" : "public-files-new" + ); + } + /** * @When /^the public gets the following properties of (?:file|folder|entry) "([^"]*)" in the last created public link using the WebDAV API$/ * @@ -288,21 +251,9 @@ class WebDavPropertiesContext implements Context { * @return void * @throws Exception */ - public function publicGetsThePropertiesOfFolder(string $path, TableNode $propertiesTable):void { - $user = $this->featureContext->getLastCreatedPublicShareToken(); - $properties = null; - foreach ($propertiesTable->getRows() as $row) { - $properties[] = $row[0]; - } - $this->featureContext->setResponseXmlObject( - $this->featureContext->listFolderAndReturnResponseXml( - $user, - $path, - '0', - $properties, - $this->featureContext->getDavPathVersion() === 1 ? "public-files" : "public-files-new" - ) - ); + public function thePublicGetsFollowingPropertiesOfEntryFromLastLinkShare(string $path, TableNode $propertiesTable):void { + $response = $this->getPropertiesOfEntryFromLastLinkShare($path, $propertiesTable); + $this->featureContext->setResponse($response); } /** @@ -312,7 +263,7 @@ class WebDavPropertiesContext implements Context { * @param string $path path on which to set properties to * @param string $propertyValue property value * - * @return void + * @return ResponseInterface * @throws Exception */ public function setPropertyWithNamespaceOfResource( @@ -321,9 +272,9 @@ class WebDavPropertiesContext implements Context { string $namespace, string $path, string $propertyValue - ):void { + ):ResponseInterface { $user = $this->featureContext->getActualUsername($user); - $response = WebDavHelper::proppatch( + return WebDavHelper::proppatch( $this->featureContext->getBaseUrl(), $this->featureContext->getActualUsername($user), $this->featureContext->getUserPassword($user), @@ -334,7 +285,6 @@ class WebDavPropertiesContext implements Context { $namespace, $this->featureContext->getDavPathVersion() ); - $this->featureContext->setResponse($response); } /** @@ -356,13 +306,14 @@ class WebDavPropertiesContext implements Context { string $path, string $propertyValue ):void { - $this->setPropertyWithNamespaceOfResource( + $response = $this->setPropertyWithNamespaceOfResource( $user, $propertyName, $namespace, $path, $propertyValue ); + $this->featureContext->setResponse($response); } /** @@ -384,14 +335,14 @@ class WebDavPropertiesContext implements Context { string $path, string $propertyValue ):void { - $this->setPropertyWithNamespaceOfResource( + $response = $this->setPropertyWithNamespaceOfResource( $user, $propertyName, $namespace, $path, $propertyValue ); - $this->featureContext->theHTTPStatusCodeShouldBeSuccess(); + $this->featureContext->theHTTPStatusCodeShouldBe(207, "", $response); } /** @@ -409,13 +360,10 @@ class WebDavPropertiesContext implements Context { string $namespaceString, string $propertyValue ):void { - $this->featureContext->setResponseXmlObject( - HttpRequestHelper::getResponseXml( - $this->featureContext->getResponse(), - __METHOD__ - ) + $responseXmlObject = $this->featureContext->getResponseXml( + $this->featureContext->getResponse(), + __METHOD__ ); - $responseXmlObject = $this->featureContext->getResponseXmlObject(); //calculate the namespace prefix and namespace $matches = []; \preg_match("/^(.*)='(.*)'$/", $namespaceString, $matches); @@ -458,13 +406,10 @@ class WebDavPropertiesContext implements Context { ):void { // let's unescape quotes first $propertyValue = \str_replace('\"', '"', $propertyValue); - $this->featureContext->setResponseXmlObject( - HttpRequestHelper::getResponseXml( - $this->featureContext->getResponse(), - __METHOD__ - ) + $responseXmlObject = $this->featureContext->getResponseXml( + $this->featureContext->getResponse(), + __METHOD__ ); - $responseXmlObject = $this->featureContext->getResponseXmlObject(); //calculate the namespace prefix and namespace $matches = []; \preg_match("/^(.*)='(.*)'$/", $namespaceString, $matches); @@ -504,7 +449,7 @@ class WebDavPropertiesContext implements Context { string $property, string $childProperty ):void { - $xmlPart = $this->featureContext->getResponseXmlObject()->xpath( + $xmlPart = $this->featureContext->getResponseXml()->xpath( "//d:prop/$property/$childProperty" ); Assert::assertTrue( @@ -526,7 +471,8 @@ class WebDavPropertiesContext implements Context { string $key, string $expectedValue ):void { - $this->checkSingleResponseContainsAPropertyWithValueAndAlternative( + $this->checkResponseContainsAPropertyWithValue( + $this->featureContext->getResponse(), $key, $expectedValue, $expectedValue @@ -548,7 +494,8 @@ class WebDavPropertiesContext implements Context { string $key, string $expectedValue ):void { - $this->checkSingleResponseContainsAPropertyWithValueAndAlternative( + $this->checkResponseContainsAPropertyWithValue( + $this->featureContext->getResponse(), $key, $expectedValue, $expectedValue, @@ -571,7 +518,8 @@ class WebDavPropertiesContext implements Context { string $expectedValue, string $altExpectedValue ):void { - $this->checkSingleResponseContainsAPropertyWithValueAndAlternative( + $this->checkResponseContainsAPropertyWithValue( + $this->featureContext->getResponse(), $key, $expectedValue, $altExpectedValue @@ -579,6 +527,7 @@ class WebDavPropertiesContext implements Context { } /** + * @param ResponseInterface $response * @param string $key * @param string $expectedValue * @param string $altExpectedValue @@ -587,13 +536,15 @@ class WebDavPropertiesContext implements Context { * @return void * @throws Exception */ - public function checkSingleResponseContainsAPropertyWithValueAndAlternative( + public function checkResponseContainsAPropertyWithValue( + ResponseInterface $response, string $key, string $expectedValue, string $altExpectedValue, ?string $user = null ):void { - $xmlPart = $this->featureContext->getResponseXmlObject()->xpath( + $xmlPart = $this->featureContext->getResponseXml($response); + $xmlPart = $xmlPart->xpath( "//d:prop/$key" ); Assert::assertTrue( @@ -666,13 +617,10 @@ class WebDavPropertiesContext implements Context { * @throws Exception */ public function assertValueOfItemInResponseAboutUserIs(string $xpath, ?string $user, string $expectedValue):void { - $resXml = $this->featureContext->getResponseXmlObject(); - if ($resXml === null) { - $resXml = HttpRequestHelper::getResponseXml( - $this->featureContext->getResponse(), - __METHOD__ - ); - } + $resXml = $this->featureContext->getResponseXml( + $this->featureContext->getResponse(), + __METHOD__ + ); $value = $this->getXmlItemByXpath($resXml, $xpath); $user = $this->featureContext->getActualUsername($user); $expectedValue = $this->featureContext->substituteInLineCodes( @@ -706,13 +654,10 @@ class WebDavPropertiesContext implements Context { if (!$expectedValue2) { $expectedValue2 = $expectedValue1; } - $resXml = $this->featureContext->getResponseXmlObject(); - if ($resXml === null) { - $resXml = HttpRequestHelper::getResponseXml( - $this->featureContext->getResponse(), - __METHOD__ - ); - } + $resXml = $this->featureContext->getResponseXml( + $this->featureContext->getResponse(), + __METHOD__ + ); $value = $this->getXmlItemByXpath($resXml, $xpath); $user = $this->featureContext->getActualUsername($user); $expectedValue1 = $this->featureContext->substituteInLineCodes( @@ -763,9 +708,9 @@ class WebDavPropertiesContext implements Context { * @throws Exception */ public function assertValueOfItemInResponseRegExp(string $xpath, string $pattern):void { - $this->assertValueOfItemInResponseToUserRegExp( + $this->assertXpathValueMatchesPattern( + $this->featureContext->getResponseXml(), $xpath, - null, $pattern ); } @@ -782,12 +727,11 @@ class WebDavPropertiesContext implements Context { */ public function publicGetsThePropertiesOfFolderAndAssertValueOfItemInResponseRegExp(string $xpath, string $path, string $pattern):void { $propertiesTable = new TableNode([['propertyName'],['d:lockdiscovery']]); - $this->publicGetsThePropertiesOfFolder($path, $propertiesTable); - - $this->featureContext->theHTTPStatusCodeShouldBe('200'); - $this->assertValueOfItemInResponseToUserRegExp( + $response = $this->getPropertiesOfEntryFromLastLinkShare($path, $propertiesTable); + $this->featureContext->theHTTPStatusCodeShouldBe('207', "", $response); + $this->assertXpathValueMatchesPattern( + $this->featureContext->getResponseXml($response), $xpath, - null, $pattern ); } @@ -802,13 +746,10 @@ class WebDavPropertiesContext implements Context { * @throws Exception */ public function assertEntryWithHrefMatchingRegExpInResponseToUser(string $expectedHref, string $user):void { - $resXml = $this->featureContext->getResponseXmlObject(); - if ($resXml === null) { - $resXml = HttpRequestHelper::getResponseXml( - $this->featureContext->getResponse(), - __METHOD__ - ); - } + $resXml = $this->featureContext->getResponseXml( + $this->featureContext->getResponse(), + __METHOD__ + ); $user = $this->featureContext->getActualUsername($user); $expectedHref = $this->featureContext->substituteInLineCodes( @@ -858,24 +799,16 @@ class WebDavPropertiesContext implements Context { } /** - * @Then the value of the item :xpath in the response to user :user should match :value - * + * @param SimpleXMLElement $responseXml * @param string $xpath - * @param string|null $user * @param string $pattern + * @param string|null $user * * @return void * @throws Exception */ - public function assertValueOfItemInResponseToUserRegExp(string $xpath, ?string $user, string $pattern):void { - $resXml = $this->featureContext->getResponseXmlObject(); - if ($resXml === null) { - $resXml = HttpRequestHelper::getResponseXml( - $this->featureContext->getResponse(), - __METHOD__ - ); - } - $xmlPart = $resXml->xpath($xpath); + public function assertXpathValueMatchesPattern(SimpleXMLElement $responseXml, string $xpath, string $pattern, ?string $user = null): void { + $xmlPart = $responseXml->xpath($xpath); Assert::assertTrue( isset($xmlPart[0]), "Cannot find item with xpath \"$xpath\"" @@ -903,6 +836,22 @@ class WebDavPropertiesContext implements Context { ); } + /** + * @Then the value of the item :xpath in the response to user :user should match :value + * + * @param string $xpath + * @param string|null $user + * @param string $pattern + * @param SimpleXMLElement|null $responseXml + * + * @return void + * @throws Exception + */ + public function theValueOfItemInResponseToUserShouldMatch(string $xpath, ?string $user, string $pattern, ?SimpleXMLElement $responseXml = null):void { + $resXml = $this->featureContext->getResponseXml(); + $this->assertXpathValueMatchesPattern($resXml, $xpath, $pattern, $user); + } + /** * @Then /^as user "([^"]*)" the lock discovery property "([^"]*)" of the (?:file|folder|entry) "([^"]*)" should match "([^"]*)"$/ * @@ -916,17 +865,17 @@ class WebDavPropertiesContext implements Context { */ public function userGetsPropertiesOfFolderAndAssertValueOfItemInResponseToUserRegExp(string $user, string $xpath, string $path, string $pattern):void { $propertiesTable = new TableNode([['propertyName'],['d:lockdiscovery']]); - $this->userGetsPropertiesOfFolder( + $response = $this->getPropertiesOfFolder( $user, $path, $propertiesTable ); - - $this->featureContext->theHTTPStatusCodeShouldBe('200'); - $this->assertValueOfItemInResponseToUserRegExp( + $this->featureContext->theHTTPStatusCodeShouldBe('207', '', $response); + $this->assertXpathValueMatchesPattern( + $this->featureContext->getResponseXml($response), $xpath, - $user, - $pattern + $pattern, + $user ); } @@ -939,7 +888,7 @@ class WebDavPropertiesContext implements Context { * @throws Exception */ public function assertItemInResponseDoesNotExist(string $xpath):void { - $xmlPart = $this->featureContext->getResponseXmlObject()->xpath($xpath); + $xmlPart = $this->featureContext->getResponseXml()->xpath($xpath); Assert::assertFalse( isset($xmlPart[0]), "Found item with xpath \"$xpath\" but it should not exist" @@ -965,15 +914,14 @@ class WebDavPropertiesContext implements Context { string $expectedValue, string $altExpectedValue ):void { - $this->featureContext->setResponseXmlObject( - $this->featureContext->listFolderAndReturnResponseXml( - $user, - $path, - '0', - [$property] - ) + $response = $this->featureContext->listFolder( + $user, + $path, + '0', + [$property] ); - $this->theSingleResponseShouldContainAPropertyWithValueAndAlternative( + $this->checkResponseContainsAPropertyWithValue( + $response, $property, $expectedValue, $altExpectedValue @@ -1019,7 +967,7 @@ class WebDavPropertiesContext implements Context { string $key, string $regex ):void { - $xmlPart = $this->featureContext->getResponseXmlObject()->xpath( + $xmlPart = $this->featureContext->getResponseXml()->xpath( "//d:prop/$key" ); Assert::assertTrue( @@ -1045,7 +993,7 @@ class WebDavPropertiesContext implements Context { public function theResponseShouldContainAShareTypesPropertyWith(TableNode $table):void { $this->featureContext->verifyTableNodeColumnsCount($table, 1); WebdavTest::assertResponseContainsShareTypes( - $this->featureContext->getResponseXmlObject(), + $this->featureContext->getResponseXml(), $table->getRows() ); } @@ -1059,7 +1007,7 @@ class WebDavPropertiesContext implements Context { * @throws Exception */ public function theResponseShouldContainAnEmptyProperty(string $property):void { - $xmlPart = $this->featureContext->getResponseXmlObject()->xpath( + $xmlPart = $this->featureContext->getResponseXml()->xpath( "//d:prop/$property" ); Assert::assertCount( @@ -1078,22 +1026,24 @@ class WebDavPropertiesContext implements Context { * @param string $path * @param string|null $storePath * - * @return void + * @return SimpleXMLElement * @throws Exception */ - public function storeEtagOfElement(string $user, string $path, ?string $storePath = ""):void { + public function storeEtagOfElement(string $user, string $path, ?string $storePath = ""):SimpleXMLElement { if ($storePath === "") { $storePath = $path; } $user = $this->featureContext->getActualUsername($user); $propertiesTable = new TableNode([['propertyName'],['getetag']]); - $this->userGetsPropertiesOfFolder( + $response = $this->getPropertiesOfFolder( $user, $path, $propertiesTable ); + $xmlObject = $this->featureContext->getResponseXml($response); $this->storedETAG[$user][$storePath] - = $this->featureContext->getEtagFromResponseXmlObject(); + = $this->featureContext->getEtagFromResponseXmlObject($xmlObject); + return $xmlObject; } /** @@ -1165,7 +1115,7 @@ class WebDavPropertiesContext implements Context { */ public function thePropertiesResponseShouldContainAnEtag():void { Assert::assertTrue( - $this->featureContext->isEtagValid(), + $this->featureContext->isEtagValid($this->featureContext->getEtagFromResponseXmlObject()), __METHOD__ . " getetag not found in response" ); @@ -1188,7 +1138,7 @@ class WebDavPropertiesContext implements Context { public function theResponseShouldHavePropertyWithValue(string $username, TableNode $expectedPropTable):void { $username = $this->featureContext->getActualUsername($username); $this->featureContext->verifyTableNodeColumns($expectedPropTable, ['resource', 'propertyName', 'propertyValue']); - $responseXmlObject = $this->featureContext->getResponseXmlObject(); + $responseXmlObject = $this->featureContext->getResponseXml(); $hrefSplittedUptoUsername = \explode("/", (string)$responseXmlObject->xpath("//d:href")[0]); $xmlHrefSplittedArray = \array_slice( @@ -1231,12 +1181,12 @@ class WebDavPropertiesContext implements Context { public function getCurrentEtagOfElement(string $path, string $user):string { $user = $this->featureContext->getActualUsername($user); $propertiesTable = new TableNode([['propertyName'],['getetag']]); - $this->userGetsPropertiesOfFolder( + $response = $this->getPropertiesOfFolder( $user, $path, $propertiesTable ); - return $this->featureContext->getEtagFromResponseXmlObject(); + return $this->featureContext->getEtagFromResponseXmlObject($this->featureContext->getResponseXml($response)); } /** diff --git a/tests/acceptance/features/coreApiShareOperationsToShares2/getWebDAVSharePermissions.feature b/tests/acceptance/features/coreApiShareOperationsToShares2/getWebDAVSharePermissions.feature index 57a15e14e..f8915b962 100644 --- a/tests/acceptance/features/coreApiShareOperationsToShares2/getWebDAVSharePermissions.feature +++ b/tests/acceptance/features/coreApiShareOperationsToShares2/getWebDAVSharePermissions.feature @@ -17,7 +17,7 @@ Feature: sharing When user "Alice" gets the following properties of file "/tmp.txt" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "19" Examples: | dav-path-version | @@ -38,7 +38,7 @@ Feature: sharing When user "Brian" gets the following properties of file "/Shares/tmp.txt" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "19" Examples: | dav-path-version | @@ -60,7 +60,7 @@ Feature: sharing When user "Brian" gets the following properties of file "/Shares/tmp.txt" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "19" Examples: | dav-path-version | @@ -97,7 +97,7 @@ Feature: sharing When user "Brian" gets the following properties of file "/Shares/tmp.txt" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "3" Examples: | dav-path-version | @@ -134,7 +134,7 @@ Feature: sharing When user "Brian" gets the following properties of file "/Shares/tmp.txt" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "17" Examples: | dav-path-version | @@ -148,7 +148,7 @@ Feature: sharing When user "Alice" gets the following properties of folder "/" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "31" Examples: | dav-path-version | @@ -169,7 +169,7 @@ Feature: sharing When user "Brian" gets the following properties of folder "/Shares/tmp" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "31" Examples: | dav-path-version | @@ -190,7 +190,7 @@ Feature: sharing When user "Brian" gets the following properties of folder "/Shares/tmp" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "31" Examples: | dav-path-version | @@ -227,7 +227,7 @@ Feature: sharing When user "Brian" gets the following properties of folder "/Shares/tmp" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "29" Examples: | dav-path-version | @@ -264,7 +264,7 @@ Feature: sharing When user "Brian" gets the following properties of folder "/Shares/tmp" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "27" Examples: | dav-path-version | @@ -301,7 +301,7 @@ Feature: sharing When user "Brian" gets the following properties of folder "/Shares/tmp" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "23" Examples: | dav-path-version | @@ -338,7 +338,7 @@ Feature: sharing When user "Brian" gets the following properties of folder "/Shares/tmp" using the WebDAV API | propertyName | | ocs:share-permissions | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the single response should contain a property "ocs:share-permissions" with value "15" Examples: | dav-path-version | diff --git a/tests/acceptance/features/coreApiWebdavProperties1/createFileFolder.feature b/tests/acceptance/features/coreApiWebdavProperties1/createFileFolder.feature index e8960b7cd..ae7e9c400 100644 --- a/tests/acceptance/features/coreApiWebdavProperties1/createFileFolder.feature +++ b/tests/acceptance/features/coreApiWebdavProperties1/createFileFolder.feature @@ -51,7 +51,7 @@ Feature: create files and folder When user "Alice" gets the following properties of folder "/test_folder" using the WebDAV API | propertyName | | d:resourcetype | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "d:resourcetype" with a child property "d:collection" Examples: | dav-path-version | @@ -70,7 +70,7 @@ Feature: create files and folder When user "Alice" gets the following properties of folder "/test_folder:5" using the WebDAV API | propertyName | | d:resourcetype | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "d:resourcetype" with a child property "d:collection" Examples: | dav-path-version | diff --git a/tests/acceptance/features/coreApiWebdavProperties2/getFileProperties.feature b/tests/acceptance/features/coreApiWebdavProperties2/getFileProperties.feature index a2c8eef1b..f2efdd4a6 100644 --- a/tests/acceptance/features/coreApiWebdavProperties2/getFileProperties.feature +++ b/tests/acceptance/features/coreApiWebdavProperties2/getFileProperties.feature @@ -12,7 +12,7 @@ Feature: get file properties Given using DAV path And user "Alice" has uploaded file with content "uploaded content" to "" When user "Alice" gets the properties of file "" using the WebDAV API - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the properties response should contain an etag Examples: | dav-path-version | file_name | @@ -38,7 +38,7 @@ Feature: get file properties Given using DAV path And user "Alice" has uploaded file with content "uploaded content" to "" When user "Alice" gets the properties of file "" using the WebDAV API - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the properties response should contain an etag And there should be an entry with href containing "" in the response to user "Alice" Examples: @@ -67,7 +67,7 @@ Feature: get file properties And user "Alice" has uploaded file with content "uploaded content" to "/file1.txt" And user "Alice" has uploaded file with content "uploaded content" to "/file2.txt" When user "Alice" gets the properties of folder "" with depth 1 using the WebDAV API - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And there should be an entry with href containing "/" in the response to user "Alice" And there should be an entry with href containing "/file1.txt" in the response to user "Alice" And there should be an entry with href containing "/file2.txt" in the response to user "Alice" @@ -105,7 +105,7 @@ Feature: get file properties And user "Alice" has created folder "" And user "Alice" has uploaded file with content "uploaded content" to "/" When user "Alice" gets the properties of file "/" using the WebDAV API - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the properties response should contain an etag Examples: | dav-path-version | folder_name | file_name | @@ -136,7 +136,7 @@ Feature: get file properties And user "Alice" has created folder "/folder ?2.txt" And user "Alice" has uploaded file with content "uploaded content" to "/folder ?2.txt/file ?2.txt" When user "Alice" gets the properties of file "/folder ?2.txt/file ?2.txt" using the WebDAV API - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the properties response should contain an etag Examples: | dav-path-version | @@ -155,7 +155,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "/test" using the WebDAV API | propertyName | | oc:share-types | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the response should contain an empty property "oc:share-types" Examples: | dav-path-version | @@ -180,7 +180,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "/test" using the WebDAV API | propertyName | | oc:share-types | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the response should contain a share-types property with | 0 | Examples: @@ -206,7 +206,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "/test" using the WebDAV API | propertyName | | oc:share-types | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the response should contain a share-types property with | 1 | Examples: @@ -229,7 +229,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "/test" using the WebDAV API | propertyName | | oc:share-types | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the response should contain a share-types property with | 3 | Examples: @@ -264,7 +264,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "/test" using the WebDAV API | propertyName | | oc:share-types | - Then the HTTP status code should be "200" + Then the HTTP status code should be "207" And the response should contain a share-types property with | 0 | | 1 | @@ -286,7 +286,7 @@ Feature: get file properties When user "Alice" gets the following properties of file "/somefile.txt" using the WebDAV API | propertyName | | oc:privatelink | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "oc:privatelink" with value like "%(/(index.php/)?f/[0-9]*)%" Examples: | dav-path-version | @@ -329,7 +329,7 @@ Feature: get file properties | propertyName | | oc:testprop1 | | oc:testprop2 | - Then the HTTP status code should be success + Then the HTTP status code should be "207" And as user "Alice" the last response should have the following properties | resource | propertyName | propertyValue | | /TestFolder/test1.txt | testprop1 | AAAAA | @@ -363,7 +363,7 @@ Feature: get file properties | propertyName | | oc:testprop1 | | oc:testprop2 | - Then the HTTP status code should be success + Then the HTTP status code should be "207" And as user "Alice" the last response should have the following properties | resource | propertyName | propertyValue | | /TestFolder/test1.txt | testprop1 | AAAAA | @@ -388,7 +388,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "/test" using the WebDAV API | propertyName | | d:getlastmodified | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "d:getlastmodified" with value like "/^[MTWFS][uedhfriatno]{2},\s(\d){2}\s[JFMAJSOND][anebrpyulgctov]{2}\s\d{4}\s\d{2}:\d{2}:\d{2} GMT$/" Examples: | dav-path-version | @@ -407,7 +407,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "/test" using the WebDAV API | propertyName | | d:getcontenttype | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "d:getcontenttype" with value "" Examples: | dav-path-version | @@ -426,7 +426,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "file.txt" using the WebDAV API | propertyName | | d:getcontenttype | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "d:getcontenttype" with value "text/plain.*" Examples: | dav-path-version | @@ -445,7 +445,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "file.txt" using the WebDAV API | propertyName | | d:getetag | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "d:getetag" with value like '%\"[a-z0-9:]{1,32}\"%' Examples: | dav-path-version | @@ -464,7 +464,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "file.txt" using the WebDAV API | propertyName | | d:resourcetype | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "d:resourcetype" with value "" Examples: | dav-path-version | @@ -483,7 +483,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "file.txt" using the WebDAV API | propertyName | | oc:size | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "oc:size" with value "16" Examples: | dav-path-version | @@ -502,7 +502,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "/test" using the WebDAV API | propertyName | | oc:size | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "oc:size" with value "0" Examples: | dav-path-version | @@ -521,7 +521,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "file.txt" using the WebDAV API | propertyName | | oc:fileid | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "oc:fileid" with value like '/[a-zA-Z0-9]+/' Examples: | dav-path-version | @@ -540,7 +540,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "/test" using the WebDAV API | propertyName | | oc:fileid | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "oc:fileid" with value like '/[a-zA-Z0-9]+/' Examples: | dav-path-version | @@ -559,7 +559,7 @@ Feature: get file properties When user "Alice" gets the following properties of file "file.txt" using the WebDAV API | propertyName | | oc:owner-display-name | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response about the file owned by "Alice" should contain a property "oc:owner-display-name" with value "%displayname%" Examples: | dav-path-version | @@ -578,7 +578,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "/test" using the WebDAV API | propertyName | | oc:owner-display-name | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response about the file owned by "Alice" should contain a property "oc:owner-display-name" with value "%displayname%" Examples: | dav-path-version | @@ -597,7 +597,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "file.txt" using the WebDAV API | propertyName | | oc:permissions | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "oc:permissions" with value like '/RM{0,1}DNVW/' Examples: | dav-path-version | @@ -616,7 +616,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "/test" using the WebDAV API | propertyName | | oc:permissions | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "oc:permissions" with value like '/RM{0,1}DNVCK/' Examples: | dav-path-version | @@ -640,7 +640,7 @@ Feature: get file properties When user "Alice" gets the following properties of folder "/test" using the WebDAV API | propertyName | | oc:size | - Then the HTTP status code should be "201" + Then the HTTP status code should be "207" And the single response should contain a property "oc:size" with value "5" Examples: | dav-path-version |