MediaWiki  REL1_24
GIFTest.php
Go to the documentation of this file.
00001 <?php
00002 
00006 class GIFHandlerTest extends MediaWikiMediaTestCase {
00007 
00009     protected $handler;
00010 
00011     protected function setUp() {
00012         parent::setUp();
00013 
00014         $this->handler = new GIFHandler();
00015     }
00016 
00020     public function testInvalidFile() {
00021         $res = $this->handler->getMetadata( null, $this->filePath . '/README' );
00022         $this->assertEquals( GIFHandler::BROKEN_FILE, $res );
00023     }
00024 
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 
00050     public function testGetImageArea( $filename, $expected ) {
00051         $file = $this->dataFile( $filename, 'image/gif' );
00052         $actual = $this->handler->getImageArea( $file, $file->getWidth(), $file->getHeight() );
00053         $this->assertEquals( $expected, $actual );
00054     }
00055 
00056     public static function provideGetImageArea() {
00057         return array(
00058             array( 'animated.gif', 5400 ),
00059             array( 'nonanimated.gif', 1350 ),
00060         );
00061     }
00062 
00069     public function testIsMetadataValid( $metadata, $expected ) {
00070         $actual = $this->handler->isMetadataValid( null, $metadata );
00071         $this->assertEquals( $expected, $actual );
00072     }
00073 
00074     public static function provideIsMetadataValid() {
00075         return array(
00076             array( GIFHandler::BROKEN_FILE, GIFHandler::METADATA_GOOD ),
00077             array( '', GIFHandler::METADATA_BAD ),
00078             array( null, GIFHandler::METADATA_BAD ),
00079             array( 'Something invalid!', GIFHandler::METADATA_BAD ),
00080             // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
00081             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 ),
00082             // @codingStandardsIgnoreEnd
00083         );
00084     }
00085 
00092     public function testGetMetadata( $filename, $expected ) {
00093         $file = $this->dataFile( $filename, 'image/gif' );
00094         $actual = $this->handler->getMetadata( $file, "$this->filePath/$filename" );
00095         $this->assertEquals( unserialize( $expected ), unserialize( $actual ) );
00096     }
00097 
00098     public static function provideGetMetadata() {
00099         return array(
00100             // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
00101             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;}}' ),
00102             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;}}' ),
00103             // @codingStandardsIgnoreEnd
00104         );
00105     }
00106 
00113     public function testGetIndependentMetaArray( $filename, $expected ) {
00114         $file = $this->dataFile( $filename, 'image/gif' );
00115         $actual = $this->handler->getCommonMetaArray( $file );
00116         $this->assertEquals( $expected, $actual );
00117     }
00118 
00119     public static function provideGetIndependentMetaArray() {
00120         return array(
00121             array( 'nonanimated.gif', array(
00122                 'GIFFileComment' => array(
00123                     'GIF test file ⁕ Created with GIMP',
00124                 ),
00125             ) ),
00126             array( 'animated-xmp.gif',
00127                 array(
00128                     'Artist' => 'Bawolff',
00129                     'ImageDescription' => array(
00130                         'x-default' => 'A file to test GIF',
00131                         '_type' => 'lang',
00132                     ),
00133                     'SublocationDest' => 'The interwebs',
00134                     'GIFFileComment' =>
00135                     array(
00136                         'GIƒ·test·file',
00137                     ),
00138                 )
00139             ),
00140         );
00141     }
00142 }