ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
MimeDirTest.php
Go to the documentation of this file.
1<?php
2
4
5use PHPUnit\Framework\TestCase;
6
11class 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
26BEGIN:VCARD
27VERSION:3.0
28FN:umlaut u - \xFC
29END:VCARD\n
30VCF;
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
42BEGIN:VCARD
43VERSION:2.1
44FN;CHARSET=ISO-8859-1:umlaut u - \xFC
45END:VCARD\n
46VCF;
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
57BEGIN:VCARD
58VERSION:3.0
59FN;CHARSET=unknown:foo-bar - \xFC
60END:VCARD\n
61VCF;
62
63 $mimeDir = new MimeDir();
64 $vcard = $mimeDir->parse($vcard);
65 $this->assertEquals("foo-bar - \xFC", $vcard->FN->getValue());
66
67 }
68
70
71 $vcard = <<<VCF
72BEGIN:VCARD
73VERSION:4.0
74FN:umlaut u - \xFC
75END:VCARD\n
76VCF;
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
104BEGIN:VCARD
105VERSION:2.1
106FN;CHARSET=foobar:nothing
107END:VCARD\n
108VCF;
109
110 $mimeDir = new MimeDir();
111 $mimeDir->parse($vcard);
112
113 }
114
116
117 $vcard = <<<VCF
118BEGIN:VCARD
119VERSION:3.0
120FN:Euro \x80
121END:VCARD\n
122VCF;
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
134BEGIN:VCARD
135VERSION:2.1
136FN;CHARSET=Windows-1252:Euro \x80
137END:VCARD\n
138VCF;
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
149BEGIN:VCARD
150VERSION:2.1
151FN;CHARSET=iSo-8859-1:Euro
152N;CHARSET=utf-8:Test2
153END:VCARD\n
154VCF;
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}
An exception for terminatinating execution or to throw for unit testing.
Note that most MimeDir related tests can actually be found in the ReaderTest class one level up.
Definition: MimeDirTest.php:11
testDecodeUnsupportedCharset()
@expectedException \InvalidArgumentException
Definition: MimeDirTest.php:91
testParseError()
@expectedException \Sabre\VObject\ParseException
Definition: MimeDirTest.php:16
testDecodeUnsupportedInlineCharset()
@expectedException \Sabre\VObject\ParseException