[BUGFIX] Add `controlsList` as known additional attribute 87/55187/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Thu, 21 Dec 2017 13:18:32 +0000 (14:18 +0100)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Thu, 21 Dec 2017 14:20:36 +0000 (15:20 +0100)
The HTML5 attribute `controlsList` is used in at least Google Chrome
to limit the control buttons. The AudioTagRenderer and VideoTagRenderer
classes are now aware of that attribute.

Resolves: #81222
Releases: master, 8.7, 7.6
Change-Id: I9a577ae077e7e7b55b9fed7852a5a61a5fd4061a
Reviewed-on: https://review.typo3.org/55187
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
typo3/sysext/core/Classes/Resource/Rendering/AudioTagRenderer.php
typo3/sysext/core/Classes/Resource/Rendering/VideoTagRenderer.php
typo3/sysext/core/Tests/Unit/Resource/Rendering/AudioTagRendererTest.php
typo3/sysext/core/Tests/Unit/Resource/Rendering/VideoTagRendererTest.php

index e1a0986..0d5ba40 100644 (file)
@@ -88,7 +88,7 @@ class AudioTagRenderer implements FileRendererInterface
         if (!empty($options['loop'])) {
             $additionalAttributes[] = 'loop';
         }
-        foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick', 'preload'] as $key) {
+        foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick', 'preload', 'controlsList'] as $key) {
             if (!empty($options[$key])) {
                 $additionalAttributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"';
             }
index 171ca50..6247282 100644 (file)
@@ -94,7 +94,7 @@ class VideoTagRenderer implements FileRendererInterface
         if (!empty($options['loop'])) {
             $attributes[] = 'loop';
         }
-        foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick'] as $key) {
+        foreach (['class', 'dir', 'id', 'lang', 'style', 'title', 'accesskey', 'tabindex', 'onclick', 'controlsList'] as $key) {
             if (!empty($options[$key])) {
                 $attributes[] = $key . '="' . htmlspecialchars($options[$key]) . '"';
             }
index bc38bc2..329b98c 100644 (file)
@@ -62,70 +62,57 @@ class AudioTagRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     }
 
     /**
-     * @test
+     * Array of configurations
      */
-    public function renderOutputIsCorrect()
+    public function renderArgumentsDataProvider()
     {
-        $audioTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer();
-
-        $fileResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
-        $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('audio/mpeg'));
-        $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue('//:path/myAudioFile?foo=bar&baz=true'));
-
-        $this->assertSame(
-            '<audio controls><source src="//:path/myAudioFile?foo=bar&amp;baz=true" type="audio/mpeg"></audio>',
-            $audioTagRenderer->render($fileResourceMock, '300m', '200')
-        );
+        return [
+            [
+                '//:path/myAudioFile?foo=bar&baz=true',
+                [],
+                '<audio controls><source src="//:path/myAudioFile?foo=bar&amp;baz=true" type="audio/mpeg"></audio>',
+            ],
+            [
+                '//:path/myAudioFile',
+                ['loop' => 1],
+                '<audio controls loop><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
+            ],
+            [
+                '//:path/myAudioFile',
+                ['autoplay' => 1],
+                '<audio controls autoplay><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
+            ],
+            [
+                '//:path/myAudioFile',
+                ['controls' => 0, 'autoplay' => 1],
+                '<audio autoplay><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
+            ],
+            [
+                '//:path/myAudioFile',
+                ['controls' => 1, 'controlsList' => 'nodownload'],
+                '<audio controls controlsList="nodownload"><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
+            ]
+        ];
     }
 
     /**
      * @test
+     * @dataProvider renderArgumentsDataProvider
+     * @param string $url
+     * @param array $arguments
+     * @param string $expected
      */
-    public function renderOutputWithLoopIsCorrect()
+    public function renderOutputIsCorrect($url, $arguments, $expected)
     {
         $audioTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer();
 
-        $fileResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
-        $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('audio/mpeg'));
-        $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue('//:path/myAudioFile'));
-
-        $this->assertSame(
-            '<audio controls loop><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
-            $audioTagRenderer->render($fileResourceMock, '300m', '200', ['loop' => 1])
-        );
-    }
-
-    /**
-     * @test
-     */
-    public function renderOutputWithAutoplayIsCorrect()
-    {
-        $audioTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer();
-
-        $fileResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
-        $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('audio/mpeg'));
-        $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue('//:path/myAudioFile'));
-
-        $this->assertSame(
-            '<audio controls autoplay><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
-            $audioTagRenderer->render($fileResourceMock, '300m', '200', ['autoplay' => 1])
-        );
-    }
-
-    /**
-     * @test
-     */
-    public function renderOutputWithAutoplayAndWithoutControllsIsCorrect()
-    {
-        $audioTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\AudioTagRenderer();
-
-        $fileResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
+        $fileResourceMock = $this->createMock(\TYPO3\CMS\Core\Resource\File::class);
         $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('audio/mpeg'));
