TYPO3 CMS  TYPO3_7-6
VimeoRendererTest.php
Go to the documentation of this file.
1 <?php
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 
22 
27 {
31  protected $subject;
32 
36  protected function setUp()
37  {
38  parent::setUp();
39 
41  $vimeoHelper = $this->getAccessibleMock(VimeoHelper::class, ['getOnlineMediaId'], ['vimeo']);
42  $vimeoHelper->expects($this->any())->method('getOnlineMediaId')->will($this->returnValue('7331'));
43 
44  $this->subject = $this->getAccessibleMock(VimeoRenderer::class, ['getOnlineMediaHelper'], []);
45  $this->subject->expects($this->any())->method('getOnlineMediaHelper')->will($this->returnValue($vimeoHelper));
46  }
47 
52  {
53  $this->assertSame(1, $this->subject->getPriority());
54  }
55 
59  public function canRenderReturnsTrueOnCorrectFile()
60  {
62  $fileResourceMock1 = $this->getMock(File::class, [], [], '', false);
63  $fileResourceMock1->expects($this->any())->method('getMimeType')->will($this->returnValue('video/vimeo'));
65  $fileResourceMock2 = $this->getMock(File::class, [], [], '', false);
66  $fileResourceMock2->expects($this->any())->method('getMimeType')->will($this->returnValue('video/unknown'));
67  $fileResourceMock2->expects($this->any())->method('getExtension')->will($this->returnValue('vimeo'));
68 
69  $this->assertTrue($this->subject->canRender($fileResourceMock1));
70  $this->assertTrue($this->subject->canRender($fileResourceMock2));
71  }
72 
76  public function canRenderReturnsFalseOnCorrectFile()
77  {
79  $fileResourceMock = $this->getMock(File::class, [], [], '', false);
80  $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('video/youtube'));
81 
82  $this->assertFalse($this->subject->canRender($fileResourceMock));
83  }
84 
88  public function renderOutputIsCorrect()
89  {
91  $fileResourceMock = $this->getMock(File::class, [], [], '', false);
92 
93  $this->assertSame(
94  '<iframe src="https://player.vimeo.com/video/7331?title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200"></iframe>',
95  $this->subject->render($fileResourceMock, '300m', '200')
96  );
97  }
98 
102  public function renderOutputWithLoopIsCorrect()
103  {
105  $fileResourceMock = $this->getMock(File::class, [], [], '', false);
106 
107  $this->assertSame(
108  '<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>',
109  $this->subject->render($fileResourceMock, '300m', '200', ['loop' => 1])
110  );
111  }
112 
116  public function renderOutputWithAutoplayIsCorrect()
117  {
119  $fileResourceMock = $this->getMock(File::class, [], [], '', false);
120 
121  $this->assertSame(
122  '<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>',
123  $this->subject->render($fileResourceMock, '300m', '200', ['autoplay' => 1])
124  );
125  }
126 
130  public function renderOutputWithAutoplayFromReferenceIsCorrect()
131  {
133  $fileResourceMock = $this->getMock(File::class, [], [], '', false);
134 
136  $fileReferenceMock = $this->getMock(FileReference::class, [], [], '', false);
137  $fileReferenceMock->expects($this->any())->method('getProperty')->will($this->returnValue(1));
138  $fileReferenceMock->expects($this->any())->method('getOriginalFile')->willReturn($fileResourceMock);
139 
140  $this->assertSame(
141  '<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>',
142  $this->subject->render($fileReferenceMock, '300m', '200')
143  );
144  }
145 
149  public function renderOutputWithAutoplayAndWithoutControllsIsCorrect()
150  {
152  $fileResourceMock = $this->getMock(File::class, [], [], '', false);
153 
154  $this->assertSame(
155  '<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>',
156  $this->subject->render($fileResourceMock, '300m', '200', ['autoplay' => 1])
157  );
158  }
159 
163  public function renderOutputIsEscaped()
164  {
166  $vimeoHelper = $this->getAccessibleMock(VimeoHelper::class, ['getOnlineMediaId'], ['vimeo']);
167  $vimeoHelper->expects($this->any())->method('getOnlineMediaId')->will(
168  $this->returnValue('7331<script>danger</script>\'"random"quotes;')
169  );
170 
171  $subject = $this->getAccessibleMock(VimeoRenderer::class, ['getOnlineMediaHelper'], []);
172  $subject->expects($this->any())->method('getOnlineMediaHelper')->will($this->returnValue($vimeoHelper));
173 
175  $fileResourceMock = $this->getMock(File::class, [], [], '', false);
176 
177  $this->assertSame(
178  '<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"></iframe>',
179  $subject->render($fileResourceMock, '300m', '200')
180  );
181  }
182 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)