MediaWiki  1.30.0
ExifBitmapTest.php
Go to the documentation of this file.
1 <?php
2 
7 
11  protected $handler;
12 
13  protected function setUp() {
14  parent::setUp();
15  $this->checkPHPExtension( 'exif' );
16 
17  $this->setMwGlobals( 'wgShowEXIF', true );
18 
19  $this->handler = new ExifBitmapHandler;
20  }
21 
25  public function testIsOldBroken() {
26  $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::OLD_BROKEN_FILE );
27  $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
28  }
29 
33  public function testIsBrokenFile() {
34  $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::BROKEN_FILE );
35  $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
36  }
37 
41  public function testIsInvalid() {
42  $res = $this->handler->isMetadataValid( null, 'Something Invalid Here.' );
43  $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
44  }
45 
49  public function testGoodMetadata() {
50  // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
51  $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;}';
52  // @codingStandardsIgnoreEnd
53  $res = $this->handler->isMetadataValid( null, $meta );
54  $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
55  }
56 
60  public function testIsOldGood() {
61  // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
62  $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;}';
63  // @codingStandardsIgnoreEnd
64  $res = $this->handler->isMetadataValid( null, $meta );
65  $this->assertEquals( ExifBitmapHandler::METADATA_COMPATIBLE, $res );
66  }
67 
72  public function testPagedTiffHandledGracefully() {
73  // @codingStandardsIgnoreStart Ignore Generic.Files.LineLength.TooLong
74  $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";}';
75  // @codingStandardsIgnoreEnd
76  $res = $this->handler->isMetadataValid( null, $meta );
77  $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
78  }
79 
83  public function testConvertMetadataLatest() {
84  $metadata = [
85  'foo' => [ 'First', 'Second', '_type' => 'ol' ],
86  'MEDIAWIKI_EXIF_VERSION' => 2
87  ];
88  $res = $this->handler->convertMetadataVersion( $metadata, 2 );
89  $this->assertEquals( $metadata, $res );
90  }
91 
95  public function testConvertMetadataToOld() {
96  $metadata = [
97  'foo' => [ 'First', 'Second', '_type' => 'ol' ],
98  'bar' => [ 'First', 'Second', '_type' => 'ul' ],
99  'baz' => [ 'First', 'Second' ],
100  'fred' => 'Single',
101  'MEDIAWIKI_EXIF_VERSION' => 2,
102  ];
103  $expected = [
104  'foo' => "\n#First\n#Second",
105  'bar' => "\n*First\n*Second",
106  'baz' => "\n*First\n*Second",
107  'fred' => 'Single',
108  'MEDIAWIKI_EXIF_VERSION' => 1,
109  ];
110  $res = $this->handler->convertMetadataVersion( $metadata, 1 );
111  $this->assertEquals( $expected, $res );
112  }
113 
117  public function testConvertMetadataSoftware() {
118  $metadata = [
119  'Software' => [ [ 'GIMP', '1.1' ] ],
120  'MEDIAWIKI_EXIF_VERSION' => 2,
121  ];
122  $expected = [
123  'Software' => 'GIMP (Version 1.1)',
124  'MEDIAWIKI_EXIF_VERSION' => 1,
125  ];
126  $res = $this->handler->convertMetadataVersion( $metadata, 1 );
127  $this->assertEquals( $expected, $res );
128  }
129 
134  $metadata = [
135  'Software' => [ "GIMP 1.2", "vim" ],
136  'MEDIAWIKI_EXIF_VERSION' => 2,
137  ];
138  $expected = [
139  'Software' => "\n*GIMP 1.2\n*vim",
140  'MEDIAWIKI_EXIF_VERSION' => 1,
141  ];
142  $res = $this->handler->convertMetadataVersion( $metadata, 1 );
143  $this->assertEquals( $expected, $res );
144  }
145 }
ExifBitmapHandler
Stuff specific to JPEG and (built-in) TIFF handler.
Definition: ExifBitmap.php:30
ExifBitmapTest\testIsInvalid
testIsInvalid()
ExifBitmapHandler::isMetadataValid.
Definition: ExifBitmapTest.php:41
ExifBitmapTest\testIsBrokenFile
testIsBrokenFile()
ExifBitmapHandler::isMetadataValid.
Definition: ExifBitmapTest.php:33
ExifBitmapTest\testConvertMetadataSoftware
testConvertMetadataSoftware()
ExifBitmapHandler::convertMetadataVersion.
Definition: ExifBitmapTest.php:117
ExifBitmapTest\testConvertMetadataLatest
testConvertMetadataLatest()
ExifBitmapHandler::convertMetadataVersion.
Definition: ExifBitmapTest.php:83
$res
$res
Definition: database.txt:21
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
MediaWikiMediaTestCase
Specificly for testing Media handlers.
Definition: MediaWikiMediaTestCase.php:5
handler
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves set to a MediaTransformOutput the error message to be returned in an array you should do so by altering $wgNamespaceProtection and $wgNamespaceContentModels outside the handler
Definition: hooks.txt:781
MediaHandler\METADATA_COMPATIBLE
const METADATA_COMPATIBLE
Definition: MediaHandler.php:34
ExifBitmapTest\testConvertMetadataSoftwareNormal
testConvertMetadataSoftwareNormal()
ExifBitmapHandler::convertMetadataVersion.
Definition: ExifBitmapTest.php:133
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:672
ExifBitmapTest\testIsOldBroken
testIsOldBroken()
ExifBitmapHandler::isMetadataValid.
Definition: ExifBitmapTest.php:25
ExifBitmapTest\testPagedTiffHandledGracefully
testPagedTiffHandledGracefully()
Handle metadata from paged tiff handler (gotten via instant commons) gracefully.
Definition: ExifBitmapTest.php:72
ExifBitmapTest\testConvertMetadataToOld
testConvertMetadataToOld()
ExifBitmapHandler::convertMetadataVersion.
Definition: ExifBitmapTest.php:95
ExifBitmapTest
Media.
Definition: ExifBitmapTest.php:6
ExifBitmapTest\$handler
ExifBitmapHandler $handler
Definition: ExifBitmapTest.php:11
ExifBitmapTest\setUp
setUp()
Definition: ExifBitmapTest.php:13
ExifBitmapHandler\OLD_BROKEN_FILE
const OLD_BROKEN_FILE
Definition: ExifBitmap.php:32
MediaHandler\METADATA_BAD
const METADATA_BAD
Definition: MediaHandler.php:33
MediaWikiTestCase\checkPHPExtension
checkPHPExtension( $extName)
Check if $extName is a loaded PHP extension, will skip the test whenever it is not loaded.
Definition: MediaWikiTestCase.php:1770
ExifBitmapTest\testIsOldGood
testIsOldGood()
ExifBitmapHandler::isMetadataValid.
Definition: ExifBitmapTest.php:60
ExifBitmapHandler\BROKEN_FILE
const BROKEN_FILE
Definition: ExifBitmap.php:31
MediaHandler\METADATA_GOOD
const METADATA_GOOD
Definition: MediaHandler.php:32
ExifBitmapTest\testGoodMetadata
testGoodMetadata()
ExifBitmapHandler::isMetadataValid.
Definition: ExifBitmapTest.php:49