Merge "Fix HTML output arround HTMLForm's submit buttons when in vform"
[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 $this->checkPHPExtension( 'exif' );
12
13 $this->filePath = __DIR__ . '/../../data/media/';
14
15 $this->setMwGlobals( 'wgShowEXIF', true );
16
17 $this->backend = new FSFileBackend( array(
18 'name' => 'localtesting',
19 'wikiId' => wfWikiId(),
20 'containerPaths' => array( 'data' => $this->filePath )
21 ) );
22 $this->repo = new FSRepo( array(
23 'name' => 'temp',
24 'url' => 'http://localhost/thumbtest',
25 'backend' => $this->backend
26 ) );
27
28 $this->handler = new JpegHandler;
29 }
30
31 public function testInvalidFile() {
32 $file = $this->dataFile( 'README', 'image/jpeg' );
33 $res = $this->handler->getMetadata( $file, $this->filePath . 'README' );
34 $this->assertEquals( ExifBitmapHandler::BROKEN_FILE, $res );
35 }
36
37 public function testJpegMetadataExtraction() {
38 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
39 $res = $this->handler->getMetadata( $file, $this->filePath . 'test.jpg' );
40 $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;}';
41
42 // Unserialize in case serialization format ever changes.
43 $this->assertEquals( unserialize( $expected ), unserialize( $res ) );
44 }
45
46 /**
47 * @covers JpegHandler::getCommonMetaArray
48 */
49 public function testGetIndependentMetaArray() {
50 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
51 $res = $this->handler->getCommonMetaArray( $file );
52 $expected = array(
53 'ImageDescription' => 'Test file',
54 'XResolution' => '72/1',
55 'YResolution' => '72/1',
56 'ResolutionUnit' => 2,
57 'YCbCrPositioning' => 1,
58 'JPEGFileComment' => array(
59 'Created with GIMP',
60 ),
61 );
62
63 $this->assertEquals( $res, $expected );
64 }
65
66 private function dataFile( $name, $type ) {
67 return new UnregisteredLocalFile( false, $this->repo,
68 "mwstore://localtesting/data/$name", $type );
69 }
70 }