class AcquiadamAssetTest in Media: Acquia DAM 8
Tests to validate that the Media source plugin works as expected.
@group media_acquiadam
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\media_acquiadam\Unit\AcquiadamAssetTest uses AcquiadamAssetDataTrait
Expanded class hierarchy of AcquiadamAssetTest
File
- tests/
src/ Unit/ AcquiadamAssetTest.php, line 24
Namespace
Drupal\Tests\media_acquiadam\UnitView source
class AcquiadamAssetTest extends UnitTestCase {
use AcquiadamAssetDataTrait, AcquiadamConfigTrait, AcquiadamMockedMediaEntityTrait;
/**
* Container builder helper.
*
* @var \Drupal\Core\DependencyInjection\ContainerBuilder
*/
protected $container;
/**
* Media: Acquia DAM media source.
*
* @var \Drupal\media_acquiadam\Plugin\media\Source\AcquiadamAsset
*/
protected $acquiadamMediaSource;
/**
* Validate that we can get generated metadata.
*/
public function testGetMetadata() {
$media = $this
->getMockedMediaEntity($this
->getAssetData()->id);
$this
->assertEquals('media:acquiadam:' . $media
->uuid(), $this->acquiadamMediaSource
->getMetadata($media, 'default_name'));
$this
->assertEquals($this
->getMockedFileEntity()
->id(), $this->acquiadamMediaSource
->getMetadata($media, 'file'));
}
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$entity_type_manager = $this
->getMockBuilder(EntityTypeManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$entity_field_manager = $this
->getMockBuilder(EntityFieldManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$field_type_plugin_manager = $this
->getMockBuilder(FieldTypePluginManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$asset_image_helper = $this
->getMockBuilder(AssetImageHelper::class)
->disableOriginalConstructor()
->getMock();
$asset_metadata_helper = $this
->getMockBuilder(AssetMetadataHelper::class)
->disableOriginalConstructor()
->getMock();
$asset_media_helper = $this
->getMockBuilder(MediaEntityHelper::class)
->disableOriginalConstructor()
->getMock();
$asset_media_helper
->method('getAsset')
->willReturn($this
->getAssetData());
$asset_media_helper
->method('getFile')
->willReturn($this
->getMockedFileEntity());
$asset_media_factory = $this
->getMockBuilder(AssetMediaFactory::class)
->disableOriginalConstructor()
->getMock();
$asset_media_factory
->method('get')
->willReturn($asset_media_helper);
$this->container = new ContainerBuilder();
$this->container
->set('entity_type.manager', $entity_type_manager);
$this->container
->set('entity_field.manager', $entity_field_manager);
$this->container
->set('plugin.manager.field.field_type', $field_type_plugin_manager);
$this->container
->set('config.factory', $this
->getConfigFactoryStub());
$this->container
->set('media_acquiadam.asset_image.helper', $asset_image_helper);
$this->container
->set('media_acquiadam.asset_metadata.helper', $asset_metadata_helper);
$this->container
->set('media_acquiadam.asset_media.factory', $asset_media_factory);
\Drupal::setContainer($this->container);
$this->acquiadamMediaSource = AcquiadamAsset::create($this->container, [
'source_field' => 'field_acquiadam_asset_id',
], 'acquiadam_asset', []);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AcquiadamAssetDataTrait:: |
protected | function | Create a new version of a given asset. | |
AcquiadamAssetDataTrait:: |
protected | function | Returns an Asset object for testing against. | |
AcquiadamAssetTest:: |
protected | property | Media: Acquia DAM media source. | |
AcquiadamAssetTest:: |
protected | property | Container builder helper. | |
AcquiadamAssetTest:: |
protected | function |
Overrides UnitTestCase:: |
|
AcquiadamAssetTest:: |
public | function | Validate that we can get generated metadata. | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |