[BUGFIX] Allow OnlineMedia Renderers to override via Fluid 76/46976/2
authorBenni Mack <benni@typo3.org>
Tue, 16 Feb 2016 13:35:44 +0000 (14:35 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Mon, 29 Feb 2016 20:21:23 +0000 (21:21 +0100)
When using the Online Media (Youtube / Vimeo) then the autoplay
option is always taken from the FileReference, overriding
the option that might be set via Fluid.

A check if the option hasn't been set yet makes the overriding
order clearer.

Resolves: #73484
Releases: master, 7.6
Change-Id: I3fb57c88383445062f5beabd8d8287ff772974d3
Reviewed-on: https://review.typo3.org/46976
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Resource/Rendering/VimeoRenderer.php
typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php
typo3/sysext/core/Tests/Unit/Resource/Rendering/VimeoRendererTest.php
typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php

index 5975690..f013f1e 100644 (file)
@@ -89,7 +89,8 @@ class VimeoRenderer implements FileRendererInterface
      */
     public function render(FileInterface $file, $width, $height, array $options = null, $usedPathsRelativeToCurrentScript = false)
     {
-        if ($file instanceof FileReference) {
+        // Check for an autoplay option at the file reference itself, if not overriden yet.
+        if (!isset($options['autoplay']) && $file instanceof FileReference) {
             $autoplay = $file->getProperty('autoplay');
             if ($autoplay !== null) {
                 $options['autoplay'] = $autoplay;
index 0282ab0..a4dfb1e 100644 (file)
@@ -89,7 +89,8 @@ class YouTubeRenderer implements FileRendererInterface
      */
     public function render(FileInterface $file, $width, $height, array $options = null, $usedPathsRelativeToCurrentScript = false)
     {
-        if ($file instanceof FileReference) {
+        // Check for an autoplay option at the file reference itself, if not overriden yet.
+        if (!isset($options['autoplay']) && $file instanceof FileReference) {
             $autoplay = $file->getProperty('autoplay');
             if ($autoplay !== null) {
                 $options['autoplay'] = $autoplay;
index 350f6ea..8821024 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Resource\Rendering;
  */
 
 use TYPO3\CMS\Core\Resource\File;
+use TYPO3\CMS\Core\Resource\FileReference;
 use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper;
 use TYPO3\CMS\Core\Resource\Rendering\VimeoRenderer;
 use TYPO3\CMS\Core\Tests\UnitTestCase;
@@ -126,6 +127,25 @@ class VimeoRendererTest extends UnitTestCase
     /**
      * @test
      */
+    public function renderOutputWithAutoplayFromReferenceIsCorrect()
+    {
+        /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
+        $fileResourceMock = $this->getMock(File::class, array(), array(), '', false);
+
+        /** @var FileReference|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
+        $fileReferenceMock = $this->getMock(FileReference::class, array(), array(), '', false);
+        $fileReferenceMock->expects($this->any())->method('getProperty')->will($this->returnValue(1));
+        $fileReferenceMock->expects($this->any())->method('getOriginalFile')->willReturn($fileResourceMock);
+
+        $this->assertSame(
+            '<iframe src="//player.vimeo.com/video/7331?autoplay=1&amp;title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200"></iframe>',
+            $this->subject->render($fileReferenceMock, '300m', '200')
+        );
+    }
+
+    /**
+     * @test
+     */
     public function renderOutputWithAutoplayAndWithoutControllsIsCorrect()
     {
         /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
index 40895d7..78fe780 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Resource\Rendering;
  */
 
 use TYPO3\CMS\Core\Resource\File;
+use TYPO3\CMS\Core\Resource\FileReference;
 use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\YouTubeHelper;
 use TYPO3\CMS\Core\Resource\Rendering\YouTubeRenderer;
 use TYPO3\CMS\Core\Tests\UnitTestCase;
@@ -129,6 +130,26 @@ class YouTubeRendererTest extends UnitTestCase
     /**
      * @test
      */
+    public function renderOutputWithAutoplayFromFileReferenceIsCorrect()
+    {
+        /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
+        $fileResourceMock = $this->getMock(File::class, array(), array(), '', false);
+
+        /** @var FileReference|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
+        $fileReferenceMock = $this->getMock(FileReference::class, array(), array(), '', false);
+        $fileReferenceMock->expects($this->any())->method('getProperty')->will($this->returnValue(1));
+        $fileReferenceMock->expects($this->any())->method('getOriginalFile')->willReturn($fileResourceMock);
+
+
+        $this->assertSame(
+            '<iframe src="//www.youtube.com/embed/7331?autohide=1&amp;controls=2&amp;autoplay=1&amp;enablejsapi=1&amp;origin=test.server.org&amp;showinfo=0" allowfullscreen width="300" height="200"></iframe>',
+            $this->subject->render($fileReferenceMock, '300m', '200')
+        );
+    }
+
+    /**
+     * @test
+     */
     public function renderOutputWithAutoplayAndWithoutControllsIsCorrect()
     {
         /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */