MediaWiki
REL1_22
|
00001 <?php 00002 class GIFHandlerTest extends MediaWikiTestCase { 00003 00005 protected $backend; 00007 protected $handler; 00009 protected $repo; 00011 protected $filePath; 00012 00013 protected function setUp() { 00014 parent::setUp(); 00015 00016 $this->filePath = __DIR__ . '/../../data/media'; 00017 $this->backend = new FSFileBackend( array( 00018 'name' => 'localtesting', 00019 'lockManager' => 'nullLockManager', 00020 'containerPaths' => array( 'data' => $this->filePath ) 00021 ) ); 00022 $this->repo = new FSRepo( array( 00023 'name' => 'temp', 00024 'url' => 'http://localhost/thumbtest', 00025 'backend' => $this->backend 00026 ) ); 00027 $this->handler = new GIFHandler(); 00028 } 00029 00033 public function testInvalidFile() { 00034 $res = $this->handler->getMetadata( null, $this->filePath . '/README' ); 00035 $this->assertEquals( GIFHandler::BROKEN_FILE, $res ); 00036 } 00037 00044 public function testIsAnimanted( $filename, $expected ) { 00045 $file = $this->dataFile( $filename, 'image/gif' ); 00046 $actual = $this->handler->isAnimatedImage( $file ); 00047 $this->assertEquals( $expected, $actual ); 00048 } 00049 00050 public static function provideIsAnimated() { 00051 return array( 00052 array( 'animated.gif', true ), 00053 array( 'nonanimated.gif', false ), 00054 ); 00055 } 00056 00063 public function testGetImageArea( $filename, $expected ) { 00064 $file = $this->dataFile( $filename, 'image/gif' ); 00065 $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() ); 00066 $this->assertEquals( $expected, $actual ); 00067 } 00068 00069 public static function provideGetImageArea() { 00070 return array( 00071 array( 'animated.gif', 5400 ), 00072 array( 'nonanimated.gif', 1350 ), 00073 ); 00074 } 00075 00082 public function testIsMetadataValid( $metadata, $expected ) { 00083 $actual = $this->handler->isMetadataValid( null, $metadata ); 00084 $this->assertEquals( $expected, $actual ); 00085 } 00086 00087 public static function provideIsMetadataValid() { 00088 return array( 00089 array( GIFHandler::BROKEN_FILE, GIFHandler::METADATA_GOOD ), 00090 array( '', GIFHandler::METADATA_BAD ), 00091 array( null, GIFHandler::METADATA_BAD ), 00092 array( 'Something invalid!', GIFHandler::METADATA_BAD ), 00093 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 ), 00094 ); 00095 } 00096 00103 public function testGetMetadata( $filename, $expected ) { 00104 $file = $this->dataFile( $filename, 'image/gif' ); 00105 $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" ); 00106 $this->assertEquals( unserialize( $expected ), unserialize( $actual ) ); 00107 } 00108 00109 public static function provideGetMetadata() { 00110 return array( 00111 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;}}' ), 00112 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;}}' ), 00113 ); 00114 } 00115 00116 private function dataFile( $name, $type ) { 00117 return new UnregisteredLocalFile( false, $this->repo, 00118 "mwstore://localtesting/data/$name", $type ); 00119 } 00120 }