MediaWiki
REL1_21
|
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 00037 public static function provideIsAnimated() { 00038 return array( 00039 array( 'animated.gif', true ), 00040 array( 'nonanimated.gif', false ), 00041 ); 00042 } 00043 00049 public function testGetImageArea( $filename, $expected ) { 00050 $file = $this->dataFile( $filename, 'image/gif' ); 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( 'animated.gif', 5400 ), 00058 array( 'nonanimated.gif', 1350 ), 00059 ); 00060 } 00061 00067 public function testIsMetadataValid( $metadata, $expected ) { 00068 $actual = $this->handler->isMetadataValid( null, $metadata ); 00069 $this->assertEquals( $expected, $actual ); 00070 } 00071 00072 public static function provideIsMetadataValid() { 00073 return array( 00074 array( GIFHandler::BROKEN_FILE, GIFHandler::METADATA_GOOD ), 00075 array( '', GIFHandler::METADATA_BAD ), 00076 array( null, GIFHandler::METADATA_BAD ), 00077 array( 'Something invalid!', GIFHandler::METADATA_BAD ), 00078 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 ), 00079 ); 00080 } 00081 00087 public function testGetMetadata( $filename, $expected ) { 00088 $file = $this->dataFile( $filename, 'image/gif' ); 00089 $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" ); 00090 $this->assertEquals( unserialize( $expected ), unserialize( $actual ) ); 00091 } 00092 00093 public static function provideGetMetadata() { 00094 return array( 00095 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;}}' ), 00096 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;}}' ), 00097 ); 00098 } 00099 00100 private function dataFile( $name, $type ) { 00101 return new UnregisteredLocalFile( false, $this->repo, 00102 "mwstore://localtesting/data/$name", $type ); 00103 } 00104 }