test: coverage recording now needs to be explicit
[mediawiki.git] / tests / phpunit / includes / media / ExifBitmapTest.php
blob1109c478c2007c7d0726e2f13347dcb8af058dec
1 <?php
3 class ExifBitmapTest extends MediaWikiTestCase {
5 protected function setUp() {
6 parent::setUp();
8 $this->setMwGlobals( 'wgShowEXIF', true );
10 $this->handler = new ExifBitmapHandler;
11 if ( !wfDl( 'exif' ) ) {
12 $this->markTestSkipped( "This test needs the exif extension." );
16 public function testIsOldBroken() {
17 $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::OLD_BROKEN_FILE );
18 $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
21 public function testIsBrokenFile() {
22 $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::BROKEN_FILE );
23 $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
26 public function testIsInvalid() {
27 $res = $this->handler->isMetadataValid( null, 'Something Invalid Here.' );
28 $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
31 public function testGoodMetadata() {
32 $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;}';
33 $res = $this->handler->isMetadataValid( null, $meta );
34 $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
37 public function testIsOldGood() {
38 $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;}';
39 $res = $this->handler->isMetadataValid( null, $meta );
40 $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
43 // Handle metadata from paged tiff handler (gotten via instant commons)
44 // gracefully.
45 public function testPagedTiffHandledGracefully() {
46 $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";}';
47 $res = $this->handler->isMetadataValid( null, $meta );
48 $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
51 function testConvertMetadataLatest() {
52 $metadata = array(
53 'foo' => array( 'First', 'Second', '_type' => 'ol' ),
54 'MEDIAWIKI_EXIF_VERSION' => 2
56 $res = $this->handler->convertMetadataVersion( $metadata, 2 );
57 $this->assertEquals( $metadata, $res );
60 function testConvertMetadataToOld() {
61 $metadata = array(
62 'foo' => array( 'First', 'Second', '_type' => 'ol' ),
63 'bar' => array( 'First', 'Second', '_type' => 'ul' ),
64 'baz' => array( 'First', 'Second' ),
65 'fred' => 'Single',
66 'MEDIAWIKI_EXIF_VERSION' => 2,
68 $expected = array(
69 'foo' => "\n#First\n#Second",
70 'bar' => "\n*First\n*Second",
71 'baz' => "\n*First\n*Second",
72 'fred' => 'Single',
73 'MEDIAWIKI_EXIF_VERSION' => 1,
75 $res = $this->handler->convertMetadataVersion( $metadata, 1 );
76 $this->assertEquals( $expected, $res );
79 function testConvertMetadataSoftware() {
80 $metadata = array(
81 'Software' => array( array( 'GIMP', '1.1' ) ),
82 'MEDIAWIKI_EXIF_VERSION' => 2,
84 $expected = array(
85 'Software' => 'GIMP (Version 1.1)',
86 'MEDIAWIKI_EXIF_VERSION' => 1,
88 $res = $this->handler->convertMetadataVersion( $metadata, 1 );
89 $this->assertEquals( $expected, $res );
92 function testConvertMetadataSoftwareNormal() {
93 $metadata = array(
94 'Software' => array( "GIMP 1.2", "vim" ),
95 'MEDIAWIKI_EXIF_VERSION' => 2,
97 $expected = array(
98 'Software' => "\n*GIMP 1.2\n*vim",
99 'MEDIAWIKI_EXIF_VERSION' => 1,
101 $res = $this->handler->convertMetadataVersion( $metadata, 1 );
102 $this->assertEquals( $expected, $res );