MediaWiki
REL1_21
|
00001 <?php 00002 class PNGHandlerTest extends MediaWikiTestCase { 00003 00004 protected function setUp() { 00005 parent::setUp(); 00006 00007 $this->filePath = __DIR__ . '/../../data/media'; 00008 $this->backend = new FSFileBackend( array( 00009 'name' => 'localtesting', 00010 'lockManager' => 'nullLockManager', 00011 'containerPaths' => array( 'data' => $this->filePath ) 00012 ) ); 00013 $this->repo = new FSRepo( array( 00014 'name' => 'temp', 00015 'url' => 'http://localhost/thumbtest', 00016 'backend' => $this->backend 00017 ) ); 00018 $this->handler = new PNGHandler(); 00019 } 00020 00021 public function testInvalidFile() { 00022 $res = $this->handler->getMetadata( null, $this->filePath . '/README' ); 00023 $this->assertEquals( PNGHandler::BROKEN_FILE, $res ); 00024 } 00025 00031 public function testIsAnimanted( $filename, $expected ) { 00032 $file = $this->dataFile( $filename, 'image/png' ); 00033 $actual = $this->handler->isAnimatedImage( $file ); 00034 $this->assertEquals( $expected, $actual ); 00035 } 00036 00037 public static function provideIsAnimated() { 00038 return array( 00039 array( 'Animated_PNG_example_bouncing_beach_ball.png', true ), 00040 array( '1bit-png.png', false ), 00041 ); 00042 } 00043 00049 public function testGetImageArea( $filename, $expected ) { 00050 $file = $this->dataFile( $filename, 'image/png' ); 00051 $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() ); 00052 $this->assertEquals( $expected, $actual ); 00053 } 00054 00055 public static function provideGetImageArea() { 00056 return array( 00057 array( '1bit-png.png', 2500 ), 00058 array( 'greyscale-png.png', 2500 ), 00059 array( 'Png-native-test.png', 126000 ), 00060 array( 'Animated_PNG_example_bouncing_beach_ball.png', 10000 ), 00061 ); 00062 } 00063 00069 public function testIsMetadataValid( $metadata, $expected ) { 00070 $actual = $this->handler->isMetadataValid( null, $metadata ); 00071 $this->assertEquals( $expected, $actual ); 00072 } 00073 00074 public static function provideIsMetadataValid() { 00075 return array( 00076 array( PNGHandler::BROKEN_FILE, PNGHandler::METADATA_GOOD ), 00077 array( '', PNGHandler::METADATA_BAD ), 00078 array( null, PNGHandler::METADATA_BAD ), 00079 array( 'Something invalid!', PNGHandler::METADATA_BAD ), 00080 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 ), 00081 ); 00082 } 00083 00089 public function testGetMetadata( $filename, $expected ) { 00090 $file = $this->dataFile( $filename, 'image/png' ); 00091 $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" ); 00092 // $this->assertEquals( unserialize( $expected ), unserialize( $actual ) ); 00093 $this->assertEquals( ( $expected ), ( $actual ) ); 00094 } 00095 00096 public static function provideGetMetadata() { 00097 return array( 00098 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;}}' ), 00099 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;}}' ), 00100 ); 00101 } 00102 00103 private function dataFile( $name, $type ) { 00104 return new UnregisteredLocalFile( false, $this->repo, 00105 "mwstore://localtesting/data/$name", $type ); 00106 } 00107 }