MediaWiki  1.23.2
ExifBitmapTest.php
Go to the documentation of this file.
1 <?php
2 
4 
8  protected $handler;
9 
10  protected function setUp() {
11  parent::setUp();
12  $this->checkPHPExtension( 'exif' );
13 
14  $this->setMwGlobals( 'wgShowEXIF', true );
15 
16  $this->handler = new ExifBitmapHandler;
17 
18  }
19 
23  public function testIsOldBroken() {
24  $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::OLD_BROKEN_FILE );
25  $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
26  }
27 
31  public function testIsBrokenFile() {
32  $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::BROKEN_FILE );
33  $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
34  }
35 
39  public function testIsInvalid() {
40  $res = $this->handler->isMetadataValid( null, 'Something Invalid Here.' );
41  $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
42  }
43 
47  public function testGoodMetadata() {
48  $meta = 'a:16:{s:10:"ImageWidth";i:20;s:11:"ImageLength";i:20;s:13:"BitsPerSample";a:3:{i:0;i:8;i:1;i:8;i:2;i:8;}s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:16:"ImageDescription";s:17:"Created with GIMP";s:12:"StripOffsets";i:8;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:3;s:12:"RowsPerStrip";i:64;s:15:"StripByteCounts";i:238;s:11:"XResolution";s:19:"1207959552/16777216";s:11:"YResolution";s:19:"1207959552/16777216";s:19:"PlanarConfiguration";i:1;s:14:"ResolutionUnit";i:2;s:22:"MEDIAWIKI_EXIF_VERSION";i:2;}';
49  $res = $this->handler->isMetadataValid( null, $meta );
50  $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
51  }
52 
56  public function testIsOldGood() {
57  $meta = 'a:16:{s:10:"ImageWidth";i:20;s:11:"ImageLength";i:20;s:13:"BitsPerSample";a:3:{i:0;i:8;i:1;i:8;i:2;i:8;}s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:16:"ImageDescription";s:17:"Created with GIMP";s:12:"StripOffsets";i:8;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:3;s:12:"RowsPerStrip";i:64;s:15:"StripByteCounts";i:238;s:11:"XResolution";s:19:"1207959552/16777216";s:11:"YResolution";s:19:"1207959552/16777216";s:19:"PlanarConfiguration";i:1;s:14:"ResolutionUnit";i:2;s:22:"MEDIAWIKI_EXIF_VERSION";i:1;}';
58  $res = $this->handler->isMetadataValid( null, $meta );
59  $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
60  }
61 
66  public function testPagedTiffHandledGracefully() {
67  $meta = 'a:6:{s:9:"page_data";a:1:{i:1;a:5:{s:5:"width";i:643;s:6:"height";i:448;s:5:"alpha";s:4:"true";s:4:"page";i:1;s:6:"pixels";i:288064;}}s:10:"page_count";i:1;s:10:"first_page";i:1;s:9:"last_page";i:1;s:4:"exif";a:9:{s:10:"ImageWidth";i:643;s:11:"ImageLength";i:448;s:11:"Compression";i:5;s:25:"PhotometricInterpretation";i:2;s:11:"Orientation";i:1;s:15:"SamplesPerPixel";i:4;s:12:"RowsPerStrip";i:50;s:19:"PlanarConfiguration";i:1;s:22:"MEDIAWIKI_EXIF_VERSION";i:1;}s:21:"TIFF_METADATA_VERSION";s:3:"1.4";}';
68  $res = $this->handler->isMetadataValid( null, $meta );
69  $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
70  }
71 
75  public function testConvertMetadataLatest() {
76  $metadata = array(
77  'foo' => array( 'First', 'Second', '_type' => 'ol' ),
78  'MEDIAWIKI_EXIF_VERSION' => 2
79  );
80  $res = $this->handler->convertMetadataVersion( $metadata, 2 );
81  $this->assertEquals( $metadata, $res );
82  }
83 
87  public function testConvertMetadataToOld() {
88  $metadata = array(
89  'foo' => array( 'First', 'Second', '_type' => 'ol' ),
90  'bar' => array( 'First', 'Second', '_type' => 'ul' ),
91  'baz' => array( 'First', 'Second' ),
92  'fred' => 'Single',
93  'MEDIAWIKI_EXIF_VERSION' => 2,
94  );
95  $expected = array(
96  'foo' => "\n#First\n#Second",
97  'bar' => "\n*First\n*Second",
98  'baz' => "\n*First\n*Second",
99  'fred' => 'Single',
100  'MEDIAWIKI_EXIF_VERSION' => 1,
101  );
102  $res = $this->handler->convertMetadataVersion( $metadata, 1 );
103  $this->assertEquals( $expected, $res );
104  }
105 
109  public function testConvertMetadataSoftware() {
110  $metadata = array(
111  'Software' => array( array( 'GIMP', '1.1' ) ),
112  'MEDIAWIKI_EXIF_VERSION' => 2,
113  );
114  $expected = array(
115  'Software' => 'GIMP (Version 1.1)',
116  'MEDIAWIKI_EXIF_VERSION' => 1,
117  );
118  $res = $this->handler->convertMetadataVersion( $metadata, 1 );
119  $this->assertEquals( $expected, $res );
120  }
121 
125  public function testConvertMetadataSoftwareNormal() {
126  $metadata = array(
127  'Software' => array( "GIMP 1.2", "vim" ),
128  'MEDIAWIKI_EXIF_VERSION' => 2,
129  );
130  $expected = array(
131  'Software' => "\n*GIMP 1.2\n*vim",
132  'MEDIAWIKI_EXIF_VERSION' => 1,
133  );
134  $res = $this->handler->convertMetadataVersion( $metadata, 1 );
135  $this->assertEquals( $expected, $res );
136  }
137 }
ExifBitmapHandler
Stuff specific to JPEG and (built-in) TIFF handler.
Definition: ExifBitmap.php:30
ExifBitmapTest\testIsInvalid
testIsInvalid()
@covers ExifBitmapHandler::isMetadataValid
Definition: ExifBitmapTest.php:38
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
ExifBitmapTest\testIsBrokenFile
testIsBrokenFile()
@covers ExifBitmapHandler::isMetadataValid
Definition: ExifBitmapTest.php:30
ExifBitmapTest\testConvertMetadataSoftware
testConvertMetadataSoftware()
@covers ExifBitmapHandler::convertMetadataVersion
Definition: ExifBitmapTest.php:108
ExifBitmapTest\testConvertMetadataLatest
testConvertMetadataLatest()
@covers ExifBitmapHandler::convertMetadataVersion
Definition: ExifBitmapTest.php:74
MediaHandler\METADATA_COMPATIBLE
const METADATA_COMPATIBLE
Definition: MediaHandler.php:33
ExifBitmapTest\testConvertMetadataSoftwareNormal
testConvertMetadataSoftwareNormal()
@covers ExifBitmapHandler::convertMetadataVersion
Definition: ExifBitmapTest.php:124
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:302
MediaWikiTestCase
Definition: MediaWikiTestCase.php:6
ExifBitmapTest\testIsOldBroken
testIsOldBroken()
@covers ExifBitmapHandler::isMetadataValid
Definition: ExifBitmapTest.php:22
ExifBitmapTest\testPagedTiffHandledGracefully
testPagedTiffHandledGracefully()
Handle metadata from paged tiff handler (gotten via instant commons) gracefully.
Definition: ExifBitmapTest.php:65
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
ExifBitmapTest\testConvertMetadataToOld
testConvertMetadataToOld()
@covers ExifBitmapHandler::convertMetadataVersion
Definition: ExifBitmapTest.php:86
ExifBitmapTest
Definition: ExifBitmapTest.php:3
ExifBitmapTest\$handler
ExifBitmapHandler $handler
Definition: ExifBitmapTest.php:7
ExifBitmapTest\setUp
setUp()
Definition: ExifBitmapTest.php:9
ExifBitmapHandler\OLD_BROKEN_FILE
const OLD_BROKEN_FILE
Definition: ExifBitmap.php:32
MediaHandler\METADATA_BAD
const METADATA_BAD
Definition: MediaHandler.php:32
MediaWikiTestCase\checkPHPExtension
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
Definition: MediaWikiTestCase.php:1005
ExifBitmapTest\testIsOldGood
testIsOldGood()
@covers ExifBitmapHandler::isMetadataValid
Definition: ExifBitmapTest.php:55
ExifBitmapHandler\BROKEN_FILE
const BROKEN_FILE
Definition: ExifBitmap.php:31
$res
$res
Definition: database.txt:21
MediaHandler\METADATA_GOOD
const METADATA_GOOD
Definition: MediaHandler.php:31
ExifBitmapTest\testGoodMetadata
testGoodMetadata()
@covers ExifBitmapHandler::isMetadataValid
Definition: ExifBitmapTest.php:46