2 class JpegTest
extends MediaWikiTestCase
{
4 protected function setUp() {
6 if ( !extension_loaded( 'exif' ) ) {
7 $this->markTestSkipped( "This test needs the exif extension." );
10 $this->filePath
= __DIR__
. '/../../data/media/';
13 $this->setMwGlobals( 'wgShowEXIF', true );
15 $this->backend
= new FSFileBackend( array(
16 'name' => 'localtesting',
17 'lockManager' => 'nullLockManager',
18 'containerPaths' => array( 'data' => $this->filePath
)
20 $this->repo
= new FSRepo( array(
22 'url' => 'http://localhost/thumbtest',
23 'backend' => $this->backend
26 $this->handler
= new JpegHandler
;
29 public function testInvalidFile() {
30 $file = $this->dataFile( 'README', 'image/jpeg' );
31 $res = $this->handler
->getMetadata( $file, $this->filePath
. 'README' );
32 $this->assertEquals( ExifBitmapHandler
::BROKEN_FILE
, $res );
35 public function testJpegMetadataExtraction() {
36 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
37 $res = $this->handler
->getMetadata( $file, $this->filePath
. 'test.jpg' );
38 $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;}';
40 // Unserialize in case serialization format ever changes.
41 $this->assertEquals( unserialize( $expected ), unserialize( $res ) );
43 public function testGetIndependentMetaArray() {
44 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
45 $res = $this->handler
->getCommonMetaArray( $file );
47 'ImageDescription' => 'Test file',
48 'XResolution' => '72/1',
49 'YResolution' => '72/1',
50 'ResolutionUnit' => 2,
51 'YCbCrPositioning' => 1,
52 'JPEGFileComment' => array(
57 $this->assertEquals( $res, $expected );
60 private function dataFile( $name, $type ) {
61 return new UnregisteredLocalFile( false, $this->repo
,
62 "mwstore://localtesting/data/$name", $type );