You are here

public function InstagramBundleTest::testMediaBundleItemCreation in D7 Media 8

Tests item creation and thumbnail.

File

src/Tests/InstagramBundleTest.php, line 86

Class

InstagramBundleTest
Ensures that media bundle for instagram can be created.

Namespace

Drupal\media\Tests

Code

public function testMediaBundleItemCreation() {

  // Define the media item name.
  $name = $this
    ->randomMachineName();
  $instagram_url = 'https://www.instagram.com/p/C/';
  $edit = [
    'name[0][value]' => $name,
    'field_instagram_url[0][uri]' => $instagram_url,
  ];

  // Save the Instagram post.
  $this
    ->drupalPostForm('media/add/' . $this->testBundle
    ->id(), $edit, t('Save and publish'));

  // Assert that the formatter exists on this page.
  $this
    ->assertFieldByXPath('//iframe');

  // Let's retrieve the media id and corresponding media entity object.
  $media_id = $this->container
    ->get('entity.query')
    ->get('media')
    ->condition('bundle', 'instagram')
    ->sort('created', 'DESC')
    ->execute();
  $media_id = reset($media_id);

  /** @var \Drupal\media_entity\MediaInterface $media */
  $media = $this->container
    ->get('entity_type.manager')
    ->getStorage('media')
    ->loadUnchanged($media_id);
  $properties = $media
    ->toArray();
  $this
    ->assertEqual($media
    ->get('field_instagram_shortcode')[0]
    ->getValue()['value'], "C", "Correct shortcode stored.");
}