From 3072dda2cb13d8f5c6f63795cfc1f422bfd11e00 Mon Sep 17 00:00:00 2001 From: Brian Wolff Date: Mon, 11 Jul 2011 16:42:15 +0000 Subject: [PATCH] (follow-up r90256) Unit tests. --- .../phpunit/includes/media/ExifBitmapTest.php | 63 ++++++++++++++++++ tests/phpunit/includes/media/JpegTest.php | 24 +++++++ tests/phpunit/includes/media/README | 3 +- tests/phpunit/includes/media/TiffTest.php | 24 +++++++ tests/phpunit/includes/media/test.jpg | Bin 0 -> 437 bytes tests/phpunit/includes/media/test.tiff | Bin 0 -> 566 bytes 6 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/includes/media/ExifBitmapTest.php create mode 100644 tests/phpunit/includes/media/JpegTest.php create mode 100644 tests/phpunit/includes/media/TiffTest.php create mode 100644 tests/phpunit/includes/media/test.jpg create mode 100644 tests/phpunit/includes/media/test.tiff diff --git a/tests/phpunit/includes/media/ExifBitmapTest.php b/tests/phpunit/includes/media/ExifBitmapTest.php new file mode 100644 index 0000000000..f8b37172d3 --- /dev/null +++ b/tests/phpunit/includes/media/ExifBitmapTest.php @@ -0,0 +1,63 @@ +markTestIncomplete( "This test needs the exif extension." ); + } + $handler = new ExifBitmapHandler; + $res = $handler->isMetadataValid( null, ExifBitmapHandler::OLD_BROKEN_FILE ); + $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res ); + } + public function testIsBrokenFile() { + global $wgShowEXIF; + if ( !$wgShowEXIF ) { + $this->markTestIncomplete( "This test needs the exif extension." ); + } + $handler = new ExifBitmapHandler; + $res = $handler->isMetadataValid( null, ExifBitmapHandler::BROKEN_FILE ); + $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res ); + } + public function testIsInvalid() { + global $wgShowEXIF; + if ( !$wgShowEXIF ) { + $this->markTestIncomplete( "This test needs the exif extension." ); + } + $handler = new ExifBitmapHandler; + $res = $handler->isMetadataValid( null, 'Something Invalid Here.' ); + $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res ); + } + public function testGoodMetadata() { + global $wgShowEXIF; + if ( !$wgShowEXIF ) { + $this->markTestIncomplete( "This test needs the exif extension." ); + } + $handler = new ExifBitmapHandler; + $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 = $handler->isMetadataValid( null, $meta ); + $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res ); + } + public function testIsOldGood() { + global $wgShowEXIF; + if ( !$wgShowEXIF ) { + $this->markTestIncomplete( "This test needs the exif extension." ); + } + $handler = new ExifBitmapHandler; + $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 = $handler->isMetadataValid( null, $meta ); + $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res ); + } + // Handle metadata from paged tiff handler (gotten via instant commons) + // gracefully. + public function testPagedTiffHandledGracefully() { + global $wgShowEXIF; + if ( !$wgShowEXIF ) { + $this->markTestIncomplete( "This test needs the exif extension." ); + } + $handler = new ExifBitmapHandler; + $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 = $handler->isMetadataValid( null, $meta ); + $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res ); + } +} diff --git a/tests/phpunit/includes/media/JpegTest.php b/tests/phpunit/includes/media/JpegTest.php new file mode 100644 index 0000000000..cc2e556157 --- /dev/null +++ b/tests/phpunit/includes/media/JpegTest.php @@ -0,0 +1,24 @@ +markTestIncomplete( "This test needs the exif extension." ); + } + $jpeg = new JpegHandler; + $res = $jpeg->getMetadata( null, dirname( __FILE__ ) . '/README' ); + $this->assertEquals( ExifBitmapHandler::BROKEN_FILE, $res ); + } + public function testTiffFile() { + global $wgShowEXIF; + if ( !$wgShowEXIF ) { + $this->markTestIncomplete( "This test needs the exif extension." ); + } + $h = new JpegHandler; + $res = $h->getMetadata( null, dirname( __FILE__ ) . '/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;}'; + // Hopefully php always serializes things in the same order. + $this->assertEquals( $expected, $res ); + } +} diff --git a/tests/phpunit/includes/media/README b/tests/phpunit/includes/media/README index 91e3c4f158..7f638c1454 100644 --- a/tests/phpunit/includes/media/README +++ b/tests/phpunit/includes/media/README @@ -16,7 +16,8 @@ TastyCakes on English Wikipedia greyscale-na-png.png, rgb-png.png, Xmp-exif-multilingual_test.jpg -greyscale-png.png, 1bit-png.png, Png-native-test.png, rgb-na-png.png +greyscale-png.png, 1bit-png.png, Png-native-test.png, rgb-na-png.png, +test.tiff, test.jpg Are all by Bawolff. I don't think they contain enough originality to claim copyright, but on the off chance they do, feel free to use them however you feel fit, without restriction. diff --git a/tests/phpunit/includes/media/TiffTest.php b/tests/phpunit/includes/media/TiffTest.php new file mode 100644 index 0000000000..8081ebf8be --- /dev/null +++ b/tests/phpunit/includes/media/TiffTest.php @@ -0,0 +1,24 @@ +markTestIncomplete( "This test needs the exif extension." ); + } + $tiff = new TiffHandler; + $res = $tiff->getMetadata( null, dirname( __FILE__ ) . '/README' ); + $this->assertEquals( ExifBitmapHandler::BROKEN_FILE, $res ); + } + public function testTiffFile() { + global $wgShowEXIF; + if ( !$wgShowEXIF ) { + $this->markTestIncomplete( "This test needs the exif extension." ); + } + $tiff = new TiffHandler; + $res = $tiff->getMetadata( null, dirname( __FILE__ ) . '/test.tiff' ); + $expected = '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;}'; + // Hopefully php always serializes things in the same order. + $this->assertEquals( $expected, $res ); + } +} diff --git a/tests/phpunit/includes/media/test.jpg b/tests/phpunit/includes/media/test.jpg new file mode 100644 index 0000000000000000000000000000000000000000..cb0842530283eb142e900366a5fa3f101a79c97c GIT binary patch literal 437 zcmex=3|F$DZffhb?n&Lf9k1o!5Qe-Yv;SnQb z)-v_5dQGC7=anC${%)eA51ilIG3`PQ@V*;Pr#dv<(HyUuK|ZkT0!NSy9pCl z_&u7UTpQLCu*7Xa!OB}~d;R(vw4VP~<=QIHs-YYDgy-8~hfVTl#I0@gZZzzPNEB~j zJ@%Sw_r3gp?5Dp(y_=(^h@CDedzi9whW>|HZ|m|CH{ML0Y2j*?AK-CiQK{Efx#ae> zhmB8jo;p_E%MhRu;#3>AnfHjVN|2|?B2F#-3oE26rafmr-t=*&OkKF%*R#*v6BL9P z{xPsHFarGz28_&Lwg`~Jh{R?BvYCNmSAYtcq2jDSJ{y$H1Z49vGBH>J>03ZGd_cAk zkSzj~5M+dy&jI8MLDhro6NR!t=88et4nVdzRQ)?3TZ)kt>>f3sInq$J9*`}AWR3=u z4RV7m5*x^6-~dDYvcw|&^73;1a{Ypg#Nt$A{gTw;l42mIpfoSDL_aexIj1xwwOBtl qH6=3