3 namespace Drupal\Tests\video_embed_media\Functional;
5 use Drupal\Tests\media\Functional\MediaFunctionalTestBase;
6 use Drupal\Tests\media\Functional\MediaFunctionalTestCreateMediaTypeTrait;
7 use Drupal\Tests\video_embed_field\Functional\AdminUserTrait;
10 * Test the video_embed_field media integration.
12 * @group video_embed_media
14 class BundleTest extends MediaFunctionalTestBase {
23 public static $modules = [
31 protected function setUp() {
36 * Test the dialog form.
38 public function testMediaBundleCreation() {
39 $this->drupalLogin($this->adminUser);
41 // Create bundle and modify form display.
42 $media_type = $this->createMediaType(['bundle' => 'video_bundle'], 'video_embed_field');
43 $source = $media_type->getSource();
44 $source_field = $source->getSourceFieldDefinition($media_type);
45 if ($source_field->isDisplayConfigurable('form')) {
46 // Use the default widget and settings.
47 $component = \Drupal::service('plugin.manager.field.widget')
48 ->prepareConfiguration('video_embed_field', []);
50 // @todo Replace entity_get_form_display() when #2367933 is done.
51 // https://www.drupal.org/node/2872159.
52 entity_get_form_display('media', $media_type->id(), 'default')
53 ->setComponent($source_field->getName(), $component)
57 // Ensure the video field is added to the media entity.
58 $this->drupalGet('admin/structure/media/manage/video_bundle/fields');
59 $this->assertSession()->pageTextContains('field_media_video_embed_field');
60 $this->assertSession()->pageTextContains('Video URL');
62 // Add a media entity with the new field.
63 $this->drupalGet('media/add/video_bundle');
65 'name[0][value]' => 'Drupal video!',
66 'field_media_video_embed_field[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
68 // We should see the video thumbnail on the media page.
69 $this->assertContains('video_thumbnails/XgYu7-DQjDQ.jpg', $this->getSession()->getPage()->getHtml());