Make partial dates in XMP not have the ommitted fields fulled out to 1's (reported...
[lhc/web/wiklou.git] / tests / phpunit / includes / media / IPTCTest.php
1 <?php
2 class IPTCTest extends MediaWikiTestCase {
3 public function testRecognizeUtf8() {
4 // utf-8 is the only one used in practise.
5 $res = IPTC::getCharset( "\x1b%G" );
6 $this->assertEquals( 'UTF-8', $res );
7 }
8
9 public function testIPTCParseNoCharset88591() {
10 // basically IPTC for keyword with value of 0xBC which is 1/4 in iso-8859-1
11 // This data doesn't specify a charset. We're supposed to guess
12 // (which basically means utf-8 if valid, windows 1252 (iso 8859-1) if not)
13 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x06\x1c\x02\x19\x00\x01\xBC";
14 $res = IPTC::Parse( $iptcData );
15 $this->assertEquals( array( '¼' ), $res['Keywords'] );
16 }
17 /* This one contains a sequence that's valid iso 8859-1 but not valid utf8 */
18 /* \xC3 = Ã, \xB8 = ¸ */
19 public function testIPTCParseNoCharset88591b() {
20 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x09\x1c\x02\x19\x00\x04\xC3\xC3\xC3\xB8";
21 $res = IPTC::Parse( $iptcData );
22 $this->assertEquals( array( 'ÃÃø' ), $res['Keywords'] );
23 }
24 /* Same as testIPTCParseNoCharset88591b, but forcing the charset to utf-8.
25 * What should happen is the first "\xC3\xC3" should be dropped as invalid,
26 * leaving \xC3\xB8, which is ø
27 */
28 public function testIPTCParseForcedUTFButInvalid() {
29 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x11\x1c\x02\x19\x00\x04\xC3\xC3\xC3\xB8"
30 . "\x1c\x01\x5A\x00\x03\x1B\x25\x47";
31 $res = IPTC::Parse( $iptcData );
32 $this->assertEquals( array( 'ø' ), $res['Keywords'] );
33 }
34 public function testIPTCParseNoCharsetUTF8() {
35 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x07\x1c\x02\x19\x00\x02¼";
36 $res = IPTC::Parse( $iptcData );
37 $this->assertEquals( array( '¼' ), $res['Keywords'] );
38 }
39 // Testing something that has 2 values for keyword
40 public function testIPTCParseMulti() {
41 $iptcData = /* identifier */ "Photoshop 3.0\08BIM\4\4"
42 /* length */ . "\0\0\0\0\0\x0D"
43 . "\x1c\x02\x19" . "\x00\x01" . "\xBC"
44 . "\x1c\x02\x19" . "\x00\x02" . "\xBC\xBD";
45 $res = IPTC::Parse( $iptcData );
46 $this->assertEquals( array( '¼', '¼½' ), $res['Keywords'] );
47 }
48 public function testIPTCParseUTF8() {
49 // This has the magic "\x1c\x01\x5A\x00\x03\x1B\x25\x47" which marks content as UTF8.
50 $iptcData = "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";
51 $res = IPTC::Parse( $iptcData );
52 $this->assertEquals( array( '¼' ), $res['Keywords'] );
53 }
54
55 }