Merge "Introduce ContentHandler::exportTransform()"
[lhc/web/wiklou.git] / tests / phpunit / includes / media / JpegTest.php
1 <?php
2 /**
3 * @covers JpegHandler
4 */
5 class JpegTest extends MediaWikiMediaTestCase {
6
7 protected function setUp() {
8 parent::setUp();
9 $this->checkPHPExtension( 'exif' );
10
11 $this->setMwGlobals( 'wgShowEXIF', true );
12
13 $this->handler = new JpegHandler;
14 }
15
16 public function testInvalidFile() {
17 $file = $this->dataFile( 'README', 'image/jpeg' );
18 $res = $this->handler->getMetadata( $file, $this->filePath . 'README' );
19 $this->assertEquals( ExifBitmapHandler::BROKEN_FILE, $res );
20 }
21
22 public function testJpegMetadataExtraction() {
23 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
24 $res = $this->handler->getMetadata( $file, $this->filePath . 'test.jpg' );
25 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
26 $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;}';
27 // @codingStandardsIgnoreEnd
28
29 // Unserialize in case serialization format ever changes.
30 $this->assertEquals( unserialize( $expected ), unserialize( $res ) );
31 }
32
33 /**
34 * @covers JpegHandler::getCommonMetaArray
35 */
36 public function testGetIndependentMetaArray() {
37 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
38 $res = $this->handler->getCommonMetaArray( $file );
39 $expected = array(
40 'ImageDescription' => 'Test file',
41 'XResolution' => '72/1',
42 'YResolution' => '72/1',
43 'ResolutionUnit' => 2,
44 'YCbCrPositioning' => 1,
45 'JPEGFileComment' => array(
46 'Created with GIMP',
47 ),
48 );
49
50 $this->assertEquals( $res, $expected );
51 }
52 }