MediaWiki  REL1_21
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         }
00008 
00012         function testPngNativetZtxt() {
00013                 $this->checkPHPExtension( 'zlib' );
00014 
00015                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00016                         'Png-native-test.png' );
00017                 $expected = "foo bar baz foo foo foo foof foo foo foo foo";
00018                 $this->assertArrayHasKey( 'text', $meta );
00019                 $meta = $meta['text'];
00020                 $this->assertArrayHasKey( 'Make', $meta );
00021                 $this->assertArrayHasKey( 'x-default', $meta['Make'] );
00022 
00023                 $this->assertEquals( $expected, $meta['Make']['x-default'] );
00024         }
00025 
00029         function testPngNativeText() {
00030                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00031                         'Png-native-test.png' );
00032                 $expected = "Some long image desc";
00033                 $this->assertArrayHasKey( 'text', $meta );
00034                 $meta = $meta['text'];
00035                 $this->assertArrayHasKey( 'ImageDescription', $meta );
00036                 $this->assertArrayHasKey( 'x-default', $meta['ImageDescription'] );
00037                 $this->assertArrayHasKey( '_type', $meta['ImageDescription'] );
00038 
00039                 $this->assertEquals( $expected, $meta['ImageDescription']['x-default'] );
00040         }
00041 
00046         function testPngNativeTextNonAscii() {
00047                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00048                         'Png-native-test.png' );
00049 
00050                 // Note the Copyright symbol here is a utf-8 one
00051                 // (aka \xC2\xA9) where in the file its iso-8859-1
00052                 // encoded as just \xA9.
00053                 $expected = "© 2010 Bawolff";
00054 
00055 
00056                 $this->assertArrayHasKey( 'text', $meta );
00057                 $meta = $meta['text'];
00058                 $this->assertArrayHasKey( 'Copyright', $meta );
00059                 $this->assertArrayHasKey( 'x-default', $meta['Copyright'] );
00060 
00061                 $this->assertEquals( $expected, $meta['Copyright']['x-default'] );
00062         }
00063 
00068         /*
00069         function testPngPhysTag () {
00070                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00071                         'Png-native-test.png' );
00072 
00073                 $this->assertArrayHasKey( 'text', $meta );
00074                 $meta = $meta['text'];
00075 
00076                 $this->assertEquals( '2835/100', $meta['XResolution'] );
00077                 $this->assertEquals( '2835/100', $meta['YResolution'] );
00078                 $this->assertEquals( 3, $meta['ResolutionUnit'] ); // 3 = cm
00079         }
00080         */
00081 
00085         function testStaticPngAnimationMetadata() {
00086                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00087                         'Png-native-test.png' );
00088 
00089                 $this->assertEquals( 0, $meta['frameCount'] );
00090                 $this->assertEquals( 1, $meta['loopCount'] );
00091                 $this->assertEquals( 0, $meta['duration'] );
00092         }
00093 
00098         function testApngAnimationMetadata() {
00099                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00100                         'Animated_PNG_example_bouncing_beach_ball.png' );
00101 
00102                 $this->assertEquals( 20, $meta['frameCount'] );
00103                 // Note loop count of 0 = infinity
00104                 $this->assertEquals( 0, $meta['loopCount'] );
00105                 $this->assertEquals( 1.5, $meta['duration'], '', 0.00001 );
00106         }
00107 
00108         function testPngBitDepth8() {
00109                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00110                         'Png-native-test.png' );
00111 
00112                 $this->assertEquals( 8, $meta['bitDepth'] );
00113         }
00114 
00115         function testPngBitDepth1() {
00116                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00117                         '1bit-png.png' );
00118                 $this->assertEquals( 1, $meta['bitDepth'] );
00119         }
00120 
00121 
00122         function testPngIndexColour() {
00123                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00124                         'Png-native-test.png' );
00125 
00126                 $this->assertEquals( 'index-coloured', $meta['colorType'] );
00127         }
00128 
00129         function testPngRgbColour() {
00130                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00131                         'rgb-png.png' );
00132                 $this->assertEquals( 'truecolour-alpha', $meta['colorType'] );
00133         }
00134 
00135         function testPngRgbNoAlphaColour() {
00136                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00137                         'rgb-na-png.png' );
00138                 $this->assertEquals( 'truecolour', $meta['colorType'] );
00139         }
00140 
00141         function testPngGreyscaleColour() {
00142                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00143                         'greyscale-png.png' );
00144                 $this->assertEquals( 'greyscale-alpha', $meta['colorType'] );
00145         }
00146 
00147         function testPngGreyscaleNoAlphaColour() {
00148                 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00149                         'greyscale-na-png.png' );
00150                 $this->assertEquals( 'greyscale', $meta['colorType'] );
00151         }
00152 
00153 }