2 class PNGHandlerTest
extends MediaWikiTestCase
{
4 protected function setUp() {
7 $this->filePath
= __DIR__
. '/../../data/media';
8 $this->backend
= new FSFileBackend( array(
9 'name' => 'localtesting',
10 'lockManager' => 'nullLockManager',
11 'containerPaths' => array( 'data' => $this->filePath
)
13 $this->repo
= new FSRepo( array(
15 'url' => 'http://localhost/thumbtest',
16 'backend' => $this->backend
18 $this->handler
= new PNGHandler();
21 public function testInvalidFile() {
22 $res = $this->handler
->getMetadata( null, $this->filePath
. '/README' );
23 $this->assertEquals( PNGHandler
::BROKEN_FILE
, $res );
27 * @param $filename String basename of the file to check
28 * @param $expected boolean Expected result.
29 * @dataProvider provideIsAnimated
31 public function testIsAnimanted( $filename, $expected ) {
32 $file = $this->dataFile( $filename, 'image/png' );
33 $actual = $this->handler
->isAnimatedImage( $file );
34 $this->assertEquals( $expected, $actual );
37 public static function provideIsAnimated() {
39 array( 'Animated_PNG_example_bouncing_beach_ball.png', true ),
40 array( '1bit-png.png', false ),
45 * @param $filename String
46 * @param $expected Integer Total image area
47 * @dataProvider provideGetImageArea
49 public function testGetImageArea( $filename, $expected ) {
50 $file = $this->dataFile( $filename, 'image/png' );
51 $actual = $this->handler
->getImageArea( $file, $file->getWidth(), $file->getHeight() );
52 $this->assertEquals( $expected, $actual );
55 public static function provideGetImageArea() {
57 array( '1bit-png.png', 2500 ),
58 array( 'greyscale-png.png', 2500 ),
59 array( 'Png-native-test.png', 126000 ),
60 array( 'Animated_PNG_example_bouncing_beach_ball.png', 10000 ),
65 * @param $metadata String Serialized metadata
66 * @param $expected Integer One of the class constants of PNGHandler
67 * @dataProvider provideIsMetadataValid
69 public function testIsMetadataValid( $metadata, $expected ) {
70 $actual = $this->handler
->isMetadataValid( null, $metadata );
71 $this->assertEquals( $expected, $actual );
74 public static function provideIsMetadataValid() {
76 array( PNGHandler
::BROKEN_FILE
, PNGHandler
::METADATA_GOOD
),
77 array( '', PNGHandler
::METADATA_BAD
),
78 array( null, PNGHandler
::METADATA_BAD
),
79 array( 'Something invalid!', PNGHandler
::METADATA_BAD
),
80 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
),
85 * @param $filename String
86 * @param $expected String Serialized array
87 * @dataProvider provideGetMetadata
89 public function testGetMetadata( $filename, $expected ) {
90 $file = $this->dataFile( $filename, 'image/png' );
91 $actual = $this->handler
->getMetadata( $file, "$this->filePath/$filename" );
92 // $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
93 $this->assertEquals( ( $expected ), ( $actual ) );
96 public static function provideGetMetadata() {
98 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;}}' ),
99 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;}}' ),
103 private function dataFile( $name, $type ) {
104 return new UnregisteredLocalFile( false, $this->repo
,
105 "mwstore://localtesting/data/$name", $type );