‪TYPO3CMS  9.5
VimeoRendererTest.php
Go to the documentation of this file.
1 <?php
2 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 
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪VimeoRendererTest extends UnitTestCase
28 {
32  protected ‪$subject;
33 
37  protected function ‪setUp()
38  {
39  parent::setUp();
40 
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 
52  public function ‪getPriorityReturnsCorrectValue()
53  {
54  $this->assertSame(1, $this->subject->getPriority());
55  }
56 
60  public function ‪canRenderReturnsTrueOnCorrectFile()
61  {
63  $fileResourceMock1 = $this->createMock(File::class);
64  $fileResourceMock1->expects($this->any())->method('getMimeType')->will($this->returnValue('video/vimeo'));
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 
78  {
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 
89  public function ‪renderOutputIsCorrect()
90  {
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" allow="fullscreen"></iframe>',
96  $this->subject->render($fileResourceMock, '300m', '200')
97  );
98  }
99 
103  public function ‪renderOutputWithLoopIsCorrect()
104  {
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" allow="fullscreen"></iframe>',
110  $this->subject->render($fileResourceMock, '300m', '200', ['loop' => 1])
111  );
112  }
113 
117  public function ‪renderOutputWithAutoplayIsCorrect()
118  {
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" allow="autoplay; fullscreen"></iframe>',
124  $this->subject->render($fileResourceMock, '300m', '200', ['autoplay' => 1])
125  );
126  }
127 
132  {
134  $fileResourceMock = $this->createMock(File::class);
135 
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" allow="autoplay; fullscreen"></iframe>',
143  $this->subject->render($fileReferenceMock, '300m', '200')
144  );
145  }
146 
151  {
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" allow="autoplay; fullscreen"></iframe>',
157  $this->subject->render($fileResourceMock, '300m', '200', ['autoplay' => 1])
158  );
159  }
160 
165  {
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" sanitizetest="&lt;&gt;&quot;&apos;test" width="300" height="200" allow="fullscreen"></iframe>',
171  $this->subject->render($fileResourceMock, '300m', '200', ['additionalAttributes' => ['foo' => 'bar', 'custom-play' => 'preload', '<"\'>sanitize^&test' => '<>"\'test']])
172  );
173  }
174 
179  {
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" data-sanitizetest="test" width="300" height="200" allow="fullscreen"></iframe>',
185  $this->subject->render($fileResourceMock, '300m', '200', ['data' => ['player-handler' => 'vimeo', 'custom-playerId' => 'player-123', '*sanitize&test"' => 'test']])
186  );
187  }
188 
193  {
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" allow="fullscreen"></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 
207  {
209  $fileResourceMock = $this->createMock(File::class);
210 
211  $this->assertSame(
212  '<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>',
213  $this->subject->render($fileResourceMock, '300m', '200', ['allow' => 'foo; bar'])
214  );
215  }
216 
221  {
223  $fileResourceMock = $this->createMock(File::class);
224 
225  $this->assertSame(
226  '<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>',
227  $this->subject->render($fileResourceMock, '300m', '200', ['allow' => 'foo; bar', 'autoplay' => 1])
228  );
229  }
230 
235  {
237  $vimeoHelper = $this->getAccessibleMock(VimeoHelper::class, ['getOnlineMediaId'], ['vimeo']);
238  $vimeoHelper->expects($this->any())->method('getOnlineMediaId')->will($this->returnValue('7331/private0123'));
239 
240  ‪$subject = $this->getAccessibleMock(VimeoRenderer::class, ['getOnlineMediaHelper'], []);
241  ‪$subject->expects($this->any())->method('getOnlineMediaHelper')->will($this->returnValue($vimeoHelper));
242 
244  $fileResourceMock = $this->createMock(File::class);
245 
246  $this->assertSame(
247  '<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>',
248  ‪$subject->‪render($fileResourceMock, '300m', '200')
249  );
250  }
251 
255  public function ‪renderOutputIsEscaped()
256  {
258  $vimeoHelper = $this->getAccessibleMock(VimeoHelper::class, ['getOnlineMediaId'], ['vimeo']);
259  $vimeoHelper->expects($this->any())->method('getOnlineMediaId')->will($this->returnValue('7331<script>danger</script>\'"random"quotes;'));
260 
261  ‪$subject = $this->getAccessibleMock(VimeoRenderer::class, ['getOnlineMediaHelper'], []);
262  ‪$subject->expects($this->any())->method('getOnlineMediaHelper')->will($this->returnValue($vimeoHelper));
263 
265  $fileResourceMock = $this->createMock(File::class);
266 
267  $this->assertSame(
268  '<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>',
269  ‪$subject->‪render($fileResourceMock, '300m', '200')
270  );
271  }
272 
277  {
279  $fileResourceMock = $this->createMock(File::class);
280 
281  self::assertSame(
282  '<iframe src="https://player.vimeo.com/video/7331?dnt=1&amp;title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200" allow="fullscreen"></iframe>',
283  $this->subject->render($fileResourceMock, '300m', '200', ['no-cookie' => 1])
284  );
285  }
286 }
‪TYPO3\CMS\Core\Resource\Rendering\VimeoRenderer
Definition: VimeoRenderer.php:27
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\getPriorityReturnsCorrectValue
‪getPriorityReturnsCorrectValue()
Definition: VimeoRendererTest.php:51
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithCustomAllowIsCorrect
‪renderOutputWithCustomAllowIsCorrect()
Definition: VimeoRendererTest.php:205
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithAutoplayFromReferenceIsCorrect
‪renderOutputWithAutoplayFromReferenceIsCorrect()
Definition: VimeoRendererTest.php:130
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithAdditionalAttributes
‪renderOutputWithAdditionalAttributes()
Definition: VimeoRendererTest.php:163
‪TYPO3\CMS\Core\Resource\FileReference
Definition: FileReference.php:31
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\canRenderReturnsTrueOnCorrectFile
‪canRenderReturnsTrueOnCorrectFile()
Definition: VimeoRendererTest.php:59
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering
Definition: AudioTagRendererTest.php:3
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithLoopIsCorrect
‪renderOutputWithLoopIsCorrect()
Definition: VimeoRendererTest.php:102
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithCombinationOfDataAndAdditionalAttributes
‪renderOutputWithCombinationOfDataAndAdditionalAttributes()
Definition: VimeoRendererTest.php:191
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputIsEscaped
‪renderOutputIsEscaped()
Definition: VimeoRendererTest.php:254
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\setUp
‪setUp()
Definition: VimeoRendererTest.php:36
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputIsCorrect
‪renderOutputIsCorrect()
Definition: VimeoRendererTest.php:88
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\$subject
‪VimeoRenderer PHPUnit_Framework_MockObject_MockObject $subject
Definition: VimeoRendererTest.php:31
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:23
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithDisabledNoCookieIsCorrect
‪renderOutputWithDisabledNoCookieIsCorrect()
Definition: VimeoRendererTest.php:275
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\canRenderReturnsFalseOnCorrectFile
‪canRenderReturnsFalseOnCorrectFile()
Definition: VimeoRendererTest.php:76
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest
Definition: VimeoRendererTest.php:28
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithDataAttributesForCustomization
‪renderOutputWithDataAttributesForCustomization()
Definition: VimeoRendererTest.php:177
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithPrivateVimeoCodeIsCorrect
‪renderOutputWithPrivateVimeoCodeIsCorrect()
Definition: VimeoRendererTest.php:233
‪TYPO3\CMS\Core\Resource\Rendering\VimeoRenderer\render
‪string render(FileInterface $file, $width, $height, array $options=[], $usedPathsRelativeToCurrentScript=false)
Definition: VimeoRenderer.php:89
‪TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper
Definition: VimeoHelper.php:25
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithCustomAllowAndAutoplayIsCorrect
‪renderOutputWithCustomAllowAndAutoplayIsCorrect()
Definition: VimeoRendererTest.php:219
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithAutoplayIsCorrect
‪renderOutputWithAutoplayIsCorrect()
Definition: VimeoRendererTest.php:116
‪TYPO3\CMS\Core\Tests\Unit\Resource\Rendering\VimeoRendererTest\renderOutputWithAutoplayAndWithoutControllsIsCorrect
‪renderOutputWithAutoplayAndWithoutControllsIsCorrect()
Definition: VimeoRendererTest.php:149