MediaWiki
master
|
00001 <?php 00002 class GIFHandlerTest 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 GIFHandler(); 00019 } 00020 00021 public function testInvalidFile() { 00022 $res = $this->handler->getMetadata( null, $this->filePath . '/README' ); 00023 $this->assertEquals( GIFHandler::BROKEN_FILE, $res ); 00024 } 00025 00031 public function testIsAnimanted( $filename, $expected ) { 00032 $file = $this->dataFile( $filename, 'image/gif' ); 00033 $actual = $this->handler->isAnimatedImage( $file ); 00034 $this->assertEquals( $expected, $actual ); 00035 } 00036 public static function provideIsAnimated() { 00037 return array( 00038 array( 'animated.gif', true ), 00039 array( 'nonanimated.gif', false ), 00040 ); 00041 } 00042 00048 public function testGetImageArea( $filename, $expected ) { 00049 $file = $this->dataFile( $filename, 'image/gif' ); 00050 $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() ); 00051 $this->assertEquals( $expected, $actual ); 00052 } 00053 public static function provideGetImageArea() { 00054 return array( 00055 array( 'animated.gif', 5400 ), 00056 array( 'nonanimated.gif', 1350 ), 00057 ); 00058 } 00059 00065 public function testIsMetadataValid( $metadata, $expected ) { 00066 $actual = $this->handler->isMetadataValid( null, $metadata ); 00067 $this->assertEquals( $expected, $actual ); 00068 } 00069 public static function provideIsMetadataValid() { 00070 return array( 00071 array( GIFHandler::BROKEN_FILE, GIFHandler::METADATA_GOOD ), 00072 array( '', GIFHandler::METADATA_BAD ), 00073 array( null, GIFHandler::METADATA_BAD ), 00074 array( 'Something invalid!', GIFHandler::METADATA_BAD ), 00075 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 ), 00076 ); 00077 } 00078 00084 public function testGetMetadata( $filename, $expected ) { 00085 $file = $this->dataFile( $filename, 'image/gif' ); 00086 $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" ); 00087 $this->assertEquals( unserialize( $expected ), unserialize( $actual ) ); 00088 } 00089 00090 public static function provideGetMetadata() { 00091 return array( 00092 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;}}' ), 00093 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;}}' ), 00094 ); 00095 } 00096 00097 private function dataFile( $name, $type ) { 00098 return new UnregisteredLocalFile( false, $this->repo, 00099 "mwstore://localtesting/data/$name", $type ); 00100 } 00101 }