Localisation updates from http://translatewiki.net.
[mediawiki.git] / tests / phpunit / mocks / media / MockBitmapHandler.php
blob742b41e4dd3c0e1bc2ae98baace563d9874d0c57
1 <?php
2 /**
3 * Fake handler for images.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Media
24 class MockBitmapHandler extends BitmapHandler {
25 function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
26 return MockImageHandler::doFakeTransform( $this, $image, $dstPath, $dstUrl, $params, $flags );
28 function doClientImage( $image, $scalerParams ) {
29 return $this->getClientScalingThumbnailImage( $image, $scalerParams );
32 class MockSvgHandler extends SvgHandler {
33 function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
34 return MockImageHandler::doFakeTransform( $this, $image, $dstPath, $dstUrl, $params, $flags );
37 /**
38 * Mock handler for images.
40 * This is really intended for unit testing.
42 * @ingroup Media
44 class MockImageHandler {
46 /**
47 * Override BitmapHandler::doTransform() making sure we do not generate
48 * a thumbnail at all. That is merely returning a ThumbnailImage that
49 * will be consumed by the unit test. There is no need to create a real
50 * thumbnail on the filesystem.
52 static function doFakeTransform( $that, $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
53 # Example of what we receive:
54 # $image: LocalFile
55 # $dstPath: /tmp/transform_7d0a7a2f1a09-1.jpg
56 # $dstUrl : http://example.com/images/thumb/0/09/Bad.jpg/320px-Bad.jpg
57 # $params: width: 320, descriptionUrl http://trunk.dev/wiki/File:Bad.jpg
59 $that->normaliseParams( $image, $params );
61 $scalerParams = array(
62 # The size to which the image will be resized
63 'physicalWidth' => $params['physicalWidth'],
64 'physicalHeight' => $params['physicalHeight'],
65 'physicalDimensions' => "{$params['physicalWidth']}x{$params['physicalHeight']}",
66 # The size of the image on the page
67 'clientWidth' => $params['width'],
68 'clientHeight' => $params['height'],
69 # Comment as will be added to the EXIF of the thumbnail
70 'comment' => isset( $params['descriptionUrl'] ) ?
71 "File source: {$params['descriptionUrl']}" : '',
72 # Properties of the original image
73 'srcWidth' => $image->getWidth(),
74 'srcHeight' => $image->getHeight(),
75 'mimeType' => $image->getMimeType(),
76 'dstPath' => $dstPath,
77 'dstUrl' => $dstUrl,
80 # In some cases, we do not bother generating a thumbnail.
81 if ( !$image->mustRender() &&
82 $scalerParams['physicalWidth'] == $scalerParams['srcWidth']
83 && $scalerParams['physicalHeight'] == $scalerParams['srcHeight']
84 ) {
85 wfDebug( __METHOD__ . ": returning unscaled image\n" );
86 // getClientScalingThumbnailImage is protected
87 return $that->doClientImage( $image, $scalerParams );
90 return new ThumbnailImage( $image, $dstUrl, false, $params );