3 namespace Sabre\VObject;
5 class ReaderTest extends \PHPUnit_Framework_TestCase {
7 function testReadComponent() {
9 $data = "BEGIN:VCALENDAR\r\nEND:VCALENDAR";
11 $result = Reader::read($data);
13 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
14 $this->assertEquals('VCALENDAR', $result->name);
15 $this->assertEquals(0, count($result->children));
19 function testReadComponentUnixNewLine() {
21 $data = "BEGIN:VCALENDAR\nEND:VCALENDAR";
23 $result = Reader::read($data);
25 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
26 $this->assertEquals('VCALENDAR', $result->name);
27 $this->assertEquals(0, count($result->children));
31 function testReadComponentMacNewLine() {
33 $data = "BEGIN:VCALENDAR\rEND:VCALENDAR";
35 $result = Reader::read($data);
37 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
38 $this->assertEquals('VCALENDAR', $result->name);
39 $this->assertEquals(0, count($result->children));
43 function testReadComponentLineFold() {
45 $data = "BEGIN:\r\n\tVCALENDAR\r\nE\r\n ND:VCALENDAR";
47 $result = Reader::read($data);
49 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
50 $this->assertEquals('VCALENDAR', $result->name);
51 $this->assertEquals(0, count($result->children));
56 * @expectedException Sabre\VObject\ParseException
58 function testReadCorruptComponent() {
60 $data = "BEGIN:VCALENDAR\r\nEND:FOO";
62 $result = Reader::read($data);
66 function testReadProperty() {
68 $data = "PROPNAME:propValue";
69 $result = Reader::read($data);
71 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
72 $this->assertEquals('PROPNAME', $result->name);
73 $this->assertEquals('propValue', $result->value);
77 function testReadPropertyWithNewLine() {
79 $data = 'PROPNAME:Line1\\nLine2\\NLine3\\\\Not the 4th line!';
80 $result = Reader::read($data);
82 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
83 $this->assertEquals('PROPNAME', $result->name);
84 $this->assertEquals("Line1\nLine2\nLine3\\Not the 4th line!", $result->value);
88 function testReadMappedProperty() {
90 $data = "DTSTART:20110529";
91 $result = Reader::read($data);
93 $this->assertInstanceOf('Sabre\\VObject\\Property\\DateTime', $result);
94 $this->assertEquals('DTSTART', $result->name);
95 $this->assertEquals('20110529', $result->value);
99 function testReadMappedPropertyGrouped() {
101 $data = "foo.DTSTART:20110529";
102 $result = Reader::read($data);
104 $this->assertInstanceOf('Sabre\\VObject\\Property\\DateTime', $result);
105 $this->assertEquals('DTSTART', $result->name);
106 $this->assertEquals('20110529', $result->value);
112 * @expectedException Sabre\VObject\ParseException
114 function testReadBrokenLine() {
116 $data = "PROPNAME;propValue";
117 $result = Reader::read($data);
121 function testReadPropertyInComponent() {
125 "PROPNAME:propValue",
129 $result = Reader::read(implode("\r\n",$data));
131 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
132 $this->assertEquals('VCALENDAR', $result->name);
133 $this->assertEquals(1, count($result->children));
134 $this->assertInstanceOf('Sabre\\VObject\\Property', $result->children[0]);
135 $this->assertEquals('PROPNAME', $result->children[0]->name);
136 $this->assertEquals('propValue', $result->children[0]->value);
140 function testReadNestedComponent() {
151 $result = Reader::read(implode("\r\n",$data));
153 $this->assertInstanceOf('Sabre\\VObject\\Component', $result);
154 $this->assertEquals('VCALENDAR', $result->name);
155 $this->assertEquals(1, count($result->children));
156 $this->assertInstanceOf('Sabre\\VObject\\Component', $result->children[0]);
157 $this->assertEquals('VTIMEZONE', $result->children[0]->name);
158 $this->assertEquals(1, count($result->children[0]->children));
159 $this->assertInstanceOf('Sabre\\VObject\\Component', $result->children[0]->children[0]);
160 $this->assertEquals('DAYLIGHT', $result->children[0]->children[0]->name);
165 function testReadPropertyParameter() {
167 $data = "PROPNAME;PARAMNAME=paramvalue:propValue";
168 $result = Reader::read($data);
170 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
171 $this->assertEquals('PROPNAME', $result->name);
172 $this->assertEquals('propValue', $result->value);
173 $this->assertEquals(1, count($result->parameters));
174 $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
175 $this->assertEquals('paramvalue', $result->parameters[0]->value);
179 function testReadPropertyNoValue() {
181 $data = "PROPNAME;PARAMNAME:propValue";
182 $result = Reader::read($data);
184 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
185 $this->assertEquals('PROPNAME', $result->name);
186 $this->assertEquals('propValue', $result->value);
187 $this->assertEquals(1, count($result->parameters));
188 $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
189 $this->assertEquals('', $result->parameters[0]->value);
193 function testReadPropertyParameterExtraColon() {
195 $data = "PROPNAME;PARAMNAME=paramvalue:propValue:anotherrandomstring";
196 $result = Reader::read($data);
198 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
199 $this->assertEquals('PROPNAME', $result->name);
200 $this->assertEquals('propValue:anotherrandomstring', $result->value);
201 $this->assertEquals(1, count($result->parameters));
202 $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
203 $this->assertEquals('paramvalue', $result->parameters[0]->value);
207 function testReadProperty2Parameters() {
209 $data = "PROPNAME;PARAMNAME=paramvalue;PARAMNAME2=paramvalue2:propValue";
210 $result = Reader::read($data);
212 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
213 $this->assertEquals('PROPNAME', $result->name);
214 $this->assertEquals('propValue', $result->value);
215 $this->assertEquals(2, count($result->parameters));
216 $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
217 $this->assertEquals('paramvalue', $result->parameters[0]->value);
218 $this->assertEquals('PARAMNAME2', $result->parameters[1]->name);
219 $this->assertEquals('paramvalue2', $result->parameters[1]->value);
223 function testReadPropertyParameterQuoted() {
225 $data = "PROPNAME;PARAMNAME=\"paramvalue\":propValue";
226 $result = Reader::read($data);
228 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
229 $this->assertEquals('PROPNAME', $result->name);
230 $this->assertEquals('propValue', $result->value);
231 $this->assertEquals(1, count($result->parameters));
232 $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
233 $this->assertEquals('paramvalue', $result->parameters[0]->value);
236 function testReadPropertyParameterNewLines() {
238 $data = "PROPNAME;PARAMNAME=paramvalue1\\nvalue2\\\\nvalue3:propValue";
239 $result = Reader::read($data);
241 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
242 $this->assertEquals('PROPNAME', $result->name);
243 $this->assertEquals('propValue', $result->value);
245 $this->assertEquals(1, count($result->parameters));
246 $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
247 $this->assertEquals("paramvalue1\nvalue2\\nvalue3", $result->parameters[0]->value);
251 function testReadPropertyParameterQuotedColon() {
253 $data = "PROPNAME;PARAMNAME=\"param:value\":propValue";
254 $result = Reader::read($data);
256 $this->assertInstanceOf('Sabre\\VObject\\Property', $result);
257 $this->assertEquals('PROPNAME', $result->name);
258 $this->assertEquals('propValue', $result->value);
259 $this->assertEquals(1, count($result->parameters));
260 $this->assertEquals('PARAMNAME', $result->parameters[0]->name);
261 $this->assertEquals('param:value', $result->parameters[0]->value);