3 class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
5 function testReadComponent() {
7 $data = "BEGIN:VCALENDAR\r\nEND:VCALENDAR";
9 $result = Sabre_VObject_Reader::read($data);
11 $this->assertInstanceOf('Sabre_VObject_Component', $result);
12 $this->assertEquals('VCALENDAR', $result->name);
13 $this->assertEquals(0, count($result->children));
17 function testReadComponentUnixNewLine() {
19 $data = "BEGIN:VCALENDAR\nEND:VCALENDAR";
21 $result = Sabre_VObject_Reader::read($data);
23 $this->assertInstanceOf('Sabre_VObject_Component', $result);
24 $this->assertEquals('VCALENDAR', $result->name);
25 $this->assertEquals(0, count($result->children));
29 function testReadComponentMacNewLine() {
31 $data = "BEGIN:VCALENDAR\rEND:VCALENDAR";
33 $result = Sabre_VObject_Reader::read($data);
35 $this->assertInstanceOf('Sabre_VObject_Component', $result);
36 $this->assertEquals('VCALENDAR', $result->name);
37 $this->assertEquals(0, count($result->children));
41 function testReadComponentLineFold() {
43 $data = "BEGIN:\r\n\tVCALENDAR\r\nE\r\n ND:VCALENDAR";
45 $result = Sabre_VObject_Reader::read($data);
47 $this->assertInstanceOf('Sabre_VObject_Component', $result);
48 $this->assertEquals('VCALENDAR', $result->name);
49 $this->assertEquals(0, count($result->children));
54 * @expectedException Sabre_VObject_ParseException
56 function testReadCorruptComponent() {
58 $data = "BEGIN:VCALENDAR\r\nEND:FOO";
60 $result = Sabre_VObject_Reader::read($data);
64 function testReadProperty() {
66 $data = "PROPNAME:propValue";
67 $result = Sabre_VObject_Reader::read($data);
69 $this->assertInstanceOf('Sabre_VObject_Property', $result);
70 $this->assertEquals('PROPNAME', $result->name);
71 $this->assertEquals('propValue', $result->value);
75 function testReadPropertyWithNewLine() {
77 $data = 'PROPNAME:Line1\\nLine2\\NLine3\\\\Not the 4th line!';
78 $result = Sabre_VObject_Reader::read($data);
80 $this->assertInstanceOf('Sabre_VObject_Property', $result);
81 $this->assertEquals('PROPNAME', $result->name);
82 $this->assertEquals("Line1\nLine2\nLine3\\Not the 4th line!", $result->value);
86 function testReadMappedProperty() {
88 $data = "DTSTART:20110529";
89 $result = Sabre_VObject_Reader::read($data);
91 $this->assertInstanceOf('Sabre_VObject_Property_DateTime', $result);
92 $this->assertEquals('DTSTART', $result->name);
93 $this->assertEquals('20110529', $result->value);
97 function testReadMappedPropertyGrouped() {
99 $data = "foo.DTSTART:20110529";
100 $result = Sabre_VObject_Reader::read($data);
102 $this->assertInstanceOf('Sabre_VObject_Property_DateTime', $result);
103 $this->assertEquals('DTSTART', $result->name);
104 $this->assertEquals('20110529', $result->value);
110 * @expectedException Sabre_VObject_ParseException
112 function testReadBrokenLine() {
114 $data = "PROPNAME;propValue";
115 $result = Sabre_VObject_Reader::read($data);
119 function testReadPropertyInComponent() {
123 "PROPNAME:propValue",
127 $result = Sabre_VObject_Reader::read(implode("\r\n",$data));
129 $this->assertInstanceOf('Sabre_VObject_Component', $result);
130 $this->assertEquals('VCALENDAR', $result->name);
131 $this->assertEquals(1, count($result->children));
132 $this->assertInstanceOf('Sabre_VObject_Property', $result->children[0]);
133 $this->assertEquals('PROPNAME', $result->children[0]->name);
134 $this->assertEquals('propValue', $result->children[0]->value);
138 function testReadNestedComponent() {
149 $result = Sabre_VObject_Reader::read(implode("\r\n",$data));
151 $this->assertInstanceOf('Sabre_VObject_Component', $result);
152 $this->assertEquals('VCALENDAR', $result->name);
153 $this->assertEquals(1, count($result->children));
154 $this->assertInstanceOf('Sabre_VObject_Component', $result->children[0]);
155 $this->assertEquals('VTIMEZONE', $result->children[0]->name);
156 $this->assertEquals(1, count($result->children[0]->children));
157 $this->assertInstanceOf('Sabre_VObject_Component', $result->children[0]->children[0]);
158 $this->assertEquals('DAYLIGHT', $result->children[0]->children[0]->name);
163 function testReadPropertyParameter() {
165 $data = "PROPNAME;PARAMNAME=paramvalue:propValue";
166 $result = Sabre_VObject_Reader::read($data);
168 $this->assertInstanceOf('Sabre_VObject_Property', $result);
169 $this->assertEquals('PROPNAME', $result->name);
170 $this->assertEquals('propValue', $result->value);
171 $this->assertEquals(1, count($result->parameters));
172 $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
173 $this->assertEquals('paramvalue', $result->parameters[0]->value);
177 function testReadPropertyNoValue() {
179 $data = "PROPNAME;PARAMNAME:propValue";
180 $result = Sabre_VObject_Reader::read($data);
182 $this->assertInstanceOf('Sabre_VObject_Property', $result);
183 $this->assertEquals('PROPNAME', $result->name);
184 $this->assertEquals('propValue', $result->value);
185 $this->assertEquals(1, count($result->parameters));
186 $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
187 $this->assertEquals('', $result->parameters[0]->value);
191 function testReadPropertyParameterExtraColon() {
193 $data = "PROPNAME;PARAMNAME=paramvalue:propValue:anotherrandomstring";
194 $result = Sabre_VObject_Reader::read($data);
196 $this->assertInstanceOf('Sabre_VObject_Property', $result);
197 $this->assertEquals('PROPNAME', $result->name);
198 $this->assertEquals('propValue:anotherrandomstring', $result->value);
199 $this->assertEquals(1, count($result->parameters));
200 $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
201 $this->assertEquals('paramvalue', $result->parameters[0]->value);
205 function testReadProperty2Parameters() {
207 $data = "PROPNAME;PARAMNAME=paramvalue;PARAMNAME2=paramvalue2:propValue";
208 $result = Sabre_VObject_Reader::read($data);
210 $this->assertInstanceOf('Sabre_VObject_Property', $result);
211 $this->assertEquals('PROPNAME', $result->name);
212 $this->assertEquals('propValue', $result->value);
213 $this->assertEquals(2, count($result->parameters));
214 $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
215 $this->assertEquals('paramvalue', $result->parameters[0]->value);
216 $this->assertEquals('PARAMNAME2', $result->parameters[1]->name);
217 $this->assertEquals('paramvalue2', $result->parameters[1]->value);
221 function testReadPropertyParameterQuoted() {
223 $data = "PROPNAME;PARAMNAME=\"paramvalue\":propValue";
224 $result = Sabre_VObject_Reader::read($data);
226 $this->assertInstanceOf('Sabre_VObject_Property', $result);
227 $this->assertEquals('PROPNAME', $result->name);
228 $this->assertEquals('propValue', $result->value);
229 $this->assertEquals(1, count($result->parameters));
230 $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
231 $this->assertEquals('paramvalue', $result->parameters[0]->value);
234 function testReadPropertyParameterNewLines() {
236 $data = "PROPNAME;PARAMNAME=paramvalue1\\nvalue2\\\\nvalue3:propValue";
237 $result = Sabre_VObject_Reader::read($data);
239 $this->assertInstanceOf('Sabre_VObject_Property', $result);
240 $this->assertEquals('PROPNAME', $result->name);
241 $this->assertEquals('propValue', $result->value);
243 $this->assertEquals(1, count($result->parameters));
244 $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
245 $this->assertEquals("paramvalue1\nvalue2\\nvalue3", $result->parameters[0]->value);
249 function testReadPropertyParameterQuotedColon() {
251 $data = "PROPNAME;PARAMNAME=\"param:value\":propValue";
252 $result = Sabre_VObject_Reader::read($data);
254 $this->assertInstanceOf('Sabre_VObject_Property', $result);
255 $this->assertEquals('PROPNAME', $result->name);
256 $this->assertEquals('propValue', $result->value);
257 $this->assertEquals(1, count($result->parameters));
258 $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
259 $this->assertEquals('param:value', $result->parameters[0]->value);