3 class ExifBitmapTest
extends MediaWikiTestCase
{
6 * @var ExifBitmapHandler
10 protected function setUp() {
12 $this->checkPHPExtension( 'exif' );
14 $this->setMwGlobals( 'wgShowEXIF', true );
16 $this->handler
= new ExifBitmapHandler
;
21 * @covers ExifBitmapHandler::isMetadataValid
23 public function testIsOldBroken() {
24 $res = $this->handler
->isMetadataValid( null, ExifBitmapHandler
::OLD_BROKEN_FILE
);
25 $this->assertEquals( ExifBitmapHandler
::METADATA_COMPATIBLE
, $res );
29 * @covers ExifBitmapHandler::isMetadataValid
31 public function testIsBrokenFile() {
32 $res = $this->handler
->isMetadataValid( null, ExifBitmapHandler
::BROKEN_FILE
);
33 $this->assertEquals( ExifBitmapHandler
::METADATA_GOOD
, $res );
37 * @covers ExifBitmapHandler::isMetadataValid
39 public function testIsInvalid() {
40 $res = $this->handler
->isMetadataValid( null, 'Something Invalid Here.' );
41 $this->assertEquals( ExifBitmapHandler
::METADATA_BAD
, $res );
45 * @covers ExifBitmapHandler::isMetadataValid
47 public function testGoodMetadata() {
48 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
49 $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;}';
50 // @codingStandardsIgnoreEnd
51 $res = $this->handler
->isMetadataValid( null, $meta );
52 $this->assertEquals( ExifBitmapHandler
::METADATA_GOOD
, $res );
56 * @covers ExifBitmapHandler::isMetadataValid
58 public function testIsOldGood() {
59 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
60 $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;}';
61 // @codingStandardsIgnoreEnd
62 $res = $this->handler
->isMetadataValid( null, $meta );
63 $this->assertEquals( ExifBitmapHandler
::METADATA_COMPATIBLE
, $res );
67 * Handle metadata from paged tiff handler (gotten via instant commons) gracefully.
68 * @covers ExifBitmapHandler::isMetadataValid
70 public function testPagedTiffHandledGracefully() {
71 // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
72 $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";}';
73 // @codingStandardsIgnoreEnd
74 $res = $this->handler
->isMetadataValid( null, $meta );
75 $this->assertEquals( ExifBitmapHandler
::METADATA_BAD
, $res );
79 * @covers ExifBitmapHandler::convertMetadataVersion
81 public function testConvertMetadataLatest() {
83 'foo' => array( 'First', 'Second', '_type' => 'ol' ),
84 'MEDIAWIKI_EXIF_VERSION' => 2
86 $res = $this->handler
->convertMetadataVersion( $metadata, 2 );
87 $this->assertEquals( $metadata, $res );
91 * @covers ExifBitmapHandler::convertMetadataVersion
93 public function testConvertMetadataToOld() {
95 'foo' => array( 'First', 'Second', '_type' => 'ol' ),
96 'bar' => array( 'First', 'Second', '_type' => 'ul' ),
97 'baz' => array( 'First', 'Second' ),
99 'MEDIAWIKI_EXIF_VERSION' => 2,
102 'foo' => "\n#First\n#Second",
103 'bar' => "\n*First\n*Second",
104 'baz' => "\n*First\n*Second",
106 'MEDIAWIKI_EXIF_VERSION' => 1,
108 $res = $this->handler
->convertMetadataVersion( $metadata, 1 );
109 $this->assertEquals( $expected, $res );
113 * @covers ExifBitmapHandler::convertMetadataVersion
115 public function testConvertMetadataSoftware() {
117 'Software' => array( array( 'GIMP', '1.1' ) ),
118 'MEDIAWIKI_EXIF_VERSION' => 2,
121 'Software' => 'GIMP (Version 1.1)',
122 'MEDIAWIKI_EXIF_VERSION' => 1,
124 $res = $this->handler
->convertMetadataVersion( $metadata, 1 );
125 $this->assertEquals( $expected, $res );
129 * @covers ExifBitmapHandler::convertMetadataVersion
131 public function testConvertMetadataSoftwareNormal() {
133 'Software' => array( "GIMP 1.2", "vim" ),
134 'MEDIAWIKI_EXIF_VERSION' => 2,
137 'Software' => "\n*GIMP 1.2\n*vim",
138 'MEDIAWIKI_EXIF_VERSION' => 1,
140 $res = $this->handler
->convertMetadataVersion( $metadata, 1 );
141 $this->assertEquals( $expected, $res );