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