You are here

protected function MediaMigrationAssertionsBaseTrait::assertMediaImageDisplayModes in Media Migration 8

Tests media image's default form and view mode configuration.

Parameters

bool $with_integer_field: If this is a image migrated from the media source DB fixture, the image bundle will have an additional image field.

2 calls to MediaMigrationAssertionsBaseTrait::assertMediaImageDisplayModes()
MediaMigrationFormatterWidgetTest::assertMediaTypeDisplayModes in tests/src/Kernel/Migrate/MediaMigrationFormatterWidgetTest.php
Tests display configuration of the migrated media types.
MediaMigrationPlainFormatterWidgetTest::assertMediaTypeDisplayModes in tests/src/Kernel/Migrate/MediaMigrationPlainFormatterWidgetTest.php
Tests display configuration of the migrated media types.

File

tests/src/Traits/MediaMigrationAssertionsBaseTrait.php, line 377

Class

MediaMigrationAssertionsBaseTrait
Trait for media migration tests.

Namespace

Drupal\Tests\media_migration\Traits

Code

protected function assertMediaImageDisplayModes(bool $with_integer_field = FALSE) {
  $entity_form_display = $this->container
    ->get('entity_type.manager')
    ->getStorage('entity_form_display')
    ->load(implode('.', [
    'media',
    'image',
    'default',
  ]));
  $form_display_expectation = [
    'status' => TRUE,
    'id' => 'media.image.default',
    'targetEntityType' => 'media',
    'bundle' => 'image',
    'mode' => 'default',
    'content' => [
      'created' => [
        'type' => 'datetime_timestamp',
        'weight' => 10,
        'region' => 'content',
        'settings' => [],
        'third_party_settings' => [],
      ],
      'field_media_image' => [
        'type' => 'image_image',
        'weight' => 0,
        'settings' => [
          'progress_indicator' => 'throbber',
          'preview_image_style' => 'thumbnail',
        ],
        'third_party_settings' => [],
        'region' => 'content',
      ],
      'name' => [
        'type' => 'string_textfield',
        'weight' => -5,
        'settings' => [
          'size' => 60,
          'placeholder' => '',
        ],
        'third_party_settings' => [],
        'region' => 'content',
      ],
      'status' => [
        'type' => 'boolean_checkbox',
        'weight' => 100,
        'settings' => [
          'display_label' => TRUE,
        ],
        'third_party_settings' => [],
        'region' => 'content',
      ],
      'uid' => [
        'type' => 'entity_reference_autocomplete',
        'weight' => 5,
        'settings' => [
          'match_operator' => 'CONTAINS',
          'size' => 60,
          'placeholder' => '',
          'match_limit' => 10,
        ],
        'third_party_settings' => [],
        'region' => 'content',
      ],
    ],
    'hidden' => [],
  ];
  if ($with_integer_field) {
    $form_display_expectation['content']['field_media_integer'] = [
      'type' => 'number',
      'weight' => -2,
      'settings' => [
        'placeholder' => '',
      ],
      'third_party_settings' => [],
      'region' => 'content',
    ];
  }
  $this
    ->assertEquals($form_display_expectation, $this
    ->getImportantEntityProperties($entity_form_display));
  $entity_view_display = $this->container
    ->get('entity_type.manager')
    ->getStorage('entity_view_display')
    ->load(implode('.', [
    'media',
    'image',
    'default',
  ]));
  $view_display_expectation = [
    'status' => TRUE,
    'id' => 'media.image.default',
    'targetEntityType' => 'media',
    'bundle' => 'image',
    'mode' => 'default',
    'content' => [
      'field_media_image' => [
        'type' => 'image',
        'weight' => 0,
        'settings' => [
          'image_style' => 'large',
          'image_link' => '',
        ],
        'third_party_settings' => [],
        'region' => 'content',
        'label' => 'visually_hidden',
      ],
    ],
    'hidden' => [
      'created' => TRUE,
      'name' => TRUE,
      'thumbnail' => TRUE,
      'uid' => TRUE,
    ],
  ];
  if ($with_integer_field) {
    $view_display_expectation['content']['field_media_integer'] = [
      'type' => 'number_integer',
      'weight' => 2,
      'settings' => [
        'thousand_separator' => '',
        'prefix_suffix' => TRUE,
      ],
      'third_party_settings' => [],
      'region' => 'content',
      'label' => 'above',
    ];
  }
  $this
    ->assertEquals($view_display_expectation, $this
    ->getImportantEntityProperties($entity_view_display));
}