-        $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue('//:path/myAudioFile'));
+        $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue($url));
 
         $this->assertSame(
-            '<audio autoplay><source src="//:path/myAudioFile" type="audio/mpeg"></audio>',
-            $audioTagRenderer->render($fileResourceMock, '300m', '200', ['controls' => 0, 'autoplay' => 1])
+            $expected,
+            $audioTagRenderer->render($fileResourceMock, '300m', '200', $arguments)
         );
     }
 }
index ac46041..e934de9 100644 (file)
@@ -65,70 +65,57 @@ class VideoTagRendererTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     }
 
     /**
-     * @test
+     * Array of configurations
      */
-    public function renderOutputIsCorrect()
+    public function renderArgumentsDataProvider()
     {
-        $VideoTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer();
-
-        $fileResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
-        $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('video/mp4'));
-        $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue('//:path/myVideoFile?foo=bar&baz=true'));
-
-        $this->assertSame(
-            '<video width="300" height="200" controls><source src="//:path/myVideoFile?foo=bar&amp;baz=true" type="video/mp4"></video>',
-            $VideoTagRenderer->render($fileResourceMock, '300m', '200')
-        );
+        return [
+            [
+                '//:path/myVideoFile?foo=bar&baz=true',
+                [],
+                '<video width="300" height="200" controls><source src="//:path/myVideoFile?foo=bar&amp;baz=true" type="video/mp4"></video>',
+            ],
+            [
+                '//:path/myVideoFile',
+                ['loop' => 1],
+                '<video width="300" height="200" controls loop><source src="//:path/myVideoFile" type="video/mp4"></video>',
+            ],
+            [
+                '//:path/myVideoFile',
+                ['autoplay' => 1],
+                '<video width="300" height="200" controls autoplay><source src="//:path/myVideoFile" type="video/mp4"></video>',
+            ],
+            [
+                '//:path/myVideoFile',
+                ['controls' => 0, 'autoplay' => 1],
+                '<video width="300" height="200" autoplay><source src="//:path/myVideoFile" type="video/mp4"></video>',
+            ],
+            [
+                '//:path/myVideoFile',
+                ['controls' => 1, 'controlsList' => 'nodownload'],
+                '<video width="300" height="200" controls controlsList="nodownload"><source src="//:path/myVideoFile" type="video/mp4"></video>',
+            ]
+        ];
     }
 
     /**
      * @test
+     * @dataProvider renderArgumentsDataProvider
+     * @param string $url
+     * @param array $arguments
+     * @param string $expected
      */
-    public function renderOutputWithLoopIsCorrect()
+    public function renderOutputIsCorrect($url, $arguments, $expected)
     {
         $VideoTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer();
 
-        $fileResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
-        $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('video/mp4'));
-        $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue('//:path/myVideoFile'));
-
-        $this->assertSame(
-            '<video width="300" height="200" controls loop><source src="//:path/myVideoFile" type="video/mp4"></video>',
-            $VideoTagRenderer->render($fileResourceMock, '300m', '200', ['loop' => 1])
-        );
-    }
-
-    /**
-     * @test
-     */
-    public function renderOutputWithAutoplayIsCorrect()
-    {
-        $VideoTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer();
-
-        $fileResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
-        $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('video/mp4'));
-        $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue('//:path/myVideoFile'));
-
-        $this->assertSame(
-            '<video width="300" height="200" controls autoplay><source src="//:path/myVideoFile" type="video/mp4"></video>',
-            $VideoTagRenderer->render($fileResourceMock, '300m', '200', ['autoplay' => 1])
-        );
-    }
-
-    /**
-     * @test
-     */
-    public function renderOutputWithAutoplayAndWithoutControllsIsCorrect()
-    {
-        $VideoTagRenderer = new \TYPO3\CMS\Core\Resource\Rendering\VideoTagRenderer();
-
-        $fileResourceMock = $this->getMock(\TYPO3\CMS\Core\Resource\File::class, [], [], '', false);
+        $fileResourceMock = $this->createMock(\TYPO3\CMS\Core\Resource\File::class);
         $fileResourceMock->expects($this->any())->method('getMimeType')->will($this->returnValue('video/mp4'));
-        $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue('//:path/myVideoFile'));
+        $fileResourceMock->expects($this->any())->method('getPublicUrl')->will($this->returnValue($url));
 
         $this->assertSame(
-            '<video width="300" height="200" autoplay><source src="//:path/myVideoFile" type="video/mp4"></video>',
-            $VideoTagRenderer->render($fileResourceMock, '300m', '200', ['controls' => 0, 'autoplay' => 1])
+            $expected,
+            $VideoTagRenderer->render($fileResourceMock, '300m', '200', $arguments)
         );
     }
 }