TYPO3 CMS  TYPO3_8-7
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 
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 
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 
77  public function canRenderReturnsFalseOnCorrectFile()
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 
131  public function renderOutputWithAutoplayFromReferenceIsCorrect()
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 
150  public function renderOutputWithAutoplayAndWithoutControllsIsCorrect()
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 
164  public function renderOutputWithCustomAllowIsCorrect()
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 width="300" height="200" allow="foo; bar"></iframe>',
171  $this->subject->render($fileResourceMock, '300m', '200', ['allow' => 'foo; bar'])
172  );
173  }
174 
178  public function renderOutputWithCustomAllowAndAutoplayIsCorrect()
179  {
181  $fileResourceMock = $this->createMock(File::class);
182 
183  $this->assertSame(
184  '<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>',
185  $this->subject->render($fileResourceMock, '300m', '200', ['allow' => 'foo; bar', 'autoplay' => 1])
186  );
187  }
188 
192  public function renderOutputWithPrivateVimeoCodeIsCorrect()
193  {
195  $vimeoHelper = $this->getAccessibleMock(VimeoHelper::class, ['getOnlineMediaId'], ['vimeo']);
196  $vimeoHelper->expects($this->any())->method('getOnlineMediaId')->will($this->returnValue('7331/private0123'));
197 
198  $subject = $this->getAccessibleMock(VimeoRenderer::class, ['getOnlineMediaHelper'], []);
199  $subject->expects($this->any())->method('getOnlineMediaHelper')->will($this->returnValue($vimeoHelper));
200 
202  $fileResourceMock = $this->createMock(File::class);
203 
204  $this->assertSame(
205  '<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>',
206  $subject->render($fileResourceMock, '300m', '200')
207  );
208  }
209 
213  public function renderOutputIsEscaped()
214  {
216  $vimeoHelper = $this->getAccessibleMock(VimeoHelper::class, ['getOnlineMediaId'], ['vimeo']);
217  $vimeoHelper->expects($this->any())->method('getOnlineMediaId')->will($this->returnValue('7331<script>danger</script>\'"random"quotes;'));
218 
219  $subject = $this->getAccessibleMock(VimeoRenderer::class, ['getOnlineMediaHelper'], []);
220  $subject->expects($this->any())->method('getOnlineMediaHelper')->will($this->returnValue($vimeoHelper));
221 
223  $fileResourceMock = $this->createMock(File::class);
224 
225  $this->assertSame(
226  '<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>',
227  $subject->render($fileResourceMock, '300m', '200')
228  );
229  }
230 }