af41aa6528aea6f80ae04f2d703368229c53845b
[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 * @test
69 */
70 public function renderOutputIsCorrect()
71 {
72 $VideoTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer();
73
74 $fileResourceMock = $this->createMock(\TYPO3\CMS\Core\Resource\File::class);
75 $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('video/mp4'));
76 $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue('//:path/myVideoFile?foo=bar&baz=true'));
77
78 $this->assertSame(
79 '<video width="300" height="200" controls><source src="//:path/myVideoFile?foo=bar&amp;baz=true" type="video/mp4"></video>',
80 $VideoTagRenderer->render($fileResourceMock, '300m', '200')
81 );
82 }
83
84 /**
85 * @test
86 */
87 public function renderOutputWithLoopIsCorrect()
88 {
89 $VideoTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer();
90
91 $fileResourceMock = $this->createMock(\TYPO3\CMS\Core\Resource\File::class);
92 $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('video/mp4'));
93 $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue('//:path/myVideoFile'));
94
95 $this->assertSame(
96 '<video width="300" height="200" controls loop><source src="//:path/myVideoFile" type="video/mp4"></video>',
97 $VideoTagRenderer->render($fileResourceMock, '300m', '200', ['loop' => 1])
98 );
99 }
100
101 /**
102 * @test
103 */
104 public function renderOutputWithAutoplayIsCorrect()
105 {
106 $VideoTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer();
107
108 $fileResourceMock = $this->createMock(\TYPO3\CMS\Core\Resource\File::class);
109 $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('video/mp4'));
110 $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue('//:path/myVideoFile'));
111
112 $this->assertSame(
113 '<video width="300" height="200" controls autoplay><source src="//:path/myVideoFile" type="video/mp4"></video>',
114 $VideoTagRenderer->render($fileResourceMock, '300m', '200', ['autoplay' => 1])
115 );
116 }
117
118 /**
119 * @test
120 */
121 public function renderOutputWithAutoplayAndWithoutControllsIsCorrect()
122 {
123 $VideoTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer();
124
125 $fileResourceMock = $this->createMock(\TYPO3\CMS\Core\Resource\File::class);
126 $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('video/mp4'));
127 $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue('//:path/myVideoFile'));
128
129 $this->assertSame(
130 '<video width="300" height="200" autoplay><source src="//:path/myVideoFile" type="video/mp4"></video>',
131 $VideoTagRenderer->render($fileResourceMock, '300m', '200', ['controls' => 0, 'autoplay' => 1])
132 );
133 }
134 }