You are here

public function MediaMigrationFormatterWidgetTest::testWidgetsAndFormattersWithoutMediaLibrary in Media Migration 8

Tests media widgets' and formatters' migration without Media Library.

@dataProvider providerTestCases

File

tests/src/Kernel/Migrate/MediaMigrationFormatterWidgetTest.php, line 55

Class

MediaMigrationFormatterWidgetTest
Tests widgets and formatters.

Namespace

Drupal\Tests\media_migration\Kernel\Migrate

Code

public function testWidgetsAndFormattersWithoutMediaLibrary(bool $classic_node_migration) {
  $this
    ->createStandardMediaTypes();
  $this
    ->setClassicNodeMigration($classic_node_migration);

  // Execute the media migrations.
  $this
    ->executeMediaMigrations($classic_node_migration);
  $media_fields = [
    'field_image' => [
      'form' => 'image_image',
      'view' => 'entity_reference_entity_view',
    ],
    'field_media' => [
      'form' => 'file_generic',
      'view' => 'entity_reference_entity_view',
    ],
  ];
  $entity_type_manager = $this->container
    ->get('entity_type.manager');
  assert($entity_type_manager instanceof EntityTypeManagerInterface);

  // Check default widget configurations. Every field widget should use.
  foreach ($media_fields as $field_name => $expected_config) {
    $entity_form_display = $entity_type_manager
      ->getStorage('entity_form_display')
      ->load(implode('.', [
      'node',
      'article',
      'default',
    ]));
    $entity_form_display_array = $entity_form_display
      ->toArray();
    $content = $entity_form_display_array['content'];
    $this
      ->assertTrue(array_key_exists($field_name, $content));
    $this
      ->assertEquals($expected_config['form'], $content[$field_name]['type']);
  }

  // Check default formatter configurations.
  foreach ($media_fields as $field_name => $expected_config) {
    $entity_form_display = $entity_type_manager
      ->getStorage('entity_view_display')
      ->load(implode('.', [
      'node',
      'article',
      'default',
    ]));
    $entity_form_display_array = $entity_form_display
      ->toArray();
    $content = $entity_form_display_array['content'];
    $this
      ->assertTrue(array_key_exists($field_name, $content));
    $this
      ->assertEquals($expected_config['view'], $content[$field_name]['type']);
  }
  $this
    ->assertMediaTypeDisplayModes();
}