2 class PNGHandlerTest
extends MediaWikiTestCase
{
4 public function setUp() {
5 $this->filePath
= dirname( __FILE__
) . '/../../data/media/';
6 $this->handler
= new PNGHandler();
9 public function testInvalidFile() {
10 $res = $this->handler
->getMetadata( null, $this->filePath
. 'README' );
11 $this->assertEquals( PNGHandler
::BROKEN_FILE
, $res );
14 * @param $filename String basename of the file to check
15 * @param $expected boolean Expected result.
16 * @dataProvider dataIsAnimated
18 public function testIsAnimanted( $filename, $expected ) {
19 $file = UnregisteredLocalFile
::newFromPath( $this->filePath
. $filename,
21 $actual = $this->handler
->isAnimatedImage( $file );
22 $this->assertEquals( $expected, $actual );
24 public function dataIsAnimated() {
26 array( 'Animated_PNG_example_bouncing_beach_ball.png', true ),
27 array( '1bit-png.png', false ),
32 * @param $filename String
33 * @param $expected Integer Total image area
34 * @dataProvider dataGetImageArea
36 public function testGetImageArea( $filename, $expected ) {
37 $file = UnregisteredLocalFile
::newFromPath( $this->filePath
. $filename,
39 $actual = $this->handler
->getImageArea( $file, $file->getWidth(), $file->getHeight() );
40 $this->assertEquals( $expected, $actual );
42 public function dataGetImageArea() {
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 ),
52 * @param $metadata String Serialized metadata
53 * @param $expected Integer One of the class constants of PNGHandler
54 * @dataProvider dataIsMetadataValid
56 public function testIsMetadataValid( $metadata, $expected ) {
57 $actual = $this->handler
->isMetadataValid( null, $metadata );
58 $this->assertEquals( $expected, $actual );
60 public function dataIsMetadataValid() {
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
),
71 * @param $filename String
72 * @param $expected String Serialized array
73 * @dataProvider dataGetMetadata
75 public function testGetMetadata( $filename, $expected ) {
76 $file = UnregisteredLocalFile
::newFromPath( $this->filePath
. $filename,
78 $actual = $this->handler
->getMetadata( $file, $this->filePath
. $filename );
79 // $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
80 $this->assertEquals( ( $expected ), ( $actual ) );
82 public function dataGetMetadata() {
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;}}' ),