class BynderApiTest in Bynder 4.0.x
Same name and namespace in other branches
- 8.3 tests/modules/bynder_test_module/src/BynderApiTest.php \Drupal\bynder_test_module\BynderApiTest
- 8 tests/modules/bynder_test_module/src/BynderApiTest.php \Drupal\bynder_test_module\BynderApiTest
- 8.2 tests/modules/bynder_test_module/src/BynderApiTest.php \Drupal\bynder_test_module\BynderApiTest
Bynder API test service.
@package Drupal\bynder
Hierarchy
- class \Drupal\bynder\BynderApi implements BynderApiInterface
- class \Drupal\bynder_test_module\BynderApiTest
Expanded class hierarchy of BynderApiTest
1 file declares its use of BynderApiTest
- UsageTest.php in tests/
src/ Functional/ UsageTest.php
File
- tests/
modules/ bynder_test_module/ src/ BynderApiTest.php, line 14
Namespace
Drupal\bynder_test_moduleView source
class BynderApiTest extends BynderApi {
const BYNDER_INTEGRATION_ID = 'a7129512-c6e3-47a3-be40-9a66503e82ed';
public function getIntegrationId() {
return self::BYNDER_INTEGRATION_ID;
}
/**
* Returns the defined value.
*/
public function getBrands() {
if ($brands = $this->state
->get('bynder.bynder_test_brands')) {
return $brands;
}
throw new RequestException('Test', new Request('test', 'test'));
}
/**
* Returns value set in state.
*
* @param string $media_uuid
* The media UUID.
*
* @return mixed
* Returns what is set in the state.
*/
public function getMediaInfo($media_uuid) {
if ($media_info = $this->state
->get('bynder.bynder_test_media_info')) {
return $media_info;
}
if ($media_list = $this->state
->get('bynder.bynder_test_media_list')) {
foreach ($media_list['media'] as $media_info) {
if ($media_uuid == $media_info['id']) {
return $media_info;
}
}
}
}
/**
* Returns value set in state.
*
* @param array $query
* Search query.
*
* @return mixed
* Returns what is set in the state.
*
* @throws \Exception
* Connection fails.
*/
public function getMediaList(array $query) {
if (!($media_list = $this->state
->get('bynder.bynder_test_media_list'))) {
throw new \Exception();
}
// Filter on keyword.
if (!empty($query['keyword'])) {
foreach ($media_list['media'] as $key => $media) {
if ($query['keyword'] != $media['keyword']) {
unset($media_list['media'][$key]);
}
}
}
// Filter on meta-property options.
$metaproperties = array_filter($query, function ($key) {
return strpos($key, 'property_') === 0;
}, ARRAY_FILTER_USE_KEY);
if ($metaproperties) {
foreach ($metaproperties as $metaproperty => $options) {
$options = explode(',', $options);
foreach ($media_list['media'] as $key => $media) {
if (empty(array_intersect($options, $media[$metaproperty]))) {
unset($media_list['media'][$key]);
}
}
}
}
// Filter on tags.
if (!empty($query['tags'])) {
foreach ($media_list['media'] as $key => $media) {
if (!in_array($query['tags'], $media['tags'])) {
unset($media_list['media'][$key]);
}
}
}
return $media_list;
}
/**
* Returns value set in state.
*/
public function getMetaproperties() {
if (!$this->state
->get('bynder.bynder_test_metaproperties')) {
throw new \Exception();
}
return $this->state
->get('bynder.bynder_test_metaproperties');
}
/**
* Returns value set in state.
*/
public function hasAccessToken() {
if (!$this->state
->get('bynder.bynder_test_access_token')) {
return FALSE;
}
return TRUE;
}
/**
* Returns value set in state.
*/
public function getTags($query = []) {
if (!$this->state
->get('bynder.bynder_test_tags')) {
throw new \Exception();
}
return $this->state
->get('bynder.bynder_test_tags');
}
/**
* Returns value set in state.
*/
public function getDerivatives() {
if (!is_array($this->state
->get('bynder.bynder_test_derivatives'))) {
throw new \Exception();
}
return $this->state
->get('bynder.bynder_test_derivatives');
}
/**
* Returns value set in state.
*
* @param string $media_uuid
* The media UUID.
*
* @return array
* Returns array of expected values.
*/
public function uploadFileAsync($media_uuid) {
return [
'success' => $this->state
->get('bynder.bynder_test_upload_success'),
'mediaid' => $this->state
->get('bynder.bynder_test_upload_mediaid'),
];
}
/**
* Simulate deleting media and returns void.
*
* @param string $media_uuid
* The media UUID.
*/
public function deleteMedia($media_uuid) {
}
/**
* Simulate upload permissions check.
*/
public function hasUploadPermissions() {
return 'MEDIAUPLOAD';
}
/**
* Simulate cache update.
*/
public function updateCachedData() {
}
/**
* Sets values in state.
*
* @param string $integration_id
* The Drupal 8 integration id.
* @param string $asset_id
* The Bynder media id.
* @param string $timestamp
* Current timestamp.
* @param string $location
* Url location for entity that references this asset.
* @param string $additional
* Additional media info.
*/
public function addAssetUsage($asset_id, $usage_url, $creation_date, $additional_info = NULL) {
$values = [
'integration_id' => $this
->getIntegrationId(),
'asset_id' => $asset_id,
'timestamp' => $creation_date,
'location' => $usage_url,
'additional' => $additional_info,
];
$this->state
->set('bynder.bynder_add_usage', $values);
}
/**
* Sets values in state.
*
* @param string $integration_id
* The Drupal 8 integration id.
* @param string $asset_id
* The Bynder media id.
* @param string $location
* Url location for entity that references this asset.
*/
public function removeAssetUsage($asset_id, $usage_url = NULL) {
$values = [
'integration_id' => $this
->getIntegrationId(),
'asset_id' => $asset_id,
'location' => $usage_url,
];
$this->state
->set('bynder.bynder_delete_usage', $values);
}
/**
* {@inheritdoc}
*/
public function getAssetUsages($asset_id) {
return $this->state
->get('bynder.bynder_add_usage');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BynderApi:: |
protected | property | Bynder Api instance. | |
BynderApi:: |
protected | property | Bynder configuration. | |
BynderApi:: |
protected | property | The configuration object. | |
BynderApi:: |
protected | property | The cache service. | |
BynderApi:: |
protected | property | The configuration factory. | |
BynderApi:: |
protected | property | The logger factory. | |
BynderApi:: |
protected | property | The active session. | |
BynderApi:: |
protected | property | The state service. | |
BynderApi:: |
protected | property | The time service. | |
BynderApi:: |
constant | List of getTags queries that are automatically updated in crons. | ||
BynderApi:: |
constant | List of API calls that should be cache with their cache keys as values. | ||
BynderApi:: |
constant | Cache ID used to store the derivatives information. | ||
BynderApi:: |
constant | Cache ID used to store the metaproperties information. | ||
BynderApi:: |
constant | Cache ID used to store the tags information. | ||
BynderApi:: |
public | function |
Finishes the access token retrieval after the user has been redirected. Overrides BynderApiInterface:: |
|
BynderApi:: |
public | function |
Gets an instance of the asset bank manager to use for DAM queries. Overrides BynderApiInterface:: |
1 |
BynderApi:: |
protected | function | ||
BynderApi:: |
protected | function | ||
BynderApi:: |
public | function |
Initiates the access token retrieval. Overrides BynderApiInterface:: |
|
BynderApi:: |
public | function |
Sets the Bynder configuration. Overrides BynderApiInterface:: |
|
BynderApi:: |
public | function | ||
BynderApi:: |
public | function | BynderApi constructor. | |
BynderApiTest:: |
public | function |
Sets values in state. Overrides BynderApi:: |
|
BynderApiTest:: |
constant |
The Bynder integration ID. Overrides BynderApi:: |
||
BynderApiTest:: |
public | function | Simulate deleting media and returns void. | |
BynderApiTest:: |
public | function |
Retrieves all asset usage for a specific asset. Overrides BynderApi:: |
|
BynderApiTest:: |
public | function | Returns the defined value. | |
BynderApiTest:: |
public | function | Returns value set in state. | |
BynderApiTest:: |
public | function |
Overrides BynderApi:: |
|
BynderApiTest:: |
public | function | Returns value set in state. | |
BynderApiTest:: |
public | function | Returns value set in state. | |
BynderApiTest:: |
public | function | Returns value set in state. | |
BynderApiTest:: |
public | function |
Returns value set in state. Overrides BynderApi:: |
|
BynderApiTest:: |
public | function |
Returns value set in state. Overrides BynderApi:: |
|
BynderApiTest:: |
public | function |
Simulate upload permissions check. Overrides BynderApi:: |
|
BynderApiTest:: |
public | function |
Sets values in state. Overrides BynderApi:: |
|
BynderApiTest:: |
public | function |
Simulate cache update. Overrides BynderApi:: |
|
BynderApiTest:: |
public | function | Returns value set in state. |