xref: /plugin/davcal/vendor/sabre/vobject/tests/VObject/Component/VCalendarTest.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\VObject\Component;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse DateTimeZone;
6*a1a3b679SAndreas Boehleruse Sabre\VObject;
7*a1a3b679SAndreas Boehler
8*a1a3b679SAndreas Boehlerclass VCalendarTest extends \PHPUnit_Framework_TestCase {
9*a1a3b679SAndreas Boehler
10*a1a3b679SAndreas Boehler    /**
11*a1a3b679SAndreas Boehler     * @dataProvider expandData
12*a1a3b679SAndreas Boehler     */
13*a1a3b679SAndreas Boehler    public function testExpand($input, $output, $timeZone = 'UTC', $start = '2011-12-01', $end = '2011-12-31') {
14*a1a3b679SAndreas Boehler
15*a1a3b679SAndreas Boehler        $vcal = VObject\Reader::read($input);
16*a1a3b679SAndreas Boehler
17*a1a3b679SAndreas Boehler        $timeZone = new DateTimeZone($timeZone);
18*a1a3b679SAndreas Boehler
19*a1a3b679SAndreas Boehler        $vcal->expand(
20*a1a3b679SAndreas Boehler            new \DateTime($start),
21*a1a3b679SAndreas Boehler            new \DateTime($end),
22*a1a3b679SAndreas Boehler            $timeZone
23*a1a3b679SAndreas Boehler        );
24*a1a3b679SAndreas Boehler
25*a1a3b679SAndreas Boehler        // This will normalize the output
26*a1a3b679SAndreas Boehler        $output = VObject\Reader::read($output)->serialize();
27*a1a3b679SAndreas Boehler
28*a1a3b679SAndreas Boehler        $this->assertEquals($output, $vcal->serialize());
29*a1a3b679SAndreas Boehler
30*a1a3b679SAndreas Boehler    }
31*a1a3b679SAndreas Boehler
32*a1a3b679SAndreas Boehler    public function expandData() {
33*a1a3b679SAndreas Boehler
34*a1a3b679SAndreas Boehler        $tests = array();
35*a1a3b679SAndreas Boehler
36*a1a3b679SAndreas Boehler        // No data
37*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
38*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
39*a1a3b679SAndreas BoehlerVERSION:2.0
40*a1a3b679SAndreas BoehlerEND:VCALENDAR
41*a1a3b679SAndreas Boehler';
42*a1a3b679SAndreas Boehler
43*a1a3b679SAndreas Boehler        $output = $input;
44*a1a3b679SAndreas Boehler        $tests[] = array($input,$output);
45*a1a3b679SAndreas Boehler
46*a1a3b679SAndreas Boehler
47*a1a3b679SAndreas Boehler        // Simple events
48*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
49*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
50*a1a3b679SAndreas BoehlerVERSION:2.0
51*a1a3b679SAndreas BoehlerBEGIN:VEVENT
52*a1a3b679SAndreas BoehlerUID:bla
53*a1a3b679SAndreas BoehlerSUMMARY:InExpand
54*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
55*a1a3b679SAndreas BoehlerEND:VEVENT
56*a1a3b679SAndreas BoehlerBEGIN:VEVENT
57*a1a3b679SAndreas BoehlerUID:bla2
58*a1a3b679SAndreas BoehlerSUMMARY:NotInExpand
59*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20120101
60*a1a3b679SAndreas BoehlerEND:VEVENT
61*a1a3b679SAndreas BoehlerEND:VCALENDAR
62*a1a3b679SAndreas Boehler';
63*a1a3b679SAndreas Boehler
64*a1a3b679SAndreas Boehler        $output = 'BEGIN:VCALENDAR
65*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
66*a1a3b679SAndreas BoehlerVERSION:2.0
67*a1a3b679SAndreas BoehlerBEGIN:VEVENT
68*a1a3b679SAndreas BoehlerUID:bla
69*a1a3b679SAndreas BoehlerSUMMARY:InExpand
70*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
71*a1a3b679SAndreas BoehlerEND:VEVENT
72*a1a3b679SAndreas BoehlerEND:VCALENDAR
73*a1a3b679SAndreas Boehler';
74*a1a3b679SAndreas Boehler
75*a1a3b679SAndreas Boehler        $tests[] = array($input, $output);
76*a1a3b679SAndreas Boehler
77*a1a3b679SAndreas Boehler        // Removing timezone info
78*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
79*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
80*a1a3b679SAndreas BoehlerVERSION:2.0
81*a1a3b679SAndreas BoehlerBEGIN:VTIMEZONE
82*a1a3b679SAndreas BoehlerTZID:Europe/Paris
83*a1a3b679SAndreas BoehlerEND:VTIMEZONE
84*a1a3b679SAndreas BoehlerBEGIN:VEVENT
85*a1a3b679SAndreas BoehlerUID:bla4
86*a1a3b679SAndreas BoehlerSUMMARY:RemoveTZ info
87*a1a3b679SAndreas BoehlerDTSTART;TZID=Europe/Paris:20111203T130102
88*a1a3b679SAndreas BoehlerEND:VEVENT
89*a1a3b679SAndreas BoehlerEND:VCALENDAR
90*a1a3b679SAndreas Boehler';
91*a1a3b679SAndreas Boehler
92*a1a3b679SAndreas Boehler        $output = 'BEGIN:VCALENDAR
93*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
94*a1a3b679SAndreas BoehlerVERSION:2.0
95*a1a3b679SAndreas BoehlerBEGIN:VEVENT
96*a1a3b679SAndreas BoehlerUID:bla4
97*a1a3b679SAndreas BoehlerSUMMARY:RemoveTZ info
98*a1a3b679SAndreas BoehlerDTSTART:20111203T120102Z
99*a1a3b679SAndreas BoehlerEND:VEVENT
100*a1a3b679SAndreas BoehlerEND:VCALENDAR
101*a1a3b679SAndreas Boehler';
102*a1a3b679SAndreas Boehler
103*a1a3b679SAndreas Boehler        $tests[] = array($input, $output);
104*a1a3b679SAndreas Boehler
105*a1a3b679SAndreas Boehler        // Recurrence rule
106*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
107*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
108*a1a3b679SAndreas BoehlerVERSION:2.0
109*a1a3b679SAndreas BoehlerBEGIN:VEVENT
110*a1a3b679SAndreas BoehlerUID:bla6
111*a1a3b679SAndreas BoehlerSUMMARY:Testing RRule
112*a1a3b679SAndreas BoehlerDTSTART:20111125T120000Z
113*a1a3b679SAndreas BoehlerDTEND:20111125T130000Z
114*a1a3b679SAndreas BoehlerRRULE:FREQ=WEEKLY
115*a1a3b679SAndreas BoehlerEND:VEVENT
116*a1a3b679SAndreas BoehlerEND:VCALENDAR
117*a1a3b679SAndreas Boehler';
118*a1a3b679SAndreas Boehler
119*a1a3b679SAndreas Boehler        $output = 'BEGIN:VCALENDAR
120*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
121*a1a3b679SAndreas BoehlerVERSION:2.0
122*a1a3b679SAndreas BoehlerBEGIN:VEVENT
123*a1a3b679SAndreas BoehlerUID:bla6
124*a1a3b679SAndreas BoehlerSUMMARY:Testing RRule
125*a1a3b679SAndreas BoehlerDTSTART:20111202T120000Z
126*a1a3b679SAndreas BoehlerDTEND:20111202T130000Z
127*a1a3b679SAndreas BoehlerRECURRENCE-ID:20111202T120000Z
128*a1a3b679SAndreas BoehlerEND:VEVENT
129*a1a3b679SAndreas BoehlerBEGIN:VEVENT
130*a1a3b679SAndreas BoehlerUID:bla6
131*a1a3b679SAndreas BoehlerSUMMARY:Testing RRule
132*a1a3b679SAndreas BoehlerDTSTART:20111209T120000Z
133*a1a3b679SAndreas BoehlerDTEND:20111209T130000Z
134*a1a3b679SAndreas BoehlerRECURRENCE-ID:20111209T120000Z
135*a1a3b679SAndreas BoehlerEND:VEVENT
136*a1a3b679SAndreas BoehlerBEGIN:VEVENT
137*a1a3b679SAndreas BoehlerUID:bla6
138*a1a3b679SAndreas BoehlerSUMMARY:Testing RRule
139*a1a3b679SAndreas BoehlerDTSTART:20111216T120000Z
140*a1a3b679SAndreas BoehlerDTEND:20111216T130000Z
141*a1a3b679SAndreas BoehlerRECURRENCE-ID:20111216T120000Z
142*a1a3b679SAndreas BoehlerEND:VEVENT
143*a1a3b679SAndreas BoehlerBEGIN:VEVENT
144*a1a3b679SAndreas BoehlerUID:bla6
145*a1a3b679SAndreas BoehlerSUMMARY:Testing RRule
146*a1a3b679SAndreas BoehlerDTSTART:20111223T120000Z
147*a1a3b679SAndreas BoehlerDTEND:20111223T130000Z
148*a1a3b679SAndreas BoehlerRECURRENCE-ID:20111223T120000Z
149*a1a3b679SAndreas BoehlerEND:VEVENT
150*a1a3b679SAndreas BoehlerBEGIN:VEVENT
151*a1a3b679SAndreas BoehlerUID:bla6
152*a1a3b679SAndreas BoehlerSUMMARY:Testing RRule
153*a1a3b679SAndreas BoehlerDTSTART:20111230T120000Z
154*a1a3b679SAndreas BoehlerDTEND:20111230T130000Z
155*a1a3b679SAndreas BoehlerRECURRENCE-ID:20111230T120000Z
156*a1a3b679SAndreas BoehlerEND:VEVENT
157*a1a3b679SAndreas BoehlerEND:VCALENDAR
158*a1a3b679SAndreas Boehler';
159*a1a3b679SAndreas Boehler
160*a1a3b679SAndreas Boehler        $tests[] = array($input, $output);
161*a1a3b679SAndreas Boehler
162*a1a3b679SAndreas Boehler        // Recurrence rule + override
163*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
164*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
165*a1a3b679SAndreas BoehlerVERSION:2.0
166*a1a3b679SAndreas BoehlerBEGIN:VEVENT
167*a1a3b679SAndreas BoehlerUID:bla6
168*a1a3b679SAndreas BoehlerSUMMARY:Testing RRule2
169*a1a3b679SAndreas BoehlerDTSTART:20111125T120000Z
170*a1a3b679SAndreas BoehlerDTEND:20111125T130000Z
171*a1a3b679SAndreas BoehlerRRULE:FREQ=WEEKLY
172*a1a3b679SAndreas BoehlerEND:VEVENT
173*a1a3b679SAndreas BoehlerBEGIN:VEVENT
174*a1a3b679SAndreas BoehlerUID:bla6
175*a1a3b679SAndreas BoehlerRECURRENCE-ID:20111209T120000Z
176*a1a3b679SAndreas BoehlerDTSTART:20111209T140000Z
177*a1a3b679SAndreas BoehlerDTEND:20111209T150000Z
178*a1a3b679SAndreas BoehlerSUMMARY:Override!
179*a1a3b679SAndreas BoehlerEND:VEVENT
180*a1a3b679SAndreas BoehlerEND:VCALENDAR
181*a1a3b679SAndreas Boehler';
182*a1a3b679SAndreas Boehler
183*a1a3b679SAndreas Boehler        $output = 'BEGIN:VCALENDAR
184*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
185*a1a3b679SAndreas BoehlerVERSION:2.0
186*a1a3b679SAndreas BoehlerBEGIN:VEVENT
187*a1a3b679SAndreas BoehlerUID:bla6
188*a1a3b679SAndreas BoehlerSUMMARY:Testing RRule2
189*a1a3b679SAndreas BoehlerDTSTART:20111202T120000Z
190*a1a3b679SAndreas BoehlerDTEND:20111202T130000Z
191*a1a3b679SAndreas BoehlerRECURRENCE-ID:20111202T120000Z
192*a1a3b679SAndreas BoehlerEND:VEVENT
193*a1a3b679SAndreas BoehlerBEGIN:VEVENT
194*a1a3b679SAndreas BoehlerUID:bla6
195*a1a3b679SAndreas BoehlerRECURRENCE-ID:20111209T120000Z
196*a1a3b679SAndreas BoehlerDTSTART:20111209T140000Z
197*a1a3b679SAndreas BoehlerDTEND:20111209T150000Z
198*a1a3b679SAndreas BoehlerSUMMARY:Override!
199*a1a3b679SAndreas BoehlerEND:VEVENT
200*a1a3b679SAndreas BoehlerBEGIN:VEVENT
201*a1a3b679SAndreas BoehlerUID:bla6
202*a1a3b679SAndreas BoehlerSUMMARY:Testing RRule2
203*a1a3b679SAndreas BoehlerDTSTART:20111216T120000Z
204*a1a3b679SAndreas BoehlerDTEND:20111216T130000Z
205*a1a3b679SAndreas BoehlerRECURRENCE-ID:20111216T120000Z
206*a1a3b679SAndreas BoehlerEND:VEVENT
207*a1a3b679SAndreas BoehlerBEGIN:VEVENT
208*a1a3b679SAndreas BoehlerUID:bla6
209*a1a3b679SAndreas BoehlerSUMMARY:Testing RRule2
210*a1a3b679SAndreas BoehlerDTSTART:20111223T120000Z
211*a1a3b679SAndreas BoehlerDTEND:20111223T130000Z
212*a1a3b679SAndreas BoehlerRECURRENCE-ID:20111223T120000Z
213*a1a3b679SAndreas BoehlerEND:VEVENT
214*a1a3b679SAndreas BoehlerBEGIN:VEVENT
215*a1a3b679SAndreas BoehlerUID:bla6
216*a1a3b679SAndreas BoehlerSUMMARY:Testing RRule2
217*a1a3b679SAndreas BoehlerDTSTART:20111230T120000Z
218*a1a3b679SAndreas BoehlerDTEND:20111230T130000Z
219*a1a3b679SAndreas BoehlerRECURRENCE-ID:20111230T120000Z
220*a1a3b679SAndreas BoehlerEND:VEVENT
221*a1a3b679SAndreas BoehlerEND:VCALENDAR
222*a1a3b679SAndreas Boehler';
223*a1a3b679SAndreas Boehler
224*a1a3b679SAndreas Boehler        $tests[] = array($input, $output);
225*a1a3b679SAndreas Boehler
226*a1a3b679SAndreas Boehler        // Floating dates and times.
227*a1a3b679SAndreas Boehler        $input = <<<ICS
228*a1a3b679SAndreas BoehlerBEGIN:VCALENDAR
229*a1a3b679SAndreas BoehlerVERSION:2.0
230*a1a3b679SAndreas BoehlerBEGIN:VEVENT
231*a1a3b679SAndreas BoehlerUID:bla1
232*a1a3b679SAndreas BoehlerDTSTART:20141112T195000
233*a1a3b679SAndreas BoehlerEND:VEVENT
234*a1a3b679SAndreas BoehlerBEGIN:VEVENT
235*a1a3b679SAndreas BoehlerUID:bla2
236*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20141112
237*a1a3b679SAndreas BoehlerEND:VEVENT
238*a1a3b679SAndreas BoehlerBEGIN:VEVENT
239*a1a3b679SAndreas BoehlerUID:bla3
240*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20141112
241*a1a3b679SAndreas BoehlerRRULE:FREQ=DAILY;COUNT=2
242*a1a3b679SAndreas BoehlerEND:VEVENT
243*a1a3b679SAndreas BoehlerEND:VCALENDAR
244*a1a3b679SAndreas BoehlerICS;
245*a1a3b679SAndreas Boehler
246*a1a3b679SAndreas Boehler        $output = <<<ICS
247*a1a3b679SAndreas BoehlerBEGIN:VCALENDAR
248*a1a3b679SAndreas BoehlerVERSION:2.0
249*a1a3b679SAndreas BoehlerBEGIN:VEVENT
250*a1a3b679SAndreas BoehlerUID:bla1
251*a1a3b679SAndreas BoehlerDTSTART:20141112T225000Z
252*a1a3b679SAndreas BoehlerEND:VEVENT
253*a1a3b679SAndreas BoehlerBEGIN:VEVENT
254*a1a3b679SAndreas BoehlerUID:bla2
255*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20141112
256*a1a3b679SAndreas BoehlerEND:VEVENT
257*a1a3b679SAndreas BoehlerBEGIN:VEVENT
258*a1a3b679SAndreas BoehlerUID:bla3
259*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20141112
260*a1a3b679SAndreas BoehlerEND:VEVENT
261*a1a3b679SAndreas BoehlerBEGIN:VEVENT
262*a1a3b679SAndreas BoehlerUID:bla3
263*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20141113
264*a1a3b679SAndreas BoehlerRECURRENCE-ID;VALUE=DATE:20141113
265*a1a3b679SAndreas BoehlerEND:VEVENT
266*a1a3b679SAndreas BoehlerEND:VCALENDAR
267*a1a3b679SAndreas BoehlerICS;
268*a1a3b679SAndreas Boehler
269*a1a3b679SAndreas Boehler        $tests[] = array($input, $output, 'America/Argentina/Buenos_Aires', '2014-01-01', '2015-01-01');
270*a1a3b679SAndreas Boehler
271*a1a3b679SAndreas Boehler        // Recurrence rule with no valid instances
272*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
273*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
274*a1a3b679SAndreas BoehlerVERSION:2.0
275*a1a3b679SAndreas BoehlerBEGIN:VEVENT
276*a1a3b679SAndreas BoehlerUID:bla6
277*a1a3b679SAndreas BoehlerSUMMARY:Testing RRule3
278*a1a3b679SAndreas BoehlerDTSTART:20111125T120000Z
279*a1a3b679SAndreas BoehlerDTEND:20111125T130000Z
280*a1a3b679SAndreas BoehlerRRULE:FREQ=WEEKLY;COUNT=1
281*a1a3b679SAndreas BoehlerEXDATE:20111125T120000Z
282*a1a3b679SAndreas BoehlerEND:VEVENT
283*a1a3b679SAndreas BoehlerEND:VCALENDAR
284*a1a3b679SAndreas Boehler';
285*a1a3b679SAndreas Boehler
286*a1a3b679SAndreas Boehler        $output = 'BEGIN:VCALENDAR
287*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
288*a1a3b679SAndreas BoehlerVERSION:2.0
289*a1a3b679SAndreas BoehlerEND:VCALENDAR
290*a1a3b679SAndreas Boehler';
291*a1a3b679SAndreas Boehler
292*a1a3b679SAndreas Boehler        $tests[] = array($input, $output);
293*a1a3b679SAndreas Boehler        return $tests;
294*a1a3b679SAndreas Boehler
295*a1a3b679SAndreas Boehler    }
296*a1a3b679SAndreas Boehler
297*a1a3b679SAndreas Boehler    /**
298*a1a3b679SAndreas Boehler     * @expectedException LogicException
299*a1a3b679SAndreas Boehler     */
300*a1a3b679SAndreas Boehler    public function testBrokenEventExpand() {
301*a1a3b679SAndreas Boehler
302*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
303*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
304*a1a3b679SAndreas BoehlerVERSION:2.0
305*a1a3b679SAndreas BoehlerBEGIN:VEVENT
306*a1a3b679SAndreas BoehlerRRULE:FREQ=WEEKLY
307*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
308*a1a3b679SAndreas BoehlerEND:VEVENT
309*a1a3b679SAndreas BoehlerEND:VCALENDAR
310*a1a3b679SAndreas Boehler';
311*a1a3b679SAndreas Boehler        $vcal = VObject\Reader::read($input);
312*a1a3b679SAndreas Boehler        $vcal->expand(
313*a1a3b679SAndreas Boehler            new \DateTime('2011-12-01'),
314*a1a3b679SAndreas Boehler            new \DateTime('2011-12-31')
315*a1a3b679SAndreas Boehler        );
316*a1a3b679SAndreas Boehler
317*a1a3b679SAndreas Boehler    }
318*a1a3b679SAndreas Boehler
319*a1a3b679SAndreas Boehler    function testGetDocumentType() {
320*a1a3b679SAndreas Boehler
321*a1a3b679SAndreas Boehler        $vcard = new VCalendar();
322*a1a3b679SAndreas Boehler        $vcard->VERSION = '2.0';
323*a1a3b679SAndreas Boehler        $this->assertEquals(VCalendar::ICALENDAR20, $vcard->getDocumentType());
324*a1a3b679SAndreas Boehler
325*a1a3b679SAndreas Boehler    }
326*a1a3b679SAndreas Boehler
327*a1a3b679SAndreas Boehler    function testValidateCorrect() {
328*a1a3b679SAndreas Boehler
329*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
330*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
331*a1a3b679SAndreas BoehlerVERSION:2.0
332*a1a3b679SAndreas BoehlerPRODID:foo
333*a1a3b679SAndreas BoehlerBEGIN:VEVENT
334*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
335*a1a3b679SAndreas BoehlerDTSTAMP:20140122T233226Z
336*a1a3b679SAndreas BoehlerUID:foo
337*a1a3b679SAndreas BoehlerEND:VEVENT
338*a1a3b679SAndreas BoehlerEND:VCALENDAR
339*a1a3b679SAndreas Boehler';
340*a1a3b679SAndreas Boehler
341*a1a3b679SAndreas Boehler        $vcal = VObject\Reader::read($input);
342*a1a3b679SAndreas Boehler        $this->assertEquals(array(), $vcal->validate(), 'Got an error');
343*a1a3b679SAndreas Boehler
344*a1a3b679SAndreas Boehler    }
345*a1a3b679SAndreas Boehler
346*a1a3b679SAndreas Boehler    function testValidateNoVersion() {
347*a1a3b679SAndreas Boehler
348*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
349*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
350*a1a3b679SAndreas BoehlerPRODID:foo
351*a1a3b679SAndreas BoehlerBEGIN:VEVENT
352*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
353*a1a3b679SAndreas BoehlerUID:foo
354*a1a3b679SAndreas BoehlerDTSTAMP:20140122T234434Z
355*a1a3b679SAndreas BoehlerEND:VEVENT
356*a1a3b679SAndreas BoehlerEND:VCALENDAR
357*a1a3b679SAndreas Boehler';
358*a1a3b679SAndreas Boehler
359*a1a3b679SAndreas Boehler        $vcal = VObject\Reader::read($input);
360*a1a3b679SAndreas Boehler        $this->assertEquals(1, count($vcal->validate()));
361*a1a3b679SAndreas Boehler
362*a1a3b679SAndreas Boehler    }
363*a1a3b679SAndreas Boehler
364*a1a3b679SAndreas Boehler    function testValidateWrongVersion() {
365*a1a3b679SAndreas Boehler
366*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
367*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
368*a1a3b679SAndreas BoehlerVERSION:3.0
369*a1a3b679SAndreas BoehlerPRODID:foo
370*a1a3b679SAndreas BoehlerBEGIN:VEVENT
371*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
372*a1a3b679SAndreas BoehlerUID:foo
373*a1a3b679SAndreas BoehlerDTSTAMP:20140122T234434Z
374*a1a3b679SAndreas BoehlerEND:VEVENT
375*a1a3b679SAndreas BoehlerEND:VCALENDAR
376*a1a3b679SAndreas Boehler';
377*a1a3b679SAndreas Boehler
378*a1a3b679SAndreas Boehler        $vcal = VObject\Reader::read($input);
379*a1a3b679SAndreas Boehler        $this->assertEquals(1, count($vcal->validate()));
380*a1a3b679SAndreas Boehler
381*a1a3b679SAndreas Boehler    }
382*a1a3b679SAndreas Boehler
383*a1a3b679SAndreas Boehler    function testValidateNoProdId() {
384*a1a3b679SAndreas Boehler
385*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
386*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
387*a1a3b679SAndreas BoehlerVERSION:2.0
388*a1a3b679SAndreas BoehlerBEGIN:VEVENT
389*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
390*a1a3b679SAndreas BoehlerUID:foo
391*a1a3b679SAndreas BoehlerDTSTAMP:20140122T234434Z
392*a1a3b679SAndreas BoehlerEND:VEVENT
393*a1a3b679SAndreas BoehlerEND:VCALENDAR
394*a1a3b679SAndreas Boehler';
395*a1a3b679SAndreas Boehler
396*a1a3b679SAndreas Boehler        $vcal = VObject\Reader::read($input);
397*a1a3b679SAndreas Boehler        $this->assertEquals(1, count($vcal->validate()));
398*a1a3b679SAndreas Boehler
399*a1a3b679SAndreas Boehler    }
400*a1a3b679SAndreas Boehler
401*a1a3b679SAndreas Boehler    function testValidateDoubleCalScale() {
402*a1a3b679SAndreas Boehler
403*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
404*a1a3b679SAndreas BoehlerVERSION:2.0
405*a1a3b679SAndreas BoehlerPRODID:foo
406*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
407*a1a3b679SAndreas BoehlerCALSCALE:GREGORIAN
408*a1a3b679SAndreas BoehlerBEGIN:VEVENT
409*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
410*a1a3b679SAndreas BoehlerUID:foo
411*a1a3b679SAndreas BoehlerDTSTAMP:20140122T234434Z
412*a1a3b679SAndreas BoehlerEND:VEVENT
413*a1a3b679SAndreas BoehlerEND:VCALENDAR
414*a1a3b679SAndreas Boehler';
415*a1a3b679SAndreas Boehler
416*a1a3b679SAndreas Boehler        $vcal = VObject\Reader::read($input);
417*a1a3b679SAndreas Boehler        $this->assertEquals(1, count($vcal->validate()));
418*a1a3b679SAndreas Boehler
419*a1a3b679SAndreas Boehler    }
420*a1a3b679SAndreas Boehler
421*a1a3b679SAndreas Boehler    function testValidateDoubleMethod() {
422*a1a3b679SAndreas Boehler
423*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
424*a1a3b679SAndreas BoehlerVERSION:2.0
425*a1a3b679SAndreas BoehlerPRODID:foo
426*a1a3b679SAndreas BoehlerMETHOD:REQUEST
427*a1a3b679SAndreas BoehlerMETHOD:REQUEST
428*a1a3b679SAndreas BoehlerBEGIN:VEVENT
429*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
430*a1a3b679SAndreas BoehlerUID:foo
431*a1a3b679SAndreas BoehlerDTSTAMP:20140122T234434Z
432*a1a3b679SAndreas BoehlerEND:VEVENT
433*a1a3b679SAndreas BoehlerEND:VCALENDAR
434*a1a3b679SAndreas Boehler';
435*a1a3b679SAndreas Boehler
436*a1a3b679SAndreas Boehler        $vcal = VObject\Reader::read($input);
437*a1a3b679SAndreas Boehler        $this->assertEquals(1, count($vcal->validate()));
438*a1a3b679SAndreas Boehler
439*a1a3b679SAndreas Boehler    }
440*a1a3b679SAndreas Boehler
441*a1a3b679SAndreas Boehler    function testValidateTwoMasterEvents() {
442*a1a3b679SAndreas Boehler
443*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
444*a1a3b679SAndreas BoehlerVERSION:2.0
445*a1a3b679SAndreas BoehlerPRODID:foo
446*a1a3b679SAndreas BoehlerMETHOD:REQUEST
447*a1a3b679SAndreas BoehlerBEGIN:VEVENT
448*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
449*a1a3b679SAndreas BoehlerUID:foo
450*a1a3b679SAndreas BoehlerDTSTAMP:20140122T234434Z
451*a1a3b679SAndreas BoehlerEND:VEVENT
452*a1a3b679SAndreas BoehlerBEGIN:VEVENT
453*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
454*a1a3b679SAndreas BoehlerUID:foo
455*a1a3b679SAndreas BoehlerDTSTAMP:20140122T234434Z
456*a1a3b679SAndreas BoehlerEND:VEVENT
457*a1a3b679SAndreas BoehlerEND:VCALENDAR
458*a1a3b679SAndreas Boehler';
459*a1a3b679SAndreas Boehler
460*a1a3b679SAndreas Boehler        $vcal = VObject\Reader::read($input);
461*a1a3b679SAndreas Boehler        $this->assertEquals(1, count($vcal->validate()));
462*a1a3b679SAndreas Boehler
463*a1a3b679SAndreas Boehler    }
464*a1a3b679SAndreas Boehler
465*a1a3b679SAndreas Boehler    function testValidateOneMasterEvent() {
466*a1a3b679SAndreas Boehler
467*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
468*a1a3b679SAndreas BoehlerVERSION:2.0
469*a1a3b679SAndreas BoehlerPRODID:foo
470*a1a3b679SAndreas BoehlerMETHOD:REQUEST
471*a1a3b679SAndreas BoehlerBEGIN:VEVENT
472*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
473*a1a3b679SAndreas BoehlerUID:foo
474*a1a3b679SAndreas BoehlerDTSTAMP:20140122T234434Z
475*a1a3b679SAndreas BoehlerEND:VEVENT
476*a1a3b679SAndreas BoehlerBEGIN:VEVENT
477*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
478*a1a3b679SAndreas BoehlerUID:foo
479*a1a3b679SAndreas BoehlerDTSTAMP:20140122T234434Z
480*a1a3b679SAndreas BoehlerRECURRENCE-ID;VALUE=DATE:20111202
481*a1a3b679SAndreas BoehlerEND:VEVENT
482*a1a3b679SAndreas BoehlerEND:VCALENDAR
483*a1a3b679SAndreas Boehler';
484*a1a3b679SAndreas Boehler
485*a1a3b679SAndreas Boehler        $vcal = VObject\Reader::read($input);
486*a1a3b679SAndreas Boehler        $this->assertEquals(0, count($vcal->validate()));
487*a1a3b679SAndreas Boehler
488*a1a3b679SAndreas Boehler    }
489*a1a3b679SAndreas Boehler
490*a1a3b679SAndreas Boehler    function testGetBaseComponent() {
491*a1a3b679SAndreas Boehler
492*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
493*a1a3b679SAndreas BoehlerVERSION:2.0
494*a1a3b679SAndreas BoehlerPRODID:foo
495*a1a3b679SAndreas BoehlerMETHOD:REQUEST
496*a1a3b679SAndreas BoehlerBEGIN:VEVENT
497*a1a3b679SAndreas BoehlerSUMMARY:test
498*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
499*a1a3b679SAndreas BoehlerUID:foo
500*a1a3b679SAndreas BoehlerDTSTAMP:20140122T234434Z
501*a1a3b679SAndreas BoehlerEND:VEVENT
502*a1a3b679SAndreas BoehlerBEGIN:VEVENT
503*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
504*a1a3b679SAndreas BoehlerUID:foo
505*a1a3b679SAndreas BoehlerDTSTAMP:20140122T234434Z
506*a1a3b679SAndreas BoehlerRECURRENCE-ID;VALUE=DATE:20111202
507*a1a3b679SAndreas BoehlerEND:VEVENT
508*a1a3b679SAndreas BoehlerEND:VCALENDAR
509*a1a3b679SAndreas Boehler';
510*a1a3b679SAndreas Boehler
511*a1a3b679SAndreas Boehler        $vcal = VObject\Reader::read($input);
512*a1a3b679SAndreas Boehler
513*a1a3b679SAndreas Boehler        $result = $vcal->getBaseComponent();
514*a1a3b679SAndreas Boehler        $this->assertEquals('test', $result->SUMMARY->getValue());
515*a1a3b679SAndreas Boehler
516*a1a3b679SAndreas Boehler    }
517*a1a3b679SAndreas Boehler
518*a1a3b679SAndreas Boehler    function testGetBaseComponentNoResult() {
519*a1a3b679SAndreas Boehler
520*a1a3b679SAndreas Boehler        $input = 'BEGIN:VCALENDAR
521*a1a3b679SAndreas BoehlerVERSION:2.0
522*a1a3b679SAndreas BoehlerPRODID:foo
523*a1a3b679SAndreas BoehlerMETHOD:REQUEST
524*a1a3b679SAndreas BoehlerBEGIN:VEVENT
525*a1a3b679SAndreas BoehlerSUMMARY:test
526*a1a3b679SAndreas BoehlerRECURRENCE-ID;VALUE=DATE:20111202
527*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
528*a1a3b679SAndreas BoehlerUID:foo
529*a1a3b679SAndreas BoehlerDTSTAMP:20140122T234434Z
530*a1a3b679SAndreas BoehlerEND:VEVENT
531*a1a3b679SAndreas BoehlerBEGIN:VEVENT
532*a1a3b679SAndreas BoehlerDTSTART;VALUE=DATE:20111202
533*a1a3b679SAndreas BoehlerUID:foo
534*a1a3b679SAndreas BoehlerDTSTAMP:20140122T234434Z
535*a1a3b679SAndreas BoehlerRECURRENCE-ID;VALUE=DATE:20111202
536*a1a3b679SAndreas BoehlerEND:VEVENT
537*a1a3b679SAndreas BoehlerEND:VCALENDAR
538*a1a3b679SAndreas Boehler';
539*a1a3b679SAndreas Boehler
540*a1a3b679SAndreas Boehler        $vcal = VObject\Reader::read($input);
541*a1a3b679SAndreas Boehler
542*a1a3b679SAndreas Boehler        $result = $vcal->getBaseComponent();
543*a1a3b679SAndreas Boehler        $this->assertNull($result);
544*a1a3b679SAndreas Boehler
545*a1a3b679SAndreas Boehler    }
546*a1a3b679SAndreas Boehler
547*a1a3b679SAndreas Boehler    function testNoComponents() {
548*a1a3b679SAndreas Boehler
549*a1a3b679SAndreas Boehler        $input = <<<ICS
550*a1a3b679SAndreas BoehlerBEGIN:VCALENDAR
551*a1a3b679SAndreas BoehlerVERSION:2.0
552*a1a3b679SAndreas BoehlerPRODID:vobject
553*a1a3b679SAndreas BoehlerEND:VCALENDAR
554*a1a3b679SAndreas BoehlerICS;
555*a1a3b679SAndreas Boehler
556*a1a3b679SAndreas Boehler        $this->assertValidate(
557*a1a3b679SAndreas Boehler            $input,
558*a1a3b679SAndreas Boehler            0,
559*a1a3b679SAndreas Boehler            3,
560*a1a3b679SAndreas Boehler           "An iCalendar object must have at least 1 component."
561*a1a3b679SAndreas Boehler        );
562*a1a3b679SAndreas Boehler
563*a1a3b679SAndreas Boehler    }
564*a1a3b679SAndreas Boehler
565*a1a3b679SAndreas Boehler    function testCalDAVNoComponents() {
566*a1a3b679SAndreas Boehler
567*a1a3b679SAndreas Boehler        $input = <<<ICS
568*a1a3b679SAndreas BoehlerBEGIN:VCALENDAR
569*a1a3b679SAndreas BoehlerVERSION:2.0
570*a1a3b679SAndreas BoehlerPRODID:vobject
571*a1a3b679SAndreas BoehlerBEGIN:VTIMEZONE
572*a1a3b679SAndreas BoehlerTZID:America/Toronto
573*a1a3b679SAndreas BoehlerEND:VTIMEZONE
574*a1a3b679SAndreas BoehlerEND:VCALENDAR
575*a1a3b679SAndreas BoehlerICS;
576*a1a3b679SAndreas Boehler
577*a1a3b679SAndreas Boehler        $this->assertValidate(
578*a1a3b679SAndreas Boehler            $input,
579*a1a3b679SAndreas Boehler            VCalendar::PROFILE_CALDAV,
580*a1a3b679SAndreas Boehler            3,
581*a1a3b679SAndreas Boehler           "A calendar object on a CalDAV server must have at least 1 component (VTODO, VEVENT, VJOURNAL)."
582*a1a3b679SAndreas Boehler        );
583*a1a3b679SAndreas Boehler
584*a1a3b679SAndreas Boehler    }
585*a1a3b679SAndreas Boehler
586*a1a3b679SAndreas Boehler    function testCalDAVMultiUID() {
587*a1a3b679SAndreas Boehler
588*a1a3b679SAndreas Boehler        $input = <<<ICS
589*a1a3b679SAndreas BoehlerBEGIN:VCALENDAR
590*a1a3b679SAndreas BoehlerVERSION:2.0
591*a1a3b679SAndreas BoehlerPRODID:vobject
592*a1a3b679SAndreas BoehlerBEGIN:VEVENT
593*a1a3b679SAndreas BoehlerUID:foo
594*a1a3b679SAndreas BoehlerDTSTAMP:20150109T184500Z
595*a1a3b679SAndreas BoehlerDTSTART:20150109T184500Z
596*a1a3b679SAndreas BoehlerEND:VEVENT
597*a1a3b679SAndreas BoehlerBEGIN:VEVENT
598*a1a3b679SAndreas BoehlerUID:bar
599*a1a3b679SAndreas BoehlerDTSTAMP:20150109T184500Z
600*a1a3b679SAndreas BoehlerDTSTART:20150109T184500Z
601*a1a3b679SAndreas BoehlerEND:VEVENT
602*a1a3b679SAndreas BoehlerEND:VCALENDAR
603*a1a3b679SAndreas BoehlerICS;
604*a1a3b679SAndreas Boehler
605*a1a3b679SAndreas Boehler        $this->assertValidate(
606*a1a3b679SAndreas Boehler            $input,
607*a1a3b679SAndreas Boehler            VCalendar::PROFILE_CALDAV,
608*a1a3b679SAndreas Boehler            3,
609*a1a3b679SAndreas Boehler           "A calendar object on a CalDAV server may only have components with the same UID."
610*a1a3b679SAndreas Boehler        );
611*a1a3b679SAndreas Boehler
612*a1a3b679SAndreas Boehler    }
613*a1a3b679SAndreas Boehler
614*a1a3b679SAndreas Boehler    function testCalDAVMultiComponent() {
615*a1a3b679SAndreas Boehler
616*a1a3b679SAndreas Boehler        $input = <<<ICS
617*a1a3b679SAndreas BoehlerBEGIN:VCALENDAR
618*a1a3b679SAndreas BoehlerVERSION:2.0
619*a1a3b679SAndreas BoehlerPRODID:vobject
620*a1a3b679SAndreas BoehlerBEGIN:VEVENT
621*a1a3b679SAndreas BoehlerUID:foo
622*a1a3b679SAndreas BoehlerRECURRENCE-ID:20150109T185200Z
623*a1a3b679SAndreas BoehlerDTSTAMP:20150109T184500Z
624*a1a3b679SAndreas BoehlerDTSTART:20150109T184500Z
625*a1a3b679SAndreas BoehlerEND:VEVENT
626*a1a3b679SAndreas BoehlerBEGIN:VTODO
627*a1a3b679SAndreas BoehlerUID:foo
628*a1a3b679SAndreas BoehlerDTSTAMP:20150109T184500Z
629*a1a3b679SAndreas BoehlerDTSTART:20150109T184500Z
630*a1a3b679SAndreas BoehlerEND:VTODO
631*a1a3b679SAndreas BoehlerEND:VCALENDAR
632*a1a3b679SAndreas BoehlerICS;
633*a1a3b679SAndreas Boehler
634*a1a3b679SAndreas Boehler        $this->assertValidate(
635*a1a3b679SAndreas Boehler            $input,
636*a1a3b679SAndreas Boehler            VCalendar::PROFILE_CALDAV,
637*a1a3b679SAndreas Boehler            3,
638*a1a3b679SAndreas Boehler           "A calendar object on a CalDAV server may only have 1 type of component (VEVENT, VTODO or VJOURNAL)."
639*a1a3b679SAndreas Boehler        );
640*a1a3b679SAndreas Boehler
641*a1a3b679SAndreas Boehler    }
642*a1a3b679SAndreas Boehler
643*a1a3b679SAndreas Boehler    function testCalDAVMETHOD() {
644*a1a3b679SAndreas Boehler
645*a1a3b679SAndreas Boehler        $input = <<<ICS
646*a1a3b679SAndreas BoehlerBEGIN:VCALENDAR
647*a1a3b679SAndreas BoehlerVERSION:2.0
648*a1a3b679SAndreas BoehlerMETHOD:PUBLISH
649*a1a3b679SAndreas BoehlerPRODID:vobject
650*a1a3b679SAndreas BoehlerBEGIN:VEVENT
651*a1a3b679SAndreas BoehlerUID:foo
652*a1a3b679SAndreas BoehlerRECURRENCE-ID:20150109T185200Z
653*a1a3b679SAndreas BoehlerDTSTAMP:20150109T184500Z
654*a1a3b679SAndreas BoehlerDTSTART:20150109T184500Z
655*a1a3b679SAndreas BoehlerEND:VEVENT
656*a1a3b679SAndreas BoehlerEND:VCALENDAR
657*a1a3b679SAndreas BoehlerICS;
658*a1a3b679SAndreas Boehler
659*a1a3b679SAndreas Boehler        $this->assertValidate(
660*a1a3b679SAndreas Boehler            $input,
661*a1a3b679SAndreas Boehler            VCalendar::PROFILE_CALDAV,
662*a1a3b679SAndreas Boehler            3,
663*a1a3b679SAndreas Boehler           "A calendar object on a CalDAV server MUST NOT have a METHOD property."
664*a1a3b679SAndreas Boehler        );
665*a1a3b679SAndreas Boehler
666*a1a3b679SAndreas Boehler    }
667*a1a3b679SAndreas Boehler
668*a1a3b679SAndreas Boehler    function assertValidate($ics, $options, $expectedLevel, $expectedMessage = null) {
669*a1a3b679SAndreas Boehler
670*a1a3b679SAndreas Boehler        $vcal = VObject\Reader::read($ics);
671*a1a3b679SAndreas Boehler        $result = $vcal->validate($options);
672*a1a3b679SAndreas Boehler
673*a1a3b679SAndreas Boehler        $this->assertValidateResult($result, $expectedLevel, $expectedMessage);
674*a1a3b679SAndreas Boehler
675*a1a3b679SAndreas Boehler    }
676*a1a3b679SAndreas Boehler
677*a1a3b679SAndreas Boehler    function assertValidateResult($input, $expectedLevel, $expectedMessage = null) {
678*a1a3b679SAndreas Boehler
679*a1a3b679SAndreas Boehler        $messages = array();
680*a1a3b679SAndreas Boehler        foreach($input as $warning) {
681*a1a3b679SAndreas Boehler            $messages[] = $warning['message'];
682*a1a3b679SAndreas Boehler        }
683*a1a3b679SAndreas Boehler
684*a1a3b679SAndreas Boehler        if ($expectedLevel === 0) {
685*a1a3b679SAndreas Boehler            $this->assertEquals(0, count($input), 'No validation messages were expected. We got: ' . implode(', ', $messages));
686*a1a3b679SAndreas Boehler        } else {
687*a1a3b679SAndreas Boehler            $this->assertEquals(1, count($input), 'We expected exactly 1 validation message, We got: ' . implode(', ', $messages));
688*a1a3b679SAndreas Boehler
689*a1a3b679SAndreas Boehler            $this->assertEquals($expectedMessage, $input[0]['message']);
690*a1a3b679SAndreas Boehler            $this->assertEquals($expectedLevel, $input[0]['level']);
691*a1a3b679SAndreas Boehler        }
692*a1a3b679SAndreas Boehler
693*a1a3b679SAndreas Boehler    }
694*a1a3b679SAndreas Boehler
695*a1a3b679SAndreas Boehler
696*a1a3b679SAndreas Boehler}
697