X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fmodules%2Fcontrib%2Fmedia%2Fsrc%2FTests%2FVideoBundleTest.php;fp=web%2Fmodules%2Fcontrib%2Fmedia%2Fsrc%2FTests%2FVideoBundleTest.php;h=4d9a64ddc3e30e4f05adf5be55ead95265bd843c;hp=0000000000000000000000000000000000000000;hb=8acec36f19c470dfcda1ae2336826a782f41874c;hpb=e0411c4e83ba0d079034db83c3f7f55be24a0e35 diff --git a/web/modules/contrib/media/src/Tests/VideoBundleTest.php b/web/modules/contrib/media/src/Tests/VideoBundleTest.php new file mode 100644 index 000000000..4d9a64ddc --- /dev/null +++ b/web/modules/contrib/media/src/Tests/VideoBundleTest.php @@ -0,0 +1,105 @@ +testBundle = $this->container->get('entity.manager')->getStorage('media_bundle')->load('video'); + + $adminUser = $this->drupalCreateUser([ + 'view media', + 'create media', + 'update media', + 'update any media', + 'delete media', + 'delete any media', + 'access media overview', + ]); + $this->drupalLogin($adminUser); + } + + /** + * Tests video media bundle creation from config files. + */ + public function testMediaBundleCreationFromModule() { + $type_configuration = [ + 'source_field' => 'field_video', + ]; + + $field_map = [ + 'id' => 'field_id', + 'source_name' => 'field_source', + ]; + + $this->assertTrue((bool) $this->testBundle, 'The media bundle from default configuration has been created in the database.'); + $this->assertEqual($this->testBundle->get('label'), 'Video', 'Correct label detected.'); + $this->assertEqual($this->testBundle->get('description'), 'Use Video for embedding videos hosted by YouTube, Vimeo, or some other provider.', 'Correct description detected.'); + $this->assertEqual($this->testBundle->get('type'), 'video_embed_field', 'Correct plugin ID detected.'); + $this->assertEqual($this->testBundle->get('type_configuration'), $type_configuration, 'Type configuration correct.'); + $this->assertEqual($this->testBundle->get('field_map'), $field_map, 'Correct field map detected.'); + } + + /** + * Tests video media bundle field maps. + */ + 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.'); + } + +}