]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/VObject/ReaderTest.php
Move friendica-specific parts into an own subdirectory
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / VObject / ReaderTest.php
1 <?php
2
3 class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
4
5     function testReadComponent() {
6
7         $data = "BEGIN:VCALENDAR\r\nEND:VCALENDAR";
8
9         $result = Sabre_VObject_Reader::read($data);
10
11         $this->assertInstanceOf('Sabre_VObject_Component', $result);
12         $this->assertEquals('VCALENDAR', $result->name);
13         $this->assertEquals(0, count($result->children));
14
15     }
16
17     function testReadComponentUnixNewLine() {
18
19         $data = "BEGIN:VCALENDAR\nEND:VCALENDAR";
20
21         $result = Sabre_VObject_Reader::read($data);
22
23         $this->assertInstanceOf('Sabre_VObject_Component', $result);
24         $this->assertEquals('VCALENDAR', $result->name);
25         $this->assertEquals(0, count($result->children));
26
27     }
28
29     function testReadComponentMacNewLine() {
30
31         $data = "BEGIN:VCALENDAR\rEND:VCALENDAR";
32
33         $result = Sabre_VObject_Reader::read($data);
34
35         $this->assertInstanceOf('Sabre_VObject_Component', $result);
36         $this->assertEquals('VCALENDAR', $result->name);
37         $this->assertEquals(0, count($result->children));
38
39     }
40
41     function testReadComponentLineFold() {
42
43         $data = "BEGIN:\r\n\tVCALENDAR\r\nE\r\n ND:VCALENDAR";
44
45         $result = Sabre_VObject_Reader::read($data);
46
47         $this->assertInstanceOf('Sabre_VObject_Component', $result);
48         $this->assertEquals('VCALENDAR', $result->name);
49         $this->assertEquals(0, count($result->children));
50
51     }
52
53     /**
54      * @expectedException Sabre_VObject_ParseException
55      */
56     function testReadCorruptComponent() {
57
58         $data = "BEGIN:VCALENDAR\r\nEND:FOO";
59
60         $result = Sabre_VObject_Reader::read($data);
61
62     }
63
64     function testReadProperty() {
65
66         $data = "PROPNAME:propValue";
67         $result = Sabre_VObject_Reader::read($data);
68
69         $this->assertInstanceOf('Sabre_VObject_Property', $result);
70         $this->assertEquals('PROPNAME', $result->name);
71         $this->assertEquals('propValue', $result->value);
72
73     }
74
75     function testReadPropertyWithNewLine() {
76
77         $data = 'PROPNAME:Line1\\nLine2\\NLine3\\\\Not the 4th line!';
78         $result = Sabre_VObject_Reader::read($data);
79
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);
83
84     }
85
86     function testReadMappedProperty() {
87
88         $data = "DTSTART:20110529";
89         $result = Sabre_VObject_Reader::read($data);
90
91         $this->assertInstanceOf('Sabre_VObject_Property_DateTime', $result);
92         $this->assertEquals('DTSTART', $result->name);
93         $this->assertEquals('20110529', $result->value);
94
95     }
96
97     function testReadMappedPropertyGrouped() {
98
99         $data = "foo.DTSTART:20110529";
100         $result = Sabre_VObject_Reader::read($data);
101
102         $this->assertInstanceOf('Sabre_VObject_Property_DateTime', $result);
103         $this->assertEquals('DTSTART', $result->name);
104         $this->assertEquals('20110529', $result->value);
105
106     }
107
108
109     /**
110      * @expectedException Sabre_VObject_ParseException
111      */
112     function testReadBrokenLine() {
113
114         $data = "PROPNAME;propValue";
115         $result = Sabre_VObject_Reader::read($data);
116
117     }
118
119     function testReadPropertyInComponent() {
120
121         $data = array(
122             "BEGIN:VCALENDAR",
123             "PROPNAME:propValue",
124             "END:VCALENDAR"
125         );
126
127         $result = Sabre_VObject_Reader::read(implode("\r\n",$data));
128
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);
135
136
137     }
138     function testReadNestedComponent() {
139
140         $data = array(
141             "BEGIN:VCALENDAR",
142             "BEGIN:VTIMEZONE",
143             "BEGIN:DAYLIGHT",
144             "END:DAYLIGHT",
145             "END:VTIMEZONE",
146             "END:VCALENDAR"
147         );
148
149         $result = Sabre_VObject_Reader::read(implode("\r\n",$data));
150
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);
159
160
161     }
162
163     function testReadPropertyParameter() {
164
165         $data = "PROPNAME;PARAMNAME=paramvalue:propValue";
166         $result = Sabre_VObject_Reader::read($data);
167
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);
174
175     }
176
177     function testReadPropertyNoValue() {
178
179         $data = "PROPNAME;PARAMNAME:propValue";
180         $result = Sabre_VObject_Reader::read($data);
181
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);
188
189     }
190
191     function testReadPropertyParameterExtraColon() {
192
193         $data = "PROPNAME;PARAMNAME=paramvalue:propValue:anotherrandomstring";
194         $result = Sabre_VObject_Reader::read($data);
195
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);
202
203     }
204
205     function testReadProperty2Parameters() {
206
207         $data = "PROPNAME;PARAMNAME=paramvalue;PARAMNAME2=paramvalue2:propValue";
208         $result = Sabre_VObject_Reader::read($data);
209
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);
218
219     }
220
221     function testReadPropertyParameterQuoted() {
222
223         $data = "PROPNAME;PARAMNAME=\"paramvalue\":propValue";
224         $result = Sabre_VObject_Reader::read($data);
225
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);
232
233     }
234     function testReadPropertyParameterNewLines() {
235
236         $data = "PROPNAME;PARAMNAME=paramvalue1\\nvalue2\\\\nvalue3:propValue";
237         $result = Sabre_VObject_Reader::read($data);
238
239         $this->assertInstanceOf('Sabre_VObject_Property', $result);
240         $this->assertEquals('PROPNAME', $result->name);
241         $this->assertEquals('propValue', $result->value);
242
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);
246
247     }
248
249     function testReadPropertyParameterQuotedColon() {
250
251         $data = "PROPNAME;PARAMNAME=\"param:value\":propValue";
252         $result = Sabre_VObject_Reader::read($data);
253
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);
260
261     }
262
263 }