From: Brian Wolff Date: Wed, 11 Jun 2014 00:15:53 +0000 (-0300) Subject: Fix misnamed SVGHandler::canAnimateThumb() X-Git-Tag: 1.31.0-rc.0~15399^2 X-Git-Url: http://git.cyclocoop.org/%28?a=commitdiff_plain;h=3a4bfb597e850eca5e07e1a22ddcca8ba8810594;p=lhc%2Fweb%2Fwiklou.git Fix misnamed SVGHandler::canAnimateThumb() 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 --- diff --git a/includes/media/SVG.php b/includes/media/SVG.php index 5a1074138a..e28b38fab8 100644 --- a/includes/media/SVG.php +++ b/includes/media/SVG.php @@ -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 index 0000000000..13e5536249 Binary files /dev/null and b/tests/phpunit/data/media/Bishzilla_blink.gif differ diff --git a/tests/phpunit/data/media/README b/tests/phpunit/data/media/README index 57879f8644..ca132a441d 100644 --- a/tests/phpunit/data/media/README +++ b/tests/phpunit/data/media/README @@ -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 index 0000000000..6bd82fc44c --- /dev/null +++ b/tests/phpunit/data/media/Soccer_ball_animated.svg @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/phpunit/includes/filerepo/files/FileTest.php b/tests/phpunit/includes/filerepo/files/FileTest.php new file mode 100644 index 0000000000..36b95ea016 --- /dev/null +++ b/tests/phpunit/includes/filerepo/files/FileTest.php @@ -0,0 +1,34 @@ +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 ), + ); + } +} diff --git a/tests/phpunit/includes/media/MediaWikiMediaTestCase.php b/tests/phpunit/includes/media/MediaWikiMediaTestCase.php index ebfcba9ec5..96347d9400 100644 --- a/tests/phpunit/includes/media/MediaWikiMediaTestCase.php +++ b/tests/phpunit/includes/media/MediaWikiMediaTestCase.php @@ -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 ); } diff --git a/tests/phpunit/includes/media/SVGMetadataExtractorTest.php b/tests/phpunit/includes/media/SVGMetadataExtractorTest.php index fa63fa64f2..f06bd6f072 100644 --- a/tests/phpunit/includes/media/SVGMetadataExtractorTest.php +++ b/tests/phpunit/includes/media/SVGMetadataExtractorTest.php @@ -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() + ), + ), ); }