Merge "Add debug logging for the case that the API goes read only"
[lhc/web/wiklou.git] / tests / phpunit / includes / media / IPTCTest.php
1 <?php
2
3 /**
4 * @group Media
5 */
6 class IPTCTest extends MediaWikiTestCase {
7
8 /**
9 * @covers IPTC::getCharset
10 */
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 );
15 }
16
17 /**
18 * @covers IPTC::Parse
19 */
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( array( '¼' ), $res['Keywords'] );
27 }
28
29 /**
30 * @covers IPTC::Parse
31 */
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( array( 'ÃÃø' ), $res['Keywords'] );
38 }
39
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
45 */
46 public function testIPTCParseForcedUTFButInvalid() {
47 if ( version_compare( PHP_VERSION, '5.5.26', '<' ) ) {
48 $this->markTestSkipped( 'Test fails on pre-PHP 5.5.25. See T124574/T39665 for details.' );
49 }
50 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x11\x1c\x02\x19\x00\x04\xC3\xC3\xC3\xB8"
51 . "\x1c\x01\x5A\x00\x03\x1B\x25\x47";
52 $res = IPTC::Parse( $iptcData );
53 $this->assertEquals( array( 'ø' ), $res['Keywords'] );
54 }
55
56 /**
57 * @covers IPTC::Parse
58 */
59 public function testIPTCParseNoCharsetUTF8() {
60 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x07\x1c\x02\x19\x00\x02¼";
61 $res = IPTC::Parse( $iptcData );
62 $this->assertEquals( array( '¼' ), $res['Keywords'] );
63 }
64
65 /**
66 * Testing something that has 2 values for keyword
67 * @covers IPTC::Parse
68 */
69 public function testIPTCParseMulti() {
70 $iptcData = /* identifier */ "Photoshop 3.0\08BIM\4\4"
71 /* length */ . "\0\0\0\0\0\x0D"
72 . "\x1c\x02\x19" . "\x00\x01" . "\xBC"
73 . "\x1c\x02\x19" . "\x00\x02" . "\xBC\xBD";
74 $res = IPTC::Parse( $iptcData );
75 $this->assertEquals( array( '¼', '¼½' ), $res['Keywords'] );
76 }
77
78 /**
79 * @covers IPTC::Parse
80 */
81 public function testIPTCParseUTF8() {
82 // This has the magic "\x1c\x01\x5A\x00\x03\x1B\x25\x47" which marks content as UTF8.
83 $iptcData =
84 "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";
85 $res = IPTC::Parse( $iptcData );
86 $this->assertEquals( array( '¼' ), $res['Keywords'] );
87 }
88 }