Further modules included.
[yaffs-website] / web / modules / contrib / media / src / Tests / VideoBundleTest.php
1 <?php
2
3 namespace Drupal\media\Tests;
4
5 use Drupal\simpletest\WebTestBase;
6
7 /**
8  * Ensures that media bundle for videos can be created.
9  *
10  * @group media
11  */
12 class VideoBundleTest extends WebTestBase {
13   /**
14    * Exempt from strict schema checking.
15    *
16    * @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
17    *
18    * @var bool
19    */
20   protected $strictConfigSchema = FALSE;
21
22   /**
23    * Modules to enable.
24    *
25    * @var array
26    */
27   public static $modules = [
28     'media',
29     'media_entity',
30     'video_embed_field',
31     'video_embed_media',
32     'node',
33     'editor',
34   ];
35
36   /**
37    * The test media bundle.
38    *
39    * @var \Drupal\media_entity\MediaBundleInterface
40    */
41   protected $testBundle;
42
43   /**
44    * {@inheritdoc}
45    */
46   protected function setUp() {
47     parent::setUp();
48     $this->testBundle = $this->container->get('entity.manager')->getStorage('media_bundle')->load('video');
49
50     $adminUser = $this->drupalCreateUser([
51       'view media',
52       'create media',
53       'update media',
54       'update any media',
55       'delete media',
56       'delete any media',
57       'access media overview',
58     ]);
59     $this->drupalLogin($adminUser);
60   }
61
62   /**
63    * Tests video media bundle creation from config files.
64    */
65   public function testMediaBundleCreationFromModule() {
66     $type_configuration = [
67       'source_field' => 'field_video',
68     ];
69
70     $field_map = [
71       'id' => 'field_id',
72       'source_name' => 'field_source',
73     ];
74
75     $this->assertTrue((bool) $this->testBundle, 'The media bundle from default configuration has been created in the database.');
76     $this->assertEqual($this->testBundle->get('label'), 'Video', 'Correct label detected.');
77     $this->assertEqual($this->testBundle->get('description'), 'Use Video for embedding videos hosted by YouTube, Vimeo, or some other provider.', 'Correct description detected.');
78     $this->assertEqual($this->testBundle->get('type'), 'video_embed_field', 'Correct plugin ID detected.');
79     $this->assertEqual($this->testBundle->get('type_configuration'), $type_configuration, 'Type configuration correct.');
80     $this->assertEqual($this->testBundle->get('field_map'), $field_map, 'Correct field map detected.');
81   }
82
83   /**
84    * Tests video media bundle field maps.
85    */
86   public function testBundleFieldMap() {
87     $edit = [
88       'name[0][value]' => 'Drupal video!',
89       'field_video[0][value]' => 'https://www.youtube.com/watch?v=XgYu7-DQjDQ',
90     ];
91     $this->drupalPostForm('media/add/' . $this->testBundle->id(), $edit, t('Save and publish'));
92
93     // Let's retrieve the media id and corresponding media entity object.
94     $media_id = $this->container->get('entity.query')->get('media')->execute();
95     $media_id = reset($media_id);
96     /** @var \Drupal\media_entity\MediaInterface $media */
97     $media = $this->container->get('entity_type.manager')
98       ->getStorage('media')
99       ->loadUnchanged($media_id);
100     $properties = $media->toArray();
101     $this->assertEqual($properties['field_id'][0]['value'], 'XgYu7-DQjDQ', 'Correct video ID detected.');
102     $this->assertEqual($properties['field_source'][0]['value'], 'youtube', 'Correct video source detected.');
103   }
104
105 }