Follow-up r92635 Make sure the Exif related tests handle not having the Exif extensio...
[lhc/web/wiklou.git] / tests / phpunit / includes / media / PNGTest.php
1 <?php
2 class PNGHandlerTest extends MediaWikiTestCase {
3
4 public function setUp() {
5 $this->filePath = dirname( __FILE__ ) . '/../../data/media/';
6 $this->handler = new PNGHandler();
7 }
8
9 public function testInvalidFile() {
10 $res = $this->handler->getMetadata( null, $this->filePath . 'README' );
11 $this->assertEquals( PNGHandler::BROKEN_FILE, $res );
12 }
13 /**
14 * @param $filename String basename of the file to check
15 * @param $expected boolean Expected result.
16 * @dataProvider dataIsAnimated
17 */
18 public function testIsAnimanted( $filename, $expected ) {
19 $file = UnregisteredLocalFile::newFromPath( $this->filePath . $filename,
20 'image/png' );
21 $actual = $this->handler->isAnimatedImage( $file );
22 $this->assertEquals( $expected, $actual );
23 }
24 public function dataIsAnimated() {
25 return array(
26 array( 'Animated_PNG_example_bouncing_beach_ball.png', true ),
27 array( '1bit-png.png', false ),
28 );
29 }
30
31 /**
32 * @param $filename String
33 * @param $expected Integer Total image area
34 * @dataProvider dataGetImageArea
35 */
36 public function testGetImageArea( $filename, $expected ) {
37 $file = UnregisteredLocalFile::newFromPath( $this->filePath . $filename,
38 'image/png' );
39 $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
40 $this->assertEquals( $expected, $actual );
41 }
42 public function dataGetImageArea() {
43 return array(
44 array( '1bit-png.png', 2500 ),
45 array( 'greyscale-png.png', 2500 ),
46 array( 'Png-native-test.png', 126000 ),
47 array( 'Animated_PNG_example_bouncing_beach_ball.png', 10000 ),
48 );
49 }
50
51 /**
52 * @param $metadata String Serialized metadata
53 * @param $expected Integer One of the class constants of PNGHandler
54 * @dataProvider dataIsMetadataValid
55 */
56 public function testIsMetadataValid( $metadata, $expected ) {
57 $actual = $this->handler->isMetadataValid( null, $metadata );
58 $this->assertEquals( $expected, $actual );
59 }
60 public function dataIsMetadataValid() {
61 return array(
62 array( PNGHandler::BROKEN_FILE, PNGHandler::METADATA_GOOD ),
63 array( '', PNGHandler::METADATA_BAD ),
64 array( null, PNGHandler::METADATA_BAD ),
65 array( 'Something invalid!', PNGHandler::METADATA_BAD ),
66 array( 'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:8;s:9:"colorType";s:10:"truecolour";s:8:"metadata";a:1:{s:15:"_MW_PNG_VERSION";i:1;}}', PNGHandler::METADATA_GOOD ),
67 );
68 }
69
70 /**
71 * @param $filename String
72 * @param $expected String Serialized array
73 * @dataProvider dataGetMetadata
74 */
75 public function testGetMetadata( $filename, $expected ) {
76 $file = UnregisteredLocalFile::newFromPath( $this->filePath . $filename,
77 'image/png' );
78 $actual = $this->handler->getMetadata( $file, $this->filePath . $filename );
79 // $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
80 $this->assertEquals( ( $expected ), ( $actual ) );
81 }
82 public function dataGetMetadata() {
83 return array(
84 array( 'rgb-na-png.png', 'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:8;s:9:"colorType";s:10:"truecolour";s:8:"metadata";a:1:{s:15:"_MW_PNG_VERSION";i:1;}}' ),
85 array( 'xmp.png', 'a:6:{s:10:"frameCount";i:0;s:9:"loopCount";i:1;s:8:"duration";d:0;s:8:"bitDepth";i:1;s:9:"colorType";s:14:"index-coloured";s:8:"metadata";a:2:{s:12:"SerialNumber";s:9:"123456789";s:15:"_MW_PNG_VERSION";i:1;}}' ),
86 );
87 }
88 }