!! end
@@ -7757,6 +7757,37 @@ Thumbnail image caption with a free URL and explicit alt
!! end
+
+!! test
+SVG thumbnails with no language set
+!! options
+!! input
+[[File:Foobar.svg|thumb|width=200]]
+!! result
+
width=200
+
+!! end
+
+!! test
+SVG thumbnails with language de
+!! options
+!! input
+[[File:Foobar.svg|thumb|width=200|lang=de]]
+!! result
+
width=200
+
+!! end
+
+!! test
+SVG thumbnails with invalid language code
+!! options
+!! input
+[[File:Foobar.svg|thumb|width=200|lang=invalid.language.code]]
+!! result
+
lang=invalid.language.code
+
+!! end
+
!! test
BUG 1887: A ISBN with a thumbnail
!! input
@@ -13965,6 +13996,7 @@ HttP://MediaWiki.Org/
!! end
+
###
### Parsoids-specific tests
### Parsoid-PHP parser incompatibilities
diff --git a/tests/phpunit/includes/parser/NewParserTest.php b/tests/phpunit/includes/parser/NewParserTest.php
index 8cee07bad6..6975939a75 100644
--- a/tests/phpunit/includes/parser/NewParserTest.php
+++ b/tests/phpunit/includes/parser/NewParserTest.php
@@ -102,6 +102,10 @@ class NewParserTest extends MediaWikiTestCase {
$tmpGlobals['wgParser'] = new StubObject( 'wgParser', $GLOBALS['wgParserConf']['class'], array( $GLOBALS['wgParserConf'] ) );
+ $tmpGlobals['wgFileExtensions'][] = 'svg';
+ $tmpGlobals['wgSVGConverter'] = 'rsvg';
+ $tmpGlobals['wgSVGConverters']['rsvg'] = '$path/rsvg-convert -w $width -h $height $input -o $output';
+
if ( $GLOBALS['wgStyleDirectory'] === false ) {
$tmpGlobals['wgStyleDirectory'] = "$IP/skins";
}
@@ -113,6 +117,8 @@ class NewParserTest extends MediaWikiTestCase {
foreach ( $wgMediaHandlers as $type => $handler ) {
$tmpGlobals['wgMediaHandlers'][$type] = 'MockBitmapHandler';
}
+ // Vector images have to be handled slightly differently
+ $tmpGlobals['wgMediaHandlers']['image/svg+xml'] = 'MockSvgHandler';
$tmpHooks = $wgHooks;
$tmpHooks['ParserTestParser'][] = 'ParserTestParserHook::setup';
@@ -270,6 +276,20 @@ class NewParserTest extends MediaWikiTestCase {
$this->db->timestamp( '20010115123500' ), $user
);
}
+ $image = wfLocalFile( Title::makeTitle( NS_FILE, 'Foobar.svg' ) );
+ if ( !$this->db->selectField( 'image', '1', array( 'img_name' => $image->getName() ) ) ) {
+ $image->recordUpload2( '', 'Upload of some lame SVG', 'Some lame SVG', array(
+ 'size' => 12345,
+ 'width' => 200,
+ 'height' => 200,
+ 'bits' => 24,
+ 'media_type' => MEDIATYPE_DRAWING,
+ 'mime' => 'image/svg+xml',
+ 'metadata' => serialize( array() ),
+ 'sha1' => wfBaseConvert( '', 16, 36, 31 ),
+ 'fileExists' => true
+ ), $this->db->timestamp( '20010115123500' ), $user );
+ }
}
//ParserTest setup/teardown functions
@@ -440,6 +460,19 @@ class NewParserTest extends MediaWikiTestCase {
$backend->store( array(
'src' => "$IP/skins/monobook/headbg.jpg", 'dst' => "$base/local-public/0/09/Bad.jpg"
) );
+
+ // No helpful SVG file to copy, so make one ourselves
+ $tmpDir = wfTempDir();
+ $tempFsFile = new TempFSFile( "$tmpDir/Foobar.svg" );
+ $tempFsFile->autocollect(); // destroy file when $tempFsFile leaves scope
+ file_put_contents( "$tmpDir/Foobar.svg",
+ '' .
+ '' );
+
+ $backend->prepare( array( 'dir' => "$base/local-public/f/ff" ) );
+ $backend->quickStore( array(
+ 'src' => "$tmpDir/Foobar.svg", 'dst' => "$base/local-public/f/ff/Foobar.svg"
+ ) );
}
/**
@@ -492,6 +525,14 @@ class NewParserTest extends MediaWikiTestCase {
"$base/local-public/0/09/Bad.jpg",
+ "$base/local-public/f/ff/Foobar.svg",
+ "$base/local-thumb/f/ff/Foobar.svg/180px-Foobar.svg.jpg",
+ "$base/local-thumb/f/ff/Foobar.svg/270px-Foobar.svg.jpg",
+ "$base/local-thumb/f/ff/Foobar.svg/360px-Foobar.svg.jpg",
+ "$base/local-thumb/f/ff/Foobar.svg/langde-180px-Foobar.svg.jpg",
+ "$base/local-thumb/f/ff/Foobar.svg/langde-270px-Foobar.svg.jpg",
+ "$base/local-thumb/f/ff/Foobar.svg/langde-360px-Foobar.svg.jpg",
+
"$base/local-public/math/f/a/5/fa50b8b616463173474302ca3e63586b.png",
)
);
diff --git a/tests/phpunit/mocks/media/MockBitmapHandler.php b/tests/phpunit/mocks/media/MockBitmapHandler.php
index 2ae30a342c..742b41e4dd 100644
--- a/tests/phpunit/mocks/media/MockBitmapHandler.php
+++ b/tests/phpunit/mocks/media/MockBitmapHandler.php
@@ -21,6 +21,19 @@
* @ingroup Media
*/
+class MockBitmapHandler extends BitmapHandler {
+ function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
+ return MockImageHandler::doFakeTransform( $this, $image, $dstPath, $dstUrl, $params, $flags );
+ }
+ function doClientImage( $image, $scalerParams ) {
+ return $this->getClientScalingThumbnailImage( $image, $scalerParams );
+ }
+}
+class MockSvgHandler extends SvgHandler {
+ function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
+ return MockImageHandler::doFakeTransform( $this, $image, $dstPath, $dstUrl, $params, $flags );
+ }
+}
/**
* Mock handler for images.
*
@@ -28,7 +41,7 @@
*
* @ingroup Media
*/
-class MockBitmapHandler extends BitmapHandler {
+class MockImageHandler {
/**
* Override BitmapHandler::doTransform() making sure we do not generate
@@ -36,14 +49,14 @@ class MockBitmapHandler extends BitmapHandler {
* will be consumed by the unit test. There is no need to create a real
* thumbnail on the filesystem.
*/
- function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
+ static function doFakeTransform( $that, $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
# Example of what we receive:
# $image: LocalFile
# $dstPath: /tmp/transform_7d0a7a2f1a09-1.jpg
# $dstUrl : http://example.com/images/thumb/0/09/Bad.jpg/320px-Bad.jpg
# $params: width: 320, descriptionUrl http://trunk.dev/wiki/File:Bad.jpg
- $this->normaliseParams( $image, $params );
+ $that->normaliseParams( $image, $params );
$scalerParams = array(
# The size to which the image will be resized
@@ -67,9 +80,11 @@ class MockBitmapHandler extends BitmapHandler {
# In some cases, we do not bother generating a thumbnail.
if ( !$image->mustRender() &&
$scalerParams['physicalWidth'] == $scalerParams['srcWidth']
- && $scalerParams['physicalHeight'] == $scalerParams['srcHeight'] ) {
+ && $scalerParams['physicalHeight'] == $scalerParams['srcHeight']
+ ) {
wfDebug( __METHOD__ . ": returning unscaled image\n" );
- return $this->getClientScalingThumbnailImage( $image, $scalerParams );
+ // getClientScalingThumbnailImage is protected
+ return $that->doClientImage( $image, $scalerParams );
}
return new ThumbnailImage( $image, $dstUrl, false, $params );