894da57d03c6483bc9418bd2a57f9d69e6853df9
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / Rendering / VimeoRendererTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Resource\Rendering;
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
17 use TYPO3\CMS\Core\Resource\File;
18 use TYPO3\CMS\Core\Resource\FileReference;
19 use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper;
20 use TYPO3\CMS\Core\Resource\Rendering\VimeoRenderer;
21
22 /**
23 * Class VimeoRendererTest
24 */
25 class VimeoRendererTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
26 {
27 /**
28 * @var VimeoRenderer|\PHPUnit_Framework_MockObject_MockObject
29 */
30 protected $subject;
31
32 /**
33 * Set up the test
34 */
35 protected function setUp()
36 {
37 parent::setUp();
38
39 /** @var VimeoHelper|\PHPUnit_Framework_MockObject_MockObject $vimeoHelper */
40 $vimeoHelper = $this->getAccessibleMock(VimeoHelper::class, ['getOnlineMediaId'], ['vimeo']);
41 $vimeoHelper->expects($this->any())->method('getOnlineMediaId')->will($this->returnValue('7331'));
42
43 $this->subject = $this->getAccessibleMock(VimeoRenderer::class, ['getOnlineMediaHelper'], []);
44 $this->subject->expects($this->any())->method('getOnlineMediaHelper')->will($this->returnValue($vimeoHelper));
45 }
46
47 /**
48 * @test
49 */
50 public function getPriorityReturnsCorrectValue()
51 {
52 $this->assertSame(1, $this->subject->getPriority());
53 }
54
55 /**
56 * @test
57 */
58 public function canRenderReturnsTrueOnCorrectFile()
59 {
60 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock1 */
61 $fileResourceMock1 = $this->createMock(File::class);
62 $fileResourceMock1->expects($this->any())->method('getMimeType')->will($this->returnValue('video/vimeo'));
63 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock2 */
64 $fileResourceMock2 = $this->createMock(File::class);
65 $fileResourceMock2->expects($this->any())->method('getMimeType')->will($this->returnValue('video/unknown'));
66 $fileResourceMock2->expects($this->any())->method('getExtension')->will($this->returnValue('vimeo'));
67
68 $this->assertTrue($this->subject->canRender($fileResourceMock1));
69 $this->assertTrue($this->subject->canRender($fileResourceMock2));
70 }
71
72 /**
73 * @test
74 */
75 public function canRenderReturnsFalseOnCorrectFile()
76 {
77 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
78 $fileResourceMock = $this->createMock(File::class);
79 $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('video/youtube'));
80
81 $this->assertFalse($this->subject->canRender($fileResourceMock));
82 }
83
84 /**
85 * @test
86 */
87 public function renderOutputIsCorrect()
88 {
89 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
90 $fileResourceMock = $this->createMock(File::class);
91
92 $this->assertSame(
93 '<iframe src="https://player.vimeo.com/video/7331?title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200"></iframe>',
94 $this->subject->render($fileResourceMock, '300m', '200')
95 );
96 }
97
98 /**
99 * @test
100 */
101 public function renderOutputWithLoopIsCorrect()
102 {
103 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
104 $fileResourceMock = $this->createMock(File::class);
105
106 $this->assertSame(
107 '<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>',
108 $this->subject->render($fileResourceMock, '300m', '200', ['loop' => 1])
109 );
110 }
111
112 /**
113 * @test
114 */
115 public function renderOutputWithAutoplayIsCorrect()
116 {
117 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
118 $fileResourceMock = $this->createMock(File::class);
119
120 $this->assertSame(
121 '<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>',
122 $this->subject->render($fileResourceMock, '300m', '200', ['autoplay' => 1])
123 );
124 }
125
126 /**
127 * @test
128 */
129 public function renderOutputWithAutoplayFromReferenceIsCorrect()
130 {
131 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
132 $fileResourceMock = $this->createMock(File::class);
133
134 /** @var FileReference|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
135 $fileReferenceMock = $this->createMock(FileReference::class);
136 $fileReferenceMock->expects($this->any())->method('getProperty')->will($this->returnValue(1));
137 $fileReferenceMock->expects($this->any())->method('getOriginalFile')->willReturn($fileResourceMock);
138
139 $this->assertSame(
140 '<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>',
141 $this->subject->render($fileReferenceMock, '300m', '200')
142 );
143 }
144
145 /**
146 * @test
147 */
148 public function renderOutputWithAutoplayAndWithoutControllsIsCorrect()
149 {
150 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
151 $fileResourceMock = $this->createMock(File::class);
152
153 $this->assertSame(
154 '<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>',
155 $this->subject->render($fileResourceMock, '300m', '200', ['autoplay' => 1])
156 );
157 }
158 }