You are here

public function AssetMetadataHelperTest::testGetMetadataFromAsset in Media: Acquia DAM 8

Validate that we can retrieve complicated metadata from assets.

File

tests/src/Unit/AssetMetadataHelperTest.php, line 90

Class

AssetMetadataHelperTest
Tests integration of the AssetMetadataHelper service.

Namespace

Drupal\Tests\media_acquiadam\Unit

Code

public function testGetMetadataFromAsset() {
  $this->assetMetadataHelper
    ->setMetadataXmpFields([
    'xmp_caption' => [
      'name' => 'Caption/Abstract',
      'label' => 'Caption/Description',
      'type' => 'textarea',
    ],
    'xmp_byline' => [
      'name' => 'By-line',
      'label' => 'Photographer',
      'type' => 'text',
    ],
  ]);

  // Check some regular properties.
  $this
    ->assertEquals(3455969, $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'id'));
  $this
    ->assertEquals(4, $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'version'));
  $this
    ->assertEquals('XAAAZZZZZ.jpg', $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'filename'));

  // Check special properties.
  $this
    ->assertEquals(90754, $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'folderID'));
  $this
    ->assertEquals('Image', $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'type'));
  $this
    ->assertNull($this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'status'));

  // Check date properties.
  $this
    ->assertEquals('2017-03-22 18:34:43', $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'datecreated'));
  $this
    ->assertEquals('2017-03-22 18:36:33', $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'datemodified'));
  $this
    ->assertEquals('2013-03-19 14:16:49', $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'datecaptured'));
  $this
    ->assertEquals('2017-03-22T18:34:43', $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'datecreated_date'));
  $this
    ->assertEquals('2017-03-22T18:36:33', $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'datemodified_date'));
  $this
    ->assertEquals('2013-03-19T14:16:49', $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'datecaptured_date'));
  $this
    ->assertEquals(1490207683, $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'datecreated_unix'));
  $this
    ->assertEquals(1490207793, $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'datemodified_unix'));
  $this
    ->assertEquals(1363702609, $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'datecaptured_unix'));

  // Check XMP properties.
  $this
    ->assertEquals('XMP Byline', $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'xmp_byline'));
  $this
    ->assertEquals('XMP Caption', $this->assetMetadataHelper
    ->getMetadataFromAsset($this
    ->getAssetData(), 'xmp_caption'));
}