MediaWiki  REL1_22
PNGMetadataExtractorTest.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class PNGMetadataExtractorTest extends MediaWikiTestCase {
00007 
00008     protected function setUp() {
00009         parent::setUp();
00010         $this->filePath = __DIR__ . '/../../data/media/';
00011     }
00012 
00016     public function testPngNativetZtxt() {
00017         $this->checkPHPExtension( 'zlib' );
00018 
00019         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00020             'Png-native-test.png' );
00021         $expected = "foo bar baz foo foo foo foof foo foo foo foo";
00022         $this->assertArrayHasKey( 'text', $meta );
00023         $meta = $meta['text'];
00024         $this->assertArrayHasKey( 'Make', $meta );
00025         $this->assertArrayHasKey( 'x-default', $meta['Make'] );
00026 
00027         $this->assertEquals( $expected, $meta['Make']['x-default'] );
00028     }
00029 
00033     public function testPngNativeText() {
00034         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00035             'Png-native-test.png' );
00036         $expected = "Some long image desc";
00037         $this->assertArrayHasKey( 'text', $meta );
00038         $meta = $meta['text'];
00039         $this->assertArrayHasKey( 'ImageDescription', $meta );
00040         $this->assertArrayHasKey( 'x-default', $meta['ImageDescription'] );
00041         $this->assertArrayHasKey( '_type', $meta['ImageDescription'] );
00042 
00043         $this->assertEquals( $expected, $meta['ImageDescription']['x-default'] );
00044     }
00045 
00050     public function testPngNativeTextNonAscii() {
00051         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00052             'Png-native-test.png' );
00053 
00054         // Note the Copyright symbol here is a utf-8 one
00055         // (aka \xC2\xA9) where in the file its iso-8859-1
00056         // encoded as just \xA9.
00057         $expected = "© 2010 Bawolff";
00058 
00059         $this->assertArrayHasKey( 'text', $meta );
00060         $meta = $meta['text'];
00061         $this->assertArrayHasKey( 'Copyright', $meta );
00062         $this->assertArrayHasKey( 'x-default', $meta['Copyright'] );
00063 
00064         $this->assertEquals( $expected, $meta['Copyright']['x-default'] );
00065     }
00066 
00071     /*
00072     public function testPngPhysTag() {
00073         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00074             'Png-native-test.png' );
00075 
00076         $this->assertArrayHasKey( 'text', $meta );
00077         $meta = $meta['text'];
00078 
00079         $this->assertEquals( '2835/100', $meta['XResolution'] );
00080         $this->assertEquals( '2835/100', $meta['YResolution'] );
00081         $this->assertEquals( 3, $meta['ResolutionUnit'] ); // 3 = cm
00082     }
00083     */
00084 
00088     public function testStaticPngAnimationMetadata() {
00089         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00090             'Png-native-test.png' );
00091 
00092         $this->assertEquals( 0, $meta['frameCount'] );
00093         $this->assertEquals( 1, $meta['loopCount'] );
00094         $this->assertEquals( 0, $meta['duration'] );
00095     }
00096 
00101     public function testApngAnimationMetadata() {
00102         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00103             'Animated_PNG_example_bouncing_beach_ball.png' );
00104 
00105         $this->assertEquals( 20, $meta['frameCount'] );
00106         // Note loop count of 0 = infinity
00107         $this->assertEquals( 0, $meta['loopCount'] );
00108         $this->assertEquals( 1.5, $meta['duration'], '', 0.00001 );
00109     }
00110 
00111     public function testPngBitDepth8() {
00112         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00113             'Png-native-test.png' );
00114 
00115         $this->assertEquals( 8, $meta['bitDepth'] );
00116     }
00117 
00118     public function testPngBitDepth1() {
00119         $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
00120             '1bit-png.png' );
00121         $this->assertEquals( 1, $meta['bitDepth'] );
00122     }
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 }