Add an interface for getting "standard" file metadata.
[lhc/web/wiklou.git] / tests / phpunit / includes / media / JpegTest.php
1 <?php
2 class JpegTest extends MediaWikiTestCase {
3
4 protected function setUp() {
5 parent::setUp();
6 if ( !extension_loaded( 'exif' ) ) {
7 $this->markTestSkipped( "This test needs the exif extension." );
8 }
9
10 $this->filePath = __DIR__ . '/../../data/media/';
11
12
13 $this->setMwGlobals( 'wgShowEXIF', true );
14
15 $this->backend = new FSFileBackend( array(
16 'name' => 'localtesting',
17 'lockManager' => 'nullLockManager',
18 'containerPaths' => array( 'data' => $this->filePath )
19 ) );
20 $this->repo = new FSRepo( array(
21 'name' => 'temp',
22 'url' => 'http://localhost/thumbtest',
23 'backend' => $this->backend
24 ) );
25
26 $this->handler = new JpegHandler;
27 }
28
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 );
33 }
34
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;}';
39
40 // Unserialize in case serialization format ever changes.
41 $this->assertEquals( unserialize( $expected ), unserialize( $res ) );
42 }
43 public function testGetIndependentMetaArray() {
44 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
45 $res = $this->handler->getCommonMetaArray( $file );
46 $expected = array(
47 'ImageDescription' => 'Test file',
48 'XResolution' => '72/1',
49 'YResolution' => '72/1',
50 'ResolutionUnit' => 2,
51 'YCbCrPositioning' => 1,
52 'JPEGFileComment' => array(
53 'Created with GIMP',
54 ),
55 );
56
57 $this->assertEquals( $res, $expected );
58 }
59
60 private function dataFile( $name, $type ) {
61 return new UnregisteredLocalFile( false, $this->repo,
62 "mwstore://localtesting/data/$name", $type );
63 }
64 }