3 namespace Drupal\Tests\video_embed_media\Functional;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\video_embed_field\Functional\AdminUserTrait;
9 * Test the video_embed_field media integration.
11 * @group video_embed_media
13 class BundleTest extends BrowserTestBase {
22 public static $modules = [
32 * Test the dialog form.
34 public function testMediaBundleCreation() {
35 $this->drupalLogin($this->createAdminUser());
37 // Create a new media bundle.
38 $this->drupalGet('admin/structure/media/add');
40 'label' => 'Video Bundle',
41 'id' => 'video_bundle',
42 'type' => 'video_embed_field',
43 ], t('Save media bundle'));
44 $this->assertSession()->pageTextContains('The media bundle Video Bundle has been added.');
46 // Ensure the video field is added to the media entity.
47 $this->drupalGet('admin/structure/media/manage/video_bundle/fields');
48 $this->assertSession()->pageTextContains('field_media_video_embed_field');
49 $this->assertSession()->pageTextContains('Video URL');
51 // Add a media entity with the new field.
52 $this->drupalGet('media/add/video_bundle');
54 'name[0][value]' => 'Drupal video!',
55 'field_media_video_embed_field[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
57 // We should see the video thumbnail on the media page.
58 $this->assertContains('video_thumbnails/XgYu7-DQjDQ.jpg', $this->getSession()->getPage()->getHtml());
60 // Add another field and change the configured media field.
61 $this->drupalGet('admin/structure/media/manage/video_bundle/fields/add-field');
63 'new_storage_type' => 'video_embed_field',
64 'label' => 'New Video Field',
65 'field_name' => 'new_video_field',
66 ], 'Save and continue');
67 $this->submitForm([], t('Save field settings'));
68 $this->submitForm([], t('Save settings'));
70 // Update video source field.
71 $this->drupalGet('admin/structure/media/manage/video_bundle');
73 'type_configuration[video_embed_field][source_field]' => 'field_new_video_field',
74 ], t('Save media bundle'));
76 // Create a video, populating both video URL fields.
77 $this->drupalGet('media/add/video_bundle');
79 'name[0][value]' => 'Another Video!',
80 'field_media_video_embed_field[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
81 'field_new_video_field[0][value]' => 'https://www.youtube.com/watch?v=gnERPdAiuSo',
84 // We should see the newly configured video thumbnail, but not the original.
85 $this->assertContains('video_thumbnails/gnERPdAiuSo.jpg', $this->getSession()->getPage()->getHtml());
86 $this->assertNotContains('video_thumbnails/XgYu7-DQjDQ.jpg', $this->getSession()->getPage()->getHtml());