You are here

public function MigrateEmbedMediaTokenToMediaEmbedTest::testMediaTokenToMediaEmbedTransform in Media Migration 8

Tests the result of Media Migration's embed media token transform.

@dataProvider providerMediaEmbedTransform

Parameters

string $reference_method: The method of how embed media is referenced.

array $extra_modules: Additional modules to enable before the migration.

bool $preexisting_media_types: Whether media types should be present before the migration.

File

tests/src/Functional/MigrateEmbedMediaTokenToMediaEmbedTest.php, line 36

Class

MigrateEmbedMediaTokenToMediaEmbedTest
Tests the transformation of embed image media tokens to media_embed.

Namespace

Drupal\Tests\media_migration\Functional

Code

public function testMediaTokenToMediaEmbedTransform(string $reference_method, array $extra_modules, bool $preexisting_media_types) {

  // Delete preexisting media types.
  $media_types = $this->container
    ->get('entity_type.manager')
    ->getStorage('media_type')
    ->loadMultiple();
  foreach ($media_types as $media_type) {
    $media_type
      ->delete();
  }
  if ($preexisting_media_types) {
    $this
      ->createStandardMediaTypes(TRUE);
  }

  // Set the reference method.
  $this
    ->setEmbedMediaReferenceMethod($reference_method);
  if (!empty($extra_modules)) {
    $this->container
      ->get('module_installer')
      ->install($extra_modules);
  }
  $this
    ->assertMigrateUpgradeViaUi();
  $this
    ->assertMediaMigrationResults();
  $expected_node1_embed_attributes = [
    0 => [
      'data-view-mode' => 'wysiwyg',
      'data-entity-type' => 'media',
      'data-entity-uuid' => TRUE,
      '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',
    ],
    1 => [
      'data-entity-type' => 'media',
      'data-entity-uuid' => TRUE,
      'data-view-mode' => 'default',
      'alt' => 'A yellow image',
      'title' => 'This is a yellow image',
    ],
  ];
  $this
    ->assertMediaTokenTransform($expected_node1_embed_attributes);
  $this
    ->assertNode1FieldValues($expected_node1_embed_attributes);
}