Follow-up r99911: fix tests
authorBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 15 Oct 2011 21:38:53 +0000 (21:38 +0000)
committerBryan Tong Minh <btongminh@users.mediawiki.org>
Sat, 15 Oct 2011 21:38:53 +0000 (21:38 +0000)
Add NullRepo to autoloader

includes/AutoLoader.php
includes/ImagePage.php
tests/phpunit/includes/media/BitmapScalingTest.php

index 640f620..2de3f1c 100644 (file)
@@ -471,6 +471,7 @@ $wgAutoloadLocalClasses = array(
        'LocalFileMoveBatch' => 'includes/filerepo/LocalFile.php',
        'LocalFileRestoreBatch' => 'includes/filerepo/LocalFile.php',
        'LocalRepo' => 'includes/filerepo/LocalRepo.php',
+       'NullRepo' => 'includes/filerepo/NullRepo.php',
        'OldLocalFile' => 'includes/filerepo/OldLocalFile.php',
        'RepoGroup' => 'includes/filerepo/RepoGroup.php',
        'UnregisteredLocalFile' => 'includes/filerepo/UnregisteredLocalFile.php',
index 9a017da..86e70a1 100644 (file)
@@ -287,6 +287,9 @@ class ImagePage extends Article {
                        $width = $width_orig;
                        $height_orig = $this->displayImg->getHeight( $page );
                        $height = $height_orig;
+                       $mustRender = $this->displayImg->getHandler() &&
+                               $this->displayImg->getHandler()->mustRender( $this->displayImg );
+                       $addFullResolutionLink = false;
 
                        $longDesc = wfMsg( 'parentheses', $this->displayImg->getLongDesc() );
 
@@ -312,14 +315,19 @@ class ImagePage extends Article {
                                                # Note that $height <= $maxHeight now, but might not be identical
                                                # because of rounding.
                                        }
-                                       $msgbig  = wfMsgHtml( 'show-big-image' );
+
                                        $otherSizes = array();
                                        foreach ( $wgImageLimits as $size ) {
                                                if ( $size[0] < $width_orig && $size[1] < $height_orig &&
                                                                $size[0] != $width && $size[1] != $height ) {
                                                        $otherSizes[] = $this->makeSizeLink( $params, $size[0], $size[1] );
-                                               }
+                                               } 
                                        }
+                                       if ( $mustRender ) {
+                                               $otherSizes[] = $this->makeSizeLink( $params, $width_orig, $height_orig, 'show-big-image' );
+                                       } else {
+                                               $addFullResolutionLink = true; 
+                                       } 
                                        $msgsmall = wfMessage( 'show-big-image-preview' )->
                                                rawParams( $this->makeSizeLink( $params, $width, $height ) )->
                                                parse() . ' ' .
@@ -347,7 +355,7 @@ class ImagePage extends Article {
                                if ( $thumbnail ) {
                                        $options = array(
                                                'alt' => $this->displayImg->getTitle()->getPrefixedText(),
-                                               'file-link' => true,
+                                               'file-link' => !$mustRender,
                                        );
                                        $wgOut->addHTML( '<div class="fullImageLink" id="file">' .
                                                $thumbnail->toHtml( $options ) .
@@ -428,8 +436,8 @@ class ImagePage extends Article {
                        if ( $showLink ) {
                                $filename = wfEscapeWikiText( $this->displayImg->getName() );
                                $linktext = $filename;
-                               if ( isset( $msgbig ) ) {
-                                       $linktext = wfEscapeWikiText( $msgbig );
+                               if ( $addFullResolutionLink ) {
+                                       $linktext = wfMsg( 'show-big-image' );
                                }
                                $medialink = "[[Media:$filename|$linktext]]";
 
@@ -484,7 +492,7 @@ EOT
         * @param int $width
         * @param int $height
         */
-       private function makeSizeLink( $params, $width, $height ) {
+       private function makeSizeLink( $params, $width, $height, $msg = 'show-big-image-size' ) {
                $params['width'] = $width;
                $params['height'] = $height;
                $thumbnail = $this->displayImg->transform( $params );
@@ -492,7 +500,7 @@ EOT
                        return Html::rawElement( 'a', array(
                                'href' => $thumbnail->getUrl(),
                                'class' => 'mw-thumbnail-link'
-                               ), wfMessage( 'show-big-image-size' )->numParams(
+                               ), wfMessage( $msg )->numParams(
                                        $thumbnail->getWidth(), $thumbnail->getHeight()
                                )->parse() );
                } else {
index 5bcd323..39fdb81 100644 (file)
@@ -3,13 +3,16 @@
 class BitmapScalingTest extends MediaWikiTestCase {
 
        function setUp() {
-               global $wgMaxImageArea;
+               global $wgMaxImageArea, $wgCustomConvertCommand;
                $this->oldMaxImageArea = $wgMaxImageArea;
+               $this->oldCustomConvertCommand = $wgCustomConvertCommand;
                $wgMaxImageArea = 1.25e7; // 3500x3500 
+               $wgCustomConvertCommand = 'dummy'; // Set so that we don't get client side rendering
        }
        function tearDown() {
-               global $wgMaxImageArea;
+               global $wgMaxImageArea, $wgCustomConvertCommand;
                $wgMaxImageArea = $this->oldMaxImageArea;
+               $wgCustomConvertCommand = $this->oldCustomConvertCommand;
        }
        /**
         * @dataProvider provideNormaliseParams
@@ -105,14 +108,16 @@ class BitmapScalingTest extends MediaWikiTestCase {
                $file = new FakeDimensionFile( array( 4000, 4000 ) );
                $handler = new BitmapHandler;
                $params = array( 'width' => '3700' ); // Still bigger than max size.
-               $this->assertFalse( $handler->normaliseParams( $file, $params ) );
+               $this->assertEquals( 'TransformParameterError', 
+                       get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
        }
        function testTooBigMustRenderImage() {
                $file = new FakeDimensionFile( array( 4000, 4000 ) );
                $file->mustRender = true;
                $handler = new BitmapHandler;
                $params = array( 'width' => '5000' ); // Still bigger than max size.
-               $this->assertFalse( $handler->normaliseParams( $file, $params ) );
+               $this->assertEquals( 'TransformParameterError', 
+                       get_class( $handler->doTransform( $file, 'dummy path', '', $params ) ) );
        }
 }
 
@@ -120,7 +125,8 @@ class FakeDimensionFile extends File {
        public $mustRender = false;
 
        public function __construct( $dimensions ) {
-               parent::__construct( Title::makeTitle( NS_FILE, 'Test' ), null );
+               parent::__construct( Title::makeTitle( NS_FILE, 'Test' ), 
+                       new NullRepo( null ) );
                
                $this->dimensions = $dimensions;
        }
@@ -133,4 +139,7 @@ class FakeDimensionFile extends File {
        public function mustRender() {
                return $this->mustRender;
        }
+       public function getPath() {
+               return '';
+       }
 }