You are here

protected function MediaLibraryIntegrationTest::setUp in Focal Point 8

Overrides BrowserTestBase::setUp

File

tests/src/FunctionalJavascript/MediaLibraryIntegrationTest.php, line 39

Class

MediaLibraryIntegrationTest
Tests Focal Point's integration with Media Library.

Namespace

Drupal\Tests\focal_point\FunctionalJavascript

Code

protected function setUp() {
  parent::setUp();
  $this
    ->drupalCreateContentType([
    'type' => 'article',
  ]);
  $this
    ->createMediaType('image', [
    'id' => 'image',
  ]);
  $field_storage = FieldStorageConfig::create([
    'entity_type' => 'node',
    'field_name' => 'field_image',
    'type' => 'entity_reference',
    'settings' => [
      'target_type' => 'media',
    ],
  ]);
  $field_storage
    ->save();
  FieldConfig::create([
    'field_storage' => $field_storage,
    'bundle' => 'article',
    'label' => 'Image',
    'settings' => [
      'handler_settings' => [
        'target_bundles' => [
          'image' => 'image',
        ],
      ],
    ],
  ])
    ->save();

  // Ensure that the media type is using Focal Point in its media library
  // form display.

  /** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
  $display_repository = $this->container
    ->get('entity_display.repository');
  $display_repository
    ->getFormDisplay('media', 'image', 'media_library')
    ->setComponent('field_media_image', [
    'type' => 'image_focal_point',
    'settings' => [
      'preview_image_style' => 'media_library',
    ],
  ])
    ->save();

  // Ensure that the media field on the Article content type is using the
  // media library.
  $display_repository
    ->getFormDisplay('node', 'article')
    ->setComponent('field_image', [
    'type' => 'media_library_widget',
  ])
    ->save();
  $user = $this
    ->drupalCreateUser([
    'create article content',
    'create media',
    'access media overview',
  ]);
  $this
    ->drupalLogin($user);
}