1<?php
2
3namespace Sabre\VObject\ITip;
4
5class BrokerProcessReplyTest extends BrokerTester {
6
7    function testReplyNoOriginal() {
8
9        $itip = <<<ICS
10BEGIN:VCALENDAR
11VERSION:2.0
12METHOD:REPLY
13BEGIN:VEVENT
14SEQUENCE:2
15UID:foobar
16ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo@example.org
17ORGANIZER:mailto:bar@example.org
18END:VEVENT
19END:VCALENDAR
20ICS;
21
22        $old = null;
23        $expected = null;
24
25        $result = $this->process($itip, $old, $expected);
26
27    }
28
29    function testReplyAccept() {
30
31        $itip = <<<ICS
32BEGIN:VCALENDAR
33VERSION:2.0
34METHOD:REPLY
35BEGIN:VEVENT
36ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo@example.org
37ORGANIZER:mailto:bar@example.org
38SEQUENCE:2
39UID:foobar
40END:VEVENT
41END:VCALENDAR
42ICS;
43
44        $old = <<<ICS
45BEGIN:VCALENDAR
46VERSION:2.0
47BEGIN:VEVENT
48SEQUENCE:2
49UID:foobar
50ATTENDEE:mailto:foo@example.org
51ORGANIZER:mailto:bar@example.org
52END:VEVENT
53END:VCALENDAR
54ICS;
55
56        $expected = <<<ICS
57BEGIN:VCALENDAR
58VERSION:2.0
59BEGIN:VEVENT
60SEQUENCE:2
61UID:foobar
62ATTENDEE;PARTSTAT=ACCEPTED;SCHEDULE-STATUS=2.0:mailto:foo@example.org
63ORGANIZER:mailto:bar@example.org
64END:VEVENT
65END:VCALENDAR
66ICS;
67
68        $result = $this->process($itip, $old, $expected);
69
70    }
71
72    function testReplyRequestStatus() {
73
74        $itip = <<<ICS
75BEGIN:VCALENDAR
76VERSION:2.0
77METHOD:REPLY
78BEGIN:VEVENT
79UID:foobar
80REQUEST-STATUS:2.3;foo-bar!
81ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo@example.org
82ORGANIZER:mailto:bar@example.org
83SEQUENCE:2
84UID:foobar
85END:VEVENT
86END:VCALENDAR
87ICS;
88
89        $old = <<<ICS
90BEGIN:VCALENDAR
91VERSION:2.0
92BEGIN:VEVENT
93UID:foobar
94SEQUENCE:2
95ATTENDEE:mailto:foo@example.org
96ORGANIZER:mailto:bar@example.org
97END:VEVENT
98END:VCALENDAR
99ICS;
100
101        $expected = <<<ICS
102BEGIN:VCALENDAR
103VERSION:2.0
104BEGIN:VEVENT
105UID:foobar
106SEQUENCE:2
107ATTENDEE;PARTSTAT=ACCEPTED;SCHEDULE-STATUS=2.3:mailto:foo@example.org
108ORGANIZER:mailto:bar@example.org
109END:VEVENT
110END:VCALENDAR
111ICS;
112
113        $result = $this->process($itip, $old, $expected);
114
115    }
116
117
118    function testReplyPartyCrasher() {
119
120        $itip = <<<ICS
121BEGIN:VCALENDAR
122VERSION:2.0
123METHOD:REPLY
124BEGIN:VEVENT
125ATTENDEE;PARTSTAT=ACCEPTED:mailto:crasher@example.org
126ORGANIZER:mailto:bar@example.org
127SEQUENCE:2
128UID:foobar
129END:VEVENT
130END:VCALENDAR
131ICS;
132
133        $old = <<<ICS
134BEGIN:VCALENDAR
135VERSION:2.0
136BEGIN:VEVENT
137SEQUENCE:2
138UID:foobar
139ATTENDEE:mailto:foo@example.org
140ORGANIZER:mailto:bar@example.org
141END:VEVENT
142END:VCALENDAR
143ICS;
144
145        $expected = <<<ICS
146BEGIN:VCALENDAR
147VERSION:2.0
148BEGIN:VEVENT
149SEQUENCE:2
150UID:foobar
151ATTENDEE:mailto:foo@example.org
152ORGANIZER:mailto:bar@example.org
153ATTENDEE;PARTSTAT=ACCEPTED:mailto:crasher@example.org
154END:VEVENT
155END:VCALENDAR
156ICS;
157
158        $result = $this->process($itip, $old, $expected);
159
160    }
161
162    function testReplyNewException() {
163
164        // This is a reply to 1 instance of a recurring event. This should
165        // automatically create an exception.
166        $itip = <<<ICS
167BEGIN:VCALENDAR
168VERSION:2.0
169METHOD:REPLY
170BEGIN:VEVENT
171ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo@example.org
172ORGANIZER:mailto:bar@example.org
173SEQUENCE:2
174RECURRENCE-ID:20140725T000000Z
175UID:foobar
176END:VEVENT
177END:VCALENDAR
178ICS;
179
180        $old = <<<ICS
181BEGIN:VCALENDAR
182VERSION:2.0
183BEGIN:VEVENT
184SEQUENCE:2
185UID:foobar
186RRULE:FREQ=DAILY
187DTSTART:20140724T000000Z
188DTEND:20140724T010000Z
189ATTENDEE:mailto:foo@example.org
190ORGANIZER:mailto:bar@example.org
191END:VEVENT
192END:VCALENDAR
193ICS;
194
195        $expected = <<<ICS
196BEGIN:VCALENDAR
197VERSION:2.0
198BEGIN:VEVENT
199SEQUENCE:2
200UID:foobar
201RRULE:FREQ=DAILY
202DTSTART:20140724T000000Z
203DTEND:20140724T010000Z
204ATTENDEE:mailto:foo@example.org
205ORGANIZER:mailto:bar@example.org
206END:VEVENT
207BEGIN:VEVENT
208SEQUENCE:2
209UID:foobar
210DTSTART:20140725T000000Z
211DTEND:20140725T010000Z
212ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo@example.org
213ORGANIZER:mailto:bar@example.org
214RECURRENCE-ID:20140725T000000Z
215END:VEVENT
216END:VCALENDAR
217ICS;
218
219        $result = $this->process($itip, $old, $expected);
220
221    }
222
223    function testReplyNewExceptionTz() {
224
225        // This is a reply to 1 instance of a recurring event. This should
226        // automatically create an exception.
227        $itip = <<<ICS
228BEGIN:VCALENDAR
229VERSION:2.0
230METHOD:REPLY
231BEGIN:VEVENT
232ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo@example.org
233ORGANIZER:mailto:bar@example.org
234SEQUENCE:2
235RECURRENCE-ID;TZID=America/Toronto:20140725T000000
236UID:foobar
237END:VEVENT
238END:VCALENDAR
239ICS;
240
241        $old = <<<ICS
242BEGIN:VCALENDAR
243VERSION:2.0
244BEGIN:VEVENT
245SEQUENCE:2
246UID:foobar
247RRULE:FREQ=DAILY
248DTSTART;TZID=America/Toronto:20140724T000000
249DTEND;TZID=America/Toronto:20140724T010000
250ATTENDEE:mailto:foo@example.org
251ORGANIZER:mailto:bar@example.org
252END:VEVENT
253END:VCALENDAR
254ICS;
255
256        $expected = <<<ICS
257BEGIN:VCALENDAR
258VERSION:2.0
259BEGIN:VEVENT
260SEQUENCE:2
261UID:foobar
262RRULE:FREQ=DAILY
263DTSTART;TZID=America/Toronto:20140724T000000
264DTEND;TZID=America/Toronto:20140724T010000
265ATTENDEE:mailto:foo@example.org
266ORGANIZER:mailto:bar@example.org
267END:VEVENT
268BEGIN:VEVENT
269SEQUENCE:2
270UID:foobar
271DTSTART;TZID=America/Toronto:20140725T000000
272DTEND;TZID=America/Toronto:20140725T010000
273ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo@example.org
274ORGANIZER:mailto:bar@example.org
275RECURRENCE-ID;TZID=America/Toronto:20140725T000000
276END:VEVENT
277END:VCALENDAR
278ICS;
279
280        $result = $this->process($itip, $old, $expected);
281
282    }
283
284    function testReplyPartyCrashCreateExcepton() {
285
286        // IN this test there's a recurring event that has an exception. The
287        // exception is missing the attendee.
288        //
289        // The attendee party crashes the instance, so it should show up in the
290        // resulting object.
291        $itip = <<<ICS
292BEGIN:VCALENDAR
293VERSION:2.0
294METHOD:REPLY
295BEGIN:VEVENT
296ATTENDEE;PARTSTAT=ACCEPTED;CN=Crasher!:mailto:crasher@example.org
297ORGANIZER:mailto:bar@example.org
298SEQUENCE:2
299RECURRENCE-ID:20140725T000000Z
300UID:foobar
301END:VEVENT
302END:VCALENDAR
303ICS;
304
305        $old = <<<ICS
306BEGIN:VCALENDAR
307VERSION:2.0
308BEGIN:VEVENT
309SEQUENCE:2
310UID:foobar
311RRULE:FREQ=DAILY
312DTSTART:20140724T000000Z
313DTEND:20140724T010000Z
314ORGANIZER:mailto:bar@example.org
315END:VEVENT
316END:VCALENDAR
317ICS;
318
319        $expected = <<<ICS
320BEGIN:VCALENDAR
321VERSION:2.0
322BEGIN:VEVENT
323SEQUENCE:2
324UID:foobar
325RRULE:FREQ=DAILY
326DTSTART:20140724T000000Z
327DTEND:20140724T010000Z
328ORGANIZER:mailto:bar@example.org
329END:VEVENT
330BEGIN:VEVENT
331SEQUENCE:2
332UID:foobar
333DTSTART:20140725T000000Z
334DTEND:20140725T010000Z
335ORGANIZER:mailto:bar@example.org
336RECURRENCE-ID:20140725T000000Z
337ATTENDEE;PARTSTAT=ACCEPTED;CN=Crasher!:mailto:crasher@example.org
338END:VEVENT
339END:VCALENDAR
340ICS;
341
342        $result = $this->process($itip, $old, $expected);
343
344    }
345
346    function testReplyNewExceptionNoMasterEvent() {
347
348        /**
349         * This iTip message would normally create a new exception, but the
350         * server is not able to create this new instance, because there's no
351         * master event to clone from.
352         *
353         * This test checks if the message is ignored.
354         */
355        $itip = <<<ICS
356BEGIN:VCALENDAR
357VERSION:2.0
358METHOD:REPLY
359BEGIN:VEVENT
360ATTENDEE;PARTSTAT=ACCEPTED;CN=Crasher!:mailto:crasher@example.org
361ORGANIZER:mailto:bar@example.org
362SEQUENCE:2
363RECURRENCE-ID:20140725T000000Z
364UID:foobar
365END:VEVENT
366END:VCALENDAR
367ICS;
368
369        $old = <<<ICS
370BEGIN:VCALENDAR
371VERSION:2.0
372BEGIN:VEVENT
373SEQUENCE:2
374UID:foobar
375RRULE:FREQ=DAILY
376DTSTART:20140724T000000Z
377DTEND:20140724T010000Z
378RECURRENCE-ID:20140724T000000Z
379ORGANIZER:mailto:bar@example.org
380END:VEVENT
381END:VCALENDAR
382ICS;
383
384        $expected = null;
385        $result = $this->process($itip, $old, $expected);
386
387    }
388
389    /**
390     * @depends testReplyAccept
391     */
392    function testReplyAcceptUpdateRSVP() {
393
394        $itip = <<<ICS
395BEGIN:VCALENDAR
396VERSION:2.0
397METHOD:REPLY
398BEGIN:VEVENT
399ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo@example.org
400ORGANIZER:mailto:bar@example.org
401SEQUENCE:2
402UID:foobar
403END:VEVENT
404END:VCALENDAR
405ICS;
406
407        $old = <<<ICS
408BEGIN:VCALENDAR
409VERSION:2.0
410BEGIN:VEVENT
411SEQUENCE:2
412UID:foobar
413ATTENDEE;RSVP=TRUE:mailto:foo@example.org
414ORGANIZER:mailto:bar@example.org
415END:VEVENT
416END:VCALENDAR
417ICS;
418
419        $expected = <<<ICS
420BEGIN:VCALENDAR
421VERSION:2.0
422BEGIN:VEVENT
423SEQUENCE:2
424UID:foobar
425ATTENDEE;PARTSTAT=ACCEPTED;SCHEDULE-STATUS=2.0:mailto:foo@example.org
426ORGANIZER:mailto:bar@example.org
427END:VEVENT
428END:VCALENDAR
429ICS;
430
431        $result = $this->process($itip, $old, $expected);
432
433    }
434
435    function testReplyNewExceptionFirstOccurence() {
436
437        // This is a reply to 1 instance of a recurring event. This should
438        // automatically create an exception.
439        $itip = <<<ICS
440BEGIN:VCALENDAR
441VERSION:2.0
442METHOD:REPLY
443BEGIN:VEVENT
444ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo@example.org
445ORGANIZER:mailto:bar@example.org
446SEQUENCE:2
447RECURRENCE-ID:20140724T000000Z
448UID:foobar
449END:VEVENT
450END:VCALENDAR
451ICS;
452
453        $old = <<<ICS
454BEGIN:VCALENDAR
455VERSION:2.0
456BEGIN:VEVENT
457SEQUENCE:2
458UID:foobar
459RRULE:FREQ=DAILY
460DTSTART:20140724T000000Z
461DTEND:20140724T010000Z
462ATTENDEE:mailto:foo@example.org
463ORGANIZER:mailto:bar@example.org
464END:VEVENT
465END:VCALENDAR
466ICS;
467
468        $expected = <<<ICS
469BEGIN:VCALENDAR
470VERSION:2.0
471BEGIN:VEVENT
472SEQUENCE:2
473UID:foobar
474RRULE:FREQ=DAILY
475DTSTART:20140724T000000Z
476DTEND:20140724T010000Z
477ATTENDEE:mailto:foo@example.org
478ORGANIZER:mailto:bar@example.org
479END:VEVENT
480BEGIN:VEVENT
481SEQUENCE:2
482UID:foobar
483DTSTART:20140724T000000Z
484DTEND:20140724T010000Z
485ATTENDEE;PARTSTAT=ACCEPTED:mailto:foo@example.org
486ORGANIZER:mailto:bar@example.org
487RECURRENCE-ID:20140724T000000Z
488END:VEVENT
489END:VCALENDAR
490ICS;
491
492        $result = $this->process($itip, $old, $expected);
493
494    }
495
496}
497