MediaWiki  REL1_24
PNGMetadataExtractorTest.php
Go to the documentation of this file.
00001 <?php
00002 
00007 class PNGMetadataExtractorTest extends MediaWikiTestCase {
00008 
00009     protected function setUp() {
00010         parent::setUp();
00011         $this->filePath = __DIR__ . '/../../data/media/';
00012     }
00013 
00017     public function testPngNativetZtxt() {
00018         $this->checkPHPExtension( 'zlib' );
00019 
00020         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00021             'Png-native-test.png' );
00022         $expected = "foo bar baz foo foo foo foof foo foo foo foo";
00023         $this->assertArrayHasKey( 'text', $meta );
00024         $meta = $meta['text'];
00025         $this->assertArrayHasKey( 'Make', $meta );
00026         $this->assertArrayHasKey( 'x-default', $meta['Make'] );
00027 
00028         $this->assertEquals( $expected, $meta['Make']['x-default'] );
00029     }
00030 
00034     public function testPngNativeText() {
00035         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00036             'Png-native-test.png' );
00037         $expected = "Some long image desc";
00038         $this->assertArrayHasKey( 'text', $meta );
00039         $meta = $meta['text'];
00040         $this->assertArrayHasKey( 'ImageDescription', $meta );
00041         $this->assertArrayHasKey( 'x-default', $meta['ImageDescription'] );
00042         $this->assertArrayHasKey( '_type', $meta['ImageDescription'] );
00043 
00044         $this->assertEquals( $expected, $meta['ImageDescription']['x-default'] );
00045     }
00046 
00051     public function testPngNativeTextNonAscii() {
00052         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00053             'Png-native-test.png' );
00054 
00055         // Note the Copyright symbol here is a utf-8 one
00056         // (aka \xC2\xA9) where in the file its iso-8859-1
00057         // encoded as just \xA9.
00058         $expected = "© 2010 Bawolff";
00059 
00060         $this->assertArrayHasKey( 'text', $meta );
00061         $meta = $meta['text'];
00062         $this->assertArrayHasKey( 'Copyright', $meta );
00063         $this->assertArrayHasKey( 'x-default', $meta['Copyright'] );
00064 
00065         $this->assertEquals( $expected, $meta['Copyright']['x-default'] );
00066     }
00067 
00072     /*
00073     public function testPngPhysTag() {
00074         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00075             'Png-native-test.png' );
00076 
00077         $this->assertArrayHasKey( 'text', $meta );
00078         $meta = $meta['text'];
00079 
00080         $this->assertEquals( '2835/100', $meta['XResolution'] );
00081         $this->assertEquals( '2835/100', $meta['YResolution'] );
00082         $this->assertEquals( 3, $meta['ResolutionUnit'] ); // 3 = cm
00083     }
00084     */
00085 
00089     public function testStaticPngAnimationMetadata() {
00090         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00091             'Png-native-test.png' );
00092 
00093         $this->assertEquals( 0, $meta['frameCount'] );
00094         $this->assertEquals( 1, $meta['loopCount'] );
00095         $this->assertEquals( 0, $meta['duration'] );
00096     }
00097 
00102     public function testApngAnimationMetadata() {
00103         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00104             'Animated_PNG_example_bouncing_beach_ball.png' );
00105 
00106         $this->assertEquals( 20, $meta['frameCount'] );
00107         // Note loop count of 0 = infinity
00108         $this->assertEquals( 0, $meta['loopCount'] );
00109         $this->assertEquals( 1.5, $meta['duration'], '', 0.00001 );
00110     }
00111 
00112     public function testPngBitDepth8() {
00113         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00114             'Png-native-test.png' );
00115 
00116         $this->assertEquals( 8, $meta['bitDepth'] );
00117     }
00118 
00119     public function testPngBitDepth1() {
00120         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00121             '1bit-png.png' );
00122         $this->assertEquals( 1, $meta['bitDepth'] );
00123     }
00124 
00125     public function testPngIndexColour() {
00126         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00127             'Png-native-test.png' );
00128 
00129         $this->assertEquals( 'index-coloured', $meta['colorType'] );
00130     }
00131 
00132     public function testPngRgbColour() {
00133         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00134             'rgb-png.png' );
00135         $this->assertEquals( 'truecolour-alpha', $meta['colorType'] );
00136     }
00137 
00138     public function testPngRgbNoAlphaColour() {
00139         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00140             'rgb-na-png.png' );
00141         $this->assertEquals( 'truecolour', $meta['colorType'] );
00142     }
00143 
00144     public function testPngGreyscaleColour() {
00145         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00146             'greyscale-png.png' );
00147         $this->assertEquals( 'greyscale-alpha', $meta['colorType'] );
00148     }
00149 
00150     public function testPngGreyscaleNoAlphaColour() {
00151         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00152             'greyscale-na-png.png' );
00153         $this->assertEquals( 'greyscale', $meta['colorType'] );
00154     }
00155 }