function MediaSourceImageTest::assertViewDisplayConfigured

Same name in other branches
  1. 8.9.x core/modules/media/tests/src/FunctionalJavascript/MediaSourceImageTest.php \Drupal\Tests\media\FunctionalJavascript\MediaSourceImageTest::assertViewDisplayConfigured()
  2. 10 core/modules/media/tests/src/FunctionalJavascript/MediaSourceImageTest.php \Drupal\Tests\media\FunctionalJavascript\MediaSourceImageTest::assertViewDisplayConfigured()
  3. 11.x core/modules/media/tests/src/FunctionalJavascript/MediaSourceImageTest.php \Drupal\Tests\media\FunctionalJavascript\MediaSourceImageTest::assertViewDisplayConfigured()

Asserts the proper entity view display components for a media type.

@internal

Parameters

string $media_type_id: The media type ID.

1 call to MediaSourceImageTest::assertViewDisplayConfigured()
MediaSourceImageTest::testMediaImageSource in core/modules/media/tests/src/FunctionalJavascript/MediaSourceImageTest.php
Tests the image media source.

File

core/modules/media/tests/src/FunctionalJavascript/MediaSourceImageTest.php, line 166

Class

MediaSourceImageTest
Tests the image media source.

Namespace

Drupal\Tests\media\FunctionalJavascript

Code

protected function assertViewDisplayConfigured(string $media_type_id) : void {
    $assert_session = $this->assertSession();
    $type = MediaType::load($media_type_id);
    $display = EntityViewDisplay::load('media.' . $media_type_id . '.' . EntityDisplayRepositoryInterface::DEFAULT_DISPLAY_MODE);
    $this->assertInstanceOf(EntityViewDisplay::class, $display);
    $source_field_definition = $type->getSource()
        ->getSourceFieldDefinition($type);
    $component = $display->getComponent($source_field_definition->getName());
    $this->assertSame('visually_hidden', $component['label']);
    if (ImageStyle::load('large')) {
        $this->assertSame('large', $component['settings']['image_style']);
    }
    else {
        $this->assertEmpty($component['settings']['image_style']);
    }
    $this->assertEmpty($component['settings']['image_link']);
    // Since components that aren't explicitly hidden can show up on the
    // display edit form, check that only the image field appears enabled on
    // the display edit form.
    $this->drupalGet('/admin/structure/media/manage/' . $media_type_id . '/display');
    // Assert that only the source field is enabled.
    $assert_session->elementExists('css', 'input[name="' . $source_field_definition->getName() . '_settings_edit"]');
    $assert_session->elementsCount('css', 'input[name$="_settings_edit"]', 1);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.