You are here

class AcquiadamAssetTest in Media: Acquia DAM 8

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

@group media_acquiadam

Hierarchy

Expanded class hierarchy of AcquiadamAssetTest

File

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

Namespace

Drupal\Tests\media_acquiadam\Unit
View 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

Namesort descending Modifiers Type Description Overrides
AcquiadamAssetDataTrait::generateNewVersion protected function Create a new version of a given asset.
AcquiadamAssetDataTrait::getAssetData protected function Returns an Asset object for testing against.
AcquiadamAssetTest::$acquiadamMediaSource protected property Media: Acquia DAM media source.
AcquiadamAssetTest::$container protected property Container builder helper.
AcquiadamAssetTest::setUp protected function Overrides UnitTestCase::setUp
AcquiadamAssetTest::testGetMetadata public function Validate that we can get generated metadata.
PhpunitCompatibilityTrait::getMock Deprecated public function Returns a mock object for the specified class using the available method.
PhpunitCompatibilityTrait::setExpectedException Deprecated public function Compatibility layer for PHPUnit 6 to support PHPUnit 4 code.
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root. 1
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName Deprecated protected function Mocks a block with a block plugin. 1
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.