diff --git a/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php b/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php index a96e7e39bd63db2f9c4a8007e1df5de2bea47b72..d4d2c4020cb325bac37d1aeb3e2a29f213d4ad32 100644 --- a/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php +++ b/typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php @@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Resource\FileReference; use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperInterface; use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\OnlineMediaHelperRegistry; use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\MathUtility; /** * YouTube renderer class @@ -106,9 +107,10 @@ class YouTubeRenderer implements FileRendererInterface $videoId = $this->getOnlineMediaHelper($file)->getOnlineMediaId($orgFile); $urlParams = ['autohide=1']; - if (!isset($options['controls']) || !empty($options['controls'])) { - $urlParams[] = 'controls=2'; - } + + $options['controls'] = MathUtility::canBeInterpretedAsInteger($options['controls']) ? (int)$options['controls'] : 2; + $options['controls'] = MathUtility::forceIntegerInRange($options['controls'], 0, 2); + $urlParams[] = 'controls=' . $options['controls']; if (!empty($options['autoplay'])) { $urlParams[] = 'autoplay=1'; } diff --git a/typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php b/typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php index b9deafba13a13c49522d92d00a0846a4f0acb7f2..de31b01e66c16bf6a5beb4992eafe9c4b26f808d 100644 --- a/typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php +++ b/typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php @@ -84,20 +84,6 @@ class YouTubeRendererTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase $this->assertFalse($this->subject->canRender($fileResourceMock)); } - /** - * @test - */ - public function renderOutputIsCorrect() - { - /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */ - $fileResourceMock = $this->createMock(File::class); - - $this->assertSame( - '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=2&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', - $this->subject->render($fileResourceMock, '300m', '200') - ); - } - /** * @test */ @@ -134,7 +120,7 @@ class YouTubeRendererTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */ $fileResourceMock = $this->createMock(File::class); - /** @var FileReference|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */ + /** @var FileReference|\PHPUnit_Framework_MockObject_MockObject $fileReferenceMock */ $fileReferenceMock = $this->createMock(FileReference::class); $fileReferenceMock->expects($this->any())->method('getProperty')->will($this->returnValue(1)); $fileReferenceMock->expects($this->any())->method('getOriginalFile')->willReturn($fileResourceMock); @@ -154,11 +140,96 @@ class YouTubeRendererTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase $fileResourceMock = $this->createMock(File::class); $this->assertSame( - '<iframe src="https://www.youtube.com/embed/7331?autohide=1&autoplay=1&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=0&autoplay=1&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', $this->subject->render($fileResourceMock, '300m', '200', ['controls' => 0, 'autoplay' => 1]) ); } + public function renderOutputWithControlsDataProvider() + { + return [ + 'no options given' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=2&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + null + ], + 'with option controls = foo as invalid string' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=2&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => 'foo'] + ], + 'with option controls = true as string' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=2&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => 'true'] + ], + 'with option controls = false as string' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=2&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => 'false'] + ], + 'with option controls = true as boolean' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=1&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => true] + ], + 'with option controls = false as boolean' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=2&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => false] + ], + 'with option controls = 0 as string' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=0&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => '0'] + ], + 'with option controls = 1 as string' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=1&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => '1'] + ], + 'with option controls = 2 as string' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=2&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => '2'] + ], + 'with option controls = 3 as string' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=2&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => '3'] + ], + 'with option controls = negative number as string' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=0&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => '-42'] + ], + 'with option controls = 0 as int' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=0&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => 0] + ], + 'with option controls = 1 as int' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=1&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => 1] + ], + 'with option controls = 2 as int' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=2&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => 2] + ], + 'with option controls = 3 as int' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=2&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => 3] + ], + 'with option controls = negative number as int' => [ + '<iframe src="https://www.youtube.com/embed/7331?autohide=1&controls=0&enablejsapi=1&origin=http%3A%2F%2Ftest.server.org&showinfo=0" allowfullscreen width="300" height="200"></iframe>', + ['controls' => -42] + ], + ]; + } + + /** + * @test + * @dataProvider renderOutputWithControlsDataProvider + */ + public function renderOutputWithDefaultControlsIsCorrect($expected, $options) + { + /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */ + $fileResourceMock = $this->createMock(File::class); + + $this->assertSame( + $expected, + $this->subject->render($fileResourceMock, '300m', '200', $options) + ); + } + /** * @test */