r91885 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91884‎ | r91885 | r91886 >
Date:16:42, 11 July 2011
Author:bawolff
Status:resolved (Comments)
Tags:
Comment:
(follow-up r90256) Unit tests.
Modified paths:
  • /trunk/phase3/tests/phpunit/includes/media/ExifBitmapTest.php (added) (history)
  • /trunk/phase3/tests/phpunit/includes/media/JpegTest.php (added) (history)
  • /trunk/phase3/tests/phpunit/includes/media/README (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/media/TiffTest.php (added) (history)
  • /trunk/phase3/tests/phpunit/includes/media/test.jpg (added) (history)
  • /trunk/phase3/tests/phpunit/includes/media/test.tiff (added) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/media/README
@@ -16,7 +16,8 @@
1717
1818
1919 greyscale-na-png.png, rgb-png.png, Xmp-exif-multilingual_test.jpg
20 -greyscale-png.png, 1bit-png.png, Png-native-test.png, rgb-na-png.png
 20+greyscale-png.png, 1bit-png.png, Png-native-test.png, rgb-na-png.png,
 21+test.tiff, test.jpg
2122 Are all by Bawolff. I don't think they contain enough originality to
2223 claim copyright, but on the off chance they do, feel free to use them
2324 however you feel fit, without restriction.
Index: trunk/phase3/tests/phpunit/includes/media/test.jpg
Cannot display: file marked as a binary type.
svn:mime-type = image/jpeg
Property changes on: trunk/phase3/tests/phpunit/includes/media/test.jpg
___________________________________________________________________
Added: svn:mime-type
2425 + image/jpeg
Index: trunk/phase3/tests/phpunit/includes/media/test.tiff
Cannot display: file marked as a binary type.
svn:mime-type = image/tiff
Property changes on: trunk/phase3/tests/phpunit/includes/media/test.tiff
___________________________________________________________________
Added: svn:mime-type
2526 + image/tiff
Index: trunk/phase3/tests/phpunit/includes/media/JpegTest.php
@@ -0,0 +1,24 @@
 2+<?php
 3+class JpegTest extends MediaWikiTestCase {
 4+
 5+ public function testInvalidFile() {
 6+ global $wgShowEXIF;
 7+ if ( !$wgShowEXIF ) {
 8+ $this->markTestIncomplete( "This test needs the exif extension." );
 9+ }
 10+ $jpeg = new JpegHandler;
 11+ $res = $jpeg->getMetadata( null, dirname( __FILE__ ) . '/README' );
 12+ $this->assertEquals( ExifBitmapHandler::BROKEN_FILE, $res );
 13+ }
 14+ public function testTiffFile() {
 15+ global $wgShowEXIF;
 16+ if ( !$wgShowEXIF ) {
 17+ $this->markTestIncomplete( "This test needs the exif extension." );
 18+ }
 19+ $h = new JpegHandler;
 20+ $res = $h->getMetadata( null, dirname( __FILE__ ) . '/test.jpg' );
 21+ $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;}';
 22+ // Hopefully php always serializes things in the same order.
 23+ $this->assertEquals( $expected, $res );
 24+ }
 25+}
Property changes on: trunk/phase3/tests/phpunit/includes/media/JpegTest.php
___________________________________________________________________
Added: svn:eol-style
126 + native
Index: trunk/phase3/tests/phpunit/includes/media/TiffTest.php
@@ -0,0 +1,24 @@
 2+<?php
 3+class TiffTest extends MediaWikiTestCase {
 4+
 5+ public function testInvalidFile() {
 6+ global $wgShowEXIF;
 7+ if ( !$wgShowEXIF ) {
 8+ $this->markTestIncomplete( "This test needs the exif extension." );
 9+ }
 10+ $tiff = new TiffHandler;
 11+ $res = $tiff->getMetadata( null, dirname( __FILE__ ) . '/README' );
 12+ $this->assertEquals( ExifBitmapHandler::BROKEN_FILE, $res );
 13+ }
 14+ public function testTiffFile() {
 15+ global $wgShowEXIF;
 16+ if ( !$wgShowEXIF ) {
 17+ $this->markTestIncomplete( "This test needs the exif extension." );
 18+ }
 19+ $tiff = new TiffHandler;
 20+ $res = $tiff->getMetadata( null, dirname( __FILE__ ) . '/test.tiff' );
 21+ $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;}';
 22+ // Hopefully php always serializes things in the same order.
 23+ $this->assertEquals( $expected, $res );
 24+ }
 25+}
