]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/VObject/Component/VCalendarTest.php
Initial Release of the calendar plugin
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / VObject / Component / VCalendarTest.php
1 <?php
2
3 class Sabre_VObject_Component_VCalendarTest extends PHPUnit_Framework_TestCase {
4
5     /**
6      * @dataProvider expandData
7      */
8     public function testExpand($input, $output) {
9
10         $vcal = Sabre_VObject_Reader::read($input);
11         $vcal->expand(
12             new DateTime('2011-12-01'),
13             new DateTime('2011-12-31')
14         );
15
16         // This will normalize the output
17         $output = Sabre_VObject_Reader::read($output)->serialize();
18
19         $this->assertEquals($output, $vcal->serialize());
20
21     }
22
23     public function expandData() {
24
25         $tests = array();
26
27         // No data
28         $input = 'BEGIN:VCALENDAR
29 CALSCALE:GREGORIAN
30 VERSION:2.0
31 END:VCALENDAR
32 ';
33
34         $output = $input;
35         $tests[] = array($input,$output);
36
37
38         // Simple events
39         $input = 'BEGIN:VCALENDAR
40 CALSCALE:GREGORIAN
41 VERSION:2.0
42 BEGIN:VEVENT
43 UID:bla
44 SUMMARY:InExpand
45 DTSTART;VALUE=DATE:20111202
46 END:VEVENT
47 BEGIN:VEVENT
48 UID:bla2
49 SUMMARY:NotInExpand
50 DTSTART;VALUE=DATE:20120101
51 END:VEVENT
52 END:VCALENDAR
53 ';
54
55         $output = 'BEGIN:VCALENDAR
56 CALSCALE:GREGORIAN
57 VERSION:2.0
58 BEGIN:VEVENT
59 UID:bla
60 SUMMARY:InExpand
61 DTSTART;VALUE=DATE:20111202
62 END:VEVENT
63 END:VCALENDAR
64 ';
65
66         $tests[] = array($input, $output);
67
68         // Removing timezone info
69         $input = 'BEGIN:VCALENDAR
70 CALSCALE:GREGORIAN
71 VERSION:2.0
72 BEGIN:VTIMEZONE
73 TZID:Europe/Paris
74 END:VTIMEZONE
75 BEGIN:VEVENT
76 UID:bla4
77 SUMMARY:RemoveTZ info
78 DTSTART;TZID=Europe/Paris:20111203T130102
79 END:VEVENT
80 END:VCALENDAR
81 ';
82
83         $output = 'BEGIN:VCALENDAR
84 CALSCALE:GREGORIAN
85 VERSION:2.0
86 BEGIN:VEVENT
87 UID:bla4
88 SUMMARY:RemoveTZ info
89 DTSTART;VALUE=DATE-TIME:20111203T120102Z
90 END:VEVENT
91 END:VCALENDAR
92 ';
93
94         $tests[] = array($input, $output);
95
96         // Recurrence rule
97         $input = 'BEGIN:VCALENDAR
98 CALSCALE:GREGORIAN
99 VERSION:2.0
100 BEGIN:VEVENT
101 UID:bla6
102 SUMMARY:Testing RRule
103 DTSTART:20111125T120000Z
104 DTEND:20111125T130000Z
105 RRULE:FREQ=WEEKLY
106 END:VEVENT
107 END:VCALENDAR
108 ';
109
110         $output = 'BEGIN:VCALENDAR
111 CALSCALE:GREGORIAN
112 VERSION:2.0
113 BEGIN:VEVENT
114 UID:bla6
115 SUMMARY:Testing RRule
116 DTSTART;VALUE=DATE-TIME:20111202T120000Z
117 DTEND;VALUE=DATE-TIME:20111202T130000Z
118 RECURRENCE-ID:20111202T120000Z
119 END:VEVENT
120 BEGIN:VEVENT
121 UID:bla6
122 SUMMARY:Testing RRule
123 DTSTART;VALUE=DATE-TIME:20111209T120000Z
124 DTEND;VALUE=DATE-TIME:20111209T130000Z
125 RECURRENCE-ID:20111209T120000Z
126 END:VEVENT
127 BEGIN:VEVENT
128 UID:bla6
129 SUMMARY:Testing RRule
130 DTSTART;VALUE=DATE-TIME:20111216T120000Z
131 DTEND;VALUE=DATE-TIME:20111216T130000Z
132 RECURRENCE-ID:20111216T120000Z
133 END:VEVENT
134 BEGIN:VEVENT
135 UID:bla6
136 SUMMARY:Testing RRule
137 DTSTART;VALUE=DATE-TIME:20111223T120000Z
138 DTEND;VALUE=DATE-TIME:20111223T130000Z
139 RECURRENCE-ID:20111223T120000Z
140 END:VEVENT
141 BEGIN:VEVENT
142 UID:bla6
143 SUMMARY:Testing RRule
144 DTSTART;VALUE=DATE-TIME:20111230T120000Z
145 DTEND;VALUE=DATE-TIME:20111230T130000Z
146 RECURRENCE-ID:20111230T120000Z
147 END:VEVENT
148 END:VCALENDAR
149 ';
150
151         // Recurrence rule + override
152         $input = 'BEGIN:VCALENDAR
153 CALSCALE:GREGORIAN
154 VERSION:2.0
155 BEGIN:VEVENT
156 UID:bla6
157 SUMMARY:Testing RRule2
158 DTSTART:20111125T120000Z
159 DTEND:20111125T130000Z
160 RRULE:FREQ=WEEKLY
161 END:VEVENT
162 BEGIN:VEVENT
163 UID:bla6
164 RECURRENCE-ID:20111209T120000Z
165 DTSTART:20111209T140000Z
166 DTEND:20111209T150000Z
167 SUMMARY:Override!
168 END:VEVENT
169 END:VCALENDAR
170 ';
171
172         $output = 'BEGIN:VCALENDAR
173 CALSCALE:GREGORIAN
174 VERSION:2.0
175 BEGIN:VEVENT
176 UID:bla6
177 SUMMARY:Testing RRule2
178 DTSTART;VALUE=DATE-TIME:20111202T120000Z
179 DTEND;VALUE=DATE-TIME:20111202T130000Z
180 RECURRENCE-ID:20111202T120000Z
181 END:VEVENT
182 BEGIN:VEVENT
183 UID:bla6
184 RECURRENCE-ID:20111209T120000Z
185 DTSTART:20111209T140000Z
186 DTEND:20111209T150000Z
187 SUMMARY:Override!
188 END:VEVENT
189 BEGIN:VEVENT
190 UID:bla6
191 SUMMARY:Testing RRule2
192 DTSTART;VALUE=DATE-TIME:20111216T120000Z
193 DTEND;VALUE=DATE-TIME:20111216T130000Z
194 RECURRENCE-ID:20111216T120000Z
195 END:VEVENT
196 BEGIN:VEVENT
197 UID:bla6
198 SUMMARY:Testing RRule2
199 DTSTART;VALUE=DATE-TIME:20111223T120000Z
200 DTEND;VALUE=DATE-TIME:20111223T130000Z
201 RECURRENCE-ID:20111223T120000Z
202 END:VEVENT
203 BEGIN:VEVENT
204 UID:bla6
205 SUMMARY:Testing RRule2
206 DTSTART;VALUE=DATE-TIME:20111230T120000Z
207 DTEND;VALUE=DATE-TIME:20111230T130000Z
208 RECURRENCE-ID:20111230T120000Z
209 END:VEVENT
210 END:VCALENDAR
211 ';
212
213         $tests[] = array($input, $output);
214         return $tests;
215
216     }
217
218     /**
219      * @expectedException LogicException
220      */
221     public function testBrokenEventExpand() {
222
223         $input = 'BEGIN:VCALENDAR
224 CALSCALE:GREGORIAN
225 VERSION:2.0
226 BEGIN:VEVENT
227 RRULE:FREQ=WEEKLY
228 DTSTART;VALUE=DATE:20111202
229 END:VEVENT
230 END:VCALENDAR
231 ';
232         $vcal = Sabre_VObject_Reader::read($input);
233         $vcal->expand(
234             new DateTime('2011-12-01'),
235             new DateTime('2011-12-31')
236         );
237
238     }
239
240 }