You are here

protected function AcquiadamAssetTest::setUp in Media: Acquia DAM 8

Overrides UnitTestCase::setUp

File

tests/src/Unit/AcquiadamAssetTest.php, line 57

Class

AcquiadamAssetTest
Tests to validate that the Media source plugin works as expected.

Namespace

Drupal\Tests\media_acquiadam\Unit

Code

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', []);
}