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