@@ -917,6 +917,69 @@ public function userMovesNewChunkFileWithIdToMychunkedfileWithSize($user, $id, $
917917 }
918918
919919
920+ /**
921+ * @Given creating a new public chunking upload with id :id
922+ */
923+ public function creatingANewPublicChunkingUploadWithId (string $ id ): void {
924+ $ this ->makePublicUploadsDavRequest ('MKCOL ' , '/ ' . $ id );
925+ }
926+
927+ /**
928+ * @Given uploading new public chunk file :num with :data to id :id
929+ */
930+ public function uploadingNewPublicChunkFileWithToId (string $ num , string $ data , string $ id ): void {
931+ $ this ->makePublicUploadsDavRequest ('PUT ' , '/ ' . $ id . '/ ' . $ num , [], \GuzzleHttp \Psr7 \Utils::streamFor ($ data ));
932+ }
933+
934+ /**
935+ * @When moving new public chunk file with id :id to :dest
936+ */
937+ public function movingNewPublicChunkFileWithIdTo (string $ id , string $ dest ): void {
938+ $ this ->makePublicUploadsDavRequest ('MOVE ' , '/ ' . $ id . '/.file ' , [
939+ 'Destination ' => $ this ->getPublicDavFilesUrl () . $ dest ,
940+ ]);
941+ }
942+
943+ /**
944+ * @When copying new public chunk file with id :id to :dest
945+ */
946+ public function copyingNewPublicChunkFileWithIdTo (string $ id , string $ dest ): void {
947+ $ this ->makePublicUploadsDavRequest ('COPY ' , '/ ' . $ id . '/.file ' , [
948+ 'Destination ' => $ this ->getPublicDavFilesUrl () . $ dest ,
949+ ]);
950+ }
951+
952+ private function getLastShareToken (): string {
953+ if (count ($ this ->lastShareData ->data ->element ) > 0 ) {
954+ return (string )$ this ->lastShareData ->data [0 ]->token ;
955+ }
956+ return (string )$ this ->lastShareData ->data ->token ;
957+ }
958+
959+ private function getPublicDavFilesUrl (): string {
960+ return substr ($ this ->baseUrl , 0 , -4 ) . 'public.php/dav/files/ ' . $ this ->getLastShareToken ();
961+ }
962+
963+ /**
964+ * Performs a request on the public chunked upload endpoint of the last created share
965+ */
966+ private function makePublicUploadsDavRequest (string $ method , string $ path , array $ headers = [], $ body = null ): void {
967+ $ fullUrl = substr ($ this ->baseUrl , 0 , -4 ) . 'public.php/dav/uploads/ ' . $ this ->getLastShareToken () . $ path ;
968+ // Non GET requests on the public DAV endpoint require the AJAX header
969+ $ headers ['X-Requested-With ' ] = 'XMLHttpRequest ' ;
970+
971+ $ client = new GClient ();
972+ try {
973+ $ this ->response = $ client ->request ($ method , $ fullUrl , [
974+ 'headers ' => $ headers ,
975+ 'body ' => $ body ,
976+ ]);
977+ } catch (\GuzzleHttp \Exception \BadResponseException $ e ) {
978+ // 4xx and 5xx responses cause an exception
979+ $ this ->response = $ e ->getResponse ();
980+ }
981+ }
982+
920983 /**
921984 * @Given user :user creates a new chunking v2 upload with id :id and destination :targetDestination
922985 */
0 commit comments