MediaWiki  REL1_23
JpegTest.php
Go to the documentation of this file.
00001 <?php
00005 class JpegTest extends MediaWikiTestCase {
00006 
00007     protected $filePath;
00008 
00009     protected function setUp() {
00010         parent::setUp();
00011         $this->checkPHPExtension( 'exif' );
00012 
00013         $this->filePath = __DIR__ . '/../../data/media/';
00014 
00015         $this->setMwGlobals( 'wgShowEXIF', true );
00016 
00017         $this->backend = new FSFileBackend( array(
00018             'name' => 'localtesting',
00019             'wikiId' => wfWikiId(),
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 
00028         $this->handler = new JpegHandler;
00029     }
00030 
00031     public function testInvalidFile() {
00032         $file = $this->dataFile( 'README', 'image/jpeg' );
00033         $res = $this->handler->getMetadata( $file, $this->filePath . 'README' );
00034         $this->assertEquals( ExifBitmapHandler::BROKEN_FILE, $res );
00035     }
00036 
00037     public function testJpegMetadataExtraction() {
00038         $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
00039         $res = $this->handler->getMetadata( $file, $this->filePath . 'test.jpg' );
00040         $expected = 'a:7:{s:16:"ImageDescription";s:9:"Test file";s:11:"XResolution";s:4:"72/1";s:11:"YResolution";s:4:"72/1";s:14:"ResolutionUnit";i:2;s:16:"YCbCrPositioning";i:1;s:15:"JPEGFileComment";a:1:{i:0;s:17:"Created with GIMP";}s:22:"MEDIAWIKI_EXIF_VERSION";i:2;}';
00041 
00042         // Unserialize in case serialization format ever changes.
00043         $this->assertEquals( unserialize( $expected ), unserialize( $res ) );
00044     }
00045 
00049     public function testGetIndependentMetaArray() {
00050         $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
00051         $res = $this->handler->getCommonMetaArray( $file );
00052         $expected = array(
00053             'ImageDescription' => 'Test file',
00054             'XResolution' => '72/1',
00055             'YResolution' => '72/1',
00056             'ResolutionUnit' => 2,
00057             'YCbCrPositioning' => 1,
00058             'JPEGFileComment' => array(
00059                 'Created with GIMP',
00060             ),
00061         );
00062 
00063         $this->assertEquals( $res, $expected );
00064     }
00065 
00066     private function dataFile( $name, $type ) {
00067         return new UnregisteredLocalFile( false, $this->repo,
00068             "mwstore://localtesting/data/$name", $type );
00069     }
00070 }