Added release notes for 'ContentHandler::runLegacyHooks' removal
[mediawiki.git] / tests / phpunit / includes / media / IPTCTest.php
blob826957ecb1ac8882b7a250af9a36f586148c9d84
1 <?php
3 /**
4 * @group Media
5 */
6 class IPTCTest extends MediaWikiTestCase {
8 /**
9 * @covers IPTC::getCharset
11 public function testRecognizeUtf8() {
12 // utf-8 is the only one used in practise.
13 $res = IPTC::getCharset( "\x1b%G" );
14 $this->assertEquals( 'UTF-8', $res );
17 /**
18 * @covers IPTC::parse
20 public function testIPTCParseNoCharset88591() {
21 // basically IPTC for keyword with value of 0xBC which is 1/4 in iso-8859-1
22 // This data doesn't specify a charset. We're supposed to guess
23 // (which basically means utf-8 if valid, windows 1252 (iso 8859-1) if not)
24 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x06\x1c\x02\x19\x00\x01\xBC";
25 $res = IPTC::parse( $iptcData );
26 $this->assertEquals( [ '¼' ], $res['Keywords'] );
29 /**
30 * @covers IPTC::parse
32 public function testIPTCParseNoCharset88591b() {
33 /* This one contains a sequence that's valid iso 8859-1 but not valid utf8 */
34 /* \xC3 = Ã, \xB8 = ¸ */
35 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x09\x1c\x02\x19\x00\x04\xC3\xC3\xC3\xB8";
36 $res = IPTC::parse( $iptcData );
37 $this->assertEquals( [ 'ÃÃø' ], $res['Keywords'] );
40 /**
41 * Same as testIPTCParseNoCharset88591b, but forcing the charset to utf-8.
42 * What should happen is the first "\xC3\xC3" should be dropped as invalid,
43 * leaving \xC3\xB8, which is ø
44 * @covers IPTC::parse
46 public function testIPTCParseForcedUTFButInvalid() {
47 if ( version_compare( PHP_VERSION, '5.5.26', '<' )
48 || ( version_compare( PHP_VERSION, '5.6.0', '>' )
49 && version_compare( PHP_VERSION, '5.6.10', '<' )
51 ) {
52 $this->markTestSkipped( 'Test fails on pre-PHP 5.5.25. See T124574/T39665 for details.' );
54 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x11\x1c\x02\x19\x00\x04\xC3\xC3\xC3\xB8"
55 . "\x1c\x01\x5A\x00\x03\x1B\x25\x47";
56 $res = IPTC::parse( $iptcData );
57 $this->assertEquals( [ 'ø' ], $res['Keywords'] );
60 /**
61 * @covers IPTC::parse
63 public function testIPTCParseNoCharsetUTF8() {
64 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x07\x1c\x02\x19\x00\x02¼";
65 $res = IPTC::parse( $iptcData );
66 $this->assertEquals( [ '¼' ], $res['Keywords'] );
69 /**
70 * Testing something that has 2 values for keyword
71 * @covers IPTC::parse
73 public function testIPTCParseMulti() {
74 $iptcData = /* identifier */ "Photoshop 3.0\08BIM\4\4"
75 /* length */ . "\0\0\0\0\0\x0D"
76 . "\x1c\x02\x19" . "\x00\x01" . "\xBC"
77 . "\x1c\x02\x19" . "\x00\x02" . "\xBC\xBD";
78 $res = IPTC::parse( $iptcData );
79 $this->assertEquals( [ '¼', '¼½' ], $res['Keywords'] );
82 /**
83 * @covers IPTC::parse
85 public function testIPTCParseUTF8() {
86 // This has the magic "\x1c\x01\x5A\x00\x03\x1B\x25\x47" which marks content as UTF8.
87 $iptcData =
88 "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x0F\x1c\x02\x19\x00\x02¼\x1c\x01\x5A\x00\x03\x1B\x25\x47";
89 $res = IPTC::parse( $iptcData );
90 $this->assertEquals( [ '¼' ], $res['Keywords'] );