MediaWiki  master
PNGMetadataExtractorTest.php
Go to the documentation of this file.
00001 <?php
00002 class PNGMetadataExtractorTest extends MediaWikiTestCase {
00003 
00004         protected function setUp() {
00005                 parent::setUp();
00006                 $this->filePath = __DIR__ . '/../../data/media/';
00007         }
00011         function testPngNativetZtxt() {
00012                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00013                         'Png-native-test.png' );
00014                 $expected = "foo bar baz foo foo foo foof foo foo foo foo";
00015                 $this->assertArrayHasKey( 'text', $meta );
00016                 $meta = $meta['text'];
00017                 $this->assertArrayHasKey( 'Make', $meta );
00018                 $this->assertArrayHasKey( 'x-default', $meta['Make'] );
00019 
00020                 $this->assertEquals( $expected, $meta['Make']['x-default'] );
00021         }
00022 
00026         function testPngNativeText() {
00027                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00028                         'Png-native-test.png' );
00029                 $expected = "Some long image desc";
00030                 $this->assertArrayHasKey( 'text', $meta );
00031                 $meta = $meta['text'];
00032                 $this->assertArrayHasKey( 'ImageDescription', $meta );
00033                 $this->assertArrayHasKey( 'x-default', $meta['ImageDescription'] );
00034                 $this->assertArrayHasKey( '_type', $meta['ImageDescription'] );
00035 
00036                 $this->assertEquals( $expected, $meta['ImageDescription']['x-default'] );
00037         }
00038 
00043         function testPngNativeTextNonAscii() {
00044                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00045                         'Png-native-test.png' );
00046 
00047                 // Note the Copyright symbol here is a utf-8 one
00048                 // (aka \xC2\xA9) where in the file its iso-8859-1
00049                 // encoded as just \xA9.
00050                 $expected = "© 2010 Bawolff";
00051 
00052 
00053                 $this->assertArrayHasKey( 'text', $meta );
00054                 $meta = $meta['text'];
00055                 $this->assertArrayHasKey( 'Copyright', $meta );
00056                 $this->assertArrayHasKey( 'x-default', $meta['Copyright'] );
00057 
00058                 $this->assertEquals( $expected, $meta['Copyright']['x-default'] );
00059         }
00060 
00065 /*
00066         function testPngPhysTag () {
00067                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00068                         'Png-native-test.png' );
00069 
00070                 $this->assertArrayHasKey( 'text', $meta );
00071                 $meta = $meta['text'];
00072 
00073                 $this->assertEquals( '2835/100', $meta['XResolution'] );
00074                 $this->assertEquals( '2835/100', $meta['YResolution'] );
00075                 $this->assertEquals( 3, $meta['ResolutionUnit'] ); // 3 = cm
00076         }
00077 */
00078 
00082         function testStaticPngAnimationMetadata() {
00083                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00084                         'Png-native-test.png' );
00085 
00086                 $this->assertEquals( 0, $meta['frameCount'] );
00087                 $this->assertEquals( 1, $meta['loopCount'] );
00088                 $this->assertEquals( 0, $meta['duration'] );
00089         }
00090 
00095         function testApngAnimationMetadata() {
00096                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00097                         'Animated_PNG_example_bouncing_beach_ball.png' );
00098 
00099                 $this->assertEquals( 20, $meta['frameCount'] );
00100                 // Note loop count of 0 = infinity
00101                 $this->assertEquals( 0, $meta['loopCount'] );
00102                 $this->assertEquals( 1.5, $meta['duration'], '', 0.00001 );
00103         }
00104 
00105         function testPngBitDepth8() {
00106                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00107                         'Png-native-test.png' );
00108 
00109                 $this->assertEquals( 8, $meta['bitDepth'] );
00110         }
00111         function testPngBitDepth1() {
00112                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00113                         '1bit-png.png' );
00114                 $this->assertEquals( 1, $meta['bitDepth'] );
00115         }
00116 
00117 
00118         function testPngIndexColour() {
00119                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00120                         'Png-native-test.png' );
00121 
00122                 $this->assertEquals( 'index-coloured', $meta['colorType'] );
00123         }
00124         function testPngRgbColour() {
00125                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00126                         'rgb-png.png' );
00127                 $this->assertEquals( 'truecolour-alpha', $meta['colorType'] );
00128         }
00129         function testPngRgbNoAlphaColour() {
00130                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00131                         'rgb-na-png.png' );
00132                 $this->assertEquals( 'truecolour', $meta['colorType'] );
00133         }
00134         function testPngGreyscaleColour() {
00135                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00136                         'greyscale-png.png' );
00137                 $this->assertEquals( 'greyscale-alpha', $meta['colorType'] );
00138         }
00139         function testPngGreyscaleNoAlphaColour() {
00140                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00141                         'greyscale-na-png.png' );
00142                 $this->assertEquals( 'greyscale', $meta['colorType'] );
00143         }
00144 
00145 }