ef3403882a93075b85ff26ab9364f3f082a0ed40
[yaffs-website] / web / modules / contrib / video_embed_field / modules / video_embed_media / tests / src / Functional / BundleTest.php
1 <?php
2
3 namespace Drupal\Tests\video_embed_media\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\video_embed_field\Functional\AdminUserTrait;
7
8 /**
9  * Test the video_embed_field media integration.
10  *
11  * @group video_embed_media
12  */
13 class BundleTest extends BrowserTestBase {
14
15   use AdminUserTrait;
16
17   /**
18    * Modules to install.
19    *
20    * @var array
21    */
22   public static $modules = [
23     'video_embed_field',
24     'video_embed_media',
25     'media_entity',
26     'field_ui',
27     'node',
28     'image',
29   ];
30
31   /**
32    * Test the dialog form.
33    */
34   public function testMediaBundleCreation() {
35     $this->drupalLogin($this->createAdminUser());
36
37     // Create a new media bundle.
38     $this->drupalGet('admin/structure/media/add');
39     $this->submitForm([
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.');
45
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');
50
51     // Add a media entity with the new field.
52     $this->drupalGet('media/add/video_bundle');
53     $this->submitForm([
54       'name[0][value]' => 'Drupal video!',
55       'field_media_video_embed_field[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
56     ], 'Save');
57     // We should see the video thumbnail on the media page.
58     $this->assertContains('video_thumbnails/XgYu7-DQjDQ.jpg', $this->getSession()->getPage()->getHtml());
59
60     // Add another field and change the configured media field.
61     $this->drupalGet('admin/structure/media/manage/video_bundle/fields/add-field');
62     $this->submitForm([
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'));
69
70     // Update video source field.
71     $this->drupalGet('admin/structure/media/manage/video_bundle');
72     $this->submitForm([
73       'type_configuration[video_embed_field][source_field]' => 'field_new_video_field',
74     ], t('Save media bundle'));
75
76     // Create a video, populating both video URL fields.
77     $this->drupalGet('media/add/video_bundle');
78     $this->submitForm([
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',
82     ], t('Save'));
83
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());
87   }
88
89 }