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