http://www.mediawiki.org/wiki/Special:Code/MediaWiki/90682
Revision: 90682
Author: bawolff
Date: 2011-06-23 23:25:49 +0000 (Thu, 23 Jun 2011)
Log Message:
-----------
Per CR on r86169, start adding unit tests for metadata extraction.
This is just some initial tests that really only cover png's. I plan
to add more soon.
Also well I'm here, fix the svn prop on broken_exif_date.jpg from r90421.
Modified Paths:
--------------
trunk/phase3/tests/phpunit/includes/media/README
Added Paths:
-----------
trunk/phase3/tests/phpunit/includes/media/1bit-png.png
trunk/phase3/tests/phpunit/includes/media/Animated_PNG_example_bouncing_beach_ball.png
trunk/phase3/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php
trunk/phase3/tests/phpunit/includes/media/PNGMetadataExtractorTest.php
trunk/phase3/tests/phpunit/includes/media/Png-native-test.png
trunk/phase3/tests/phpunit/includes/media/Xmp-exif-multilingual_test.jpg
trunk/phase3/tests/phpunit/includes/media/greyscale-na-png.png
trunk/phase3/tests/phpunit/includes/media/greyscale-png.png
trunk/phase3/tests/phpunit/includes/media/rgb-na-png.png
trunk/phase3/tests/phpunit/includes/media/rgb-png.png
Property Changed:
----------------
trunk/phase3/tests/phpunit/includes/media/broken_exif_date.jpg
Added: trunk/phase3/tests/phpunit/includes/media/1bit-png.png
===================================================================
(Binary files differ)
Property changes on: trunk/phase3/tests/phpunit/includes/media/1bit-png.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added:
trunk/phase3/tests/phpunit/includes/media/Animated_PNG_example_bouncing_beach_ball.png
===================================================================
(Binary files differ)
Property changes on:
trunk/phase3/tests/phpunit/includes/media/Animated_PNG_example_bouncing_beach_ball.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/phase3/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php
===================================================================
--- trunk/phase3/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php
(rev 0)
+++ trunk/phase3/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php
2011-06-23 23:25:49 UTC (rev 90682)
@@ -0,0 +1,27 @@
+<?php
+class BitmapMetadataHandlerTest extends MediaWikiTestCase {
+ /**
+ * Test if having conflicting metadata values from different
+ * types of metadata, that the right one takes precedence.
+ *
+ * Basically the file has IPTC and XMP metadata, the
+ * IPTC should override the XMP, except for the multilingual
+ * translation (to en) where XMP should win.
+ */
+ public function testMultilingualCascade() {
+
+ $meta = BitmapMetadataHandler::Jpeg( dirname( __FILE__ ) .
+ '/Xmp-exif-multilingual_test.jpg' );
+
+ $expected = array(
+ 'x-default' => 'right(iptc)',
+ 'en' => 'right translation',
+ '_type' => 'lang'
+ );
+
+ $this->assertArrayHasKey( 'ImageDescription', $meta,
+ 'Did not extract any ImageDescription info?!' );
+
+ $this->assertEquals( $expected, $meta['ImageDescription'] );
+ }
+}
Property changes on:
trunk/phase3/tests/phpunit/includes/media/BitmapMetadataHandlerTest.php
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/phase3/tests/phpunit/includes/media/PNGMetadataExtractorTest.php
===================================================================
--- trunk/phase3/tests/phpunit/includes/media/PNGMetadataExtractorTest.php
(rev 0)
+++ trunk/phase3/tests/phpunit/includes/media/PNGMetadataExtractorTest.php
2011-06-23 23:25:49 UTC (rev 90682)
@@ -0,0 +1,138 @@
+<?php
+class PNGMetadataExtractorTest extends MediaWikiTestCase {
+ /**
+ * Tests zTXt tag (compressed textual metadata)
+ */
+ function testPNGNativetzTXt() {
+ $meta = PNGMetadataExtractor::getMetadata( dirname( __FILE__ ) .
+ '/Png-native-test.png' );
+ $expected = "foo bar baz foo foo foo foof foo foo foo foo";
+ $this->assertArrayHasKey( 'text', $meta );
+ $meta = $meta['text'];
+ $this->assertArrayHasKey( 'Make', $meta );
+ $this->assertArrayHasKey( 'x-default', $meta['Make'] );
+
+ $this->assertEquals( $expected, $meta['Make']['x-default'] );
+ }
+
+ /**
+ * Test tEXt tag (Uncompressed textual metadata)
+ */
+ function testPNGNativetEXt() {
+ $meta = PNGMetadataExtractor::getMetadata( dirname( __FILE__ ) .
+ '/Png-native-test.png' );
+ $expected = "Some long image desc";
+ $this->assertArrayHasKey( 'text', $meta );
+ $meta = $meta['text'];
+ $this->assertArrayHasKey( 'ImageDescription', $meta );
+ $this->assertArrayHasKey( 'x-default',
$meta['ImageDescription'] );
+ $this->assertArrayHasKey( '_type', $meta['ImageDescription'] );
+
+ $this->assertEquals( $expected,
$meta['ImageDescription']['x-default'] );
+ }
+
+ /**
+ * tEXt tags must be encoded iso-8859-1 (vs iTXt which are utf-8)
+ * Make sure non-ascii characters get converted properly
+ */
+ function testPNGNativettEXtNonASCII() {
+ $meta = PNGMetadataExtractor::getMetadata( dirname( __FILE__ ) .
+ '/Png-native-test.png' );
+
+ // Note the Copyright symbol here is a utf-8 one
+ // (aka \xC2\xA9) where in the file its iso-8859-1
+ // encoded as just \xA9.
+ $expected = "© 2010 Bawolff";
+
+
+ $this->assertArrayHasKey( 'text', $meta );
+ $meta = $meta['text'];
+ $this->assertArrayHasKey( 'Copyright', $meta );
+ $this->assertArrayHasKey( 'x-default', $meta['Copyright'] );
+
+ $this->assertEquals( $expected, $meta['Copyright']['x-default']
);
+ }
+
+ /**
+ * Test extraction of pHYs tags, which can tell what the
+ * actual resolution of the image is (aka in dots per meter).
+ function testPNGpHYsTag () {
+ $meta = PNGMetadataExtractor::getMetadata( dirname( __FILE__ ) .
+ '/Png-native-test.png' );
+
+ $this->assertArrayHasKey( 'text', $meta );
+ $meta = $meta['text'];
+
+ $this->assertEquals( '2835/100', $meta['XResolution'] );
+ $this->assertEquals( '2835/100', $meta['YResolution'] );
+ $this->assertEquals( 3, $meta['ResolutionUnit'] ); // 3 = cm
+ }
+
+ /**
+ * Given a normal static PNG, check the animation metadata returned.
+ */
+ function testStaticPNGAnimationMetadata() {
+ $meta = PNGMetadataExtractor::getMetadata( dirname( __FILE__ ) .
+ '/Png-native-test.png' );
+
+ $this->assertEquals( 0, $meta['frameCount'] );
+ $this->assertEquals( 1, $meta['loopCount'] );
+ $this->assertEquals( 0, $meta['duration'] );
+ }
+
+ /**
+ * Given an animated APNG image file
+ * check it gets animated metadata right.
+ */
+ function testAPNGAnimationMetadata() {
+ $meta = PNGMetadataExtractor::getMetadata( dirname( __FILE__ ) .
+ '/Animated_PNG_example_bouncing_beach_ball.png' );
+
+ $this->assertEquals( 20, $meta['frameCount'] );
+ // Note loop count of 0 = infinity
+ $this->assertEquals( 0, $meta['loopCount'] );
+ $this->assertEquals( 1.5, $meta['duration'], '', 0.00001 );
+ }
+
+ function testPNGBitDepth8() {
+ $meta = PNGMetadataExtractor::getMetadata( dirname( __FILE__ ) .
+ '/Png-native-test.png' );
+
+ $this->assertEquals( 8, $meta['bitDepth'] );
+ }
+ function testPNGBitDepth1() {
+ $meta = PNGMetadataExtractor::getMetadata( dirname( __FILE__ ) .
+ '/1bit-png.png' );
+ $this->assertEquals( 1, $meta['bitDepth'] );
+ }
+
+
+ function testPNGindexColour() {
+ $meta = PNGMetadataExtractor::getMetadata( dirname( __FILE__ ) .
+ '/Png-native-test.png' );
+
+ $this->assertEquals( 'index-coloured', $meta['colorType'] );
+ }
+ function testPNGrgbColour() {
+ $meta = PNGMetadataExtractor::getMetadata( dirname( __FILE__ ) .
+ '/rgb-png.png' );
+ $this->assertEquals( 'truecolour-alpha', $meta['colorType'] );
+ }
+ function testPNGrgbNoAlphaColour() {
+ $meta = PNGMetadataExtractor::getMetadata( dirname( __FILE__ ) .
+ '/rgb-na-png.png' );
+ $this->assertEquals( 'truecolour', $meta['colorType'] );
+ }
+ function testPNGgreyscaleColour() {
+ $meta = PNGMetadataExtractor::getMetadata( dirname( __FILE__ ) .
+ '/greyscale-png.png' );
+ $this->assertEquals( 'greyscale-alpha', $meta['colorType'] );
+ }
+ function testPNGgreyscaleNoAlphaColour() {
+ $meta = PNGMetadataExtractor::getMetadata( dirname( __FILE__ ) .
+ '/greyscale-na-png.png' );
+ $this->assertEquals( 'greyscale', $meta['colorType'] );
+ }
+
+
+}
Property changes on:
trunk/phase3/tests/phpunit/includes/media/PNGMetadataExtractorTest.php
___________________________________________________________________
Added: svn:eol-style
+ native
Added: trunk/phase3/tests/phpunit/includes/media/Png-native-test.png
===================================================================
(Binary files differ)
Property changes on:
trunk/phase3/tests/phpunit/includes/media/Png-native-test.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Modified: trunk/phase3/tests/phpunit/includes/media/README
===================================================================
--- trunk/phase3/tests/phpunit/includes/media/README 2011-06-23 22:19:56 UTC
(rev 90681)
+++ trunk/phase3/tests/phpunit/includes/media/README 2011-06-23 23:25:49 UTC
(rev 90682)
@@ -14,3 +14,15 @@
CC-BY 3.0
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
+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.
+
+Animated_PNG_example_bouncing_beach_ball.png
+http://commons.wikimedia.org/wiki/File:Animated_PNG_example_bouncing_beach_ball.png
(originally http://www.treebuilder.de/default.asp?file=89031.xml )
+Public Domain
+Holger Will
+
Added: trunk/phase3/tests/phpunit/includes/media/Xmp-exif-multilingual_test.jpg
===================================================================
(Binary files differ)
Property changes on:
trunk/phase3/tests/phpunit/includes/media/Xmp-exif-multilingual_test.jpg
___________________________________________________________________
Added: svn:mime-type
+ image/jpeg
Property changes on:
trunk/phase3/tests/phpunit/includes/media/broken_exif_date.jpg
___________________________________________________________________
Modified: svn:mime-type
- application/octet-stream
+ image/jpeg
Added: trunk/phase3/tests/phpunit/includes/media/greyscale-na-png.png
===================================================================
(Binary files differ)
Property changes on:
trunk/phase3/tests/phpunit/includes/media/greyscale-na-png.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/phase3/tests/phpunit/includes/media/greyscale-png.png
===================================================================
(Binary files differ)
Property changes on: trunk/phase3/tests/phpunit/includes/media/greyscale-png.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/phase3/tests/phpunit/includes/media/rgb-na-png.png
===================================================================
(Binary files differ)
Property changes on: trunk/phase3/tests/phpunit/includes/media/rgb-na-png.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
Added: trunk/phase3/tests/phpunit/includes/media/rgb-png.png
===================================================================
(Binary files differ)
Property changes on: trunk/phase3/tests/phpunit/includes/media/rgb-png.png
___________________________________________________________________
Added: svn:mime-type
+ image/png
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs