Follow-up r92635 Make sure the Exif related tests handle not having the Exif extensio...
authorBrian Wolff <bawolff@users.mediawiki.org>
Sun, 18 Sep 2011 01:53:09 +0000 (01:53 +0000)
committerBrian Wolff <bawolff@users.mediawiki.org>
Sun, 18 Sep 2011 01:53:09 +0000 (01:53 +0000)
This should fix issues reported in http://lists.wikimedia.org/pipermail/wikitech-l/2011-September/055212.html Lots of these tests loaded the exif extension dynamically, but then didn't reset $wgShowEXIF var properly.

Also change some of the markTestIncomplete to markTestSkipped as that seemed more correct.

tests/phpunit/includes/media/BitmapMetadataHandlerTest.php
tests/phpunit/includes/media/ExifBitmapTest.php
tests/phpunit/includes/media/ExifRotationTest.php
tests/phpunit/includes/media/ExifTest.php
tests/phpunit/includes/media/FormatMetadataTest.php
tests/phpunit/includes/media/JpegTest.php
tests/phpunit/includes/media/XMPTest.php

index 1e11d50..bb0f0bb 100644 (file)
@@ -15,8 +15,14 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase {
         */
        public function testMultilingualCascade() {
                if ( !wfDl( 'exif' ) ) {
-                       $this->markTestIncomplete( "This test needs the exif extension." );
+                       $this->markTestSkipped( "This test needs the exif extension." );
                }
+               if ( !wfDl( 'xml' ) ) {
+                       $this->markTestSkipped( "This test needs the xml extension." );
+               }
+               global $wgShowEXIF;
+               $oldExif = $wgShowEXIF;
+               $wgShowEXIF = true;
 
                $meta = BitmapMetadataHandler::Jpeg( $this->filePath .
                        '/Xmp-exif-multilingual_test.jpg' );
@@ -31,6 +37,8 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase {
                        'Did not extract any ImageDescription info?!' );
 
                $this->assertEquals( $expected, $meta['ImageDescription'] );
+
+               $wgShowEXIF = $oldExif;
        }
 
        /**
@@ -94,6 +102,9 @@ class BitmapMetadataHandlerTest extends MediaWikiTestCase {
        }
 
        public function testPNGXMP() {
+               if ( !wfDl( 'xml' ) ) {
+                       $this->markTestSkipped( "This test needs the xml extension." );
+               }
                $handler = new BitmapMetadataHandler();
                $result = $handler->png( $this->filePath . 'xmp.png' );
                $expected = array (
index d6bca82..00e7c62 100644 (file)
@@ -7,46 +7,29 @@ class ExifBitmapTest extends MediaWikiTestCase {
                $this->showExif = $wgShowEXIF;
                $wgShowEXIF = true;
                $this->handler = new ExifBitmapHandler;
-       }
-
-       public function tearDown() {
-               global $wgShowEXIF;
-               $wgShowEXIF = $this->showExif;
+               if ( !wfDl( 'exif' ) ) {
+                       $this->markTestSkipped( "This test needs the exif extension." );
+               }
        }
 
        public function testIsOldBroken() {
-               if ( !wfDl( 'exif' ) ) {
-                       $this->markTestIncomplete( "This test needs the exif extension." );
-               }
                $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::OLD_BROKEN_FILE );
                $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
        }
        public function testIsBrokenFile() {
-               if ( !wfDl( 'exif' ) ) {
-                       $this->markTestIncomplete( "This test needs the exif extension." );
-               }
                $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::BROKEN_FILE );
                $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
        }
        public function testIsInvalid() {
-               if ( !wfDl( 'exif' ) ) {
-                       $this->markTestIncomplete( "This test needs the exif extension." );
-               }
                $res = $this->handler->isMetadataValid( null, 'Something Invalid Here.' );
                $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
        }
        public function testGoodMetadata() {
-               if ( !wfDl( 'exif' ) ) {
-                       $this->markTestIncomplete( "This test needs the exif extension." );
-               }
                $meta = 'a:16:{s:10:"ImageWidth";i:20;s:11:"ImageLength";i:20;s:13:"BitsPerSample";a:3:{i:0;i:8;i:1;i:8;i:2;i:8;}s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:16:"ImageDescription";s:17:"Created with GIMP";s:12:"StripOffsets";i:8;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:3;s:12:"RowsPerStrip";i:64;s:15:"StripByteCounts";i:238;s:11:"XResolution";s:19:"1207959552/16777216";s:11:"YResolution";s:19:"1207959552/16777216";s:19:"PlanarConfiguration";i:1;s:14:"ResolutionUnit";i:2;s:22:"MEDIAWIKI_EXIF_VERSION";i:2;}';
                $res = $this->handler->isMetadataValid( null, $meta );
                $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
        }
        public function testIsOldGood() {
-               if ( !wfDl( 'exif' ) ) {
-                       $this->markTestIncomplete( "This test needs the exif extension." );
-               }
                $meta = 'a:16:{s:10:"ImageWidth";i:20;s:11:"ImageLength";i:20;s:13:"BitsPerSample";a:3:{i:0;i:8;i:1;i:8;i:2;i:8;}s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:16:"ImageDescription";s:17:"Created with GIMP";s:12:"StripOffsets";i:8;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:3;s:12:"RowsPerStrip";i:64;s:15:"StripByteCounts";i:238;s:11:"XResolution";s:19:"1207959552/16777216";s:11:"YResolution";s:19:"1207959552/16777216";s:19:"PlanarConfiguration";i:1;s:14:"ResolutionUnit";i:2;s:22:"MEDIAWIKI_EXIF_VERSION";i:1;}';
                $res = $this->handler->isMetadataValid( null, $meta );
                $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
@@ -54,9 +37,6 @@ class ExifBitmapTest extends MediaWikiTestCase {
        // Handle metadata from paged tiff handler (gotten via instant commons)
        // gracefully.
        public function testPagedTiffHandledGracefully() {
-               if ( !wfDl( 'exif' ) ) {
-                       $this->markTestIncomplete( "This test needs the exif extension." );
-               }
                $meta = 'a:6:{s:9:"page_data";a:1:{i:1;a:5:{s:5:"width";i:643;s:6:"height";i:448;s:5:"alpha";s:4:"true";s:4:"page";i:1;s:6:"pixels";i:288064;}}s:10:"page_count";i:1;s:10:"first_page";i:1;s:9:"last_page";i:1;s:4:"exif";a:9:{s:10:"ImageWidth";i:643;s:11:"ImageLength";i:448;s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:4;s:12:"RowsPerStrip";i:50;s:19:"PlanarConfiguration";i:1;s:22:"MEDIAWIKI_EXIF_VERSION";i:1;}s:21:"TIFF_METADATA_VERSION";s:3:"1.4";}';
                $res = $this->handler->isMetadataValid( null, $meta );
                $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
index d7e781f..ea2b983 100644 (file)
@@ -9,6 +9,16 @@ class ExifRotationTest extends MediaWikiTestCase {
                parent::setUp();
                $this->filePath = dirname( __FILE__ ) . '/../../data/media/';
                $this->handler = new BitmapHandler();
+               if ( !wfDl( 'exif' ) ) {
+                       $this->markTestSkipped( "This test needs the exif extension." );
+               }
+               global $wgShowEXIF;
+               $this->show = $wgShowEXIF;
+               $wgShowEXIF = true;
+       }
+       public function tearDown() {
+               global $wgShowEXIF;
+               $wgShowEXIF = $this->show;
        }
 
        /**
@@ -33,7 +43,7 @@ class ExifRotationTest extends MediaWikiTestCase {
                
                # Any further test require a scaler that can rotate
                if ( !BitmapHandler::canRotate() ) {
-                       $this->markTestIncomplete( 'Scaler does not support rotation' );
+                       $this->markTestSkipped( 'Scaler does not support rotation' );
                        return;
                }
                
@@ -102,6 +112,11 @@ class ExifRotationTest extends MediaWikiTestCase {
        }
 
        function testWidthFlipping() {
+               # Any further test require a scaler that can rotate
+               if ( !BitmapHandler::canRotate() ) {
+                       $this->markTestSkipped( 'Scaler does not support rotation' );
+                       return;
+               }
                $file = UnregisteredLocalFile::newFromPath( $this->filePath . 'portrait-rotated.jpg', 'image/jpeg' );
                $params = array( 'width' => '50' );
                $this->assertTrue( $this->handler->normaliseParams( $file, $params ) );
index 9b490e9..b39c15e 100644 (file)
@@ -4,6 +4,9 @@ class ExifTest extends MediaWikiTestCase {
        public function setUp() {
                $this->mediaPath = dirname( __FILE__ ) . '/../../data/media/';
 
+               if ( !wfDl( 'exif' ) ) {
+                       $this->markTestSkipped( "This test needs the exif extension." );
+               }
                 global $wgShowEXIF;
                 $this->showExif = $wgShowEXIF;
                 $wgShowEXIF = true;
@@ -14,9 +17,6 @@ class ExifTest extends MediaWikiTestCase {
         }
 
        public function testGPSExtraction() {
-               if ( !wfDl( 'exif' ) ) {
-                       $this->markTestIncomplete( "This test needs the exif extension." );
-               }
 
                $filename = $this->mediaPath . 'exif-gps.jpg';
                $seg = JpegMetadataExtractor::segmentSplitter( $filename ); 
@@ -32,9 +32,6 @@ class ExifTest extends MediaWikiTestCase {
                $this->assertEquals( $expected, $data, '', 0.0000000001 );
        }
        public function testUnicodeUserComment() {
-               if ( !wfDl( 'exif' ) ) {
-                       $this->markTestIncomplete( "This test needs the exif extension." );
-               }
 
                $filename = $this->mediaPath . 'exif-user-comment.jpg';
                $seg = JpegMetadataExtractor::segmentSplitter( $filename ); 
index 159b53b..276c000 100644 (file)
@@ -1,10 +1,19 @@
 <?php
 class FormatMetadataTest extends MediaWikiTestCase {
-       public function testInvalidDate() {
+       public function setUp() {
                if ( !wfDl( 'exif' ) ) {
-                       $this->markTestIncomplete( "This test needs the exif extension." );
+                       $this->markTestSkipped( "This test needs the exif extension." );
                }
-               
+               global $wgShowEXIF;
+               $this->show = $wgShowEXIF;
+               $wgShowEXIF = true;
+       }
+       public function tearDown() {
+               global $wgShowEXIF;
+               $wgShowEXIF = $this->show;
+       }
+
+       public function testInvalidDate() {
                $file = UnregisteredLocalFile::newFromPath( dirname( __FILE__ ) . 
                        '/../../data/media/broken_exif_date.jpg', 'image/jpeg' );
                
index 3a2900b..ddabf5b 100644 (file)
@@ -3,20 +3,24 @@ class JpegTest extends MediaWikiTestCase {
 
        public function setUp() {
                $this->filePath = dirname( __FILE__ ) . '/../../data/media/';
+               if ( !wfDl( 'exif' ) ) {
+                       $this->markTestSkipped( "This test needs the exif extension." );
+               }
+               global $wgShowEXIF;
+               $this->show = $wgShowEXIF;
+               $wgShowEXIF = true;
+       }
+       public function tearDown() {
+               global $wgShowEXIF;
+               $wgShowEXIF = $this->show;
        }
 
        public function testInvalidFile() {
-               if ( !wfDl( 'exif' ) ) {
-                       $this->markTestIncomplete( "This test needs the exif extension." );
-               }
                $jpeg = new JpegHandler;
                $res = $jpeg->getMetadata( null, $this->filePath . 'README' );
                $this->assertEquals( ExifBitmapHandler::BROKEN_FILE, $res );
        }
        public function testJpegMetadataExtraction() {
-               if ( !wfDl( 'exif' ) ) {
-                       $this->markTestIncomplete( "This test needs the exif extension." );
-               }
                $h = new JpegHandler;
                $res = $h->getMetadata( null, $this->filePath . 'test.jpg' );
                $expected = 'a:7:{s:16:"ImageDescription";s:9:"Test file";s:11:"XResolution";s:4:"72/1";s:11:"YResolution";s:4:"72/1";s:14:"ResolutionUnit";i:2;s:16:"YCbCrPositioning";i:1;s:15:"JPEGFileComment";a:1:{i:0;s:17:"Created with GIMP";}s:22:"MEDIAWIKI_EXIF_VERSION";i:2;}';
index d1ec476..c952b23 100644 (file)
@@ -1,6 +1,12 @@
 <?php
 class XMPTest extends MediaWikiTestCase {
 
+       function setUp() {
+               if ( !wfDl( 'xml' ) ) {
+                       $this->markTestSkipped( 'Requires libxml to do XMP parsing' );
+               }
+       }
+
        /**
         * Put XMP in, compare what comes out...
         *
@@ -11,9 +17,6 @@ class XMPTest extends MediaWikiTestCase {
         * @dataProvider dataXMPParse
         */
        public function testXMPParse( $xmp, $expected, $info ) {
-               if ( !function_exists( 'xml_parser_create_ns' ) ) {
-                       $this->markIncomplete( 'Requires libxml to do XMP parsing' );
-               }
                if ( !is_string( $xmp ) || !is_array( $expected ) ) {
                        throw new Exception( "Invalid data provided to " . __METHOD__ );
                }