ece13725ce52b5bb7ead41ad0ae1f988124b32c5
[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\media\Functional\MediaFunctionalTestBase;
6 use Drupal\Tests\media\Functional\MediaFunctionalTestCreateMediaTypeTrait;
7 use Drupal\Tests\video_embed_field\Functional\AdminUserTrait;
8
9 /**
10  * Test the video_embed_field media integration.
11  *
12  * @group video_embed_media
13  */
14 class BundleTest extends MediaFunctionalTestBase {
15
16   use AdminUserTrait;
17
18   /**
19    * Modules to install.
20    *
21    * @var array
22    */
23   public static $modules = [
24     'video_embed_field',
25     'video_embed_media',
26   ];
27
28   /**
29    * {@inheritdoc}
30    */
31   protected function setUp() {
32     parent::setUp();
33   }
34
35   /**
36    * Test the dialog form.
37    */
38   public function testMediaBundleCreation() {
39     $this->drupalLogin($this->adminUser);
40
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', []);
49
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)
54         ->save();
55     }
56
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');
61
62     // Add a media entity with the new field.
63     $this->drupalGet('media/add/video_bundle');
64     $this->submitForm([
65       'name[0][value]' => 'Drupal video!',
66       'field_media_video_embed_field[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
67     ], 'Save');
68     // We should see the video thumbnail on the media page.
69     $this->assertContains('video_thumbnails/XgYu7-DQjDQ.jpg', $this->getSession()->getPage()->getHtml());
70   }
71
72 }