MediaWiki
REL1_24
|
00001 <?php 00002 00006 class IPTCTest extends MediaWikiTestCase { 00007 00011 public function testRecognizeUtf8() { 00012 // utf-8 is the only one used in practise. 00013 $res = IPTC::getCharset( "\x1b%G" ); 00014 $this->assertEquals( 'UTF-8', $res ); 00015 } 00016 00020 public function testIPTCParseNoCharset88591() { 00021 // basically IPTC for keyword with value of 0xBC which is 1/4 in iso-8859-1 00022 // This data doesn't specify a charset. We're supposed to guess 00023 // (which basically means utf-8 if valid, windows 1252 (iso 8859-1) if not) 00024 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x06\x1c\x02\x19\x00\x01\xBC"; 00025 $res = IPTC::Parse( $iptcData ); 00026 $this->assertEquals( array( '¼' ), $res['Keywords'] ); 00027 } 00028 00032 public function testIPTCParseNoCharset88591b() { 00033 /* This one contains a sequence that's valid iso 8859-1 but not valid utf8 */ 00034 /* \xC3 = Ã, \xB8 = ¸ */ 00035 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x09\x1c\x02\x19\x00\x04\xC3\xC3\xC3\xB8"; 00036 $res = IPTC::Parse( $iptcData ); 00037 $this->assertEquals( array( 'ÃÃø' ), $res['Keywords'] ); 00038 } 00039 00046 public function testIPTCParseForcedUTFButInvalid() { 00047 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x11\x1c\x02\x19\x00\x04\xC3\xC3\xC3\xB8" 00048 . "\x1c\x01\x5A\x00\x03\x1B\x25\x47"; 00049 $res = IPTC::Parse( $iptcData ); 00050 $this->assertEquals( array( 'ø' ), $res['Keywords'] ); 00051 } 00052 00056 public function testIPTCParseNoCharsetUTF8() { 00057 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x07\x1c\x02\x19\x00\x02¼"; 00058 $res = IPTC::Parse( $iptcData ); 00059 $this->assertEquals( array( '¼' ), $res['Keywords'] ); 00060 } 00061 00066 public function testIPTCParseMulti() { 00067 $iptcData = /* identifier */ "Photoshop 3.0\08BIM\4\4" 00068 /* length */ . "\0\0\0\0\0\x0D" 00069 . "\x1c\x02\x19" . "\x00\x01" . "\xBC" 00070 . "\x1c\x02\x19" . "\x00\x02" . "\xBC\xBD"; 00071 $res = IPTC::Parse( $iptcData ); 00072 $this->assertEquals( array( '¼', '¼½' ), $res['Keywords'] ); 00073 } 00074 00078 public function testIPTCParseUTF8() { 00079 // This has the magic "\x1c\x01\x5A\x00\x03\x1B\x25\x47" which marks content as UTF8. 00080 $iptcData = 00081 "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"; 00082 $res = IPTC::Parse( $iptcData ); 00083 $this->assertEquals( array( '¼' ), $res['Keywords'] ); 00084 } 00085 }