MediaWiki  1.23.2
PNGMetadataExtractorTest.php
Go to the documentation of this file.
1 <?php
2 
7 
8  protected function setUp() {
9  parent::setUp();
10  $this->filePath = __DIR__ . '/../../data/media/';
11  }
12 
16  public function testPngNativetZtxt() {
17  $this->checkPHPExtension( 'zlib' );
18 
19  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
20  'Png-native-test.png' );
21  $expected = "foo bar baz foo foo foo foof foo foo foo foo";
22  $this->assertArrayHasKey( 'text', $meta );
23  $meta = $meta['text'];
24  $this->assertArrayHasKey( 'Make', $meta );
25  $this->assertArrayHasKey( 'x-default', $meta['Make'] );
26 
27  $this->assertEquals( $expected, $meta['Make']['x-default'] );
28  }
29 
33  public function testPngNativeText() {
34  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
35  'Png-native-test.png' );
36  $expected = "Some long image desc";
37  $this->assertArrayHasKey( 'text', $meta );
38  $meta = $meta['text'];
39  $this->assertArrayHasKey( 'ImageDescription', $meta );
40  $this->assertArrayHasKey( 'x-default', $meta['ImageDescription'] );
41  $this->assertArrayHasKey( '_type', $meta['ImageDescription'] );
42 
43  $this->assertEquals( $expected, $meta['ImageDescription']['x-default'] );
44  }
45 
50  public function testPngNativeTextNonAscii() {
51  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
52  'Png-native-test.png' );
53 
54  // Note the Copyright symbol here is a utf-8 one
55  // (aka \xC2\xA9) where in the file its iso-8859-1
56  // encoded as just \xA9.
57  $expected = "© 2010 Bawolff";
58 
59  $this->assertArrayHasKey( 'text', $meta );
60  $meta = $meta['text'];
61  $this->assertArrayHasKey( 'Copyright', $meta );
62  $this->assertArrayHasKey( 'x-default', $meta['Copyright'] );
63 
64  $this->assertEquals( $expected, $meta['Copyright']['x-default'] );
65  }
66 
71  /*
72  public function testPngPhysTag() {
73  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
74  'Png-native-test.png' );
75 
76  $this->assertArrayHasKey( 'text', $meta );
77  $meta = $meta['text'];
78 
79  $this->assertEquals( '2835/100', $meta['XResolution'] );
80  $this->assertEquals( '2835/100', $meta['YResolution'] );
81  $this->assertEquals( 3, $meta['ResolutionUnit'] ); // 3 = cm
82  }
83  */
84 
88  public function testStaticPngAnimationMetadata() {
89  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
90  'Png-native-test.png' );
91 
92  $this->assertEquals( 0, $meta['frameCount'] );
93  $this->assertEquals( 1, $meta['loopCount'] );
94  $this->assertEquals( 0, $meta['duration'] );
95  }
96 
101  public function testApngAnimationMetadata() {
102  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
103  'Animated_PNG_example_bouncing_beach_ball.png' );
104 
105  $this->assertEquals( 20, $meta['frameCount'] );
106  // Note loop count of 0 = infinity
107  $this->assertEquals( 0, $meta['loopCount'] );
108  $this->assertEquals( 1.5, $meta['duration'], '', 0.00001 );
109  }
110 
111  public function testPngBitDepth8() {
112  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
113  'Png-native-test.png' );
114 
115  $this->assertEquals( 8, $meta['bitDepth'] );
116  }
117 
118  public function testPngBitDepth1() {
119  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
120  '1bit-png.png' );
121  $this->assertEquals( 1, $meta['bitDepth'] );
122  }
123 
124  public function testPngIndexColour() {
125  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
126  'Png-native-test.png' );
127 
128  $this->assertEquals( 'index-coloured', $meta['colorType'] );
129  }
130 
131  public function testPngRgbColour() {
132  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
133  'rgb-png.png' );
134  $this->assertEquals( 'truecolour-alpha', $meta['colorType'] );
135  }
136 
137  public function testPngRgbNoAlphaColour() {
138  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
139  'rgb-na-png.png' );
140  $this->assertEquals( 'truecolour', $meta['colorType'] );
141  }
142 
143  public function testPngGreyscaleColour() {
144  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
145  'greyscale-png.png' );
146  $this->assertEquals( 'greyscale-alpha', $meta['colorType'] );
147  }
148 
149  public function testPngGreyscaleNoAlphaColour() {
150  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
151  'greyscale-na-png.png' );
152  $this->assertEquals( 'greyscale', $meta['colorType'] );
153  }
154 }
PNGMetadataExtractorTest\testPngNativetZtxt
testPngNativetZtxt()
Tests zTXt tag (compressed textual metadata)
Definition: PNGMetadataExtractorTest.php:16
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
PNGMetadataExtractorTest\testApngAnimationMetadata
testApngAnimationMetadata()
Given an animated APNG image file check it gets animated metadata right.
Definition: PNGMetadataExtractorTest.php:101
PNGMetadataExtractorTest\testPngRgbNoAlphaColour
testPngRgbNoAlphaColour()
Definition: PNGMetadataExtractorTest.php:137
PNGMetadataExtractorTest\testPngGreyscaleColour
testPngGreyscaleColour()
Definition: PNGMetadataExtractorTest.php:143
PNGMetadataExtractorTest
@covers PNGMetadataExtractor
Definition: PNGMetadataExtractorTest.php:6
PNGMetadataExtractorTest\testStaticPngAnimationMetadata
testStaticPngAnimationMetadata()
Test extraction of pHYs tags, which can tell what the actual resolution of the image is (aka in dots ...
Definition: PNGMetadataExtractorTest.php:88
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
PNGMetadataExtractorTest\testPngRgbColour
testPngRgbColour()
Definition: PNGMetadataExtractorTest.php:131
PNGMetadataExtractorTest\testPngBitDepth1
testPngBitDepth1()
Definition: PNGMetadataExtractorTest.php:118
PNGMetadataExtractor\getMetadata
static getMetadata( $filename)
Definition: PNGMetadataExtractor.php:46
PNGMetadataExtractorTest\testPngIndexColour
testPngIndexColour()
Definition: PNGMetadataExtractorTest.php:124
PNGMetadataExtractorTest\testPngNativeText
testPngNativeText()
Test tEXt tag (Uncompressed textual metadata)
Definition: PNGMetadataExtractorTest.php:33
PNGMetadataExtractorTest\testPngBitDepth8
testPngBitDepth8()
Definition: PNGMetadataExtractorTest.php:111
MediaWikiTestCase\checkPHPExtension
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
Definition: MediaWikiTestCase.php:1005
PNGMetadataExtractorTest\testPngNativeTextNonAscii
testPngNativeTextNonAscii()
tEXt tags must be encoded iso-8859-1 (vs iTXt which are utf-8) Make sure non-ascii characters get con...
Definition: PNGMetadataExtractorTest.php:50
PNGMetadataExtractorTest\testPngGreyscaleNoAlphaColour
testPngGreyscaleNoAlphaColour()
Definition: PNGMetadataExtractorTest.php:149
PNGMetadataExtractorTest\setUp
setUp()
Definition: PNGMetadataExtractorTest.php:8