You are here

public function MigrateEmbedMediaTokenToEntityEmbedTest::testMediaTokenToEntityEmbedTransform in Media Migration 8

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

@dataProvider providerEntityEmbedTransform

Parameters

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

string|null $destination_format_plugin_id: The embed token transformation's destination format plugin ID to write into settings.php, or NULL.

string|bool[][] $expected_embed_html_properties: The expected attributes of the embed entity HTML tags, keyed by their delta (from their order in node with ID '1').

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

File

tests/src/Functional/MigrateEmbedMediaTokenToEntityEmbedTest.php, line 51

Class

MigrateEmbedMediaTokenToEntityEmbedTest
Tests the transformation of embed image media tokens to entity embed.

Namespace

Drupal\Tests\media_migration\Functional

Code

public function testMediaTokenToEntityEmbedTransform(string $reference_method, $destination_format_plugin_id, array $expected_embed_html_properties, 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);

  // Set the token transformation's destination filter plugin ID.
  $this
    ->setEmbedTokenDestinationFilterPlugin($destination_format_plugin_id);

  // Delete preexisting embed_button config entities.
  // Entity Embed module has an optional 'node' embed button that is installed
  // when node module is enabled. We don't want to depend on Entity Embed's
  // default embed_button config entities since those can be changed in the
  // future. But we need to assert that the 'media' embed button (that we
  // migrate conditionally) exists after the migration.
  if ($storage = $this
    ->getEntityStorage('embed_button')) {
    foreach ($storage
      ->loadMultiple() as $embed_button) {
      $embed_button
        ->delete();
    }
  }

  // Run the migration.
  $this
    ->assertMigrateUpgradeViaUi();
  $this
    ->assertMediaMigrationResults();
  $this
    ->assertMediaTokenTransform($expected_embed_html_properties);
  $this
    ->assertNode1FieldValues($expected_embed_html_properties);
}