You are here

protected function MediaLibraryDisplayModeTest::assertFormDisplay in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/media_library/tests/src/Functional/MediaLibraryDisplayModeTest.php \Drupal\Tests\media_library\Functional\MediaLibraryDisplayModeTest::assertFormDisplay()

Asserts the media library form display components for a media type.

Parameters

string $type_id: The media type ID.

bool $has_name: Whether the media library form display should contain the name field or not.

bool $has_source_field: Whether the media library form display should contain the source field or not.

1 call to MediaLibraryDisplayModeTest::assertFormDisplay()
MediaLibraryDisplayModeTest::testDisplayModes in core/modules/media_library/tests/src/Functional/MediaLibraryDisplayModeTest.php
Tests that the Media Library can automatically configure display modes.

File

core/modules/media_library/tests/src/Functional/MediaLibraryDisplayModeTest.php, line 226

Class

MediaLibraryDisplayModeTest
Tests that the Media Library automatically configures form/view modes.

Namespace

Drupal\Tests\media_library\Functional

Code

protected function assertFormDisplay($type_id, $has_name, $has_source_field) {

  // These components are added by default and invisible.
  $components = [
    'revision_log_message',
    'langcode',
  ];

  // Only assert the name and source field if needed.
  if ($has_name) {
    $components[] = 'name';
  }
  if ($has_source_field) {
    $type = MediaType::load($type_id);
    $components[] = $type
      ->getSource()
      ->getSourceFieldDefinition($type)
      ->getName();
  }
  $form_display = EntityFormDisplay::load('media.' . $type_id . '.media_library');
  $this
    ->assertInstanceOf(EntityFormDisplay::class, $form_display);
  $actual_components = array_keys($form_display
    ->getComponents());
  sort($components);
  sort($actual_components);
  $this
    ->assertSame($components, $actual_components);
}