You are here

public function AcquiadamMediaTest::testAssetFileIsCorrect in Media: Acquia DAM 8

Tests if updating multiple revisionable entities.

See DAM-157 for context.

File

tests/src/Kernel/AcquiadamMediaTest.php, line 138

Class

AcquiadamMediaTest
Tests Media entities with Media: Acquia DAM source.

Namespace

Drupal\Tests\media_acquiadam\Kernel

Code

public function testAssetFileIsCorrect() {

  // Store the unchanged FID and create a new revision.
  $expected_fid = $this
    ->getAssetFileEntity($this->media)
    ->id();
  $this
    ->createNewMediaRevision();

  // Create other media entity to test if its asset file won't be referenced
  // by first media entity.
  $other_asset = $this
    ->getAssetData([
    'id' => 3455970,
    'filename' => 'other_file.jpg',
  ]);
  $this->testClient
    ->addAsset($other_asset);
  $other_media = $this
    ->createMedia($other_asset->id);
  $other_file = $this
    ->getAssetFileEntity($other_media);

  // Create a new version for intial asset and re-save corresponding media
  // entity to test if file was updated correctly.
  $this
    ->saveNewVersion();

  // Re-loads FID to assert it's unchanged.
  $actual_fid = $this
    ->getAssetFileEntity($this->media)
    ->id();
  $this
    ->assertEqual($actual_fid, $expected_fid, 'First media entity still has reference to the expected file.');

  // Asserts second media file is still correct.
  $this
    ->assertEqual($other_file
    ->getFileUri(), $this
    ->getAssetUri($other_asset, $other_media), 'Second media entity still has the expected URI.');
}