MediaWiki
REL1_19
|
00001 <?php 00002 class GIFHandlerTest 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 GIFHandler(); 00017 } 00018 00019 public function testInvalidFile() { 00020 $res = $this->handler->getMetadata( null, $this->filePath . '/README' ); 00021 $this->assertEquals( GIFHandler::BROKEN_FILE, $res ); 00022 } 00028 public function testIsAnimanted( $filename, $expected ) { 00029 $file = $this->dataFile( $filename, 'image/gif' ); 00030 $actual = $this->handler->isAnimatedImage( $file ); 00031 $this->assertEquals( $expected, $actual ); 00032 } 00033 public function dataIsAnimated() { 00034 return array( 00035 array( 'animated.gif', true ), 00036 array( 'nonanimated.gif', false ), 00037 ); 00038 } 00039 00045 public function testGetImageArea( $filename, $expected ) { 00046 $file = $this->dataFile( $filename, 'image/gif' ); 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( 'animated.gif', 5400 ), 00053 array( 'nonanimated.gif', 1350 ), 00054 ); 00055 } 00056 00062 public function testIsMetadataValid( $metadata, $expected ) { 00063 $actual = $this->handler->isMetadataValid( null, $metadata ); 00064 $this->assertEquals( $expected, $actual ); 00065 } 00066 public function dataIsMetadataValid() { 00067 return array( 00068 array( GIFHandler::BROKEN_FILE, GIFHandler::METADATA_GOOD ), 00069 array( '', GIFHandler::METADATA_BAD ), 00070 array( null, GIFHandler::METADATA_BAD ), 00071 array( 'Something invalid!', GIFHandler::METADATA_BAD ), 00072 array( 'a:4:{s:10:"frameCount";i:1;s:6:"looped";b:0;s:8:"duration";d:0.1000000000000000055511151231257827021181583404541015625;s:8:"metadata";a:2:{s:14:"GIFFileComment";a:1:{i:0;s:35:"GIF test file ⁕ Created with GIMP";}s:15:"_MW_GIF_VERSION";i:1;}}', GIFHandler::METADATA_GOOD ), 00073 ); 00074 } 00075 00081 public function testGetMetadata( $filename, $expected ) { 00082 $file = $this->dataFile( $filename, 'image/gif' ); 00083 $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" ); 00084 $this->assertEquals( unserialize( $expected ), unserialize( $actual ) ); 00085 } 00086 00087 public function dataGetMetadata() { 00088 return array( 00089 array( 'nonanimated.gif', 'a:4:{s:10:"frameCount";i:1;s:6:"looped";b:0;s:8:"duration";d:0.1000000000000000055511151231257827021181583404541015625;s:8:"metadata";a:2:{s:14:"GIFFileComment";a:1:{i:0;s:35:"GIF test file ⁕ Created with GIMP";}s:15:"_MW_GIF_VERSION";i:1;}}' ), 00090 array( 'animated-xmp.gif', 'a:4:{s:10:"frameCount";i:4;s:6:"looped";b:1;s:8:"duration";d:2.399999999999999911182158029987476766109466552734375;s:8:"metadata";a:5:{s:6:"Artist";s:7:"Bawolff";s:16:"ImageDescription";a:2:{s:9:"x-default";s:18:"A file to test GIF";s:5:"_type";s:4:"lang";}s:15:"SublocationDest";s:13:"The interwebs";s:14:"GIFFileComment";a:1:{i:0;s:16:"GIƒ·test·file";}s:15:"_MW_GIF_VERSION";i:1;}}' ), 00091 ); 00092 } 00093 00094 private function dataFile( $name, $type ) { 00095 return new UnregisteredLocalFile( false, $this->repo, 00096 "mwstore://localtesting/data/$name", $type ); 00097 } 00098 }