Interim commit.
[yaffs-website] / web / modules / contrib / video_embed_field / tests / src / Kernel / VideoEmbedIFrameTest.php
1 <?php
2
3 namespace Drupal\Tests\video_embed_field\Kernel;
4
5 /**
6  * Test that the iframe element works.
7  *
8  * @group video_embed_field
9  */
10 class VideoEmbedIFrameTest extends KernelTestBase {
11
12   /**
13    * Test cases for the embed iframe.
14    *
15    * @return array
16    *   Video iframe test cases.
17    */
18   public function videoEmbedIframeTestCases() {
19     return [
20       'Default' => [
21         [
22           '#type' => 'video_embed_iframe',
23         ],
24         '<iframe></iframe>',
25       ],
26       'URL' => [
27         [
28           '#type' => 'video_embed_iframe',
29           '#url' => 'https://www.youtube.com/embed/fdbFVWupSsw',
30         ],
31         '<iframe src="https://www.youtube.com/embed/fdbFVWupSsw"></iframe>',
32       ],
33       'URL, query' => [
34         [
35           '#type' => 'video_embed_iframe',
36           '#url' => 'https://www.youtube.com/embed/fdbFVWupSsw',
37           '#query' => ['autoplay' => '1'],
38         ],
39         '<iframe src="https://www.youtube.com/embed/fdbFVWupSsw?autoplay=1"></iframe>',
40       ],
41       'URL, query, attributes' => [
42         [
43           '#type' => 'video_embed_iframe',
44           '#url' => 'https://www.youtube.com/embed/fdbFVWupSsw',
45           '#query' => ['autoplay' => '1'],
46           '#attributes' => [
47             'width' => '100',
48           ],
49         ],
50         '<iframe width="100" src="https://www.youtube.com/embed/fdbFVWupSsw?autoplay=1"></iframe>',
51       ],
52       'Query' => [
53         [
54           '#type' => 'video_embed_iframe',
55           '#query' => ['autoplay' => '1'],
56         ],
57         '<iframe></iframe>',
58       ],
59       'Query, attributes' => [
60         [
61           '#type' => 'video_embed_iframe',
62           '#query' => ['autoplay' => '1'],
63           '#attributes' => [
64             'width' => '100',
65           ],
66         ],
67         '<iframe width="100"></iframe>',
68       ],
69       'Attributes' => [
70         [
71           '#type' => 'video_embed_iframe',
72           '#attributes' => [
73             'width' => '100',
74           ],
75         ],
76         '<iframe width="100"></iframe>',
77       ],
78       'Fragment' => [
79         [
80           '#type' => 'video_embed_iframe',
81           '#url' => 'https://example.com',
82           '#fragment' => 'test fragment',
83         ],
84         '<iframe src="https://example.com#test fragment"></iframe>',
85       ],
86       'XSS Testing' => [
87         [
88           '#type' => 'video_embed_iframe',
89           '#attributes' => [
90             'xss' => '">',
91           ],
92           '#query' => ['xss' => '">'],
93           '#url' => '">',
94           '#fragment' => '">',
95         ],
96         '<iframe xss="&quot;&gt;" src="&quot;&gt;?xss=%22%3E#&quot;&gt;"></iframe>',
97       ],
98     ];
99   }
100
101   /**
102    * Test the video embed iframe renders correctly.
103    *
104    * @dataProvider videoEmbedIframeTestCases
105    */
106   public function testVideoEmbedIframe($renderable, $markup) {
107     $this->assertEquals($markup, trim($this->container->get('renderer')->renderRoot($renderable)));
108   }
109
110 }