[TASK] Make VimeoRendererTest notice free
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / Rendering / VimeoRendererTest.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\FileReference;
20 use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper;
21 use TYPO3\CMS\Core\Resource\Rendering\VimeoRenderer;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23
24 /**
25 * Class VimeoRendererTest
26 */
27 class VimeoRendererTest extends UnitTestCase
28 {
29 /**
30 * @var VimeoRenderer|\PHPUnit_Framework_MockObject_MockObject
31 */
32 protected $subject;
33
34 /**
35 * Set up the test
36 */
37 protected function setUp()
38 {
39 parent::setUp();
40
41 /** @var VimeoHelper|\PHPUnit_Framework_MockObject_MockObject $vimeoHelper */
42 $vimeoHelper = $this->getAccessibleMock(VimeoHelper::class, ['getOnlineMediaId'], ['vimeo']);
43 $vimeoHelper->expects($this->any())->method('getOnlineMediaId')->will($this->returnValue('7331'));
44
45 $this->subject = $this->getAccessibleMock(VimeoRenderer::class, ['getOnlineMediaHelper'], []);
46 $this->subject->expects($this->any())->method('getOnlineMediaHelper')->will($this->returnValue($vimeoHelper));
47 }
48
49 /**
50 * @test
51 */
52 public function getPriorityReturnsCorrectValue()
53 {
54 $this->assertSame(1, $this->subject->getPriority());
55 }
56
57 /**
58 * @test
59 */
60 public function canRenderReturnsTrueOnCorrectFile()
61 {
62 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock1 */
63 $fileResourceMock1 = $this->createMock(File::class);
64 $fileResourceMock1->expects($this->any())->method('getMimeType')->will($this->returnValue('video/vimeo'));
65 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock2 */
66 $fileResourceMock2 = $this->createMock(File::class);
67 $fileResourceMock2->expects($this->any())->method('getMimeType')->will($this->returnValue('video/unknown'));
68 $fileResourceMock2->expects($this->any())->method('getExtension')->will($this->returnValue('vimeo'));
69
70 $this->assertTrue($this->subject->canRender($fileResourceMock1));
71 $this->assertTrue($this->subject->canRender($fileResourceMock2));
72 }
73
74 /**
75 * @test
76 */
77 public function canRenderReturnsFalseOnCorrectFile()
78 {
79 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
80 $fileResourceMock = $this->createMock(File::class);
81 $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('video/youtube'));
82
83 $this->assertFalse($this->subject->canRender($fileResourceMock));
84 }
85
86 /**
87 * @test
88 */
89 public function renderOutputIsCorrect()
90 {
91 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
92 $fileResourceMock = $this->createMock(File::class);
93
94 $this->assertSame(
95 '<iframe src="https://player.vimeo.com/video/7331?title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200"></iframe>',
96 $this->subject->render($fileResourceMock, '300m', '200')
97 );
98 }
99
100 /**
101 * @test
102 */
103 public function renderOutputWithLoopIsCorrect()
104 {
105 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
106 $fileResourceMock = $this->createMock(File::class);
107
108 $this->assertSame(
109 '<iframe src="https://player.vimeo.com/video/7331?loop=1&amp;title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200"></iframe>',
110 $this->subject->render($fileResourceMock, '300m', '200', ['loop' => 1])
111 );
112 }
113
114 /**
115 * @test
116 */
117 public function renderOutputWithAutoplayIsCorrect()
118 {
119 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
120 $fileResourceMock = $this->createMock(File::class);
121
122 $this->assertSame(
123 '<iframe src="https://player.vimeo.com/video/7331?autoplay=1&amp;title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200"></iframe>',
124 $this->subject->render($fileResourceMock, '300m', '200', ['autoplay' => 1])
125 );
126 }
127
128 /**
129 * @test
130 */
131 public function renderOutputWithAutoplayFromReferenceIsCorrect()
132 {
133 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
134 $fileResourceMock = $this->createMock(File::class);
135
136 /** @var FileReference|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
137 $fileReferenceMock = $this->createMock(FileReference::class);
138 $fileReferenceMock->expects($this->any())->method('getProperty')->will($this->returnValue(1));
139 $fileReferenceMock->expects($this->any())->method('getOriginalFile')->willReturn($fileResourceMock);
140
141 $this->assertSame(
142 '<iframe src="https://player.vimeo.com/video/7331?autoplay=1&amp;title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200"></iframe>',
143 $this->subject->render($fileReferenceMock, '300m', '200')
144 );
145 }
146
147 /**
148 * @test
149 */
150 public function renderOutputWithAutoplayAndWithoutControllsIsCorrect()
151 {
152 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
153 $fileResourceMock = $this->createMock(File::class);
154
155 $this->assertSame(
156 '<iframe src="https://player.vimeo.com/video/7331?autoplay=1&amp;title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200"></iframe>',
157 $this->subject->render($fileResourceMock, '300m', '200', ['autoplay' => 1])
158 );
159 }
160
161 /**
162 * @test
163 */
164 public function renderOutputWithAdditionalAttributes()
165 {
166 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
167 $fileResourceMock = $this->createMock(File::class);
168
169 $this->assertSame(
170 '<iframe src="https://player.vimeo.com/video/7331?title=0&amp;byline=0&amp;portrait=0" allowfullscreen foo="bar" custom-play="preload" width="300" height="200"></iframe>',
171 $this->subject->render($fileResourceMock, '300m', '200', ['additionalAttributes' => ['foo' => 'bar', 'custom-play' => 'preload']])
172 );
173 }
174
175 /**
176 * @test
177 */
178 public function renderOutputWithDataAttributesForCustomization()
179 {
180 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
181 $fileResourceMock = $this->createMock(File::class);
182
183 $this->assertSame(
184 '<iframe src="https://player.vimeo.com/video/7331?title=0&amp;byline=0&amp;portrait=0" allowfullscreen data-player-handler="vimeo" data-custom-playerId="player-123" width="300" height="200"></iframe>',
185 $this->subject->render($fileResourceMock, '300m', '200', ['data' => ['player-handler' => 'vimeo', 'custom-playerId' => 'player-123']])
186 );
187 }
188
189 /**
190 * @test
191 */
192 public function renderOutputWithCombinationOfDataAndAdditionalAttributes()
193 {
194 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
195 $fileResourceMock = $this->createMock(File::class);
196
197 $this->assertSame(
198 '<iframe src="https://player.vimeo.com/video/7331?title=0&amp;byline=0&amp;portrait=0" allowfullscreen foo="bar" custom-play="preload" data-player-handler="vimeo" data-custom-playerId="player-123" width="300" height="200"></iframe>',
199 $this->subject->render($fileResourceMock, '300m', '200', ['data' => ['player-handler' => 'vimeo', 'custom-playerId' => 'player-123'], 'additionalAttributes' => ['foo' => 'bar', 'custom-play' => 'preload']])
200 );
201 }
202 }