MediaWiki  1.30.0
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  /*
73  public function testPngPhysTag() {
74  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
75  'Png-native-test.png' );
76 
77  $this->assertArrayHasKey( 'text', $meta );
78  $meta = $meta['text'];
79 
80  $this->assertEquals( '2835/100', $meta['XResolution'] );
81  $this->assertEquals( '2835/100', $meta['YResolution'] );
82  $this->assertEquals( 3, $meta['ResolutionUnit'] ); // 3 = cm
83  }
84  */
85 
89  public function testStaticPngAnimationMetadata() {
90  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
91  'Png-native-test.png' );
92 
93  $this->assertEquals( 0, $meta['frameCount'] );
94  $this->assertEquals( 1, $meta['loopCount'] );
95  $this->assertEquals( 0, $meta['duration'] );
96  }
97 
102  public function testApngAnimationMetadata() {
103  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
104  'Animated_PNG_example_bouncing_beach_ball.png' );
105 
106  $this->assertEquals( 20, $meta['frameCount'] );
107  // Note loop count of 0 = infinity
108  $this->assertEquals( 0, $meta['loopCount'] );
109  $this->assertEquals( 1.5, $meta['duration'], '', 0.00001 );
110  }
111 
112  public function testPngBitDepth8() {
113  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
114  'Png-native-test.png' );
115 
116  $this->assertEquals( 8, $meta['bitDepth'] );
117  }
118 
119  public function testPngBitDepth1() {
120  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
121  '1bit-png.png' );
122  $this->assertEquals( 1, $meta['bitDepth'] );
123  }
124 
125  public function testPngIndexColour() {
126  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
127  'Png-native-test.png' );
128 
129  $this->assertEquals( 'index-coloured', $meta['colorType'] );
130  }
131 
132  public function testPngRgbColour() {
133  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
134  'rgb-png.png' );
135  $this->assertEquals( 'truecolour-alpha', $meta['colorType'] );
136  }
137 
138  public function testPngRgbNoAlphaColour() {
139  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
140  'rgb-na-png.png' );
141  $this->assertEquals( 'truecolour', $meta['colorType'] );
142  }
143 
144  public function testPngGreyscaleColour() {
145  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
146  'greyscale-png.png' );
147  $this->assertEquals( 'greyscale-alpha', $meta['colorType'] );
148  }
149 
150  public function testPngGreyscaleNoAlphaColour() {
151  $meta = PNGMetadataExtractor::getMetadata( $this->filePath .
152  'greyscale-na-png.png' );
153  $this->assertEquals( 'greyscale', $meta['colorType'] );
154  }
155 }
PNGMetadataExtractorTest\testPngNativetZtxt
testPngNativetZtxt()
Tests zTXt tag (compressed textual metadata)
Definition: PNGMetadataExtractorTest.php:17
PNGMetadataExtractorTest\testApngAnimationMetadata
testApngAnimationMetadata()
Given an animated APNG image file check it gets animated metadata right.
Definition: PNGMetadataExtractorTest.php:102
PNGMetadataExtractorTest\testPngRgbNoAlphaColour
testPngRgbNoAlphaColour()
Definition: PNGMetadataExtractorTest.php:138
PNGMetadataExtractorTest\testPngGreyscaleColour
testPngGreyscaleColour()
Definition: PNGMetadataExtractorTest.php:144
PNGMetadataExtractorTest
Media PNGMetadataExtractor.
Definition: PNGMetadataExtractorTest.php:7
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
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:89
MediaWikiTestCase
Definition: MediaWikiTestCase.php:15
PNGMetadataExtractorTest\testPngRgbColour
testPngRgbColour()
Definition: PNGMetadataExtractorTest.php:132
PNGMetadataExtractorTest\testPngBitDepth1
testPngBitDepth1()
Definition: PNGMetadataExtractorTest.php:119
PNGMetadataExtractor\getMetadata
static getMetadata( $filename)
Definition: PNGMetadataExtractor.php:46
PNGMetadataExtractorTest\testPngIndexColour
testPngIndexColour()
Definition: PNGMetadataExtractorTest.php:125
PNGMetadataExtractorTest\testPngNativeText
testPngNativeText()
Test tEXt tag (Uncompressed textual metadata)
Definition: PNGMetadataExtractorTest.php:34
PNGMetadataExtractorTest\testPngBitDepth8
testPngBitDepth8()
Definition: PNGMetadataExtractorTest.php:112
MediaWikiTestCase\checkPHPExtension
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
Definition: MediaWikiTestCase.php:1770
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:51
PNGMetadataExtractorTest\testPngGreyscaleNoAlphaColour
testPngGreyscaleNoAlphaColour()
Definition: PNGMetadataExtractorTest.php:150
PNGMetadataExtractorTest\setUp
setUp()
Definition: PNGMetadataExtractorTest.php:9