493f64837cabfc410b12e0ee5fdead10616a5d9e
[yaffs-website] / web / modules / contrib / video_embed_field / modules / video_embed_media / tests / src / Kernel / DefaultNameTest.php
1 <?php
2
3 namespace Drupal\Tests\video_embed_media\Kernel;
4
5 use Drupal\media_entity\Entity\Media;
6 use Drupal\media_entity\Entity\MediaBundle;
7 use Drupal\Tests\video_embed_field\Kernel\KernelTestBase;
8 use Drupal\video_embed_media\Plugin\MediaEntity\Type\VideoEmbedField;
9
10 /**
11  * Test the media bundle default names.
12  *
13  * @group video_embed_media
14  */
15 class DefaultNameTest extends KernelTestBase {
16
17   /**
18    * Modules to enable.
19    *
20    * @var array
21    */
22   public static $modules = [
23     'video_embed_media',
24     'media_entity',
25     'file',
26     'views',
27   ];
28
29   /**
30    * The media video plugin manager.
31    *
32    * @var \Drupal\media_entity\MediaTypeManager
33    */
34   protected $mediaVideoPlugin;
35
36   /**
37    * Test cases for ::testDefaultName().
38    */
39   public function defaultNameTestCases() {
40     return [
41       'YouTube' => [
42         'https://www.youtube.com/watch?v=gnERPdAiuSo',
43         'YouTube Video (gnERPdAiuSo)',
44       ],
45       'Vimeo' => [
46         'https://vimeo.com/21681203',
47         'Drupal Commerce at DrupalCon Chicago',
48       ],
49     ];
50   }
51
52   /**
53    * Test the default name.
54    *
55    * @dataProvider defaultNameTestCases
56    */
57   public function testDefaultName($input, $expected) {
58     $entity = Media::create([
59       'bundle' => 'video',
60       VideoEmbedField::VIDEO_EMBED_FIELD_DEFAULT_NAME => [['value' => $input]],
61     ]);
62     $actual = $this->mediaVideoPlugin->getDefaultName($entity);
63     $this->assertEquals($expected, $actual);
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   public function setup() {
70     parent::setup();
71     $this->installConfig(['media_entity']);
72     $this->mediaVideoPlugin = $this->container->get('plugin.manager.media_entity.type')->createInstance('video_embed_field', []);
73     $bundle = MediaBundle::create([
74       'id' => 'video',
75       'type' => 'video_embed_field',
76     ]);
77     $bundle->save();
78   }
79
80 }