ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
MimeDirTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\VObject\Parser;
4 
6 
11 class MimeDirTest extends TestCase {
12 
16  function testParseError() {
17 
18  $mimeDir = new MimeDir();
19  $mimeDir->parse(fopen(__FILE__, 'a'));
20 
21  }
22 
23  function testDecodeLatin1() {
24 
25  $vcard = <<<VCF
26 BEGIN:VCARD
27 VERSION:3.0
28 FN:umlaut u - \xFC
29 END:VCARD\n
30 VCF;
31 
32  $mimeDir = new MimeDir();
33  $mimeDir->setCharset('ISO-8859-1');
34  $vcard = $mimeDir->parse($vcard);
35  $this->assertEquals("umlaut u - \xC3\xBC", $vcard->FN->getValue());
36 
37  }
38 
40 
41  $vcard = <<<VCF
42 BEGIN:VCARD
43 VERSION:2.1
44 FN;CHARSET=ISO-8859-1:umlaut u - \xFC
45 END:VCARD\n
46 VCF;
47 
48  $mimeDir = new MimeDir();
49  $vcard = $mimeDir->parse($vcard);
50  $this->assertEquals("umlaut u - \xC3\xBC", $vcard->FN->getValue());
51 
52  }
53 
55 
56  $vcard = <<<VCF
57 BEGIN:VCARD
58 VERSION:3.0
59 FN;CHARSET=unknown:foo-bar - \xFC
60 END:VCARD\n
61 VCF;
62 
63  $mimeDir = new MimeDir();
64  $vcard = $mimeDir->parse($vcard);
65  $this->assertEquals("foo-bar - \xFC", $vcard->FN->getValue());
66 
67  }
68 
69  function testDontDecodeLatin1() {
70 
71  $vcard = <<<VCF
72 BEGIN:VCARD
73 VERSION:4.0
74 FN:umlaut u - \xFC
75 END:VCARD\n
76 VCF;
77 
78  $mimeDir = new MimeDir();
79  $vcard = $mimeDir->parse($vcard);
80  // This basically tests that we don't touch the input string if
81  // the encoding was set to UTF-8. The result is actually invalid
82  // and the validator should report this, but it tests effectively
83  // that we pass through the string byte-by-byte.
84  $this->assertEquals("umlaut u - \xFC", $vcard->FN->getValue());
85 
86  }
87 
92 
93  $mimeDir = new MimeDir();
94  $mimeDir->setCharset('foobar');
95 
96  }
97 
102 
103  $vcard = <<<VCF
104 BEGIN:VCARD
105 VERSION:2.1
106 FN;CHARSET=foobar:nothing
107 END:VCARD\n
108 VCF;
109 
110  $mimeDir = new MimeDir();
111  $mimeDir->parse($vcard);
112 
113  }
114 
116 
117  $vcard = <<<VCF
118 BEGIN:VCARD
119 VERSION:3.0
120 FN:Euro \x80
121 END:VCARD\n
122 VCF;
123 
124  $mimeDir = new MimeDir();
125  $mimeDir->setCharset('Windows-1252');
126  $vcard = $mimeDir->parse($vcard);
127  $this->assertEquals("Euro \xE2\x82\xAC", $vcard->FN->getValue());
128 
129  }
130 
132 
133  $vcard = <<<VCF
134 BEGIN:VCARD
135 VERSION:2.1
136 FN;CHARSET=Windows-1252:Euro \x80
137 END:VCARD\n
138 VCF;
139 
140  $mimeDir = new MimeDir();
141  $vcard = $mimeDir->parse($vcard);
142  $this->assertEquals("Euro \xE2\x82\xAC", $vcard->FN->getValue());
143 
144  }
145 
147 
148  $vcard = <<<VCF
149 BEGIN:VCARD
150 VERSION:2.1
151 FN;CHARSET=iSo-8859-1:Euro
152 N;CHARSET=utf-8:Test2
153 END:VCARD\n
154 VCF;
155 
156  $mimeDir = new MimeDir();
157  $vcard = $mimeDir->parse($vcard);
158  // we can do a simple assertion here. As long as we don't get an exception, everything is thing
159  $this->assertEquals("Euro", $vcard->FN->getValue());
160  $this->assertEquals("Test2", $vcard->N->getValue());
161 
162  }
163 }
if(! $in) print Initializing normalization quick check tables n
MimeDir parser.
Definition: MimeDir.php:25
Note that most MimeDir related tests can actually be found in the ReaderTest class one level up...
Definition: MimeDirTest.php:11