[TASK] Allow preload Tag in VideoTagRenderer
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / Rendering / VideoTagRendererTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Core\Tests\Unit\Resource\Rendering;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Core\Resource\File;
19 use TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer;
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21
22 /**
23 * Class VideoTagRendererTest
24 */
25 class VideoTagRendererTest extends UnitTestCase
26 {
27 /**
28 * @test
29 */
30 public function getPriorityReturnsCorrectValue()
31 {
32 $VideoTagRenderer = new VideoTagRenderer();
33
34 $this->assertSame(1, $VideoTagRenderer->getPriority());
35 }
36
37 /**
38 * @test
39 */
40 public function canRenderReturnsTrueOnCorrectFile()
41 {
42 $VideoTagRenderer = new VideoTagRenderer();
43
44 $fileResourceMock1 = $this->createMock(File::class);
45 $fileResourceMock1->expects($this->any())->method('getMimeType')->will($this->returnValue('video/mp4'));
46 $fileResourceMock2 = $this->createMock(File::class);
47 $fileResourceMock2->expects($this->any())->method('getMimeType')->will($this->returnValue('video/webm'));
48 $fileResourceMock3 = $this->createMock(File::class);
49 $fileResourceMock3->expects($this->any())->method('getMimeType')->will($this->returnValue('video/ogg'));
50 $fileResourceMock4 = $this->createMock(File::class);
51 $fileResourceMock4->expects($this->any())->method('getMimeType')->will($this->returnValue('application/ogg'));
52
53 $this->assertTrue($VideoTagRenderer->canRender($fileResourceMock1));
54 $this->assertTrue($VideoTagRenderer->canRender($fileResourceMock2));
55 $this->assertTrue($VideoTagRenderer->canRender($fileResourceMock3));
56 $this->assertTrue($VideoTagRenderer->canRender($fileResourceMock4));
57 }
58
59 /**
60 * @test
61 */
62 public function canRenderReturnsFalseOnCorrectFile()
63 {
64 $VideoTagRenderer = new VideoTagRenderer();
65
66 $fileResourceMock = $this->createMock(File::class);
67 $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('audio/mpeg'));
68
69 $this->assertFalse($VideoTagRenderer->canRender($fileResourceMock));
70 }
71
72 /**
73 * Array of configurations
74 */
75 public function renderArgumentsDataProvider()
76 {
77 return [
78 [
79 '//:path/myVideoFile?foo=bar&baz=true',
80 [],
81 '<video width="300" height="200" controls><source src="//:path/myVideoFile?foo=bar&amp;baz=true" type="video/mp4"></video>',
82 ],
83 [
84 '//:path/myVideoFile',
85 ['loop' => 1],
86 '<video width="300" height="200" controls loop><source src="//:path/myVideoFile" type="video/mp4"></video>',
87 ],
88 [
89 '//:path/myVideoFile',
90 ['autoplay' => 1],
91 '<video width="300" height="200" controls autoplay><source src="//:path/myVideoFile" type="video/mp4"></video>',
92 ],
93 [
94 '//:path/myVideoFile',
95 ['controls' => 0, 'autoplay' => 1],
96 '<video width="300" height="200" autoplay><source src="//:path/myVideoFile" type="video/mp4"></video>',
97 ],
98 [
99 '//:path/myVideoFile',
100 ['controls' => 1, 'controlsList' => 'nodownload'],
101 '<video width="300" height="200" controls controlsList="nodownload"><source src="//:path/myVideoFile" type="video/mp4"></video>',
102 ],
103 [
104 '//:path/myVideoFile',
105 ['additionalAttributes' => ['muted' => 'muted', 'foo' => 'bar']],
106 '<video muted="muted" foo="bar" width="300" height="200" controls><source src="//:path/myVideoFile" type="video/mp4"></video>',
107 ],
108 [
109 '//:path/myVideoFile',
110 ['data' => ['js-required' => 'yes', 'custom-id' => 'video-123']],
111 '<video data-js-required="yes" data-custom-id="video-123" width="300" height="200" controls><source src="//:path/myVideoFile" type="video/mp4"></video>',
112 ],
113 [
114 '//:path/myVideoFile',
115 [
116 'data' => [
117 'js-required' => 'yes',
118 'custom-id' => 'video-123'
119 ],
120 'additionalAttributes' => [
121 'muted' => 'muted',
122 'foo' => 'bar'
123 ],
124 'additionalConfig' => [
125 'playsinline' => '1',
126 'controls' => '1'
127 ]
128 ],
129 '<video muted="muted" foo="bar" data-js-required="yes" data-custom-id="video-123" width="300" height="200" controls playsinline><source src="//:path/myVideoFile" type="video/mp4"></video>',
130 ],
131 [
132 '//:path/myVideoFile',
133 ['preload' => 'auto'],
134 '<video width="300" height="200" controls preload="auto"><source src="//:path/myVideoFile" type="video/mp4"></video>',
135 ],
136 ];
137 }
138
139 /**
140 * @test
141 * @dataProvider renderArgumentsDataProvider
142 * @param string $url
143 * @param array $arguments
144 * @param string $expected
145 */
146 public function renderOutputIsCorrect($url, $arguments, $expected)
147 {
148 $VideoTagRenderer = new VideoTagRenderer();
149
150 $fileResourceMock = $this->createMock(File::class);
151 $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('video/mp4'));
152 $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue($url));
153
154 $this->assertSame(
155 $expected,
156 $VideoTagRenderer->render($fileResourceMock, '300m', '200', $arguments)
157 );
158 }
159 }