5 class JpegTest
extends MediaWikiTestCase
{
9 protected function setUp() {
11 $this->checkPHPExtension( 'exif' );
13 $this->filePath
= __DIR__
. '/../../data/media/';
15 $this->setMwGlobals( 'wgShowEXIF', true );
17 $this->backend
= new FSFileBackend( array(
18 'name' => 'localtesting',
19 'wikiId' => wfWikiId(),
20 'containerPaths' => array( 'data' => $this->filePath
)
22 $this->repo
= new FSRepo( array(
24 'url' => 'http://localhost/thumbtest',
25 'backend' => $this->backend
28 $this->handler
= new JpegHandler
;
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 );
37 public function testJpegMetadataExtraction() {
38 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
39 $res = $this->handler
->getMetadata( $file, $this->filePath
. 'test.jpg' );
40 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
41 $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;}';
42 // @codingStandardsIgnoreEnd
44 // Unserialize in case serialization format ever changes.
45 $this->assertEquals( unserialize( $expected ), unserialize( $res ) );
49 * @covers JpegHandler::getCommonMetaArray
51 public function testGetIndependentMetaArray() {
52 $file = $this->dataFile( 'test.jpg', 'image/jpeg' );
53 $res = $this->handler
->getCommonMetaArray( $file );
55 'ImageDescription' => 'Test file',
56 'XResolution' => '72/1',
57 'YResolution' => '72/1',
58 'ResolutionUnit' => 2,
59 'YCbCrPositioning' => 1,
60 'JPEGFileComment' => array(
65 $this->assertEquals( $res, $expected );
68 private function dataFile( $name, $type ) {
69 return new UnregisteredLocalFile( false, $this->repo
,
70 "mwstore://localtesting/data/$name", $type );