Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 64 additions & 2 deletions src/Bynder/Api/Impl/AssetBankManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ public function getProfiles()
return $this->requestHandler->sendRequestAsync('GET', 'api/v4/profiles/');
}

/**
* Gets account information
*
* @return \GuzzleHttp\Promise\PromiseInterface
* @throws \Exception
*/
public function getAccount()
{
return $this->requestHandler->sendRequestAsync('GET', "api/v4/account/");
}

/**
* Gets a list of all available brands.
*
Expand Down Expand Up @@ -171,6 +182,42 @@ public function getMetapropertyOptionsById($propertyId, $query)
);
}

/**
* Creates an option for a metaproperty.
*
* @param string $metaPropId
* @param array $data
* @return \GuzzleHttp\Promise\Promise
* @throws \Exception
*/
public function createMetaPropertyOption($metaPropId, $data)
{
return $this->requestHandler->sendRequestAsync(
'POST',
sprintf('api/v4/metaproperties/%s/options/', $metaPropId),
['form_params' => ['data' => json_encode($data)]]
);
}

/**
* Modifies existing metaproperty option.
*
* @param string $metaPropId
* @param string $optionId
* @param array $data
*
* @return \GuzzleHttp\Promise\Promise
* @throws \Exception
*/
public function modifyMetaPropertyOption($metaPropId, $optionId, $data)
{
return $this->requestHandler->sendRequestAsync(
'POST',
sprintf('api/v4/metaproperties/%s/options/%s/', $metaPropId, $optionId),
['form_params' => ['data' => json_encode($data)]]
);
}

/**
* Gets a list of all meta property option dependencies (globally).
*
Expand Down Expand Up @@ -386,7 +433,7 @@ public function getUsage($query)
*
* @param $query
* @return \GuzzleHttp\Promise\Promise
* @throws \GuzzleHttp\Exception\RequestException
* @throws \GuzzleHttp\Exception\RequestException
*/
public function deleteUsage($query)
{
Expand All @@ -395,6 +442,21 @@ public function deleteUsage($query)
);
}

/**
* Synchronizes asset usages
*
* @param array $data
*
* @return mixed
* @throws \Exception
*/
public function syncAssetUsage($data)
{
return $this->requestHandler->sendRequestAsync('POST', 'api/media/usage/sync',
['json' => $data]
);
}

/**
* Gets all collections based on optional query parameters.
*
Expand All @@ -420,4 +482,4 @@ public function getCollectionAssets($collectionId)
{
return $this->requestHandler->sendRequestAsync('GET', "api/v4/collections/$collectionId/media/");
}
}
}
152 changes: 152 additions & 0 deletions tests/AssetBank/AssetBankManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,48 @@ public function testGetProfiles()
self::assertEquals($brands, $returnedBrands);
}

/**
* Test if we call getAccount it will use the correct params for the request and returns successfully.
*
* @group collections
*
* @covers \Bynder\Api\Impl\AssetBankManager::getCollections()
* @throws \Exception
*/
public function testGetAccount()
{
$returnedAccount = [
"availableLanguages" => [
"nl_NL",
"en_GB",
"en_US",
"fr_FR",
"de_DE",
"it_IT",
"es_ES",
"pl_PL",
],
"defaultLanguage" => "en_US",
"name" => "Bynder",
"timeZone" => "Europe/Amsterdam",
"isOpenImageBank" => false,
];

$stub = $this->getMockBuilder('Bynder\Api\Impl\OAuth2\RequestHandler')
->disableOriginalConstructor()
->getMock();

$stub->method('sendRequestAsync')
->with('GET', "api/v4/account/")
->willReturn($returnedAccount);

$assetBankManager = new AssetBankManager($stub);
$account = $assetBankManager->getAccount();

self::assertNotNull($account);
self::assertEquals($account, $returnedAccount);
}

