You are here

protected function MediaMigrationAssertionsForNonMediaSourceTrait::assertNonMediaToMedia10FieldValues in Media Migration 8

Asserts the migration result from file ID 10 to media 10.

5 calls to MediaMigrationAssertionsForNonMediaSourceTrait::assertNonMediaToMedia10FieldValues()
DrushWithCoreMigrationsFromFileTest::testAllMigrationWithDrush in tests/src/Functional/DrushWithCoreMigrationsFromFileTest.php
Test all migrations with Drush and Migrate Tools.
DrushWithCoreMigrationsFromFileTest::testMigrationWithDrush in tests/src/Functional/DrushWithCoreMigrationsFromFileTest.php
Test migrations provided by core Migrate API with Drush and Migrate Tools.
DrushWithMigrateUpgradeFromFileTest::testMigrationWithDrush in tests/src/Functional/DrushWithMigrateUpgradeFromFileTest.php
Tests migrations with Migrate Upgrade, Drush and Migrate Tools.
MediaMigrationPlainTest::testPlainFileToMediaMigration in tests/src/Kernel/Migrate/MediaMigrationPlainTest.php
Tests the migration of plain file and image fields to media reference.
MigrateMediaFromNonMediaSourceTest::testPlainFileToMediaMigration in tests/src/Functional/MigrateMediaFromNonMediaSourceTest.php
Tests the result of the media migration.

File

tests/src/Traits/MediaMigrationAssertionsForNonMediaSourceTrait.php, line 244

Class

MediaMigrationAssertionsForNonMediaSourceTrait
Trait for non-media source to media migration tests.

Namespace

Drupal\Tests\media_migration\Traits

Code

protected function assertNonMediaToMedia10FieldValues() {
  $media = $this->container
    ->get('entity_type.manager')
    ->getStorage('media')
    ->load(10);
  assert($media instanceof MediaInterface);
  $expected_entity_properties = [
    'mid' => [
      [
        'value' => '10',
      ],
    ],
    'bundle' => [
      [
        'target_id' => 'image',
      ],
    ],
    'name' => [
      [
        'value' => 'yellow.webp',
      ],
    ],
    'uid' => [
      [
        'target_id' => '2',
      ],
    ],
    'status' => [
      [
        'value' => '1',
      ],
    ],
    'created' => [
      [
        'value' => '1594368881',
      ],
    ],
    'field_media_image' => [
      [
        'target_id' => '10',
        'alt' => 'Description of yellow.webp',
        'title' => NULL,
        'width' => NULL,
        'height' => NULL,
      ],
    ],
  ];
  $toolkit_manager = $this->container
    ->get('image.toolkit.manager');
  assert($toolkit_manager instanceof ImageToolkitManager);
  $toolkit = $toolkit_manager
    ->getDefaultToolkit();
  if ($toolkit instanceof ImageToolkitInterface && in_array('webp', $toolkit::getSupportedExtensions())) {
    $expected_entity_properties['field_media_image'][0]['width'] = 640;
    $expected_entity_properties['field_media_image'][0]['height'] = 400;
  }
  $this
    ->assertEquals($expected_entity_properties, $this
    ->getImportantEntityProperties($media));

  // Check the media field.
  $media_field = $this
    ->getReferencedEntities($media, 'field_media_image', 1);
  assert($media_field[0] instanceof FileInterface);

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