Localisation updates from https://translatewiki.net.
[mediawiki.git] / tests / phpunit / includes / media / ExifBitmapTest.php
blob0390edee82e8531935daca0de0af37fbac21aad4
1 <?php
3 use MediaWiki\MainConfigNames;
5 /**
6 * @group Media
7 * @covers \ExifBitmapHandler
8 * @requires extension exif
9 */
10 class ExifBitmapTest extends MediaWikiMediaTestCase {
12 /**
13 * @var ExifBitmapHandler
15 protected $handler;
17 protected function setUp(): void {
18 parent::setUp();
20 $this->overrideConfigValue( MainConfigNames::ShowEXIF, true );
22 $this->handler = new ExifBitmapHandler;
25 public static function provideIsFileMetadataValid() {
26 return [
27 'old broken' => [
28 ExifBitmapHandler::OLD_BROKEN_FILE,
29 ExifBitmapHandler::METADATA_COMPATIBLE
31 'broken' => [
32 ExifBitmapHandler::BROKEN_FILE,
33 ExifBitmapHandler::METADATA_GOOD
35 'invalid' => [
36 'Something Invalid Here.',
37 ExifBitmapHandler::METADATA_BAD
39 'good' => [
40 '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;}',
41 ExifBitmapHandler::METADATA_GOOD
43 'old good' => [
44 '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;}',
45 ExifBitmapHandler::METADATA_COMPATIBLE
47 // Handle metadata from paged tiff handler (gotten via instant commons) gracefully.
48 'paged tiff' => [
49 '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";}',
50 ExifBitmapHandler::METADATA_BAD
56 /** @dataProvider provideIsFileMetadataValid */
57 public function testIsFileMetadataValid( $serializedMetadata, $expected ) {
58 $file = $this->getMockFileWithMetadata( $serializedMetadata );
59 $res = $this->handler->isFileMetadataValid( $file );
60 $this->assertEquals( $expected, $res );
63 public function testConvertMetadataLatest() {
64 $metadata = [
65 'foo' => [ 'First', 'Second', '_type' => 'ol' ],
66 'MEDIAWIKI_EXIF_VERSION' => 2
68 $res = $this->handler->convertMetadataVersion( $metadata, 2 );
69 $this->assertEquals( $metadata, $res );
72 public function testConvertMetadataToOld() {
73 $metadata = [
74 'foo' => [ 'First', 'Second', '_type' => 'ol' ],
75 'bar' => [ 'First', 'Second', '_type' => 'ul' ],
76 'baz' => [ 'First', 'Second' ],
77 'fred' => 'Single',
78 'MEDIAWIKI_EXIF_VERSION' => 2,
80 $expected = [
81 'foo' => "\n#First\n#Second",
82 'bar' => "\n*First\n*Second",
83 'baz' => "\n*First\n*Second",
84 'fred' => 'Single',
85 'MEDIAWIKI_EXIF_VERSION' => 1,
87 $res = $this->handler->convertMetadataVersion( $metadata, 1 );
88 $this->assertEquals( $expected, $res );
91 public function testConvertMetadataSoftware() {
92 $metadata = [
93 'Software' => [ [ 'GIMP', '1.1' ] ],
94 'MEDIAWIKI_EXIF_VERSION' => 2,
96 $expected = [
97 'Software' => 'GIMP (Version 1.1)',
98 'MEDIAWIKI_EXIF_VERSION' => 1,
100 $res = $this->handler->convertMetadataVersion( $metadata, 1 );
101 $this->assertEquals( $expected, $res );
104 public function testConvertMetadataSoftwareNormal() {
105 $metadata = [
106 'Software' => [ "GIMP 1.2", "vim" ],
107 'MEDIAWIKI_EXIF_VERSION' => 2,
109 $expected = [
110 'Software' => "\n*GIMP 1.2\n*vim",
111 'MEDIAWIKI_EXIF_VERSION' => 1,
113 $res = $this->handler->convertMetadataVersion( $metadata, 1 );
114 $this->assertEquals( $expected, $res );