From ffed20a5da8dd8c0596fe93f3b5704638f7fb2b0 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Sun, 18 Sep 2011 01:53:09 +0000 Subject: [PATCH] Follow-up r92635 Make sure the Exif related tests handle not having the Exif extension available properly 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. --- .../media/BitmapMetadataHandlerTest.php | 13 +++++++++- .../phpunit/includes/media/ExifBitmapTest.php | 26 +++---------------- .../includes/media/ExifRotationTest.php | 17 +++++++++++- tests/phpunit/includes/media/ExifTest.php | 9 +++---- .../includes/media/FormatMetadataTest.php | 15 ++++++++--- tests/phpunit/includes/media/JpegTest.php | 16 +++++++----- tests/phpunit/includes/media/XMPTest.php | 9 ++++--- 7 files changed, 62 insertions(+), 43 deletions(-) diff --git a/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php b/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php index 1e11d50399..bb0f0bb8c6 100644 --- a/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php +++ b/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php @@ -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 ( diff --git a/tests/phpunit/includes/media/ExifBitmapTest.php b/tests/phpunit/includes/media/ExifBitmapTest.php index d6bca82701..00e7c62950 100644 --- a/tests/phpunit/includes/media/ExifBitmapTest.php +++ b/tests/phpunit/includes/media/ExifBitmapTest.php @@ -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 ); diff --git a/tests/phpunit/includes/media/ExifRotationTest.php b/tests/phpunit/includes/media/ExifRotationTest.php index d7e781f29e..ea2b9831b6 100644 --- a/tests/phpunit/includes/media/ExifRotationTest.php +++ b/tests/phpunit/includes/media/ExifRotationTest.php @@ -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 ) ); diff --git a/tests/phpunit/includes/media/ExifTest.php b/tests/phpunit/includes/media/ExifTest.php index 9b490e92dc..b39c15e400 100644 --- a/tests/phpunit/includes/media/ExifTest.php +++ b/tests/phpunit/includes/media/ExifTest.php @@ -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 ); diff --git a/tests/phpunit/includes/media/FormatMetadataTest.php b/tests/phpunit/includes/media/FormatMetadataTest.php index 159b53bf0c..276c000092 100644 --- a/tests/phpunit/includes/media/FormatMetadataTest.php +++ b/tests/phpunit/includes/media/FormatMetadataTest.php @@ -1,10 +1,19 @@ 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' ); diff --git a/tests/phpunit/includes/media/JpegTest.php b/tests/phpunit/includes/media/JpegTest.php index 3a2900bf21..ddabf5b8cd 100644 --- a/tests/phpunit/includes/media/JpegTest.php +++ b/tests/phpunit/includes/media/JpegTest.php @@ -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;}'; diff --git a/tests/phpunit/includes/media/XMPTest.php b/tests/phpunit/includes/media/XMPTest.php index d1ec4767df..c952b23c94 100644 --- a/tests/phpunit/includes/media/XMPTest.php +++ b/tests/phpunit/includes/media/XMPTest.php @@ -1,6 +1,12 @@ 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__ ); } -- 2.20.1