6 class ExifBitmapTest
extends MediaWikiTestCase
{
9 * @var ExifBitmapHandler
13 protected function setUp() {
15 $this->checkPHPExtension( 'exif' );
17 $this->setMwGlobals( 'wgShowEXIF', true );
19 $this->handler
= new ExifBitmapHandler
;
24 * @covers ExifBitmapHandler::isMetadataValid
26 public function testIsOldBroken() {
27 $res = $this->handler
->isMetadataValid( null, ExifBitmapHandler
::OLD_BROKEN_FILE
);
28 $this->assertEquals( ExifBitmapHandler
::METADATA_COMPATIBLE
, $res );
32 * @covers ExifBitmapHandler::isMetadataValid
34 public function testIsBrokenFile() {
35 $res = $this->handler
->isMetadataValid( null, ExifBitmapHandler
::BROKEN_FILE
);
36 $this->assertEquals( ExifBitmapHandler
::METADATA_GOOD
, $res );
40 * @covers ExifBitmapHandler::isMetadataValid
42 public function testIsInvalid() {
43 $res = $this->handler
->isMetadataValid( null, 'Something Invalid Here.' );
44 $this->assertEquals( ExifBitmapHandler
::METADATA_BAD
, $res );
48 * @covers ExifBitmapHandler::isMetadataValid
50 public function testGoodMetadata() {
51 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
52 $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;}';
53 // @codingStandardsIgnoreEnd
54 $res = $this->handler
->isMetadataValid( null, $meta );
55 $this->assertEquals( ExifBitmapHandler
::METADATA_GOOD
, $res );
59 * @covers ExifBitmapHandler::isMetadataValid
61 public function testIsOldGood() {
62 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
63 $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;}';
64 // @codingStandardsIgnoreEnd
65 $res = $this->handler
->isMetadataValid( null, $meta );
66 $this->assertEquals( ExifBitmapHandler
::METADATA_COMPATIBLE
, $res );
70 * Handle metadata from paged tiff handler (gotten via instant commons) gracefully.
71 * @covers ExifBitmapHandler::isMetadataValid
73 public function testPagedTiffHandledGracefully() {
74 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
75 $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";}';
76 // @codingStandardsIgnoreEnd
77 $res = $this->handler
->isMetadataValid( null, $meta );
78 $this->assertEquals( ExifBitmapHandler
::METADATA_BAD
, $res );
82 * @covers ExifBitmapHandler::convertMetadataVersion
84 public function testConvertMetadataLatest() {
86 'foo' => array( 'First', 'Second', '_type' => 'ol' ),
87 'MEDIAWIKI_EXIF_VERSION' => 2
89 $res = $this->handler
->convertMetadataVersion( $metadata, 2 );
90 $this->assertEquals( $metadata, $res );
94 * @covers ExifBitmapHandler::convertMetadataVersion
96 public function testConvertMetadataToOld() {
98 'foo' => array( 'First', 'Second', '_type' => 'ol' ),
99 'bar' => array( 'First', 'Second', '_type' => 'ul' ),
100 'baz' => array( 'First', 'Second' ),
102 'MEDIAWIKI_EXIF_VERSION' => 2,
105 'foo' => "\n#First\n#Second",
106 'bar' => "\n*First\n*Second",
107 'baz' => "\n*First\n*Second",
109 'MEDIAWIKI_EXIF_VERSION' => 1,
111 $res = $this->handler
->convertMetadataVersion( $metadata, 1 );
112 $this->assertEquals( $expected, $res );
116 * @covers ExifBitmapHandler::convertMetadataVersion
118 public function testConvertMetadataSoftware() {
120 'Software' => array( array( 'GIMP', '1.1' ) ),
121 'MEDIAWIKI_EXIF_VERSION' => 2,
124 'Software' => 'GIMP (Version 1.1)',
125 'MEDIAWIKI_EXIF_VERSION' => 1,
127 $res = $this->handler
->convertMetadataVersion( $metadata, 1 );
128 $this->assertEquals( $expected, $res );
132 * @covers ExifBitmapHandler::convertMetadataVersion
134 public function testConvertMetadataSoftwareNormal() {
136 'Software' => array( "GIMP 1.2", "vim" ),
137 'MEDIAWIKI_EXIF_VERSION' => 2,
140 'Software' => "\n*GIMP 1.2\n*vim",
141 'MEDIAWIKI_EXIF_VERSION' => 1,
143 $res = $this->handler
->convertMetadataVersion( $metadata, 1 );
144 $this->assertEquals( $expected, $res );