You are here

public function MediaMigrationTest::testChangeTracking in Media Migration 8

Tests media entity migration with change tracking enabled.

File

tests/src/Kernel/Migrate/MediaMigrationTest.php, line 338

Class

MediaMigrationTest
Tests media migration.

Namespace

Drupal\Tests\media_migration\Kernel\Migrate

Code

public function testChangeTracking() {
  $module_installer = \Drupal::service('module_installer');
  assert($module_installer instanceof ModuleInstallerInterface);
  $module_installer
    ->install([
    'media_migration_test_change_tracking',
  ]);
  $this
    ->testMediaMigration('media_embed', 'uuid', FALSE, [
    [
      'data-entity-type' => 'media',
      'data-entity-uuid' => TRUE,
      'data-view-mode' => 'wysiwyg',
      'alt' => 'Different alternative text about blue.png in the test article',
      'title' => 'Different title copy for blue.png in the test article',
      'data-align' => 'center',
    ],
    [
      'data-entity-type' => 'media',
      'data-entity-uuid' => TRUE,
      'data-view-mode' => 'default',
      'alt' => 'A yellow image',
      'title' => 'This is a yellow image',
    ],
  ], FALSE);

  // Update file with ID 1 (BLUE png).
  $this->sourceDatabase
    ->update('file_managed')
    ->condition('fid', 1)
    ->fields([
    'filename' => 'Blue PNG changed',
  ])
    ->execute();

  // To get clever failure on PHPUnit 9, we need this.
  // @see https://drupal.org/i/3197324
  try {
    $this
      ->executeMediaMigrations();
  } catch (\Exception $exception) {
    throw new AssertionFailedError($exception
      ->getMessage() . "\n" . $exception
      ->getLine() . "\n" . $exception
      ->getTraceAsString());
  }
  $this
    ->assertMedia1FieldValues('Blue PNG changed');
}