@@ -355,9 +355,11 @@ public function getResourceId(string $user, string $spaceName, string $folderNam
355355 $ this ->featureContext ->getPasswordForUser ($ user ),
356356 ['Depth ' => '0 ' ],
357357 );
358- $ responseArray = json_decode (json_encode ($ this ->featureContext ->getResponseXml ($ response )->xpath ("//d:response/d:propstat/d:prop/oc:fileid " )), true , 512 , JSON_THROW_ON_ERROR );
359- Assert::assertNotEmpty ($ responseArray , "the PROPFIND response for $ folderName is empty " );
360- return $ responseArray [0 ][0 ];
358+
359+ $ this ->featureContext ->theHttpStatusCodeShouldBe (207 , '' , $ response );
360+ $ xmlResponse = $ this ->featureContext ->getResponseXml ($ response );
361+ $ fileId = $ xmlResponse ->xpath ("//d:response/d:propstat/d:prop/oc:fileid " )[0 ];
362+ return $ fileId ->__toString ();
361363 }
362364
363365 /**
@@ -3701,9 +3703,8 @@ public function userSendsPropfindRequestToSpaceUsingTheWebdavApi(string $user, s
37013703 * @throws GuzzleException
37023704 */
37033705 public function userSendsPropfindRequestFromTheSpaceToTheResourceWithDepthUsingTheWebdavApi (string $ user , string $ spaceName , string $ resource , ?string $ folderDepth = "1 " ): void {
3704- $ this ->featureContext ->setResponse (
3705- $ this ->sendPropfindRequestToSpace ($ user , $ spaceName , $ resource , null , $ folderDepth )
3706- );
3706+ $ response = $ this ->sendPropfindRequestToSpace ($ user , $ spaceName , $ resource , null , $ folderDepth );
3707+ $ this ->featureContext ->setResponse ($ response );
37073708 }
37083709
37093710 /**
@@ -3768,6 +3769,16 @@ public function sendPropfindRequestToSpace(string $user, string $spaceName, ?str
37683769 'd:lockdiscovery ' ,
37693770 'd:activelock '
37703771 ];
3772+
3773+ $ davPathVersion = $ this ->featureContext ->getDavPathVersion ();
3774+ if ($ spaceName === 'Shares ' && $ davPathVersion !== WebDavHelper::DAV_VERSION_SPACES ) {
3775+ if ($ resource === '' || $ resource === '/ ' ) {
3776+ $ resource = $ spaceName ;
3777+ } else {
3778+ $ resource = $ spaceName . '/ ' . $ resource ;
3779+ }
3780+ }
3781+
37713782 return WebDavHelper::propfind (
37723783 $ this ->featureContext ->getBaseUrl (),
37733784 $ this ->featureContext ->getActualUsername ($ user ),
@@ -3777,127 +3788,110 @@ public function sendPropfindRequestToSpace(string $user, string $spaceName, ?str
37773788 $ this ->featureContext ->getStepLineRef (),
37783789 $ folderDepth ,
37793790 "files " ,
3780- $ this -> featureContext -> getDavPathVersion () ,
3791+ $ davPathVersion ,
37813792 null ,
37823793 $ headers
37833794 );
37843795 }
37853796
37863797 /**
3787- * @Then /^the "([^"]*)" response should contain a space "([^"]*)" with these key and value pairs:$/
3788- *
3789- * @param string $method # method should be either PROPFIND or REPORT
3790- * @param string $space
3791- * @param TableNode $table
3792- *
3793- * @return void
3794- * @throws GuzzleException
3795- * @throws JsonException
3796- */
3797- public function theResponseShouldContainSpace (string $ method , string $ space , TableNode $ table ): void {
3798- $ this ->featureContext ->verifyTableNodeColumns ($ table , ['key ' , 'value ' ]);
3799- $ this ->theResponseShouldContain ($ method , $ this ->getSpaceCreator ($ space ), $ space , $ table );
3800- }
3801-
3802- /**
3803- * @Then /^the "([^"]*)" response to user "([^"]*)" should contain a mountpoint "([^"]*)" with these key and value pairs:$/
3804- * @Then /^the "([^"]*)" response to user "([^"]*)" should contain a space "([^"]*)" with these key and value pairs:$/
3798+ * @Then /^as user "([^"]*)" the (PROPFIND|REPORT) response should contain a (mountpoint|space) "([^"]*)" with these key and value pairs:$/
38053799 *
3806- * @param string $method # method should be either PROPFIND or REPORT
38073800 * @param string $user
3801+ * @param string $method # method should be either PROPFIND or REPORT
3802+ * @param string $type # type should be either mountpoint or space
38083803 * @param string $mountPoint
38093804 * @param TableNode $table
38103805 *
38113806 * @return void
38123807 * @throws GuzzleException
38133808 * @throws JsonException
38143809 */
3815- public function theResponseShouldContainMountPoint (string $ method , string $ user , string $ mountPoint , TableNode $ table ): void {
3810+ public function asUsertheXMLResponseShouldContainMountpointWithTheseKeyAndValuePair (string $ user , string $ method , string $ type , string $ mountPoint , TableNode $ table ): void {
38163811 $ this ->featureContext ->verifyTableNodeColumns ($ table , ['key ' , 'value ' ]);
3817- $ this ->theResponseShouldContain ($ method , $ user , $ mountPoint , $ table );
3812+ if ($ this ->featureContext ->getDavPathVersion () === WebDavHelper::DAV_VERSION_SPACES && $ type === 'space ' ) {
3813+ $ space = $ this ->getSpaceByName ($ user , $ mountPoint );
3814+ $ mountPoint = $ space ['id ' ];
3815+ } else {
3816+ $ mountPoint = \rawurlencode ($ mountPoint );
3817+ }
3818+ $ this ->theXMLResponseShouldContain ($ mountPoint , $ table );
38183819 }
38193820
38203821 /**
3821- * @param string $method # method should be either PROPFIND or REPORT
3822- * @param string $user
38233822 * @param string $spaceNameOrMountPoint # an entity inside a space, or the space name itself
38243823 * @param TableNode $table
38253824 *
38263825 * @return void
38273826 * @throws GuzzleException
38283827 * @throws JsonException
38293828 */
3830- public function theResponseShouldContain (string $ method , string $ user , string $ spaceNameOrMountPoint , TableNode $ table ): void {
3831- $ xmlRes = $ this ->featureContext ->getResponseXml ();
3829+ public function theXMLResponseShouldContain (string $ spaceNameOrMountPoint , TableNode $ table ): void {
3830+ $ xmlResponse = $ this ->featureContext ->getResponseXml ();
3831+ $ hrefs = array_map (fn ($ href ) => $ href ->__toString (), $ xmlResponse ->xpath ("//d:response/d:href " ));
3832+
3833+ $ currentHref = '' ;
3834+ foreach ($ hrefs as $ href ) {
3835+ if (\str_ends_with (\rtrim ($ href , "/ " ), "/ $ spaceNameOrMountPoint " )) {
3836+ $ currentHref = $ href ;
3837+ break ;
3838+ }
3839+ }
3840+
38323841 foreach ($ table ->getHash () as $ row ) {
3833- $ findItem = $ row ['key ' ];
3834- $ xmlResponses = $ xmlRes ->xpath ("//d:response/ d:propstat/d:prop/ $ findItem " );
3842+ $ itemToFind = $ row ['key ' ];
3843+ $ foundXmlItem = $ xmlResponse ->xpath ("//d:href[text()=' $ currentHref ']/following-sibling:: d:propstat// $ itemToFind " );
38353844 Assert::assertNotEmpty (
3836- $ xmlResponses ,
3837- 'The xml response " ' . $ xmlRes ->asXML () . '" did not contain "< ' . $ findItem . '>" element '
3845+ $ foundXmlItem ,
3846+ 'The xml response " ' . $ xmlResponse ->asXML () . '" did not contain "< ' . $ itemToFind . '>" element '
38383847 );
38393848
3840- $ responseValues = [];
3841- foreach ($ xmlResponses as $ xmlResponse ) {
3842- $ responseValues [] = $ xmlResponse [0 ]->__toString ();
3843- }
3849+ $ actualValue = $ foundXmlItem [0 ]->__toString ();
3850+ $ expectedValue = $ this ->featureContext ->substituteInLineCodes ($ row ['value ' ]);
38443851
3845- $ value = str_replace ('UUIDof: ' , '' , $ row ['value ' ]);
3846- switch ($ findItem ) {
3852+ switch ($ itemToFind ) {
38473853 case "oc:fileid " :
3848- $ resourceType = $ xmlRes ->xpath ("//d:response/d:propstat/d:prop/d:getcontenttype " )[0 ]->__toString ();
3849- if ($ method === 'PROPFIND ' ) {
3850- if (!$ resourceType ) {
3851- Assert::assertContainsEquals ($ this ->getResourceId ($ user , $ spaceNameOrMountPoint , $ value ), $ responseValues , 'wrong fileId in the response ' );
3852- } else {
3853- Assert::assertContainsEquals ($ this ->getFileId ($ user , $ spaceNameOrMountPoint , $ value ), $ responseValues , 'wrong fileId in the response ' );
3854- }
3855- } else {
3856- if ($ resourceType === 'httpd/unix-directory ' ) {
3857- Assert::assertContainsEquals ($ this ->getResourceId ($ user , $ spaceNameOrMountPoint , $ value ), $ responseValues , 'wrong fileId in the response ' );
3858- } else {
3859- Assert::assertContainsEquals ($ this ->getFileId ($ user , $ spaceNameOrMountPoint , $ value ), $ responseValues , 'wrong fileId in the response ' );
3860- }
3861- }
3854+ $ expectedValue = GraphHelper::sanitizeRegexPattern ($ expectedValue );
3855+ Assert::assertRegExp ($ expectedValue , $ actualValue , 'wrong "fileid" in the response ' );
38623856 break ;
38633857 case "oc:file-parent " :
3864- Assert::assertContainsEquals ($ this ->getResourceId ($ user , $ spaceNameOrMountPoint , $ value ), $ responseValues , 'wrong file-parentId in the response ' );
3858+ $ expectedValue = GraphHelper::sanitizeRegexPattern ($ expectedValue );
3859+ Assert::assertRegExp ($ expectedValue , $ actualValue , 'wrong "file-parent" in the response ' );
38653860 break ;
38663861 case "oc:privatelink " :
3867- Assert::assertContainsEquals ($ this ->getPrivateLink ($ user , $ spaceNameOrMountPoint ), $ responseValues , 'cannot find private link for space or resource in the response ' );
3862+ $ expectedValue = GraphHelper::sanitizeRegexPattern ($ expectedValue );
3863+ Assert::assertRegExp ($ expectedValue , $ actualValue , 'wrong "privatelink" in the response ' );
38683864 break ;
38693865 case "oc:tags " :
38703866 // The value should be a comma-separated string of tag names.
38713867 // We do not care what order they happen to be in, so compare as sorted lists.
3872- $ expectedTags = \explode (", " , $ value );
3868+ $ expectedTags = \explode (", " , $ expectedValue );
38733869 \sort ($ expectedTags );
38743870 $ expectedTags = \implode (", " , $ expectedTags );
3875- $ actualTags = [];
3876- foreach ($ responseValues as $ responseValue ) {
3877- $ responseValue = \explode (", " , $ responseValue );
3878- \sort ($ responseValue );
3879- $ responseValue = \implode (", " , $ responseValue );
3880- $ actualTags [] = $ responseValue ;
3881- }
3882- Assert::assertContainsEquals ($ expectedTags , $ actualTags , "wrong $ findItem in the response " );
3871+
3872+ $ actualTags = \explode (", " , $ actualValue );
3873+ \sort ($ actualTags );
3874+ $ actualTags = \implode (", " , $ actualValue );
3875+ Assert::assertEquals ($ expectedTags , $ actualTags , "wrong ' $ itemToFind' in the response " );
38833876 break ;
38843877 case "d:lockdiscovery/d:activelock/d:timeout " :
3885- if ($ value === "Infinity " ) {
3886- Assert::assertContainsEquals ( $ value , $ responseValues , "wrong $ findItem in the response " );
3878+ if ($ expectedValue === "Infinity " ) {
3879+ Assert::assertEquals ( $ expectedValue , $ actualValue , "wrong ' $ itemToFind ' in the response " );
38873880 } else {
38883881 // some time may be required between a lock and propfind request.
3889- $ responseValue = explode ('- ' , $ responseValues [ 0 ] );
3882+ $ responseValue = explode ('- ' , $ actualValue );
38903883 $ responseValue = \intval ($ responseValue [1 ]);
3891- $ value = explode ('- ' , $ value );
3892- $ value = \intval ($ value [1 ]);
3893- Assert::assertTrue ($ responseValue >= ($ value - 3 ));
3884+ $ expectedValue = explode ('- ' , $ expectedValue );
3885+ $ expectedValue = \intval ($ expectedValue [1 ]);
3886+ Assert::assertTrue ($ responseValue >= ($ expectedValue - 3 ));
38943887 }
38953888 break ;
38963889 case "oc:remote-item-id " :
3897- Assert::assertContainsEquals ($ this ->getResourceId ($ user , $ spaceNameOrMountPoint , $ value ), $ responseValues , 'wrong remoteItemId in the response ' );
3890+ $ expectedValue = GraphHelper::sanitizeRegexPattern ($ expectedValue );
3891+ Assert::assertRegExp ($ expectedValue , $ actualValue , 'wrong "remote-item-id" in the response ' );
38983892 break ;
38993893 default :
3900- Assert::assertContainsEquals ( $ value , $ responseValues , "wrong $ findItem in the response " );
3894+ Assert::assertEquals ( $ expectedValue , $ actualValue , "wrong ' $ itemToFind ' in the response " );
39013895 break ;
39023896 }
39033897 }
0 commit comments