[TASK] Always use HTTPS for youtube and vimeo
[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 use TYPO3\CMS\Core\Tests\UnitTestCase;
22
23 /**
24 * Class VimeoRendererTest
25 */
26 class VimeoRendererTest extends UnitTestCase
27 {
28 /**
29 * @var VimeoRenderer|\PHPUnit_Framework_MockObject_MockObject
30 */
31 protected $subject;
32
33 /**
34 * Set up the test
35 */
36 protected function setUp()
37 {
38 parent::setUp();
39
40 /** @var VimeoHelper|\PHPUnit_Framework_MockObject_MockObject $vimeoHelper */
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
48 /**
49 * @test
50 */
51 public function getPriorityReturnsCorrectValue()
52 {
53 $this->assertSame(1, $this->subject->getPriority());
54 }
55
56 /**
57 * @test
58 */
59 public function canRenderReturnsTrueOnCorrectFile()
60 {
61 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock1 */
62 $fileResourceMock1 = $this->getMock(File::class, [], [], '', false);
63 $fileResourceMock1->expects($this->any())->method('getMimeType')->will($this->returnValue('video/vimeo'));
64 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock2 */
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
73 /**
74 * @test
75 */
76 public function canRenderReturnsFalseOnCorrectFile()
77 {
78 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
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
85 /**
86 * @test
87 */
88 public function renderOutputIsCorrect()
89 {
90 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
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
99 /**
100 * @test
101 */
102 public function renderOutputWithLoopIsCorrect()
103 {
104 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
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
113 /**
114 * @test
115 */
116 public function renderOutputWithAutoplayIsCorrect()
117 {
118 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
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
127 /**
128 * @test
129 */
130 public function renderOutputWithAutoplayFromReferenceIsCorrect()
131 {
132 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
133 $fileResourceMock = $this->getMock(File::class, [], [], '', false);
134
135 /** @var FileReference|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
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
146 /**
147 * @test
148 */
149 public function renderOutputWithAutoplayAndWithoutControllsIsCorrect()
150 {
151 /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
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 }