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