‪TYPO3CMS  10.4
VimeoRendererTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
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 
19 
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪VimeoRendererTest extends UnitTestCase
30 {
34  protected ‪$subject;
35 
39  protected function ‪setUp(): void
40  {
41  parent::setUp();
42 
44  $vimeoHelper = $this->getAccessibleMock(VimeoHelper::class, ['getOnlineMediaId'], ['vimeo']);
45  $vimeoHelper->expects(self::any())->method('getOnlineMediaId')->willReturn('7331');
46 
47  $this->subject = $this->getAccessibleMock(VimeoRenderer::class, ['getOnlineMediaHelper'], []);
48  $this->subject->expects(self::any())->method('getOnlineMediaHelper')->willReturn($vimeoHelper);
49  }
50 
54  public function ‪getPriorityReturnsCorrectValue()
55  {
56  self::assertSame(1, $this->subject->getPriority());
57  }
58 
62  public function ‪canRenderReturnsTrueOnCorrectFile()
63  {
65  $fileResourceMock1 = $this->createMock(File::class);
66  $fileResourceMock1->expects(self::any())->method('getMimeType')->willReturn('video/vimeo');
68  $fileResourceMock2 = $this->createMock(File::class);
69  $fileResourceMock2->expects(self::any())->method('getMimeType')->willReturn('video/unknown');
70  $fileResourceMock2->expects(self::any())->method('getExtension')->willReturn('vimeo');
71 
72  self::assertTrue($this->subject->canRender($fileResourceMock1));
73  self::assertTrue($this->subject->canRender($fileResourceMock2));
74  }
75 
80  {
82  $fileResourceMock = $this->createMock(File::class);
83  $fileResourceMock->expects(self::any())->method('getMimeType')->willReturn('video/youtube');
84 
85  self::assertFalse($this->subject->canRender($fileResourceMock));
86  }
87 
91  public function ‪renderOutputIsCorrect()
92  {
94  $fileResourceMock = $this->createMock(File::class);
95 
96  self::assertSame(
97  '<iframe src="https://player.vimeo.com/video/7331?title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200" allow="fullscreen"></iframe>',
98  $this->subject->render($fileResourceMock, '300m', '200')
99  );
100  }
101 
105  public function ‪renderOutputWithLoopIsCorrect()
106  {
108  $fileResourceMock = $this->createMock(File::class);
109 
110  self::assertSame(
111  '<iframe src="https://player.vimeo.com/video/7331?loop=1&amp;title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200" allow="fullscreen"></iframe>',
112  $this->subject->render($fileResourceMock, '300m', '200', ['loop' => 1])
113  );
114  }
115 
119  public function ‪renderOutputWithAutoplayIsCorrect()
120  {
122  $fileResourceMock = $this->createMock(File::class);
123 
124  self::assertSame(
125  '<iframe src="https://player.vimeo.com/video/7331?autoplay=1&amp;title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200" allow="autoplay; fullscreen"></iframe>',
126  $this->subject->render($fileResourceMock, '300m', '200', ['autoplay' => 1])
127  );
128  }
129 
134  {
136  $fileResourceMock = $this->createMock(File::class);
137 
139  $fileReferenceMock = $this->createMock(FileReference::class);
140  $fileReferenceMock->expects(self::any())->method('getProperty')->willReturn(1);
141  $fileReferenceMock->expects(self::any())->method('getOriginalFile')->willReturn($fileResourceMock);
142 
143  self::assertSame(
144  '<iframe src="https://player.vimeo.com/video/7331?autoplay=1&amp;title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200" allow="autoplay; fullscreen"></iframe>',
145  $this->subject->render($fileReferenceMock, '300m', '200')
146  );
147  }
148 
153  {
155  $fileResourceMock = $this->createMock(File::class);
156 
157  self::assertSame(
158  '<iframe src="https://player.vimeo.com/video/7331?autoplay=1&amp;title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200" allow="autoplay; fullscreen"></iframe>',
159  $this->subject->render($fileResourceMock, '300m', '200', ['autoplay' => 1])
160  );
161  }
162 
167  {
169  $fileResourceMock = $this->createMock(File::class);
170 
171  self::assertSame(
172  '<iframe src="https://player.vimeo.com/video/7331?title=0&amp;byline=0&amp;portrait=0" allowfullscreen foo="bar" custom-play="preload" sanitizetest="&lt;&gt;&quot;&apos;test" width="300" height="200" allow="fullscreen"></iframe>',
173  $this->subject->render($fileResourceMock, '300m', '200', ['additionalAttributes' => ['foo' => 'bar', 'custom-play' => 'preload', '<"\'>sanitize^&test' => '<>"\'test']])
174  );
175  }
176 
181  {
183  $fileResourceMock = $this->createMock(File::class);
184 
185  self::assertSame(
186  '<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" data-sanitizetest="test" width="300" height="200" allow="fullscreen"></iframe>',
187  $this->subject->render($fileResourceMock, '300m', '200', ['data' => ['player-handler' => 'vimeo', 'custom-playerId' => 'player-123', '*sanitize&test"' => 'test']])
188  );
189  }
190 
195  {
197  $fileResourceMock = $this->createMock(File::class);
198 
199  self::assertSame(
200  '<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" allow="fullscreen"></iframe>',
201  $this->subject->render($fileResourceMock, '300m', '200', ['data' => ['player-handler' => 'vimeo', 'custom-playerId' => 'player-123'], 'additionalAttributes' => ['foo' => 'bar', 'custom-play' => 'preload']])
202  );
203  }
204 
209  {
211  $fileResourceMock = $this->createMock(File::class);
212 
213  self::assertSame(
214  '<iframe src="https://player.vimeo.com/video/7331?title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200" allow="foo; bar"></iframe>',
215  $this->subject->render($fileResourceMock, '300m', '200', ['allow' => 'foo; bar'])
216  );
217  }
218 
223  {
225  $fileResourceMock = $this->createMock(File::class);
226 
227  self::assertSame(
228  '<iframe src="https://player.vimeo.com/video/7331?autoplay=1&amp;title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200" allow="foo; bar"></iframe>',
229  $this->subject->render($fileResourceMock, '300m', '200', ['allow' => 'foo; bar', 'autoplay' => 1])
230  );
231  }
232 
237  {
239  $vimeoHelper = $this->getAccessibleMock(VimeoHelper::class, ['getOnlineMediaId'], ['vimeo']);
240  $vimeoHelper->expects(self::any())->method('getOnlineMediaId')->willReturn('7331/private0123');
241 
242  ‪$subject = $this->getAccessibleMock(VimeoRenderer::class, ['getOnlineMediaHelper'], []);
243  ‪$subject->expects(self::any())->method('getOnlineMediaHelper')->willReturn($vimeoHelper);
244 
246  $fileResourceMock = $this->createMock(File::class);
247 
248  self::assertSame(
249  '<iframe src="https://player.vimeo.com/video/7331/private0123?title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200" allow="fullscreen"></iframe>',
250  ‪$subject->‪render($fileResourceMock, '300m', '200')
251  );
252  }
253 
257  public function ‪renderOutputIsEscaped()
258  {
260  $vimeoHelper = $this->getAccessibleMock(VimeoHelper::class, ['getOnlineMediaId'], ['vimeo']);
261  $vimeoHelper->expects(self::any())->method('getOnlineMediaId')->willReturn('7331<script>danger</script>\'"random"quotes;');
262 
263  ‪$subject = $this->getAccessibleMock(VimeoRenderer::class, ['getOnlineMediaHelper'], []);
264  ‪$subject->expects(self::any())->method('getOnlineMediaHelper')->willReturn($vimeoHelper);
265 
267  $fileResourceMock = $this->createMock(File::class);
268 
269  self::assertSame(
270  '<iframe src="https://player.vimeo.com/video/7331&lt;script&gt;danger&lt;/script&gt;&apos;&quot;random&quot;quotes;?title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200" allow="fullscreen"></iframe>',
271  ‪$subject->‪render($fileResourceMock, '300m', '200')
272  );
273  }
274 
278  public function ‪renderOutputWithApiIsCorrect()
279  {
281  $fileResourceMock = $this->createMock(File::class);
282 
283  self::assertSame(
284  '<iframe src="https://player.vimeo.com/video/7331?api=1&amp;title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200" allow="fullscreen"></iframe>',
285  $this->subject->render($fileResourceMock, '300m', '200', ['api' => 1])
286  );
287  }
288 
293  {
295  $fileResourceMock = $this->createMock(File::class);
296 
297  self::assertSame(
298  '<iframe src="https://player.vimeo.com/video/7331?api=1&amp;dnt=1&amp;title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200" allow="fullscreen"></iframe>',
299  $this->subject->render($fileResourceMock, '300m', '200', ['api' => 1, 'no-cookie' => 1])
300  );
301  }
302 }
‪TYPO3\CMS\Core\Resource\Rendering\VimeoRenderer
Definition: VimeoRenderer.php:28
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\getPriorityReturnsCorrectValue
‪getPriorityReturnsCorrectValue()
Definition: VimeoRendererTest.php:53
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithCustomAllowIsCorrect
‪renderOutputWithCustomAllowIsCorrect()
Definition: VimeoRendererTest.php:207
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithAutoplayFromReferenceIsCorrect
‪renderOutputWithAutoplayFromReferenceIsCorrect()
Definition: VimeoRendererTest.php:132
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithAdditionalAttributes
‪renderOutputWithAdditionalAttributes()
Definition: VimeoRendererTest.php:165
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithApiIsCorrect
‪renderOutputWithApiIsCorrect()
Definition: VimeoRendererTest.php:277
‪TYPO3\CMS\Core\Resource\FileReference
Definition: FileReference.php:33
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\canRenderReturnsTrueOnCorrectFile
‪canRenderReturnsTrueOnCorrectFile()
Definition: VimeoRendererTest.php:61
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering
Definition: AudioTagRendererTest.php:18
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithLoopIsCorrect
‪renderOutputWithLoopIsCorrect()
Definition: VimeoRendererTest.php:104
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithCombinationOfDataAndAdditionalAttributes
‪renderOutputWithCombinationOfDataAndAdditionalAttributes()
Definition: VimeoRendererTest.php:193
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputIsEscaped
‪renderOutputIsEscaped()
Definition: VimeoRendererTest.php:256
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\setUp
‪setUp()
Definition: VimeoRendererTest.php:38
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputIsCorrect
‪renderOutputIsCorrect()
Definition: VimeoRendererTest.php:90
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithDisabledNoCookieIsCorrect
‪renderOutputWithDisabledNoCookieIsCorrect()
Definition: VimeoRendererTest.php:291
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\$subject
‪VimeoRenderer PHPUnit Framework MockObject MockObject $subject
Definition: VimeoRendererTest.php:33
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\canRenderReturnsFalseOnCorrectFile
‪canRenderReturnsFalseOnCorrectFile()
Definition: VimeoRendererTest.php:78
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest
Definition: VimeoRendererTest.php:30
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithDataAttributesForCustomization
‪renderOutputWithDataAttributesForCustomization()
Definition: VimeoRendererTest.php:179
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithPrivateVimeoCodeIsCorrect
‪renderOutputWithPrivateVimeoCodeIsCorrect()
Definition: VimeoRendererTest.php:235
‪TYPO3\CMS\Core\Resource\Rendering\VimeoRenderer\render
‪string render(FileInterface $file, $width, $height, array $options=[], $usedPathsRelativeToCurrentScript=false)
Definition: VimeoRenderer.php:90
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithAutoplayAndWithoutControlsIsCorrect
‪renderOutputWithAutoplayAndWithoutControlsIsCorrect()
Definition: VimeoRendererTest.php:151
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper
Definition: VimeoHelper.php:26
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithCustomAllowAndAutoplayIsCorrect
‪renderOutputWithCustomAllowAndAutoplayIsCorrect()
Definition: VimeoRendererTest.php:221
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithAutoplayIsCorrect
‪renderOutputWithAutoplayIsCorrect()
Definition: VimeoRendererTest.php:118