protected function AssetMediaFactoryTest::setUp in Media: Acquia DAM 8
Overrides UnitTestCase::setUp
File
- tests/
src/ Unit/ AssetMediaFactoryTest.php, line 189
Class
- AssetMediaFactoryTest
- Class AssetMediaFactoryTest.
Namespace
Drupal\Tests\media_acquiadam\UnitCode
protected function setUp() {
parent::setUp();
$asset = $this
->getAssetData();
$this->mediaEntity = $this
->getMockedMediaEntity($asset->id);
$media_bundle = $this
->getMockBuilder(MediaTypeInterface::class)
->disableOriginalConstructor()
->getMock();
$media_bundle
->method('getSource')
->willReturn($this->mediaEntity
->getSource());
$media_bundle
->method('getFieldMap')
->willReturn([
'file' => 'phpunit_file_field',
]);
$entity_storage = $this
->getMockBuilder(EntityStorageInterface::class)
->disableOriginalConstructor()
->getMock();
$entity_storage
->method('loadByProperties')
->with([
'source' => 'acquiadam_asset',
])
->willReturn([
'acquiadam_asset' => $media_bundle,
'acquiadam_image' => $media_bundle,
]);
$entity_storage
->method('load')
->willReturnMap([
[
$this->mediaEntity
->id(),
$this->mediaEntity,
],
[
$this
->getMockedFileEntity()
->id(),
$this
->getMockedFileEntity(),
],
[
'acquiadam',
$media_bundle,
],
]);
$entity_type_manager = $this
->getMockBuilder(EntityTypeManagerInterface::class)
->disableOriginalConstructor()
->getMock();
$entity_type_manager
->method('getStorage')
->willReturnMap([
[
'media_type',
$entity_storage,
],
[
'media',
$entity_storage,
],
[
'file',
$entity_storage,
],
]);
$asset_data = $this
->getMockBuilder(AssetDataInterface::class)
->disableOriginalConstructor()
->getMock();
$acquiadam_client = $this
->getMockBuilder(AcquiadamInterface::class)
->disableOriginalConstructor()
->getMock();
$asset_file_helper = $this
->getMockBuilder(AssetFileEntityHelper::class)
->disableOriginalConstructor()
->getMock();
$this->container = new ContainerBuilder();
$this->container
->set('entity_type.manager', $entity_type_manager);
$this->container
->set('media_acquiadam.asset_data', $asset_data);
$this->container
->set('media_acquiadam.acquiadam', $acquiadam_client);
$this->container
->set('media_acquiadam.asset_file.helper', $asset_file_helper);
\Drupal::setContainer($this->container);
$this->assetMediaFactory = $this
->getMockBuilder(AssetMediaFactory::class)
->setConstructorArgs([
$this->container
->get('entity_type.manager'),
])
->setMethods([
'getMediaBundleFields',
])
->getMock();
$this->assetMediaFactory
->method('getMediaBundleFields')
->willReturnMap([
[
'acquiadam_asset',
'phpunit_asset_id_field',
$asset->id,
[
$this->mediaEntity
->getRevisionId() => $this->mediaEntity
->id(),
],
],
[
'acquiadam_image',
'phpunit_asset_id_field',
$asset->id,
[
$this->mediaEntity
->getRevisionId() => $this->mediaEntity
->id(),
],
],
]);
}