MediaWiki
REL1_22
|
00001 <?php 00002 00003 class IPTCTest extends MediaWikiTestCase { 00004 00008 public function testRecognizeUtf8() { 00009 // utf-8 is the only one used in practise. 00010 $res = IPTC::getCharset( "\x1b%G" ); 00011 $this->assertEquals( 'UTF-8', $res ); 00012 } 00013 00017 public function testIPTCParseNoCharset88591() { 00018 // basically IPTC for keyword with value of 0xBC which is 1/4 in iso-8859-1 00019 // This data doesn't specify a charset. We're supposed to guess 00020 // (which basically means utf-8 if valid, windows 1252 (iso 8859-1) if not) 00021 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x06\x1c\x02\x19\x00\x01\xBC"; 00022 $res = IPTC::Parse( $iptcData ); 00023 $this->assertEquals( array( '¼' ), $res['Keywords'] ); 00024 } 00025 00029 public function testIPTCParseNoCharset88591b() { 00030 /* This one contains a sequence that's valid iso 8859-1 but not valid utf8 */ 00031 /* \xC3 = Ã, \xB8 = ¸ */ 00032 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x09\x1c\x02\x19\x00\x04\xC3\xC3\xC3\xB8"; 00033 $res = IPTC::Parse( $iptcData ); 00034 $this->assertEquals( array( 'ÃÃø' ), $res['Keywords'] ); 00035 } 00036 00043 public function testIPTCParseForcedUTFButInvalid() { 00044 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x11\x1c\x02\x19\x00\x04\xC3\xC3\xC3\xB8" 00045 . "\x1c\x01\x5A\x00\x03\x1B\x25\x47"; 00046 $res = IPTC::Parse( $iptcData ); 00047 $this->assertEquals( array( 'ø' ), $res['Keywords'] ); 00048 } 00049 00053 public function testIPTCParseNoCharsetUTF8() { 00054 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x07\x1c\x02\x19\x00\x02¼"; 00055 $res = IPTC::Parse( $iptcData ); 00056 $this->assertEquals( array( '¼' ), $res['Keywords'] ); 00057 } 00058 00063 public function testIPTCParseMulti() { 00064 $iptcData = /* identifier */ "Photoshop 3.0\08BIM\4\4" 00065 /* length */ . "\0\0\0\0\0\x0D" 00066 . "\x1c\x02\x19" . "\x00\x01" . "\xBC" 00067 . "\x1c\x02\x19" . "\x00\x02" . "\xBC\xBD"; 00068 $res = IPTC::Parse( $iptcData ); 00069 $this->assertEquals( array( '¼', '¼½' ), $res['Keywords'] ); 00070 } 00071 00075 public function testIPTCParseUTF8() { 00076 // This has the magic "\x1c\x01\x5A\x00\x03\x1B\x25\x47" which marks content as UTF8. 00077 $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"; 00078 $res = IPTC::Parse( $iptcData ); 00079 $this->assertEquals( array( '¼' ), $res['Keywords'] ); 00080 } 00081 }