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