test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / media / PNGMetadataExtractorTest.php
blob58d791fdfe5d92d9fad2673af5b2448777d0026c
1 <?php
2 class PNGMetadataExtractorTest extends MediaWikiTestCase {
4 protected function setUp() {
5 parent::setUp();
6 $this->filePath = __DIR__ . '/../../data/media/';
9 /**
10 * Tests zTXt tag (compressed textual metadata)
12 function testPngNativetZtxt() {
13 $this->checkPHPExtension( 'zlib' );
15 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
16 'Png-native-test.png' );
17 $expected = "foo bar baz foo foo foo foof foo foo foo foo";
18 $this->assertArrayHasKey( 'text', $meta );
19 $meta = $meta['text'];
20 $this->assertArrayHasKey( 'Make', $meta );
21 $this->assertArrayHasKey( 'x-default', $meta['Make'] );
23 $this->assertEquals( $expected, $meta['Make']['x-default'] );
26 /**
27 * Test tEXt tag (Uncompressed textual metadata)
29 function testPngNativeText() {
30 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
31 'Png-native-test.png' );
32 $expected = "Some long image desc";
33 $this->assertArrayHasKey( 'text', $meta );
34 $meta = $meta['text'];
35 $this->assertArrayHasKey( 'ImageDescription', $meta );
36 $this->assertArrayHasKey( 'x-default', $meta['ImageDescription'] );
37 $this->assertArrayHasKey( '_type', $meta['ImageDescription'] );
39 $this->assertEquals( $expected, $meta['ImageDescription']['x-default'] );
42 /**
43 * tEXt tags must be encoded iso-8859-1 (vs iTXt which are utf-8)
44 * Make sure non-ascii characters get converted properly
46 function testPngNativeTextNonAscii() {
47 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
48 'Png-native-test.png' );
50 // Note the Copyright symbol here is a utf-8 one
51 // (aka \xC2\xA9) where in the file its iso-8859-1
52 // encoded as just \xA9.
53 $expected = "© 2010 Bawolff";
55 $this->assertArrayHasKey( 'text', $meta );
56 $meta = $meta['text'];
57 $this->assertArrayHasKey( 'Copyright', $meta );
58 $this->assertArrayHasKey( 'x-default', $meta['Copyright'] );
60 $this->assertEquals( $expected, $meta['Copyright']['x-default'] );
63 /**
64 * Test extraction of pHYs tags, which can tell what the
65 * actual resolution of the image is (aka in dots per meter).
68 function testPngPhysTag() {
69 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
70 'Png-native-test.png' );
72 $this->assertArrayHasKey( 'text', $meta );
73 $meta = $meta['text'];
75 $this->assertEquals( '2835/100', $meta['XResolution'] );
76 $this->assertEquals( '2835/100', $meta['YResolution'] );
77 $this->assertEquals( 3, $meta['ResolutionUnit'] ); // 3 = cm
81 /**
82 * Given a normal static PNG, check the animation metadata returned.
84 function testStaticPngAnimationMetadata() {
85 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
86 'Png-native-test.png' );
88 $this->assertEquals( 0, $meta['frameCount'] );
89 $this->assertEquals( 1, $meta['loopCount'] );
90 $this->assertEquals( 0, $meta['duration'] );
93 /**
94 * Given an animated APNG image file
95 * check it gets animated metadata right.
97 function testApngAnimationMetadata() {
98 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
99 'Animated_PNG_example_bouncing_beach_ball.png' );
101 $this->assertEquals( 20, $meta['frameCount'] );
102 // Note loop count of 0 = infinity
103 $this->assertEquals( 0, $meta['loopCount'] );
104 $this->assertEquals( 1.5, $meta['duration'], '', 0.00001 );
107 function testPngBitDepth8() {
108 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
109 'Png-native-test.png' );
111 $this->assertEquals( 8, $meta['bitDepth'] );
114 function testPngBitDepth1() {
115 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
116 '1bit-png.png' );
117 $this->assertEquals( 1, $meta['bitDepth'] );
121 function testPngIndexColour() {
122 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
123 'Png-native-test.png' );
125 $this->assertEquals( 'index-coloured', $meta['colorType'] );
128 function testPngRgbColour() {
129 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
130 'rgb-png.png' );
131 $this->assertEquals( 'truecolour-alpha', $meta['colorType'] );
134 function testPngRgbNoAlphaColour() {
135 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
136 'rgb-na-png.png' );
137 $this->assertEquals( 'truecolour', $meta['colorType'] );
140 function testPngGreyscaleColour() {
141 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
142 'greyscale-png.png' );
143 $this->assertEquals( 'greyscale-alpha', $meta['colorType'] );
146 function testPngGreyscaleNoAlphaColour() {
147 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
148 'greyscale-na-png.png' );
149 $this->assertEquals( 'greyscale', $meta['colorType'] );