Fixed dependencies for jquery.collapsibleTabs
[lhc/web/wiklou.git] / tests / phpunit / includes / media / PNGMetadataExtractorTest.php
1 <?php
2 class PNGMetadataExtractorTest extends MediaWikiTestCase {
3
4 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 function testPngPhysTag () {
64 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
65 'Png-native-test.png' );
66
67 $this->assertArrayHasKey( 'text', $meta );
68 $meta = $meta['text'];
69
70 $this->assertEquals( '2835/100', $meta['XResolution'] );
71 $this->assertEquals( '2835/100', $meta['YResolution'] );
72 $this->assertEquals( 3, $meta['ResolutionUnit'] ); // 3 = cm
73 }
74
75 /**
76 * Given a normal static PNG, check the animation metadata returned.
77 */
78 function testStaticPngAnimationMetadata() {
79 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
80 'Png-native-test.png' );
81
82 $this->assertEquals( 0, $meta['frameCount'] );
83 $this->assertEquals( 1, $meta['loopCount'] );
84 $this->assertEquals( 0, $meta['duration'] );
85 }
86
87 /**
88 * Given an animated APNG image file
89 * check it gets animated metadata right.
90 */
91 function testApngAnimationMetadata() {
92 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
93 'Animated_PNG_example_bouncing_beach_ball.png' );
94
95 $this->assertEquals( 20, $meta['frameCount'] );
96 // Note loop count of 0 = infinity
97 $this->assertEquals( 0, $meta['loopCount'] );
98 $this->assertEquals( 1.5, $meta['duration'], '', 0.00001 );
99 }
100
101 function testPngBitDepth8() {
102 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
103 'Png-native-test.png' );
104
105 $this->assertEquals( 8, $meta['bitDepth'] );
106 }
107 function testPngBitDepth1() {
108 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
109 '1bit-png.png' );
110 $this->assertEquals( 1, $meta['bitDepth'] );
111 }
112
113
114 function testPngIndexColour() {
115 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
116 'Png-native-test.png' );
117
118 $this->assertEquals( 'index-coloured', $meta['colorType'] );
119 }
120 function testPngRgbColour() {
121 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
122 'rgb-png.png' );
123 $this->assertEquals( 'truecolour-alpha', $meta['colorType'] );
124 }
125 function testPngRgbNoAlphaColour() {
126 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
127 'rgb-na-png.png' );
128 $this->assertEquals( 'truecolour', $meta['colorType'] );
129 }
130 function testPngGreyscaleColour() {
131 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
132 'greyscale-png.png' );
133 $this->assertEquals( 'greyscale-alpha', $meta['colorType'] );
134 }
135 function testPngGreyscaleNoAlphaColour() {
136 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
137 'greyscale-na-png.png' );
138 $this->assertEquals( 'greyscale', $meta['colorType'] );
139 }
140
141 }