Property changes on: trunk/phase3/tests/phpunit/includes/media/TiffTest.php
___________________________________________________________________
Added: svn:eol-style
126 + native
Index: trunk/phase3/tests/phpunit/includes/media/ExifBitmapTest.php
@@ -0,0 +1,63 @@
 2+<?php
 3+class ExifBitmapTest extends MediaWikiTestCase {
 4+
 5+ public function testIsOldBroken() {
 6+ global $wgShowEXIF;
 7+ if ( !$wgShowEXIF ) {
 8+ $this->markTestIncomplete( "This test needs the exif extension." );
 9+ }
 10+ $handler = new ExifBitmapHandler;
 11+ $res = $handler->isMetadataValid( null, ExifBitmapHandler::OLD_BROKEN_FILE );
 12+ $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
 13+ }
 14+ public function testIsBrokenFile() {
 15+ global $wgShowEXIF;
 16+ if ( !$wgShowEXIF ) {
 17+ $this->markTestIncomplete( "This test needs the exif extension." );
 18+ }
 19+ $handler = new ExifBitmapHandler;
 20+ $res = $handler->isMetadataValid( null, ExifBitmapHandler::BROKEN_FILE );
 21+ $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
 22+ }
 23+ public function testIsInvalid() {
 24+ global $wgShowEXIF;
 25+ if ( !$wgShowEXIF ) {
 26+ $this->markTestIncomplete( "This test needs the exif extension." );
 27+ }
 28+ $handler = new ExifBitmapHandler;
 29+ $res = $handler->isMetadataValid( null, 'Something Invalid Here.' );
 30+ $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
 31+ }
 32+ public function testGoodMetadata() {
 33+ global $wgShowEXIF;
 34+ if ( !$wgShowEXIF ) {
 35+ $this->markTestIncomplete( "This test needs the exif extension." );
 36+ }
 37+ $handler = new ExifBitmapHandler;
 38+ $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;}';
 39+ $res = $handler->isMetadataValid( null, $meta );
 40+ $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
 41+ }
 42+ public function testIsOldGood() {
 43+ global $wgShowEXIF;
 44+ if ( !$wgShowEXIF ) {
 45+ $this->markTestIncomplete( "This test needs the exif extension." );
 46+ }
 47+ $handler = new ExifBitmapHandler;
 48+ $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;}';
 49+ $res = $handler->isMetadataValid( null, $meta );
 50+ $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
 51+ }
 52+ // Handle metadata from paged tiff handler (gotten via instant commons)
 53+ // gracefully.
 54+ public function testPagedTiffHandledGracefully() {
 55+ global $wgShowEXIF;
 56+ if ( !$wgShowEXIF ) {
 57+ $this->markTestIncomplete( "This test needs the exif extension." );
 58+ }
 59+ $handler = new ExifBitmapHandler;
 60+ $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";}';
 61+ $res = $handler->isMetadataValid( null, $meta );
 62+ $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
 63+ }
 64+}
Property changes on: trunk/phase3/tests/phpunit/includes/media/ExifBitmapTest.php
___________________________________________________________________
Added: svn:eol-style
165 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r92638Fix for r91885....platonides15:33, 20 July 2011
r94825follow-up r91885 - address CR comments...bawolff21:53, 17 August 2011
r94862follow-up r91885 rename testTiffFile since its not about tiff files...bawolff03:53, 18 August 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r90256(follow-up r86567) per CR rename the class JpegOrTiffHandler to ExifBitmapHan...bawolff03:37, 17 June 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   23:32, 11 July 2011

Hmm... this seems to sound like it'll *drop* metadata from a paged tiff file proxied from another site via an API repo. This would presumably lose ability to select pages etc or...? Should ExifBitmapHandler ever be testing metadata from a PagedTiffHandler?

#Comment by Bawolff (talk | contribs)   16:35, 17 August 2011

The built in tiff handler doesn't have the ability to select pages, so it can't lose that ability (Built in tiff handler only uses the metadata to display to user in the little box on the file page, it doesn't change the way it handles a file based on its metadata). Previously it misunderstood the metadata from pagedTiffHandler and displayed garbage to the user, so just dropping it is an improvement. Code could be added to check for, and handle PagedTiffHandler style metadata appropriately, if we wanted to.

#Comment by Bryan (talk | contribs)   16:15, 19 July 2011
+		// Hopefully php always serializes things in the same order.

You can unserialize and and compare the resulting arrays.

+	public function testTiffFile() {

This test can be better named.

#Comment by Bawolff (talk | contribs)   23:37, 17 August 2011

Thanks. Addressed in r94825

Status & tagging log