Fix misnamed SVGHandler::canAnimateThumb()
authorBrian Wolff <bawolff+wn@gmail.com>
Wed, 11 Jun 2014 00:15:53 +0000 (21:15 -0300)
committerBrian Wolff <bawolff+wn@gmail.com>
Wed, 11 Jun 2014 00:15:53 +0000 (21:15 -0300)
Caused the animation warning to not be present on
image description pages

Also add unit tests. Since I'm adding an animated svg file for
this unit test, also add a metadata extraction test for animated
svgs, since we're missing one.

Change-Id: Id03e1a0e1c151d3c575a695a42c54b709187d10a
follow-up: 876128f8c9f0ce6a8424336f

includes/media/SVG.php
tests/phpunit/data/media/Bishzilla_blink.gif [new file with mode: 0644]
tests/phpunit/data/media/README
tests/phpunit/data/media/Soccer_ball_animated.svg [new file with mode: 0644]
tests/phpunit/includes/filerepo/files/FileTest.php [new file with mode: 0644]
tests/phpunit/includes/media/MediaWikiMediaTestCase.php
tests/phpunit/includes/media/SVGMetadataExtractorTest.php

index 5a10741..e28b38f 100644 (file)
@@ -116,7 +116,7 @@ class SvgHandler extends ImageHandler {
        /**
         * We do not support making animated svg thumbnails
         */
-       function canAnimateThumb( $file ) {
+       function canAnimateThumbnail( $file ) {
                return false;
        }
 
diff --git a/tests/phpunit/data/media/Bishzilla_blink.gif b/tests/phpunit/data/media/Bishzilla_blink.gif
new file mode 100644 (file)
index 0000000..13e5536
Binary files /dev/null and b/tests/phpunit/data/media/Bishzilla_blink.gif differ
index 57879f8..ca132a4 100644 (file)
@@ -46,3 +46,12 @@ https://commons.wikimedia.org/wiki/File:Speech_bubbles.svg
 CC BY-SA 3.0
 Jarry1250
 
+Soccer_ball_animated.svg
+https://commons.wikimedia.org/wiki/File:Soccer_ball_animated.svg
+GFDL 1.2 or later, CC-BY-SA 3.0 unported, CC-BY-SA 2.5 generic, CC-BY-SA 2.0 generic, or CC-BY-SA 1.0 generic
+Pumbaa80
+
+Bishzilla_blink.gif
+https://commons.wikimedia.org/wiki/File:Bishzilla_blink.gif
+Public domain
+Bishonen
diff --git a/tests/phpunit/data/media/Soccer_ball_animated.svg b/tests/phpunit/data/media/Soccer_ball_animated.svg
new file mode 100644 (file)
index 0000000..6bd82fc
--- /dev/null
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<!DOCTYPE svg>\r
+<svg width="150" height="150" viewBox="-105 -105 210 210" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">\r
+   <defs>\r
+      <clipPath id="ball">\r
+         <circle r="100" stroke-width="0"/>\r
+      </clipPath>\r
+      <radialGradient id="shadow1" cx=".4" cy=".3" r=".8">\r
+        <stop offset="0" stop-color="white" stop-opacity="1"/>\r
+        <stop offset=".4" stop-color="white" stop-opacity="1"/>\r
+        <stop offset=".8" stop-color="#EEEEEE" stop-opacity="1"/>\r
+      </radialGradient>\r
+      <radialGradient id="shadow2" cx=".5" cy=".5" r=".5">\r
+        <stop offset="0" stop-color="white" stop-opacity="0"/>\r
+        <stop offset=".8" stop-color="white" stop-opacity="0"/>\r
+        <stop offset=".99" stop-color="black" stop-opacity=".3"/>\r
+        <stop offset="1" stop-color="black" stop-opacity="1"/>\r
+      </radialGradient>\r
+      <g id="black_stuff" stroke-linejoin="round" clip-path="url(#ball)">\r
+         <g fill="black">\r
+            <path d="M 6,-32 Q 26,-28 46,-19 Q 57,-35 64,-47 Q 50,-68 37,-76 Q 17,-75 1,-68 Q 4,-51 6,-32"/>\r
+            <path d="M -26,-2 Q -45,-8 -62,-11 Q -74,5 -76,22 Q -69,40 -50,54 Q -32,47 -17,39 Q -23,15 -26,-2"/>\r
+            <path d="M -95,22 Q -102,12 -102,-8 V 80 H -85 Q -95,45 -95,22"/>\r
+            <path d="M 55,24 Q 41,41 24,52 Q 28,65 31,79 Q 55,78 68,67 Q 78,50 80,35 Q 65,28 55,24"/>\r
+            <path d="M 0,120 L -3,95 Q -25,93 -42,82 Q -50,84 -60,81"/>\r
+            <path d="M -90,-48 Q -80,-52 -68,-49 Q -52,-71 -35,-77 Q -35,-100 -40,-100 H -100"/>\r
+            <path d="M 100,-55 L 87,-37 Q 98,-10 97,5 L 100,6"/>\r
+         </g>\r
+         <g fill="none">\r
+            <path d="M 6,-32 Q -18,-12 -26,-2\r
+                     M 46,-19 Q 54,5 55,24\r
+                     M 64,-47 Q 77,-44 87,-37\r
+                     M 37,-76 Q 39,-90 36,-100\r
+                     M 1,-68 Q -13,-77 -35,-77\r
+                     M -62,-11 Q -67,-25 -68,-49\r
+                     M -76,22 Q -85,24 -95,22\r
+                     M -50,54 Q -49,70 -42,82\r
+                     M -17,39 Q 0,48 24,52\r
+                     M 31,79 Q 20,92 -3,95\r
+                     M 68,67 L 80,80\r
+                     M 80,35 Q 90,25 97,5\r
+            "/>\r
+         </g>\r
+      </g>\r
+   </defs>\r
+   <circle r="100" fill="white" stroke="none"/>\r
+   <circle r="100" fill="url(#shadow1)" stroke="none"/>\r
+   <g><animateTransform attributeName="transform" attributeType="XML" type="rotate" from="0" to="360" begin="0s" dur="3s" repeatCount="indefinite"/>\r
+      <use xlink:href="#black_stuff" stroke="#EEE" stroke-width="7"/>\r
+      <use xlink:href="#black_stuff" stroke="#DDD" stroke-width="4"/>\r
+      <use xlink:href="#black_stuff" stroke="#999" stroke-width="2"/>\r
+      <use xlink:href="#black_stuff" stroke="black" stroke-width="1"/>\r
+   </g>\r
+   <circle r="100" fill="url(#shadow2)" stroke="none"/>\r
+</svg>\r
diff --git a/tests/phpunit/includes/filerepo/files/FileTest.php b/tests/phpunit/includes/filerepo/files/FileTest.php
new file mode 100644 (file)
index 0000000..36b95ea
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+class FileTest extends MediaWikiMediaTestCase {
+
+       function setUp() {
+               $this->setMWGlobals( 'wgMaxAnimatedGifArea', 9000 );
+               parent::setUp();
+       }
+
+       /**
+        * @param $filename String
+        * @param $expected boolean
+        * @dataProvider providerCanAnimate
+        */
+       function testCanAnimateThumbIfAppropriate( $filename, $expected ) {
+               $file = $this->dataFile( $filename );
+               $this->assertEquals( $file->canAnimateThumbIfAppropriate(), $expected );
+       }
+
+       function providerCanAnimate() {
+               return array(
+                       array( 'nonanimated.gif', true ),
+                       array( 'jpeg-comment-utf.jpg', true ),
+                       array( 'test.tiff', true ),
+                       array( 'Animated_PNG_example_bouncing_beach_ball.png', false ),
+                       array( 'greyscale-png.png', true ),
+                       array( 'Toll_Texas_1.svg', true ),
+                       array( 'LoremIpsum.djvu', true ),
+                       array( '80x60-2layers.xcf', true ),
+                       array( 'Soccer_ball_animated.svg', false ),
+                       array( 'Bishzilla_blink.gif', false ),
+                       array( 'animated.gif', true ),
+               );
+       }
+}
index ebfcba9..96347d9 100644 (file)
@@ -63,10 +63,16 @@ abstract class MediaWikiMediaTestCase extends MediaWikiTestCase {
         *
         * File must be in the path returned by getFilePath()
         * @param $name String File name
-        * @param $type String MIME type
+        * @param $type String MIME type [optional]
         * @return UnregisteredLocalFile
         */
-       protected function dataFile( $name, $type ) {
+       protected function dataFile( $name, $type = null ) {
+               if ( !$type ) {
+                       // Autodetect by file extension for the lazy.
+                       $magic = MimeMagic::singleton();
+                       $parts = explode( $name, '.' );
+                       $type = $magic->guessTypesForExtension( $parts[count( $parts ) - 1]  );
+               }
                return new UnregisteredLocalFile( false, $this->repo,
                        "mwstore://localtesting/data/$name", $type );
        }
index fa63fa6..f06bd6f 100644 (file)
@@ -116,6 +116,17 @@ class SVGMetadataExtractorTest extends MediaWikiTestCase {
                                        ),
                                )
                        ),
+                       array(
+                               "$base/Soccer_ball_animated.svg",
+                               array(
+                                       'width' => 150,
+                                       'height' => 150,
+                                       'originalWidth' => '150',
+                                       'originalHeight' => '150',
+                                       'animated' => true,
+                                       'translations' => array()
+                               ),
+                       ),
                );
        }