[BUGFIX] Provide full url as origin for embedded Youtube videos 72/49572/2
authorSebastian Michaelsen <sebastian@michaelsen.io>
Mon, 8 Aug 2016 07:45:37 +0000 (09:45 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Wed, 24 Aug 2016 12:19:19 +0000 (14:19 +0200)
To use the javascript API for embedded Youtube videos the documentation
recommends to provide the "full website url" as origin parameter

Change-Id: I318083b4c67b48c7eb708e54b11cd8dd1c69d646
Resolves: #77409
Releases: master, 7.6
Reviewed-on: https://review.typo3.org/49572
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/core/Classes/Resource/Rendering/YouTubeRenderer.php
typo3/sysext/core/Tests/Unit/Resource/Rendering/YouTubeRendererTest.php

index a4dfb1e..acdee82 100644 (file)
@@ -108,7 +108,7 @@ class YouTubeRenderer implements FileRendererInterface
             $urlParams[] = 'loop=1';
         }
         if (!isset($options['enablejsapi']) || !empty($options['enablejsapi'])) {
-            $urlParams[] = 'enablejsapi=1&amp;origin=' . GeneralUtility::getIndpEnv('HTTP_HOST');
+            $urlParams[] = 'enablejsapi=1&amp;origin=' . GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
         }
         $urlParams[] = 'showinfo=' . (int)!empty($options['showinfo']);
 
index a9cd3fa..5de9472 100644 (file)
@@ -39,6 +39,7 @@ class YouTubeRendererTest extends UnitTestCase
         parent::setUp();
         GeneralUtility::flushInternalRuntimeCaches();
         $_SERVER['HTTP_HOST'] = 'test.server.org';
+        $_SERVER['REQUEST_URI'] = '/test-page/';
 
         /** @var YouTubeHelper|\PHPUnit_Framework_MockObject_MockObject $youTubeHelper */
         $youTubeHelper = $this->getAccessibleMock(YouTubeHelper::class, array('getOnlineMediaId'), array('youtube'));
@@ -94,7 +95,7 @@ class YouTubeRendererTest extends UnitTestCase
         $fileResourceMock = $this->getMock(File::class, array(), array(), '', false);
 
         $this->assertSame(
-            '<iframe src="//www.youtube.com/embed/7331?autohide=1&amp;controls=2&amp;enablejsapi=1&amp;origin=test.server.org&amp;showinfo=0" allowfullscreen width="300" height="200"></iframe>',
+            '<iframe src="//www.youtube.com/embed/7331?autohide=1&amp;controls=2&amp;enablejsapi=1&amp;origin=http://test.server.org/test-page/&amp;showinfo=0" allowfullscreen width="300" height="200"></iframe>',
             $this->subject->render($fileResourceMock, '300m', '200')
         );
     }
@@ -108,7 +109,7 @@ class YouTubeRendererTest extends UnitTestCase
         $fileResourceMock = $this->getMock(File::class, array(), array(), '', false);
 
         $this->assertSame(
-            '<iframe src="//www.youtube.com/embed/7331?autohide=1&amp;controls=2&amp;loop=1&amp;enablejsapi=1&amp;origin=test.server.org&amp;showinfo=0" allowfullscreen width="300" height="200"></iframe>',
+            '<iframe src="//www.youtube.com/embed/7331?autohide=1&amp;controls=2&amp;loop=1&amp;enablejsapi=1&amp;origin=http://test.server.org/test-page/&amp;showinfo=0" allowfullscreen width="300" height="200"></iframe>',
             $this->subject->render($fileResourceMock, '300m', '200', array('loop' => 1))
         );
     }
@@ -122,7 +123,7 @@ class YouTubeRendererTest extends UnitTestCase
         $fileResourceMock = $this->getMock(File::class, array(), array(), '', false);
 
         $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>',
+            '<iframe src="//www.youtube.com/embed/7331?autohide=1&amp;controls=2&amp;autoplay=1&amp;enablejsapi=1&amp;origin=http://test.server.org/test-page/&amp;showinfo=0" allowfullscreen width="300" height="200"></iframe>',
             $this->subject->render($fileResourceMock, '300m', '200', array('autoplay' => 1))
         );
     }
@@ -141,7 +142,7 @@ class YouTubeRendererTest extends UnitTestCase
         $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>',
+            '<iframe src="//www.youtube.com/embed/7331?autohide=1&amp;controls=2&amp;autoplay=1&amp;enablejsapi=1&amp;origin=http://test.server.org/test-page/&amp;showinfo=0" allowfullscreen width="300" height="200"></iframe>',
             $this->subject->render($fileReferenceMock, '300m', '200')
         );
     }
@@ -155,7 +156,7 @@ class YouTubeRendererTest extends UnitTestCase
         $fileResourceMock = $this->getMock(File::class, array(), array(), '', false);
 
         $this->assertSame(
-            '<iframe src="//www.youtube.com/embed/7331?autohide=1&amp;autoplay=1&amp;enablejsapi=1&amp;origin=test.server.org&amp;showinfo=0" allowfullscreen width="300" height="200"></iframe>',
+            '<iframe src="//www.youtube.com/embed/7331?autohide=1&amp;autoplay=1&amp;enablejsapi=1&amp;origin=http://test.server.org/test-page/&amp;showinfo=0" allowfullscreen width="300" height="200"></iframe>',
             $this->subject->render($fileResourceMock, '300m', '200', array('controls' => 0, 'autoplay' => 1))
         );
     }