MediaWiki  REL1_19
IPTCTest.php
Go to the documentation of this file.
00001 <?php
00002 class IPTCTest extends MediaWikiTestCase {
00003         public function testRecognizeUtf8() {
00004                 // utf-8 is the only one used in practise.
00005                 $res = IPTC::getCharset( "\x1b%G" );
00006                 $this->assertEquals( 'UTF-8', $res );
00007         }
00008 
00009         public function testIPTCParseNoCharset88591() {
00010                 // basically IPTC for keyword with value of 0xBC which is 1/4 in iso-8859-1
00011                 // This data doesn't specify a charset. We're supposed to guess
00012                 // (which basically means utf-8 if valid, windows 1252 (iso 8859-1) if not)
00013                 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x06\x1c\x02\x19\x00\x01\xBC";
00014                 $res = IPTC::Parse( $iptcData );
00015                 $this->assertEquals( array( '¼' ), $res['Keywords'] );
00016         }
00017         /* This one contains a sequence that's valid iso 8859-1 but not valid utf8 */
00018         /* \xC3 = Ã, \xB8 = ¸  */
00019         public function testIPTCParseNoCharset88591b() {
00020                 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x09\x1c\x02\x19\x00\x04\xC3\xC3\xC3\xB8";
00021                 $res = IPTC::Parse( $iptcData );
00022                 $this->assertEquals( array( 'ÃÃø' ), $res['Keywords'] );
00023         }
00024         /* Same as testIPTCParseNoCharset88591b, but forcing the charset to utf-8.
00025          * What should happen is the first "\xC3\xC3" should be dropped as invalid,
00026          * leaving \xC3\xB8, which is ø
00027          */
00028         public function testIPTCParseForcedUTFButInvalid() {
00029                 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x11\x1c\x02\x19\x00\x04\xC3\xC3\xC3\xB8"
00030                         . "\x1c\x01\x5A\x00\x03\x1B\x25\x47";
00031                 $res = IPTC::Parse( $iptcData );
00032                 $this->assertEquals( array( 'ø' ), $res['Keywords'] );
00033         }
00034         public function testIPTCParseNoCharsetUTF8() {
00035                 $iptcData = "Photoshop 3.0\08BIM\4\4\0\0\0\0\0\x07\x1c\x02\x19\x00\x02¼";
00036                 $res = IPTC::Parse( $iptcData );
00037                 $this->assertEquals( array( '¼' ), $res['Keywords'] );
00038         }
00039         // Testing something that has 2 values for keyword
00040         public function testIPTCParseMulti() {
00041                 $iptcData = /* identifier */ "Photoshop 3.0\08BIM\4\4"
00042                         /* length */ . "\0\0\0\0\0\x0D"
00043                         . "\x1c\x02\x19" . "\x00\x01" . "\xBC"
00044                         . "\x1c\x02\x19" . "\x00\x02" . "\xBC\xBD";
00045                 $res = IPTC::Parse( $iptcData );
00046                 $this->assertEquals( array( '¼', '¼½' ), $res['Keywords'] );
00047         }
00048         public function testIPTCParseUTF8() {
00049                 // This has the magic "\x1c\x01\x5A\x00\x03\x1B\x25\x47" which marks content as UTF8.
00050                 $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";
00051                 $res = IPTC::Parse( $iptcData );
00052                 $this->assertEquals( array( '¼' ), $res['Keywords'] );
00053         }
00054 
00055 }