You are here

public function GalleryBundleTest::addImageItem in D7 Media 8

Adds image type item.

1 call to GalleryBundleTest::addImageItem()
GalleryBundleTest::testGalleryItemThumbnail in src/Tests/GalleryBundleTest.php
Tests thumbnail of the gallery item.

File

src/Tests/GalleryBundleTest.php, line 132

Class

GalleryBundleTest
Ensures that media bundle for gallery can be created.

Namespace

Drupal\media\Tests

Code

public function addImageItem() {

  // Let's add image first.
  $name = $this
    ->randomMachineName();
  $testImage = current($this
    ->drupalGetTestFiles('image'));
  $file_path = $this->container
    ->get('file_system')
    ->realpath($testImage->uri);
  $edit = [
    'name[0][value]' => $name,
    'files[field_image_0]' => $file_path,
  ];

  // Save the image.
  $this
    ->drupalPostForm('media/add/image', $edit, t('Save and publish'));
  $this
    ->drupalPostForm(NULL, [
    'field_image[0][alt]' => $name,
  ], t('Save and publish'));

  // Obtain the image id.
  $media_id = $this->container
    ->get('entity.query')
    ->get('media')
    ->condition('bundle', 'image')
    ->sort('created', 'DESC')
    ->execute();
  $media_id = reset($media_id);
  $edit['id'] = $media_id;
  return $edit;
}