-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for access keys management in Account Provisioning API
- Loading branch information
1 parent
1c7d6c4
commit 268a290
Showing
8 changed files
with
261 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?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\Helpers; | ||
|
||
use Cloudinary\Api\Provisioning\AccountApi; | ||
|
||
/** | ||
* Class MockAccountApi | ||
*/ | ||
class MockAccountApi extends AccountApi | ||
{ | ||
use MockApiTrait; | ||
|
||
/** | ||
* MockSearchApi constructor. | ||
* | ||
* @param mixed $configuration | ||
*/ | ||
public function __construct($configuration = null) | ||
{ | ||
parent::__construct($configuration); | ||
|
||
$this->accountApiClient = new MockAccountApiClient($configuration); | ||
} | ||
|
||
/** | ||
* Returns a mock api client. | ||
* | ||
* @return MockAccountApiClient | ||
*/ | ||
public function getApiClient() | ||
{ | ||
return $this->accountApiClient; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?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\Helpers; | ||
|
||
use Cloudinary\Api\Provisioning\AccountApiClient; | ||
|
||
/** | ||
* Class MockApiClient | ||
*/ | ||
class MockAccountApiClient extends AccountApiClient | ||
{ | ||
use MockApiClientTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace Cloudinary\Test\Unit\Provisioning; | ||
|
||
use Cloudinary\Test\Helpers\MockAccountApi; | ||
use Cloudinary\Test\Helpers\RequestAssertionsTrait; | ||
|
||
/** | ||
* Class AccessKeysTest | ||
*/ | ||
class AccessKeysTest extends ProvisioningUnitTestCase | ||
{ | ||
use RequestAssertionsTrait; | ||
|
||
const SUB_ACCOUNT_ID = 'sub_account123'; | ||
const API_KEY = 'key'; | ||
|
||
/** | ||
* Should allow listing access keys. | ||
*/ | ||
public function testAccessKeys() | ||
{ | ||
$mockAccApi = new MockAccountApi(); | ||
|
||
$mockAccApi->accessKeys( | ||
self::SUB_ACCOUNT_ID, | ||
['page_size' => 2, 'page' => 1, 'sort_by' => 'name', 'sort_order' => 'asc'] | ||
); | ||
|
||
$lastRequest = $mockAccApi->getMockHandler()->getLastRequest(); | ||
|
||
self::assertAccountRequestUrl($lastRequest, '/sub_accounts/' . self::SUB_ACCOUNT_ID . '/access_keys'); | ||
|
||
self::assertRequestGet($lastRequest); | ||
|
||
self::assertRequestQueryStringSubset($lastRequest, ['page_size' => '2']); | ||
self::assertRequestQueryStringSubset($lastRequest, ['page' => '1']); | ||
self::assertRequestQueryStringSubset($lastRequest, ['sort_by' => 'name']); | ||
self::assertRequestQueryStringSubset($lastRequest, ['sort_order' => 'asc']); | ||
} | ||
|
||
/** | ||
* Should allow generating access keys. | ||
*/ | ||
public function testGenerateAccessKey() | ||
{ | ||
$mockAccApi = new MockAccountApi(); | ||
|
||
$mockAccApi->generateAccessKey( | ||
self::SUB_ACCOUNT_ID, | ||
['enabled' => true, 'name' => 'test_key'] | ||
); | ||
|
||
$lastRequest = $mockAccApi->getMockHandler()->getLastRequest(); | ||
|
||
self::assertAccountRequestUrl($lastRequest, '/sub_accounts/' . self::SUB_ACCOUNT_ID . '/access_keys'); | ||
self::assertRequestPost($lastRequest); | ||
|
||
self::assertRequestJsonBodySubset($lastRequest, ['enabled' => true, 'name' => 'test_key']); | ||
} | ||
|
||
/** | ||
* Should allow updating access keys. | ||
*/ | ||
public function testUpdateAccessKey() | ||
{ | ||
$mockAccApi = new MockAccountApi(); | ||
|
||
$mockAccApi->updateAccessKey( | ||
self::SUB_ACCOUNT_ID, | ||
self::API_KEY, | ||
['enabled' => false, 'name' => 'updated_key'] | ||
); | ||
|
||
$lastRequest = $mockAccApi->getMockHandler()->getLastRequest(); | ||
|
||
self::assertAccountRequestUrl( | ||
$lastRequest, | ||
'/sub_accounts/' . self::SUB_ACCOUNT_ID . '/access_keys/' . self::API_KEY | ||
); | ||
self::assertRequestPut($lastRequest); | ||
|
||
self::assertRequestJsonBodySubset($lastRequest, ['enabled' => false, 'name' => 'updated_key']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters