Remove messages.inc, rebuildLanguage.php, writeMessagesArray.inc
[mediawiki.git] / tests / phpunit / includes / media / ExifBitmapTest.php
blob44b20702bf54fd4e83241e2df6afa6f7288b9a3f
1 <?php
3 class ExifBitmapTest extends MediaWikiTestCase {
5 /**
6 * @var ExifBitmapHandler
7 */
8 protected $handler;
10 protected function setUp() {
11 parent::setUp();
12 $this->checkPHPExtension( 'exif' );
14 $this->setMwGlobals( 'wgShowEXIF', true );
16 $this->handler = new ExifBitmapHandler;
20 /**
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 );
28 /**
29 * @covers ExifBitmapHandler::isMetadataValid
31 public function testIsBrokenFile() {
32 $res = $this->handler->isMetadataValid( null, ExifBitmapHandler::BROKEN_FILE );
33 $this->assertEquals( ExifBitmapHandler::METADATA_GOOD, $res );
36 /**
37 * @covers ExifBitmapHandler::isMetadataValid
39 public function testIsInvalid() {
40 $res = $this->handler->isMetadataValid( null, 'Something Invalid Here.' );
41 $this->assertEquals( ExifBitmapHandler::METADATA_BAD, $res );
44 /**
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 );
55 /**
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 );
66 /**
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 );
78 /**
79 * @covers ExifBitmapHandler::convertMetadataVersion
81 public function testConvertMetadataLatest() {
82 $metadata = array(
83 'foo' => array( 'First', 'Second', '_type' => 'ol' ),
84 'MEDIAWIKI_EXIF_VERSION' => 2
86 $res = $this->handler->convertMetadataVersion( $metadata, 2 );
87 $this->assertEquals( $metadata, $res );
90 /**
91 * @covers ExifBitmapHandler::convertMetadataVersion
93 public function testConvertMetadataToOld() {
94 $metadata = array(
95 'foo' => array( 'First', 'Second', '_type' => 'ol' ),
96 'bar' => array( 'First', 'Second', '_type' => 'ul' ),
97 'baz' => array( 'First', 'Second' ),
98 'fred' => 'Single',
99 'MEDIAWIKI_EXIF_VERSION' => 2,
101 $expected = array(
102 'foo' => "\n#First\n#Second",
103 'bar' => "\n*First\n*Second",
104 'baz' => "\n*First\n*Second",
105 'fred' => 'Single',
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() {
116 $metadata = array(
117 'Software' => array( array( 'GIMP', '1.1' ) ),
118 'MEDIAWIKI_EXIF_VERSION' => 2,
120 $expected = array(
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() {
132 $metadata = array(
133 'Software' => array( "GIMP 1.2", "vim" ),
134 'MEDIAWIKI_EXIF_VERSION' => 2,
136 $expected = array(
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 );