1<?php 2 3namespace Sabre\VObject\Parser; 4 5/** 6 * Note that most MimeDir related tests can actually be found in the ReaderTest 7 * class one level up. 8 */ 9class MimeDirTest extends \PHPUnit_Framework_TestCase { 10 11 /** 12 * @expectedException \Sabre\VObject\ParseException 13 */ 14 function testParseError() { 15 16 $mimeDir = new MimeDir(); 17 $mimeDir->parse(fopen(__FILE__, 'a')); 18 19 } 20 21 function testDecodeLatin1() { 22 23 $vcard = <<<VCF 24BEGIN:VCARD 25VERSION:3.0 26FN:umlaut u - \xFC 27END:VCARD\n 28VCF; 29 30 $mimeDir = new MimeDir(); 31 $mimeDir->setCharset('ISO-8859-1'); 32 $vcard = $mimeDir->parse($vcard); 33 $this->assertEquals("umlaut u - \xC3\xBC", $vcard->FN->getValue()); 34 35 } 36 37 function testDecodeInlineLatin1() { 38 39 $vcard = <<<VCF 40BEGIN:VCARD 41VERSION:2.1 42FN;CHARSET=ISO-8859-1:umlaut u - \xFC 43END:VCARD\n 44VCF; 45 46 $mimeDir = new MimeDir(); 47 $vcard = $mimeDir->parse($vcard); 48 $this->assertEquals("umlaut u - \xC3\xBC", $vcard->FN->getValue()); 49 50 } 51 52 function testIgnoreCharsetVCard30() { 53 54 $vcard = <<<VCF 55BEGIN:VCARD 56VERSION:3.0 57FN;CHARSET=unknown:foo-bar - \xFC 58END:VCARD\n 59VCF; 60 61 $mimeDir = new MimeDir(); 62 $vcard = $mimeDir->parse($vcard); 63 $this->assertEquals("foo-bar - \xFC", $vcard->FN->getValue()); 64 65 } 66 67 function testDontDecodeLatin1() { 68 69 $vcard = <<<VCF 70BEGIN:VCARD 71VERSION:4.0 72FN:umlaut u - \xFC 73END:VCARD\n 74VCF; 75 76 $mimeDir = new MimeDir(); 77 $vcard = $mimeDir->parse($vcard); 78 // This basically tests that we don't touch the input string if 79 // the encoding was set to UTF-8. The result is actually invalid 80 // and the validator should report this, but it tests effectively 81 // that we pass through the string byte-by-byte. 82 $this->assertEquals("umlaut u - \xFC", $vcard->FN->getValue()); 83 84 } 85 86 /** 87 * @expectedException \InvalidArgumentException 88 */ 89 function testDecodeUnsupportedCharset() { 90 91 $mimeDir = new MimeDir(); 92 $mimeDir->setCharset('foobar'); 93 94 } 95 96 /** 97 * @expectedException \Sabre\VObject\ParseException 98 */ 99 function testDecodeUnsupportedInlineCharset() { 100 101 $vcard = <<<VCF 102BEGIN:VCARD 103VERSION:2.1 104FN;CHARSET=foobar:nothing 105END:VCARD\n 106VCF; 107 108 $mimeDir = new MimeDir(); 109 $mimeDir->parse($vcard); 110 111 } 112 113 function testDecodeWindows1252() { 114 115 $vcard = <<<VCF 116BEGIN:VCARD 117VERSION:3.0 118FN:Euro \x80 119END:VCARD\n 120VCF; 121 122 $mimeDir = new MimeDir(); 123 $mimeDir->setCharset('Windows-1252'); 124 $vcard = $mimeDir->parse($vcard); 125 $this->assertEquals("Euro \xE2\x82\xAC", $vcard->FN->getValue()); 126 127 } 128 129 function testDecodeWindows1252Inline() { 130 131 $vcard = <<<VCF 132BEGIN:VCARD 133VERSION:2.1 134FN;CHARSET=Windows-1252:Euro \x80 135END:VCARD\n 136VCF; 137 138 $mimeDir = new MimeDir(); 139 $vcard = $mimeDir->parse($vcard); 140 $this->assertEquals("Euro \xE2\x82\xAC", $vcard->FN->getValue()); 141 142 } 143} 144