3 namespace Drupal\media\Tests;
5 use Drupal\simpletest\WebTestBase;
8 * Ensures that media bundle for videos can be created.
12 class VideoBundleTest extends WebTestBase {
14 * Exempt from strict schema checking.
16 * @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
20 protected $strictConfigSchema = FALSE;
27 public static $modules = [
37 * The test media bundle.
39 * @var \Drupal\media_entity\MediaBundleInterface
41 protected $testBundle;
46 protected function setUp() {
48 $this->testBundle = $this->container->get('entity.manager')->getStorage('media_bundle')->load('video');
50 $adminUser = $this->drupalCreateUser([
57 'access media overview',
59 $this->drupalLogin($adminUser);
63 * Tests video media bundle creation from config files.
65 public function testMediaBundleCreationFromModule() {
66 $type_configuration = [
67 'source_field' => 'field_video',
72 'source_name' => 'field_source',
75 $this->assertTrue((bool) $this->testBundle, 'The media bundle from default configuration has been created in the database.');
76 $this->assertEqual($this->testBundle->get('label'), 'Video', 'Correct label detected.');
77 $this->assertEqual($this->testBundle->get('description'), 'Use Video for embedding videos hosted by YouTube, Vimeo, or some other provider.', 'Correct description detected.');
78 $this->assertEqual($this->testBundle->get('type'), 'video_embed_field', 'Correct plugin ID detected.');
79 $this->assertEqual($this->testBundle->get('type_configuration'), $type_configuration, 'Type configuration correct.');
80 $this->assertEqual($this->testBundle->get('field_map'), $field_map, 'Correct field map detected.');
84 * Tests video media bundle field maps.
86 public function testBundleFieldMap() {
88 'name[0][value]' => 'Drupal video!',
89 'field_video[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
91 $this->drupalPostForm('media/add/' . $this->testBundle->id(), $edit, t('Save and publish'));
93 // Let's retrieve the media id and corresponding media entity object.
94 $media_id = $this->container->get('entity.query')->get('media')->execute();
95 $media_id = reset($media_id);
96 /** @var \Drupal\media_entity\MediaInterface $media */
97 $media = $this->container->get('entity_type.manager')
99 ->loadUnchanged($media_id);
100 $properties = $media->toArray();
101 $this->assertEqual($properties['field_id'][0]['value'], 'XgYu7-DQjDQ', 'Correct video ID detected.');
102 $this->assertEqual($properties['field_source'][0]['value'], 'youtube', 'Correct video source detected.');