You are here

protected function MediaTrait::createImageMedia in Entity Reference Hierarchy 3.x

Same name and namespace in other branches
  1. 8.2 modules/entity_hierarchy_microsite/tests/src/Traits/MediaTrait.php \Drupal\Tests\entity_hierarchy_microsite\Traits\MediaTrait::createImageMedia()

Create an image media entity.

Parameters

array $values: Optional key => values to assign to the media entity.

\Drupal\file\Entity\File $file: Optional file entity to use.

Return value

\Drupal\media\Entity\Media A media entity.

6 calls to MediaTrait::createImageMedia()
MicrositeAdminTest::testAdmin in modules/entity_hierarchy_microsite/tests/src/Functional/MicrositeAdminTest.php
Tests admin.
MicrositeLogoBrandingBlockTest::testBrandingBlock in modules/entity_hierarchy_microsite/tests/src/Functional/MicrositeLogoBrandingBlockTest.php
Tests branding block.
MicrositeMenuBlockTest::testMenuBlock in modules/entity_hierarchy_microsite/tests/src/Functional/MicrositeMenuBlockTest.php
Tests menu block.
MicrositeMenuItemsTest::testMicrositeMenuLinkDerivation in modules/entity_hierarchy_microsite/tests/src/Kernel/MicrositeMenuItemsTest.php
Tests the microsite menu link integration.
MicrositeMenuItemsTest::testMicrositeMenuLinkMaxDepth in modules/entity_hierarchy_microsite/tests/src/Kernel/MicrositeMenuItemsTest.php
Tests microsite menus do not exceed the maximum depth.

... See full list

File

modules/entity_hierarchy_microsite/tests/src/Traits/MediaTrait.php, line 29

Class

MediaTrait
Defines a class for media utilties in tests.

Namespace

Drupal\Tests\entity_hierarchy_microsite\Traits

Code

protected function createImageMedia(array $values = [], File $file = NULL) {
  if (!$file) {
    $image = $this
      ->getTestFiles('image')[0];
    $file = $this
      ->createFile($image->uri);
  }
  $values = $values + [
    'bundle' => 'image',
    'field_media_image' => [
      'target_id' => $file
        ->id(),
    ],
  ];
  $media = Media::create($values);
  $media
    ->save();
  return $media;
}