You are here

protected function MediaMigrationAssertionsForMediaSourceTrait::assertMedia3FieldValues in Media Migration 8

Assertions of media 3.

Assert "red.jpeg" image media properties with alt, title and integer.

5 calls to MediaMigrationAssertionsForMediaSourceTrait::assertMedia3FieldValues()
DrushWithCoreMigrationsFromMediaTest::testAllMigrationWithDrush in tests/src/Functional/DrushWithCoreMigrationsFromMediaTest.php
Test all migrations with Drush and Migrate Tools.
DrushWithCoreMigrationsFromMediaTest::testMigrationWithDrush in tests/src/Functional/DrushWithCoreMigrationsFromMediaTest.php
Test media migrations with Drush and Migrate Tools.
DrushWithMigrateUpgradeFromMediaTest::testMigrationWithDrush in tests/src/Functional/DrushWithMigrateUpgradeFromMediaTest.php
Tests migrations with Migrate Upgrade, Drush and Migrate Tools.
MediaMigrationTest::testMediaMigration in tests/src/Kernel/Migrate/MediaMigrationTest.php
Tests the migration of media entities.
MigrateMediaTest::testMediaMigrate in tests/src/Functional/MigrateMediaTest.php
Tests the result of the media migration.

File

tests/src/Traits/MediaMigrationAssertionsForMediaSourceTrait.php, line 100

Class

MediaMigrationAssertionsForMediaSourceTrait
Trait for media migration tests.

Namespace

Drupal\Tests\media_migration\Traits

Code

protected function assertMedia3FieldValues() {
  $media3 = $this->container
    ->get('entity_type.manager')
    ->getStorage('media')
    ->load(3);
  assert($media3 instanceof MediaInterface);
  $this
    ->assertEquals('red.jpeg', $media3
    ->label());
  $this
    ->assertEquals('image', $media3
    ->bundle());

  // Check 'field media image' field.
  $media3_image = $this
    ->getReferencedEntities($media3, 'field_media_image', 1);
  assert($media3_image[0] instanceof FileInterface);
  $this
    ->assertEquals('3', $media3_image[0]
    ->id());
  $this
    ->assertEquals('3', $media3->field_media_image->target_id);

  // Alt and title properties should be migrated to the corresponding media
  // image field and have to be editable on the UI.
  $this
    ->assertEquals('Alternative text about red.jpeg', $media3->field_media_image->alt);
  $this
    ->assertEquals('Title copy for red.jpeg', $media3->field_media_image->title);
  $this
    ->assertEquals('333', $media3->field_media_integer->value);

  // The following fields should not be present.
  $this
    ->assertFalse($media3
    ->hasField('field_file_image_alt_text'));
  $this
    ->assertFalse($media3
    ->hasField('field_file_image_title_text'));

  // Author should be user 1.
  $this
    ->assertEquals('1', $media3
    ->getOwnerId());

  // Assert authored on date.
  $this
    ->assertEquals('1587726037', $media3
    ->getCreatedTime());

  // The image file should exist.
  $this
    ->assertTrue(file_exists($media3_image[0]
    ->getFileUri()));
}