AcquiadamNotificationTest.php in Media: Acquia DAM 8
File
tests/src/Kernel/AcquiadamNotificationTest.php
View source
<?php
namespace Drupal\Tests\media_acquiadam\Kernel;
use cweagans\webdam\Entity\Asset;
use Drupal\media\Entity\Media;
class AcquiadamNotificationTest extends AcquiadamKernelTestBase {
protected function setUp() {
parent::setUp();
$this
->enableNotificationSync();
}
public function testNotifications() {
$test_asset_data = [
[
'id' => 3455969,
'filename' => 'file1.jpg',
'bundle' => self::DEFAULT_BUNDLE,
],
[
'id' => 3455970,
'filename' => 'file2.jpg',
'bundle' => 'acquia_dam_other_asset',
],
[
'id' => 3455971,
'filename' => 'file3.jpg',
'bundle' => self::DEFAULT_BUNDLE,
],
];
$asset_ids_to_update = [
3455969,
3455970,
];
$mids = [];
foreach ($test_asset_data as $test_asset) {
$bundle = $test_asset['bundle'];
unset($test_asset['bundle']);
$this->testClient
->addAsset($this
->getAssetData($test_asset));
$mids[] = $this
->createMedia($test_asset['id'], $bundle)
->id();
}
foreach ($asset_ids_to_update as $asset_id) {
$this
->generateNewVersionAndNotify($this->testClient
->getAsset($asset_id));
}
$this->container
->get('cron')
->run();
foreach (Media::loadMultiple($mids) as $media) {
$asset_id = (int) $media
->get('field_acquiadam_asset_id')
->getString();
$asset = $this->testClient
->getAsset($asset_id);
$this
->assertEqual($media
->label(), $asset->filename, 'Media entity updated correctly.');
}
}
protected function enableNotificationSync() {
$config_factory = $this->container
->get('config.factory');
$config = $config_factory
->getEditable('media_acquiadam.settings');
$config
->set('sync_interval', -1);
$config
->set('notifications_sync', 1);
$config
->save(TRUE);
}
protected function generateNewVersionAndNotify(Asset $asset) {
$this
->generateNewVersion($asset);
$this->testClient
->addNotification([
'action' => 'asset_version',
'source' => [
'type' => 'asset',
'id' => $asset->id,
],
]);
}
}