From ab1b9cbec56160d27c80bdab5005dc63e7059fa0 Mon Sep 17 00:00:00 2001 From: Constantine Nathanson Date: Wed, 8 May 2024 13:38:47 +0300 Subject: [PATCH] Add support for `renameFolder` Admin API --- src/Api/Admin/FoldersTrait.php | 21 ++++++++++++++ tests/Unit/Admin/FoldersTest.php | 47 ++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tests/Unit/Admin/FoldersTest.php diff --git a/src/Api/Admin/FoldersTrait.php b/src/Api/Admin/FoldersTrait.php index 4f149592..7274089f 100644 --- a/src/Api/Admin/FoldersTrait.php +++ b/src/Api/Admin/FoldersTrait.php @@ -87,6 +87,27 @@ public function createFolder($path) return $this->apiClient->post($uri); } + /** + * Renames folder. + * + * @param string $fromPath The full path of an existing asset folder. + * @param string $toPath The full path of the new asset folder. + * + * @return ApiResponse + * + * @throws ApiError + * + * @see https://cloudinary.com/documentation/admin_api#rename_folder + */ + public function renameFolder($fromPath, $toPath) + { + $uri = [ApiEndPoint::FOLDERS, $fromPath]; + + $params = ['to_folder' => $toPath]; + + return $this->apiClient->put($uri, $params); + } + /** * Deletes an empty folder. * diff --git a/tests/Unit/Admin/FoldersTest.php b/tests/Unit/Admin/FoldersTest.php new file mode 100644 index 00000000..f84e561e --- /dev/null +++ b/tests/Unit/Admin/FoldersTest.php @@ -0,0 +1,47 @@ +renameFolder(self::API_TEST_ASSET_ID, self::API_TEST_ASSET_ID2); + + $lastRequest = $mockAdminApi->getMockHandler()->getLastRequest(); + + self::assertRequestPut($lastRequest); + self::assertRequestUrl($lastRequest, '/folders/' . self::API_TEST_ASSET_ID); + self::assertRequestBodySubset( + $lastRequest, + [ + "to_folder" => self::API_TEST_ASSET_ID2, + ] + ); + } +}