@@ -345,14 +345,18 @@ public function userHasCreatedFolder(
345345 continue ;
346346 }
347347 $ fullFolderString .= "/ " . trim ($ folder );
348+ // check if the file or folder already exists
349+ if ($ this ->isElementExist ($ user , $ fullFolderString )) {
350+ continue ;
351+ }
348352 $ this ->response = $ this ->makeDavRequest (
349353 $ user ,
350354 $ this ->regularUserPassword ,
351355 "MKCOL " ,
352356 $ fullFolderString
353357 );
354358 $ this ->theHTTPStatusCodeShouldBe (
355- ["201 " , " 500 " ], // 405 is returned if the folder already exists
359+ ["201 " ],
356360 "HTTP status code was not 201 while trying to create folder ' $ fullFolderString' for user ' $ user' "
357361 );
358362 }
@@ -692,8 +696,8 @@ public function verifyTableNodeColumns(TableNode $table, ?array $requiredHeader
692696 }
693697 }
694698
695- public function getIdOfElement (string $ user , string $ element ): int {
696- $ propfindResponse = $ this ->makeDavRequest (
699+ public function getElementResponse (string $ user , string $ element ): ResponseInterface {
700+ return $ this ->makeDavRequest (
697701 $ user ,
698702 $ this ->regularUserPassword ,
699703 "PROPFIND " ,
@@ -706,14 +710,23 @@ public function getIdOfElement(string $user, string $element): int {
706710 </d:prop>
707711 </d:propfind> '
708712 );
709- $ xmlBody = $ propfindResponse ->getBody ()->getContents ();
710- $ responseXmlObject = new SimpleXMLElement ($ xmlBody );
713+ }
714+
715+ public function getIdOfElement (string $ user , string $ element ): int {
716+ $ propfindResponse = $ this ->getElementResponse ($ user , $ element );
717+ $ this ->theHTTPStatusCodeShouldBe (207 , "" , $ propfindResponse );
718+ $ responseXmlObject = new SimpleXMLElement ($ propfindResponse ->getBody ()->getContents ());
711719 $ responseXmlObject ->registerXPathNamespace (
712720 'oc ' ,
713721 'http://owncloud.org/ns '
714722 );
715723 return (int )(string )$ responseXmlObject ->xpath ('//oc:fileid ' )[0 ];
716724 }
725+
726+ public function isElementExist (string $ user , string $ element ): bool {
727+ return $ this ->getElementResponse ($ user , $ element )->getStatusCode () === 207 ;
728+ }
729+
717730 /**
718731 * @param string $path
719732 * @param string $method
0 commit comments