2 class PNGHandlerTest
extends MediaWikiTestCase
{
4 public function setUp() {
5 $this->filePath
= __DIR__
. '/../../data/media';
6 $this->backend
= new FSFileBackend( array(
7 'name' => 'localtesting',
8 'lockManager' => 'nullLockManager',
9 'containerPaths' => array( 'data' => $this->filePath
)
11 $this->repo
= new FSRepo( array(
13 'url' => 'http://localhost/thumbtest',
14 'backend' => $this->backend
16 $this->handler
= new PNGHandler();
19 public function testInvalidFile() {
20 $res = $this->handler
->getMetadata( null, $this->filePath
. '/README' );
21 $this->assertEquals( PNGHandler
::BROKEN_FILE
, $res );
24 * @param $filename String basename of the file to check
25 * @param $expected boolean Expected result.
26 * @dataProvider dataIsAnimated
28 public function testIsAnimanted( $filename, $expected ) {
29 $file = $this->dataFile( $filename, 'image/png' );
30 $actual = $this->handler
->isAnimatedImage( $file );
31 $this->assertEquals( $expected, $actual );
33 public function dataIsAnimated() {
35 array( 'Animated_PNG_example_bouncing_beach_ball.png', true ),
36 array( '1bit-png.png', false ),
41 * @param $filename String
42 * @param $expected Integer Total image area
43 * @dataProvider dataGetImageArea
45 public function testGetImageArea( $filename, $expected ) {
46 $file = $this->dataFile($filename, 'image/png' );
47 $actual = $this->handler
->getImageArea( $file, $file->getWidth(), $file->getHeight() );
48 $this->assertEquals( $expected, $actual );
50 public function dataGetImageArea() {
52 array( '1bit-png.png', 2500 ),
53 array( 'greyscale-png.png', 2500 ),
54 array( 'Png-native-test.png', 126000 ),
55 array( 'Animated_PNG_example_bouncing_beach_ball.png', 10000 ),
60 * @param $metadata String Serialized metadata
61 * @param $expected Integer One of the class constants of PNGHandler
62 * @dataProvider dataIsMetadataValid
64 public function testIsMetadataValid( $metadata, $expected ) {
65 $actual = $this->handler
->isMetadataValid( null, $metadata );
66 $this->assertEquals( $expected, $actual );
68 public function dataIsMetadataValid() {
70 array( PNGHandler
::BROKEN_FILE
, PNGHandler
::METADATA_GOOD
),
71 array( '', PNGHandler
::METADATA_BAD
),
72 array( null, PNGHandler
::METADATA_BAD
),
73 array( 'Something invalid!', PNGHandler
::METADATA_BAD
),
74 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
),
79 * @param $filename String
80 * @param $expected String Serialized array
81 * @dataProvider dataGetMetadata
83 public function testGetMetadata( $filename, $expected ) {
84 $file = $this->dataFile( $filename, 'image/png' );
85 $actual = $this->handler
->getMetadata( $file, "$this->filePath/$filename" );
86 // $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
87 $this->assertEquals( ( $expected ), ( $actual ) );
89 public function dataGetMetadata() {
91 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;}}' ),
92 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;}}' ),
96 private function dataFile( $name, $type ) {
97 return new UnregisteredLocalFile( false, $this->repo
,
98 "mwstore://localtesting/data/$name", $type );