/**
* Test if we call getBrands it will use the correct params for the request and returns successfully.
*
Expand Down Expand Up @@ -548,6 +590,72 @@ public function testGetMetapropertyOptionsById()
self::assertEquals($result, ['query']);
}

/**
* Tests the createMetaPropertyOption function.
*
* @covers \Bynder\Api\Impl\AssetBankManager::createMetaPropertyOption()
* @throws \Exception
*/
public function testCreateMetaPropertyOption()
{
$stub = $this->getMockBuilder('Bynder\Api\Impl\OAuth2\RequestHandler')
->disableOriginalConstructor()
->getMock();

$queryData = [
'name' => 'TEST_NAME',
'externalReference' => 'TEST_EXTERNAL_REFERENCE',
'label' => 'TEST_EXTERNAL_LABEL',
];

$stub->method('sendRequestAsync')
->with('POST', 'api/v4/metaproperties/TEST_METAPROPERTY_ID/options/', [
'form_params' => ['data' => json_encode($queryData)],
])
->willReturn([]);

$assetBankManager = new AssetBankManager($stub);
$result = $assetBankManager->createMetaPropertyOption('TEST_METAPROPERTY_ID', $queryData);

self::assertNotNull($result);
self::assertEquals($result, []);
}

/**
* Tests the modifyMetaPropertyOption function.
*
* @covers \Bynder\Api\Impl\AssetBankManager::createMetaPropertyOption()
* @throws \Exception
*/
public function testModifyMetaPropertyOption()
{
$stub = $this->getMockBuilder('Bynder\Api\Impl\OAuth2\RequestHandler')
->disableOriginalConstructor()
->getMock();

$queryData = [
'name' => 'TEST_NAME',
'externalReference' => 'TEST_EXTERNAL_REFERENCE',
'label' => 'TEST_EXTERNAL_LABEL',
];

$stub->method('sendRequestAsync')
->with('POST', 'api/v4/metaproperties/TEST_METAPROPERTY_ID/options/TEST_OPTION_ID/', [
'form_params' => ['data' => json_encode($queryData)],
])
->willReturn([]);

$assetBankManager = new AssetBankManager($stub);
$result = $assetBankManager->modifyMetaPropertyOption(
'TEST_METAPROPERTY_ID',
'TEST_OPTION_ID',
$queryData
);

self::assertNotNull($result);
self::assertEquals($result, []);
}

/**
* Test if we call getMetapropetryGlobalOptionDependencies it will use the correct params for the request and
* returns successfully.
Expand Down Expand Up @@ -720,6 +828,50 @@ public function testDeleteAssetUsage()
self::assertEquals($result, array());
}

/**
* Tests the syncAssetUsage function.
*
* @covers \Bynder\Api\Impl\AssetBankManager::deleteUsage()
* @throws \Exception
*/
public function testSyncAssetUsage()
{
$stub = $this->getMockBuilder('Bynder\Api\Impl\OAuth2\RequestHandler')
->disableOriginalConstructor()
->getMock();

$queryData = [
'integration_id' => 'TEST_INTEGRATION_ID',
'uris' => ['TEST_URI_1', 'TEST_URI_2', 'TEST_URI_TO_DELETE_1'],
'usages' => [
'integration_id' => 'TEST_INTEGRATION_ID',
'asset_id' => 'TEST_ASSET_ID_1',
'timestamp' => (new \Datetime())->format('Y-m-d\TH:i:s\Z'),
'additional' => 'TEST_ADDITIONAL_DATA_1',
'uri' => 'TEST_URI_1',
],
[
'integration_id' => 'TEST_INTEGRATION_ID',
'asset_id' => 'TEST_ASSET_ID_2',
'timestamp' => (new \Datetime())->format('Y-m-d\TH:i:s\Z'),
'additional' => 'TEST_ADDITIONAL_DATA_2',
'uri' => 'TEST_URI_2',
],
];

$stub->method('sendRequestAsync')
->with('POST', 'api/media/usage/sync', [
'json' => $queryData,
])
->willReturn([]);

$assetBankManager = new AssetBankManager($stub);
$result = $assetBankManager->syncAssetUsage($queryData);

self::assertNotNull($result);
self::assertEquals($result, []);
}

/**
* Test if we call getCollections it will use the correct params for the request and returns successfully.
*
Expand Down