You are here

public function GalleryBundleTest::testGalleryItemThumbnail in D7 Media 8

Tests thumbnail of the gallery item.

File

src/Tests/GalleryBundleTest.php, line 81

Class

GalleryBundleTest
Ensures that media bundle for gallery can be created.

Namespace

Drupal\media\Tests

Code

public function testGalleryItemThumbnail() {

  // Let's add one image and one video.
  $imageItem = $this
    ->addImageItem();
  $videoItem = $this
    ->addVideoItem();
  $this
    ->drupalGet('media/add/gallery');
  $pathValue = (string) current($this
    ->xpath('//input[@data-drupal-selector="edit-field-slide-entity-browser-entity-browser-path"]/@value'));
  $edit = [
    'name[0][value]' => 'Gallery item',
    'field_slide[target_id]' => 'media:' . $imageItem['id'] . ' media:' . $videoItem['id'],
    'field_slide[entity_browser][entity_browser][path]' => $pathValue,
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save and publish'));

  // Let's load all the media items.
  $gallery_id = $this->container
    ->get('entity.query')
    ->get('media')
    ->condition('bundle', 'gallery')
    ->sort('created', 'DESC')
    ->execute();
  $gallery = $this
    ->loadMediaItem(reset($gallery_id));
  $image = $this
    ->loadMediaItem($imageItem['id']);
  $video = $this
    ->loadMediaItem($videoItem['id']);

  // Let's check thumbnail now.
  $gallery_thumbnail = $gallery
    ->getType()
    ->thumbnail($gallery);
  $image_thumbnail = $image
    ->getType()
    ->thumbnail($image);
  $video_thumbnail = $video
    ->getType()
    ->thumbnail($video);
  $this
    ->assertEqual($gallery_thumbnail, $image_thumbnail, "Correct thumbnail detected.");
  $this
    ->drupalGet('media/add/gallery');
  $edit = [
    'name[0][value]' => 'Gallery item 2',
    'field_slide[target_id]' => 'media:' . $videoItem['id'] . ' media:' . $imageItem['id'],
    'field_slide[entity_browser][entity_browser][path]' => $pathValue,
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save and publish'));

  // Let's check the thumbnail again.
  $gallery_id = $this->container
    ->get('entity.query')
    ->get('media')
    ->condition('bundle', 'gallery')
    ->sort('created', 'DESC')
    ->execute();
  $gallery = $this
    ->loadMediaItem(reset($gallery_id));
  $gallery_thumbnail = $gallery
    ->getType()
    ->thumbnail($gallery);
  $this
    ->assertEqual($gallery_thumbnail, $video_thumbnail, "Correct thumbnail detected.");
}