You are here

public function VideoBundleTest::testBundleFieldMap in D7 Media 8

Tests video media bundle field maps.

File

src/Tests/VideoBundleTest.php, line 86

Class

VideoBundleTest
Ensures that media bundle for videos can be created.

Namespace

Drupal\media\Tests

Code

public function testBundleFieldMap() {
  $edit = [
    'name[0][value]' => 'Drupal video!',
    'field_video[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
  ];
  $this
    ->drupalPostForm('media/add/' . $this->testBundle
    ->id(), $edit, t('Save and publish'));

  // Let's retrieve the media id and corresponding media entity object.
  $media_id = $this->container
    ->get('entity.query')
    ->get('media')
    ->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($properties['field_id'][0]['value'], 'XgYu7-DQjDQ', 'Correct video ID detected.');
  $this
    ->assertEqual($properties['field_source'][0]['value'], 'youtube', 'Correct video source detected.');
}