Merge "CologneBlue rewrite: fix talkLink() to use generic nav links"
[lhc/web/wiklou.git] / tests / phpunit / includes / media / PNGMetadataExtractorTest.php
1 <?php
2 class PNGMetadataExtractorTest extends MediaWikiTestCase {
3
4 protected function setUp() {
5 $this->filePath = __DIR__ . '/../../data/media/';
6 }
7 /**
8 * Tests zTXt tag (compressed textual metadata)
9 */
10 function testPngNativetZtxt() {
11 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
12 'Png-native-test.png' );
13 $expected = "foo bar baz foo foo foo foof foo foo foo foo";
14 $this->assertArrayHasKey( 'text', $meta );
15 $meta = $meta['text'];
16 $this->assertArrayHasKey( 'Make', $meta );
17 $this->assertArrayHasKey( 'x-default', $meta['Make'] );
18
19 $this->assertEquals( $expected, $meta['Make']['x-default'] );
20 }
21
22 /**
23 * Test tEXt tag (Uncompressed textual metadata)
24 */
25 function testPngNativeText() {
26 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
27 'Png-native-test.png' );
28 $expected = "Some long image desc";
29 $this->assertArrayHasKey( 'text', $meta );
30 $meta = $meta['text'];
31 $this->assertArrayHasKey( 'ImageDescription', $meta );
32 $this->assertArrayHasKey( 'x-default', $meta['ImageDescription'] );
33 $this->assertArrayHasKey( '_type', $meta['ImageDescription'] );
34
35 $this->assertEquals( $expected, $meta['ImageDescription']['x-default'] );
36 }
37
38 /**
39 * tEXt tags must be encoded iso-8859-1 (vs iTXt which are utf-8)
40 * Make sure non-ascii characters get converted properly
41 */
42 function testPngNativeTextNonAscii() {
43 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
44 'Png-native-test.png' );
45
46 // Note the Copyright symbol here is a utf-8 one
47 // (aka \xC2\xA9) where in the file its iso-8859-1
48 // encoded as just \xA9.
49 $expected = "© 2010 Bawolff";
50
51
52 $this->assertArrayHasKey( 'text', $meta );
53 $meta = $meta['text'];
54 $this->assertArrayHasKey( 'Copyright', $meta );
55 $this->assertArrayHasKey( 'x-default', $meta['Copyright'] );
56
57 $this->assertEquals( $expected, $meta['Copyright']['x-default'] );
58 }
59
60 /**
61 * Test extraction of pHYs tags, which can tell what the
62 * actual resolution of the image is (aka in dots per meter).
63 */
64 /*
65 function testPngPhysTag () {
66 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
67 'Png-native-test.png' );
68
69 $this->assertArrayHasKey( 'text', $meta );
70 $meta = $meta['text'];
71
72 $this->assertEquals( '2835/100', $meta['XResolution'] );
73 $this->assertEquals( '2835/100', $meta['YResolution'] );
74 $this->assertEquals( 3, $meta['ResolutionUnit'] ); // 3 = cm
75 }
76 */
77
78 /**
79 * Given a normal static PNG, check the animation metadata returned.
80 */
81 function testStaticPngAnimationMetadata() {
82 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
83 'Png-native-test.png' );
84
85 $this->assertEquals( 0, $meta['frameCount'] );
86 $this->assertEquals( 1, $meta['loopCount'] );
87 $this->assertEquals( 0, $meta['duration'] );
88 }
89
90 /**
91 * Given an animated APNG image file
92 * check it gets animated metadata right.
93 */
94 function testApngAnimationMetadata() {
95 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
96 'Animated_PNG_example_bouncing_beach_ball.png' );
97
98 $this->assertEquals( 20, $meta['frameCount'] );
99 // Note loop count of 0 = infinity
100 $this->assertEquals( 0, $meta['loopCount'] );
101 $this->assertEquals( 1.5, $meta['duration'], '', 0.00001 );
102 }
103
104 function testPngBitDepth8() {
105 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
106 'Png-native-test.png' );
107
108 $this->assertEquals( 8, $meta['bitDepth'] );
109 }
110 function testPngBitDepth1() {
111 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
112 '1bit-png.png' );
113 $this->assertEquals( 1, $meta['bitDepth'] );
114 }
115
116
117 function testPngIndexColour() {
118 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
119 'Png-native-test.png' );
120
121 $this->assertEquals( 'index-coloured', $meta['colorType'] );
122 }
123 function testPngRgbColour() {
124 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
125 'rgb-png.png' );
126 $this->assertEquals( 'truecolour-alpha', $meta['colorType'] );
127 }
128 function testPngRgbNoAlphaColour() {
129 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
130 'rgb-na-png.png' );
131 $this->assertEquals( 'truecolour', $meta['colorType'] );
132 }
133 function testPngGreyscaleColour() {
134 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
135 'greyscale-png.png' );
136 $this->assertEquals( 'greyscale-alpha', $meta['colorType'] );
137 }
138 function testPngGreyscaleNoAlphaColour() {
139 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
140 'greyscale-na-png.png' );
141 $this->assertEquals( 'greyscale', $meta['colorType'] );
142 }
143
144 }