MediaWiki
REL1_19
|
00001 <?php 00002 class PNGHandlerTest extends MediaWikiTestCase { 00003 00004 public function setUp() { 00005 $this->filePath = dirname( __FILE__ ) . '/../../data/media'; 00006 $this->backend = new FSFileBackend( array( 00007 'name' => 'localtesting', 00008 'lockManager' => 'nullLockManager', 00009 'containerPaths' => array( 'data' => $this->filePath ) 00010 ) ); 00011 $this->repo = new FSRepo( array( 00012 'name' => 'temp', 00013 'url' => 'http://localhost/thumbtest', 00014 'backend' => $this->backend 00015 ) ); 00016 $this->handler = new PNGHandler(); 00017 } 00018 00019 public function testInvalidFile() { 00020 $res = $this->handler->getMetadata( null, $this->filePath . '/README' ); 00021 $this->assertEquals( PNGHandler::BROKEN_FILE, $res ); 00022 } 00028 public function testIsAnimanted( $filename, $expected ) { 00029 $file = $this->dataFile( $filename, 'image/png' ); 00030 $actual = $this->handler->isAnimatedImage( $file ); 00031 $this->assertEquals( $expected, $actual ); 00032 } 00033 public function dataIsAnimated() { 00034 return array( 00035 array( 'Animated_PNG_example_bouncing_beach_ball.png', true ), 00036 array( '1bit-png.png', false ), 00037 ); 00038 } 00039 00045 public function testGetImageArea( $filename, $expected ) { 00046 $file = $this->dataFile($filename, 'image/png' ); 00047 $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() ); 00048 $this->assertEquals( $expected, $actual ); 00049 } 00050 public function dataGetImageArea() { 00051 return array( 00052 array( '1bit-png.png', 2500 ), 00053 array( 'greyscale-png.png', 2500 ), 00054 array( 'Png-native-test.png', 126000 ), 00055 array( 'Animated_PNG_example_bouncing_beach_ball.png', 10000 ), 00056 ); 00057 } 00058 00064 public function testIsMetadataValid( $metadata, $expected ) { 00065 $actual = $this->handler->isMetadataValid( null, $metadata ); 00066 $this->assertEquals( $expected, $actual ); 00067 } 00068 public function dataIsMetadataValid() { 00069 return array( 00070 array( PNGHandler::BROKEN_FILE, PNGHandler::METADATA_GOOD ), 00071 array( '', PNGHandler::METADATA_BAD ), 00072 array( null, PNGHandler::METADATA_BAD ), 00073 array( 'Something invalid!', PNGHandler::METADATA_BAD ), 00074 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 ), 00075 ); 00076 } 00077 00083 public function testGetMetadata( $filename, $expected ) { 00084 $file = $this->dataFile( $filename, 'image/png' ); 00085 $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" ); 00086 // $this->assertEquals( unserialize( $expected ), unserialize( $actual ) ); 00087 $this->assertEquals( ( $expected ), ( $actual ) ); 00088 } 00089 public function dataGetMetadata() { 00090 return array( 00091 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;}}' ), 00092 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;}}' ), 00093 ); 00094 } 00095 00096 private function dataFile( $name, $type ) { 00097 return new UnregisteredLocalFile( false, $this->repo, 00098 "mwstore://localtesting/data/$name", $type ); 00099 } 00100 }