[BUGFIX] VimeoRenderer render private links 04/58404/4
authorGuido Schmechel <guido.schmechel@brandung.de>
Wed, 26 Sep 2018 18:24:31 +0000 (20:24 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Fri, 28 Sep 2018 12:07:01 +0000 (14:07 +0200)
Now it is also possible to add private Vimeo links.

Releases: master, 8.7
Resolves: #83852
Change-Id: Icb425d4aea98a687b91216fefcd69b5fecc1a01e
Reviewed-on: https://review.typo3.org/58404
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Jörg Bösche <typo3@joergboesche.de>
Tested-by: Jörg Bösche <typo3@joergboesche.de>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/core/Classes/Resource/OnlineMedia/Helpers/VimeoHelper.php
typo3/sysext/core/Tests/Unit/Resource/OnlineMedia/Helpers/VimeoHelperTest.php [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/Resource/Rendering/VimeoRendererTest.php

index ac7d31d..968df03 100644 (file)
@@ -70,10 +70,10 @@ class VimeoHelper extends AbstractOEmbedHelper
         $videoId = null;
         // Try to get the Vimeo code from given url.
         // Next formats are supported with and without http(s)://
-        // - vimeo.com/<code> # Share URL
-        // - player.vimeo.com/video/<code> # URL form iframe embed code, can also get code from full iframe snippet
-        if (preg_match('/vimeo\.com\/(video\/)*([0-9]+)/i', $url, $matches)) {
-            $videoId = $matches[2];
+        // - vimeo.com/<code>/<optionalPrivateCode> # Share URL
+        // - player.vimeo.com/video/<code>/<optionalPrivateCode> # URL form iframe embed code, can also get code from full iframe snippet
+        if (preg_match('/vimeo\.com\/(?:video\/)?([0-9a-z\/]+)/i', $url, $matches)) {
+            $videoId = $matches[1];
         }
         if (empty($videoId)) {
             return null;
diff --git a/typo3/sysext/core/Tests/Unit/Resource/OnlineMedia/Helpers/VimeoHelperTest.php b/typo3/sysext/core/Tests/Unit/Resource/OnlineMedia/Helpers/VimeoHelperTest.php
new file mode 100644 (file)
index 0000000..1d1d03b
--- /dev/null
@@ -0,0 +1,87 @@
+<?php
+declare(strict_types = 1);
+
+namespace TYPO3\CMS\Core\Tests\Unit\Resource\OnlineMedia\Helpers;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Core\Resource\File;
+use TYPO3\CMS\Core\Resource\Folder;
+use TYPO3\CMS\Core\Resource\OnlineMedia\Helpers\VimeoHelper;
+use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
+
+/**
+ * Class VimeoHelperTest
+ */
+class VimeoHelperTest extends UnitTestCase
+{
+    /**
+     * @var VimeoHelper|\PHPUnit_Framework_MockObject_MockObject
+     */
+    protected $subject;
+
+    /**
+     * @var string
+     */
+    protected $extension;
+
+    /**
+     * Set up the test
+     */
+    protected function setUp()
+    {
+        parent::setUp();
+
+        $this->extension = 'video/vimeo';
+        $this->subject = $this->getAccessibleMock(VimeoHelper::class, ['transformMediaIdToFile'], [$this->extension]);
+    }
+
+    /**
+     * @test
+     * @dataProvider transformUrlDataProvider
+     *
+     * @param string $url
+     * @param string $videoId
+     * @param File|null $expectedResult
+     *
+     * @throws \ReflectionException
+     */
+    public function transformUrlToFileReturnsExpectedResult($url, $videoId, $expectedResult): void
+    {
+        /** @var Folder|\PHPUnit_Framework_MockObject_MockObject $mockedFolder */
+        $mockedFolder = $this->createMock(Folder::class);
+
+        $this->subject->expects($this->any())->method('transformMediaIdToFile')
+            ->with($videoId, $mockedFolder, $this->extension)
+            ->will($this->returnValue($expectedResult));
+
+        $result = $this->subject->transformUrlToFile($url . $videoId, $mockedFolder);
+
+        $this->assertSame($expectedResult, $result);
+    }
+
+    public function transformUrlDataProvider()
+    {
+        $fileResourceMock = $this->createMock(File::class);
+
+        return [
+            [null, null, null],
+            ['https://typo3.org/', null, null],
+            ['https://vimeo.com/', '7215347324', $fileResourceMock],
+            ['https://vimeo.com/', '7215347324/hasf8a65sdsa7d', $fileResourceMock],
+            ['https://player.vimeo.com/', '7215347324', $fileResourceMock],
+            ['https://player.vimeo.com/', '7215347324/hasf8a65sdsa7d', $fileResourceMock]
+        ];
+    }
+}
index 5bea55a..5235b56 100644 (file)
@@ -227,4 +227,25 @@ class VimeoRendererTest extends UnitTestCase
             $this->subject->render($fileResourceMock, '300m', '200', ['allow' => 'foo; bar', 'autoplay' => 1])
         );
     }
+
+    /**
+     * @test
+     */
+    public function renderOutputWithPrivateVimeoCodeIsCorrect()
+    {
+        /** @var VimeoHelper|\PHPUnit_Framework_MockObject_MockObject $vimeoHelper */
+        $vimeoHelper = $this->getAccessibleMock(VimeoHelper::class, ['getOnlineMediaId'], ['vimeo']);
+        $vimeoHelper->expects($this->any())->method('getOnlineMediaId')->will($this->returnValue('7331/private0123'));
+
+        $subject = $this->getAccessibleMock(VimeoRenderer::class, ['getOnlineMediaHelper'], []);
+        $subject->expects($this->any())->method('getOnlineMediaHelper')->will($this->returnValue($vimeoHelper));
+
+        /** @var File|\PHPUnit_Framework_MockObject_MockObject $fileResourceMock */
+        $fileResourceMock = $this->createMock(File::class);
+
+        $this->assertSame(
+            '<iframe src="https://player.vimeo.com/video/7331/private0123?title=0&amp;byline=0&amp;portrait=0" allowfullscreen width="300" height="200" allow="fullscreen"></iframe>',
+            $subject->render($fileResourceMock, '300m', '200')
+        );
+    }
 }