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