MediaWiki REL1_31
PNGMetadataExtractorTest.php
Go to the documentation of this file.
1<?php
2
8
9 protected function setUp() {
10 parent::setUp();
11 $this->filePath = __DIR__ . '/../../data/media/';
12 }
13
17 public function testPngNativetZtxt() {
18 $this->checkPHPExtension( 'zlib' );
19
20 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
21 'Png-native-test.png' );
22 $expected = "foo bar baz foo foo foo foof foo foo foo foo";
23 $this->assertArrayHasKey( 'text', $meta );
24 $meta = $meta['text'];
25 $this->assertArrayHasKey( 'Make', $meta );
26 $this->assertArrayHasKey( 'x-default', $meta['Make'] );
27
28 $this->assertEquals( $expected, $meta['Make']['x-default'] );
29 }
30
34 public function testPngNativeText() {
35 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
36 'Png-native-test.png' );
37 $expected = "Some long image desc";
38 $this->assertArrayHasKey( 'text', $meta );
39 $meta = $meta['text'];
40 $this->assertArrayHasKey( 'ImageDescription', $meta );
41 $this->assertArrayHasKey( 'x-default', $meta['ImageDescription'] );
42 $this->assertArrayHasKey( '_type', $meta['ImageDescription'] );
43
44 $this->assertEquals( $expected, $meta['ImageDescription']['x-default'] );
45 }
46
51 public function testPngNativeTextNonAscii() {
52 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
53 'Png-native-test.png' );
54
55 // Note the Copyright symbol here is a utf-8 one
56 // (aka \xC2\xA9) where in the file its iso-8859-1
57 // encoded as just \xA9.
58 $expected = "© 2010 Bawolff";
59
60 $this->assertArrayHasKey( 'text', $meta );
61 $meta = $meta['text'];
62 $this->assertArrayHasKey( 'Copyright', $meta );
63 $this->assertArrayHasKey( 'x-default', $meta['Copyright'] );
64
65 $this->assertEquals( $expected, $meta['Copyright']['x-default'] );
66 }
67
72 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
73 'Png-native-test.png' );
74
75 $this->assertEquals( 0, $meta['frameCount'] );
76 $this->assertEquals( 1, $meta['loopCount'] );
77 $this->assertEquals( 0, $meta['duration'] );
78 }
79
84 public function testApngAnimationMetadata() {
85 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
86 'Animated_PNG_example_bouncing_beach_ball.png' );
87
88 $this->assertEquals( 20, $meta['frameCount'] );
89 // Note loop count of 0 = infinity
90 $this->assertEquals( 0, $meta['loopCount'] );
91 $this->assertEquals( 1.5, $meta['duration'], '', 0.00001 );
92 }
93
94 public function testPngBitDepth8() {
95 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
96 'Png-native-test.png' );
97
98 $this->assertEquals( 8, $meta['bitDepth'] );
99 }
100
101 public function testPngBitDepth1() {
102 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
103 '1bit-png.png' );
104 $this->assertEquals( 1, $meta['bitDepth'] );
105 }
106
107 public function testPngIndexColour() {
108 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
109 'Png-native-test.png' );
110
111 $this->assertEquals( 'index-coloured', $meta['colorType'] );
112 }
113
114 public function testPngRgbColour() {
115 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
116 'rgb-png.png' );
117 $this->assertEquals( 'truecolour-alpha', $meta['colorType'] );
118 }
119
120 public function testPngRgbNoAlphaColour() {
121 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
122 'rgb-na-png.png' );
123 $this->assertEquals( 'truecolour', $meta['colorType'] );
124 }
125
126 public function testPngGreyscaleColour() {
127 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
128 'greyscale-png.png' );
129 $this->assertEquals( 'greyscale-alpha', $meta['colorType'] );
130 }
131
133 $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
134 'greyscale-na-png.png' );
135 $this->assertEquals( 'greyscale', $meta['colorType'] );
136 }
137}
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
Media PNGMetadataExtractor.
testPngNativetZtxt()
Tests zTXt tag (compressed textual metadata)
testPngNativeText()
Test tEXt tag (Uncompressed textual metadata)
testPngNativeTextNonAscii()
tEXt tags must be encoded iso-8859-1 (vs iTXt which are utf-8) Make sure non-ascii characters get con...
testStaticPngAnimationMetadata()
Given a normal static PNG, check the animation metadata returned.
testApngAnimationMetadata()
Given an animated APNG image file check it gets animated metadata right.
static getMetadata( $filename)