Skip to content

Commit

Permalink
Add support for renameFolder Admin API
Browse files Browse the repository at this point in the history
  • Loading branch information
const-cloudinary committed May 16, 2024
1 parent 5967558 commit ab1b9cb
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Api/Admin/FoldersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
47 changes: 47 additions & 0 deletions tests/Unit/Admin/FoldersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/**
* This file is part of the Cloudinary PHP package.
*
* (c) Cloudinary
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Cloudinary\Test\Unit\Admin;

use Cloudinary\Api\Exception\ApiError;
use Cloudinary\Configuration\Configuration;
use Cloudinary\Test\Helpers\MockAdminApi;
use Cloudinary\Test\Helpers\RequestAssertionsTrait;
use Cloudinary\Test\Unit\UnitTestCase;

/**
* Class FoldersTest
*/
final class FoldersTest extends UnitTestCase
{
use RequestAssertionsTrait;

/**
* Test rename folder.
*
* @throws ApiError
*/
public function testRenameFolder()
{
$mockAdminApi = new MockAdminApi();
$mockAdminApi->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,
]
);
}
}

0 comments on commit ab1b9cb

Please sign in to comment.