1<?php
2
3namespace Sabre\VObject\ITip;
4
5class BrokerAttendeeReplyTest extends BrokerTester {
6
7    function testAccepted() {
8
9        $oldMessage = <<<ICS
10BEGIN:VCALENDAR
11VERSION:2.0
12BEGIN:VEVENT
13UID:foobar
14SUMMARY:B-day party
15SEQUENCE:1
16ORGANIZER;CN=Strunk:mailto:strunk@example.org
17ATTENDEE;CN=One:mailto:one@example.org
18DTSTART:20140716T120000Z
19END:VEVENT
20END:VCALENDAR
21ICS;
22
23
24        $newMessage = <<<ICS
25BEGIN:VCALENDAR
26VERSION:2.0
27BEGIN:VEVENT
28UID:foobar
29SUMMARY:B-day party
30SEQUENCE:1
31ORGANIZER;CN=Strunk:mailto:strunk@example.org
32ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
33DTSTART:20140716T120000Z
34END:VEVENT
35END:VCALENDAR
36ICS;
37
38        $version = \Sabre\VObject\Version::VERSION;
39
40        $expected = array(
41            array(
42                'uid' => 'foobar',
43                'method' => 'REPLY',
44                'component' => 'VEVENT',
45                'sender' => 'mailto:one@example.org',
46                'senderName' => 'One',
47                'recipient' => 'mailto:strunk@example.org',
48                'recipientName' => 'Strunk',
49                'message' => <<<ICS
50BEGIN:VCALENDAR
51VERSION:2.0
52PRODID:-//Sabre//Sabre VObject $version//EN
53CALSCALE:GREGORIAN
54METHOD:REPLY
55BEGIN:VEVENT
56UID:foobar
57SEQUENCE:1
58DTSTART:20140716T120000Z
59SUMMARY:B-day party
60ORGANIZER;CN=Strunk:mailto:strunk@example.org
61ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
62END:VEVENT
63END:VCALENDAR
64ICS
65
66            ),
67
68        );
69
70        $result = $this->parse($oldMessage, $newMessage, $expected);
71
72    }
73
74    function testRecurringReply() {
75
76        $oldMessage = <<<ICS
77BEGIN:VCALENDAR
78VERSION:2.0
79BEGIN:VEVENT
80UID:foobar
81SEQUENCE:1
82ORGANIZER;CN=Strunk:mailto:strunk@example.org
83ATTENDEE;CN=One:mailto:one@example.org
84DTSTART:20140724T120000Z
85SUMMARY:Daily sprint
86RRULE;FREQ=DAILY
87END:VEVENT
88END:VCALENDAR
89ICS;
90
91
92        $newMessage = <<<ICS
93BEGIN:VCALENDAR
94VERSION:2.0
95BEGIN:VEVENT
96UID:foobar
97SEQUENCE:1
98ORGANIZER;CN=Strunk:mailto:strunk@example.org
99ATTENDEE;PARTSTAT=NEEDS-ACTION;CN=One:mailto:one@example.org
100DTSTART:20140724T120000Z
101SUMMARY:Daily sprint
102END:VEVENT
103BEGIN:VEVENT
104UID:foobar
105SEQUENCE:1
106ORGANIZER;CN=Strunk:mailto:strunk@example.org
107ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
108DTSTART:20140726T120000Z
109RECURRENCE-ID:20140726T120000Z
110END:VEVENT
111BEGIN:VEVENT
112UID:foobar
113SEQUENCE:1
114ORGANIZER;CN=Strunk:mailto:strunk@example.org
115ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one@example.org
116DTSTART:20140724T120000Z
117RECURRENCE-ID:20140724T120000Z
118END:VEVENT
119BEGIN:VEVENT
120UID:foobar
121SEQUENCE:1
122ORGANIZER;CN=Strunk:mailto:strunk@example.org
123ATTENDEE;PARTSTAT=TENTATIVE;CN=One:mailto:one@example.org
124DTSTART:20140728T120000Z
125RECURRENCE-ID:20140728T120000Z
126END:VEVENT
127BEGIN:VEVENT
128UID:foobar
129SEQUENCE:1
130ORGANIZER;CN=Strunk:mailto:strunk@example.org
131ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
132DTSTART:20140729T120000Z
133RECURRENCE-ID:20140729T120000Z
134END:VEVENT
135BEGIN:VEVENT
136UID:foobar
137SEQUENCE:1
138ORGANIZER;CN=Strunk:mailto:strunk@example.org
139ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one@example.org
140DTSTART:20140725T120000Z
141RECURRENCE-ID:20140725T120000Z
142END:VEVENT
143END:VCALENDAR
144ICS;
145
146        $version = \Sabre\VObject\Version::VERSION;
147
148        $expected = array(
149            array(
150                'uid' => 'foobar',
151                'method' => 'REPLY',
152                'component' => 'VEVENT',
153                'sender' => 'mailto:one@example.org',
154                'senderName' => 'One',
155                'recipient' => 'mailto:strunk@example.org',
156                'recipientName' => 'Strunk',
157                'message' => <<<ICS
158BEGIN:VCALENDAR
159VERSION:2.0
160PRODID:-//Sabre//Sabre VObject $version//EN
161CALSCALE:GREGORIAN
162METHOD:REPLY
163BEGIN:VEVENT
164UID:foobar
165SEQUENCE:1
166DTSTART:20140726T120000Z
167SUMMARY:Daily sprint
168RECURRENCE-ID:20140726T120000Z
169ORGANIZER;CN=Strunk:mailto:strunk@example.org
170ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
171END:VEVENT
172BEGIN:VEVENT
173UID:foobar
174SEQUENCE:1
175DTSTART:20140724T120000Z
176SUMMARY:Daily sprint
177RECURRENCE-ID:20140724T120000Z
178ORGANIZER;CN=Strunk:mailto:strunk@example.org
179ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one@example.org
180END:VEVENT
181BEGIN:VEVENT
182UID:foobar
183SEQUENCE:1
184DTSTART:20140728T120000Z
185SUMMARY:Daily sprint
186RECURRENCE-ID:20140728T120000Z
187ORGANIZER;CN=Strunk:mailto:strunk@example.org
188ATTENDEE;PARTSTAT=TENTATIVE;CN=One:mailto:one@example.org
189END:VEVENT
190BEGIN:VEVENT
191UID:foobar
192SEQUENCE:1
193DTSTART:20140729T120000Z
194SUMMARY:Daily sprint
195RECURRENCE-ID:20140729T120000Z
196ORGANIZER;CN=Strunk:mailto:strunk@example.org
197ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
198END:VEVENT
199BEGIN:VEVENT
200UID:foobar
201SEQUENCE:1
202DTSTART:20140725T120000Z
203SUMMARY:Daily sprint
204RECURRENCE-ID:20140725T120000Z
205ORGANIZER;CN=Strunk:mailto:strunk@example.org
206ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one@example.org
207END:VEVENT
208END:VCALENDAR
209ICS
210
211            ),
212
213        );
214
215        $result = $this->parse($oldMessage, $newMessage, $expected);
216
217    }
218
219    function testRecurringAllDay() {
220
221        $oldMessage = <<<ICS
222BEGIN:VCALENDAR
223VERSION:2.0
224BEGIN:VEVENT
225UID:foobar
226SEQUENCE:1
227ORGANIZER;CN=Strunk:mailto:strunk@example.org
228ATTENDEE;CN=One:mailto:one@example.org
229DTSTART;VALUE=DATE:20140724
230RRULE;FREQ=DAILY
231END:VEVENT
232END:VCALENDAR
233ICS;
234
235
236    $newMessage = <<<ICS
237BEGIN:VCALENDAR
238VERSION:2.0
239BEGIN:VEVENT
240UID:foobar
241SEQUENCE:1
242ORGANIZER;CN=Strunk:mailto:strunk@example.org
243ATTENDEE;PARTSTAT=NEEDS-ACTION;CN=One:mailto:one@example.org
244DTSTART;VALUE=DATE:20140724
245END:VEVENT
246BEGIN:VEVENT
247UID:foobar
248SEQUENCE:1
249ORGANIZER;CN=Strunk:mailto:strunk@example.org
250ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
251DTSTART;VALUE=DATE:20140726
252RECURRENCE-ID;VALUE=DATE:20140726
253END:VEVENT
254BEGIN:VEVENT
255UID:foobar
256SEQUENCE:1
257ORGANIZER;CN=Strunk:mailto:strunk@example.org
258ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one@example.org
259DTSTART;VALUE=DATE:20140724
260RECURRENCE-ID;VALUE=DATE:20140724
261END:VEVENT
262BEGIN:VEVENT
263UID:foobar
264SEQUENCE:1
265ORGANIZER;CN=Strunk:mailto:strunk@example.org
266ATTENDEE;PARTSTAT=TENTATIVE;CN=One:mailto:one@example.org
267DTSTART;VALUE=DATE:20140728
268RECURRENCE-ID;VALUE=DATE:20140728
269END:VEVENT
270BEGIN:VEVENT
271UID:foobar
272SEQUENCE:1
273ORGANIZER;CN=Strunk:mailto:strunk@example.org
274ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
275DTSTART;VALUE=DATE:20140729
276RECURRENCE-ID;VALUE=DATE:20140729
277END:VEVENT
278BEGIN:VEVENT
279UID:foobar
280SEQUENCE:1
281ORGANIZER;CN=Strunk:mailto:strunk@example.org
282ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one@example.org
283DTSTART;VALUE=DATE:20140725
284RECURRENCE-ID;VALUE=DATE:20140725
285END:VEVENT
286END:VCALENDAR
287ICS;
288
289    $version = \Sabre\VObject\Version::VERSION;
290
291    $expected = array(
292        array(
293            'uid' => 'foobar',
294            'method' => 'REPLY',
295            'component' => 'VEVENT',
296            'sender' => 'mailto:one@example.org',
297            'senderName' => 'One',
298            'recipient' => 'mailto:strunk@example.org',
299            'recipientName' => 'Strunk',
300            'message' => <<<ICS
301BEGIN:VCALENDAR
302VERSION:2.0
303PRODID:-//Sabre//Sabre VObject $version//EN
304CALSCALE:GREGORIAN
305METHOD:REPLY
306BEGIN:VEVENT
307UID:foobar
308SEQUENCE:1
309DTSTART;VALUE=DATE:20140726
310RECURRENCE-ID;VALUE=DATE:20140726
311ORGANIZER;CN=Strunk:mailto:strunk@example.org
312ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
313END:VEVENT
314BEGIN:VEVENT
315UID:foobar
316SEQUENCE:1
317DTSTART;VALUE=DATE:20140724
318RECURRENCE-ID;VALUE=DATE:20140724
319ORGANIZER;CN=Strunk:mailto:strunk@example.org
320ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one@example.org
321END:VEVENT
322BEGIN:VEVENT
323UID:foobar
324SEQUENCE:1
325DTSTART;VALUE=DATE:20140728
326RECURRENCE-ID;VALUE=DATE:20140728
327ORGANIZER;CN=Strunk:mailto:strunk@example.org
328ATTENDEE;PARTSTAT=TENTATIVE;CN=One:mailto:one@example.org
329END:VEVENT
330BEGIN:VEVENT
331UID:foobar
332SEQUENCE:1
333DTSTART;VALUE=DATE:20140729
334RECURRENCE-ID;VALUE=DATE:20140729
335ORGANIZER;CN=Strunk:mailto:strunk@example.org
336ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
337END:VEVENT
338BEGIN:VEVENT
339UID:foobar
340SEQUENCE:1
341DTSTART;VALUE=DATE:20140725
342RECURRENCE-ID;VALUE=DATE:20140725
343ORGANIZER;CN=Strunk:mailto:strunk@example.org
344ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one@example.org
345END:VEVENT
346END:VCALENDAR
347ICS
348
349            ),
350
351        );
352
353        $result = $this->parse($oldMessage, $newMessage, $expected);
354
355    }
356
357    function testNoChange() {
358
359        $oldMessage = <<<ICS
360BEGIN:VCALENDAR
361VERSION:2.0
362BEGIN:VEVENT
363UID:foobar
364SEQUENCE:1
365ORGANIZER;CN=Strunk:mailto:strunk@example.org
366ATTENDEE;CN=One:mailto:one@example.org
367DTSTART:20140716T120000Z
368END:VEVENT
369END:VCALENDAR
370ICS;
371
372
373        $newMessage = <<<ICS
374BEGIN:VCALENDAR
375VERSION:2.0
376BEGIN:VEVENT
377UID:foobar
378SEQUENCE:1
379ORGANIZER;CN=Strunk:mailto:strunk@example.org
380ATTENDEE;PARTSTAT=NEEDS-ACTION;CN=One:mailto:one@example.org
381DTSTART:20140716T120000Z
382END:VEVENT
383END:VCALENDAR
384ICS;
385
386
387        $expected = array();
388        $result = $this->parse($oldMessage, $newMessage, $expected);
389
390    }
391
392    function testNoChangeForceSend() {
393
394        $oldMessage = <<<ICS
395BEGIN:VCALENDAR
396VERSION:2.0
397BEGIN:VEVENT
398UID:foobar
399SEQUENCE:1
400ORGANIZER;CN=Strunk:mailto:strunk@example.org
401ATTENDEE;CN=One:mailto:one@example.org
402DTSTART:20140716T120000Z
403END:VEVENT
404END:VCALENDAR
405ICS;
406
407
408        $newMessage = <<<ICS
409BEGIN:VCALENDAR
410VERSION:2.0
411BEGIN:VEVENT
412UID:foobar
413SEQUENCE:1
414ORGANIZER;SCHEDULE-FORCE-SEND=REPLY;CN=Strunk:mailto:strunk@example.org
415ATTENDEE;PARTSTAT=NEEDS-ACTION;CN=One:mailto:one@example.org
416DTSTART:20140716T120000Z
417END:VEVENT
418END:VCALENDAR
419ICS;
420
421        $version = \Sabre\VObject\Version::VERSION;
422        $expected = array(
423            array(
424                'uid' => 'foobar',
425                'method' => 'REPLY',
426                'component' => 'VEVENT',
427                'sender' => 'mailto:one@example.org',
428                'senderName' => 'One',
429                'recipient' => 'mailto:strunk@example.org',
430                'recipientName' => 'Strunk',
431                'message' => <<<ICS
432BEGIN:VCALENDAR
433VERSION:2.0
434PRODID:-//Sabre//Sabre VObject $version//EN
435CALSCALE:GREGORIAN
436METHOD:REPLY
437BEGIN:VEVENT
438UID:foobar
439SEQUENCE:1
440DTSTART:20140716T120000Z
441ORGANIZER;CN=Strunk:mailto:strunk@example.org
442ATTENDEE;PARTSTAT=NEEDS-ACTION;CN=One:mailto:one@example.org
443END:VEVENT
444END:VCALENDAR
445ICS
446            )
447
448        );
449        $result = $this->parse($oldMessage, $newMessage, $expected);
450
451    }
452
453    function testNoRelevantAttendee() {
454
455        $oldMessage = <<<ICS
456BEGIN:VCALENDAR
457VERSION:2.0
458BEGIN:VEVENT
459UID:foobar
460SEQUENCE:1
461ORGANIZER;CN=Strunk:mailto:strunk@example.org
462ATTENDEE;CN=Two:mailto:two@example.org
463DTSTART:20140716T120000Z
464END:VEVENT
465END:VCALENDAR
466ICS;
467
468
469        $newMessage = <<<ICS
470BEGIN:VCALENDAR
471VERSION:2.0
472BEGIN:VEVENT
473UID:foobar
474SEQUENCE:1
475ORGANIZER;CN=Strunk:mailto:strunk@example.org
476ATTENDEE;PARTSTAT=ACCEPTED;CN=Two:mailto:two@example.org
477DTSTART:20140716T120000Z
478END:VEVENT
479END:VCALENDAR
480ICS;
481
482        $expected = array();
483        $result = $this->parse($oldMessage, $newMessage, $expected);
484
485    }
486
487    /**
488     * In this test, an event exists in an attendees calendar. The event
489     * is recurring, and the attendee deletes 1 instance of the event.
490     * This instance shows up in EXDATE
491     *
492     * This should automatically generate a DECLINED message for that
493     * specific instance.
494     */
495    function testCreateReplyByException() {
496
497
498        $oldMessage = <<<ICS
499BEGIN:VCALENDAR
500VERSION:2.0
501BEGIN:VEVENT
502UID:foobar
503SEQUENCE:1
504DTSTART:20140811T200000Z
505RRULE:FREQ=WEEKLY
506ORGANIZER:mailto:organizer@example.org
507ATTENDEE:mailto:one@example.org
508END:VEVENT
509END:VCALENDAR
510ICS;
511
512        $newMessage = <<<ICS
513BEGIN:VCALENDAR
514VERSION:2.0
515BEGIN:VEVENT
516UID:foobar
517SEQUENCE:1
518DTSTART:20140811T200000Z
519RRULE:FREQ=WEEKLY
520ORGANIZER:mailto:organizer@example.org
521ATTENDEE:mailto:one@example.org
522EXDATE:20140818T200000Z
523END:VEVENT
524END:VCALENDAR
525ICS;
526
527        $version = \Sabre\VObject\Version::VERSION;
528        $expected = array(
529            array(
530                'uid' => 'foobar',
531                'method' => 'REPLY',
532                'component' => 'VEVENT',
533                'sender' => 'mailto:one@example.org',
534                'senderName' => null,
535                'recipient' => 'mailto:organizer@example.org',
536                'recipientName' => null,
537                'message' => <<<ICS
538BEGIN:VCALENDAR
539VERSION:2.0
540PRODID:-//Sabre//Sabre VObject $version//EN
541CALSCALE:GREGORIAN
542METHOD:REPLY
543BEGIN:VEVENT
544UID:foobar
545SEQUENCE:1
546DTSTART:20140818T200000Z
547RECURRENCE-ID:20140818T200000Z
548ORGANIZER:mailto:organizer@example.org
549ATTENDEE;PARTSTAT=DECLINED:mailto:one@example.org
550END:VEVENT
551END:VCALENDAR
552ICS
553
554            ),
555        );
556        $result = $this->parse($oldMessage, $newMessage, $expected);
557
558    }
559
560    /**
561     * This test is identical to the last, but now we're working with
562     * timezones.
563     *
564     * @depends testCreateReplyByException
565     */
566    function testCreateReplyByExceptionTz() {
567
568
569        $oldMessage = <<<ICS
570BEGIN:VCALENDAR
571VERSION:2.0
572BEGIN:VEVENT
573UID:foobar
574SEQUENCE:1
575DTSTART;TZID=America/Toronto:20140811T200000
576RRULE:FREQ=WEEKLY
577ORGANIZER:mailto:organizer@example.org
578ATTENDEE:mailto:one@example.org
579END:VEVENT
580END:VCALENDAR
581ICS;
582
583        $newMessage = <<<ICS
584BEGIN:VCALENDAR
585VERSION:2.0
586BEGIN:VEVENT
587UID:foobar
588SEQUENCE:1
589DTSTART;TZID=America/Toronto:20140811T200000
590RRULE:FREQ=WEEKLY
591ORGANIZER:mailto:organizer@example.org
592ATTENDEE:mailto:one@example.org
593EXDATE;TZID=America/Toronto:20140818T200000
594END:VEVENT
595END:VCALENDAR
596ICS;
597
598        $version = \Sabre\VObject\Version::VERSION;
599        $expected = array(
600            array(
601                'uid' => 'foobar',
602                'method' => 'REPLY',
603                'component' => 'VEVENT',
604                'sender' => 'mailto:one@example.org',
605                'senderName' => null,
606                'recipient' => 'mailto:organizer@example.org',
607                'recipientName' => null,
608                'message' => <<<ICS
609BEGIN:VCALENDAR
610VERSION:2.0
611PRODID:-//Sabre//Sabre VObject $version//EN
612CALSCALE:GREGORIAN
613METHOD:REPLY
614BEGIN:VEVENT
615UID:foobar
616SEQUENCE:1
617DTSTART;TZID=America/Toronto:20140818T200000
618RECURRENCE-ID;TZID=America/Toronto:20140818T200000
619ORGANIZER:mailto:organizer@example.org
620ATTENDEE;PARTSTAT=DECLINED:mailto:one@example.org
621END:VEVENT
622END:VCALENDAR
623ICS
624
625            ),
626        );
627        $result = $this->parse($oldMessage, $newMessage, $expected);
628
629    }
630
631    /**
632     * @depends testCreateReplyByException
633     */
634    function testCreateReplyByExceptionAllDay() {
635
636
637        $oldMessage = <<<ICS
638BEGIN:VCALENDAR
639VERSION:2.0
640BEGIN:VEVENT
641SUMMARY:Weekly meeting
642UID:foobar
643SEQUENCE:1
644DTSTART;VALUE=DATE:20140811
645RRULE:FREQ=WEEKLY
646ORGANIZER:mailto:organizer@example.org
647ATTENDEE:mailto:one@example.org
648END:VEVENT
649END:VCALENDAR
650ICS;
651
652        $newMessage = <<<ICS
653BEGIN:VCALENDAR
654VERSION:2.0
655BEGIN:VEVENT
656SUMMARY:Weekly meeting
657UID:foobar
658SEQUENCE:1
659DTSTART;VALUE=DATE:20140811
660RRULE:FREQ=WEEKLY
661ORGANIZER:mailto:organizer@example.org
662ATTENDEE:mailto:one@example.org
663EXDATE;VALUE=DATE:20140818
664END:VEVENT
665END:VCALENDAR
666ICS;
667
668        $version = \Sabre\VObject\Version::VERSION;
669        $expected = array(
670            array(
671                'uid' => 'foobar',
672                'method' => 'REPLY',
673                'component' => 'VEVENT',
674                'sender' => 'mailto:one@example.org',
675                'senderName' => null,
676                'recipient' => 'mailto:organizer@example.org',
677                'recipientName' => null,
678                'message' => <<<ICS
679BEGIN:VCALENDAR
680VERSION:2.0
681PRODID:-//Sabre//Sabre VObject $version//EN
682CALSCALE:GREGORIAN
683METHOD:REPLY
684BEGIN:VEVENT
685UID:foobar
686SEQUENCE:1
687DTSTART;VALUE=DATE:20140818
688SUMMARY:Weekly meeting
689RECURRENCE-ID;VALUE=DATE:20140818
690ORGANIZER:mailto:organizer@example.org
691ATTENDEE;PARTSTAT=DECLINED:mailto:one@example.org
692END:VEVENT
693END:VCALENDAR
694ICS
695
696            ),
697        );
698        $result = $this->parse($oldMessage, $newMessage, $expected);
699
700    }
701
702    function testDeclined() {
703
704        $oldMessage = <<<ICS
705BEGIN:VCALENDAR
706VERSION:2.0
707BEGIN:VEVENT
708UID:foobar
709SEQUENCE:1
710ORGANIZER;CN=Strunk:mailto:strunk@example.org
711ATTENDEE;CN=One:mailto:one@example.org
712DTSTART:20140716T120000Z
713END:VEVENT
714END:VCALENDAR
715ICS;
716
717
718        $newMessage = <<<ICS
719BEGIN:VCALENDAR
720VERSION:2.0
721BEGIN:VEVENT
722UID:foobar
723SEQUENCE:1
724ORGANIZER;CN=Strunk:mailto:strunk@example.org
725ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one@example.org
726DTSTART:20140716T120000Z
727END:VEVENT
728END:VCALENDAR
729ICS;
730
731        $version = \Sabre\VObject\Version::VERSION;
732
733        $expected = array(
734            array(
735                'uid' => 'foobar',
736                'method' => 'REPLY',
737                'component' => 'VEVENT',
738                'sender' => 'mailto:one@example.org',
739                'senderName' => 'One',
740                'recipient' => 'mailto:strunk@example.org',
741                'recipientName' => 'Strunk',
742                'message' => <<<ICS
743BEGIN:VCALENDAR
744VERSION:2.0
745PRODID:-//Sabre//Sabre VObject $version//EN
746CALSCALE:GREGORIAN
747METHOD:REPLY
748BEGIN:VEVENT
749UID:foobar
750SEQUENCE:1
751DTSTART:20140716T120000Z
752ORGANIZER;CN=Strunk:mailto:strunk@example.org
753ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one@example.org
754END:VEVENT
755END:VCALENDAR
756ICS
757
758            ),
759
760        );
761
762        $result = $this->parse($oldMessage, $newMessage, $expected);
763
764    }
765
766    function testDeclinedCancelledEvent() {
767
768        $oldMessage = <<<ICS
769BEGIN:VCALENDAR
770VERSION:2.0
771BEGIN:VEVENT
772STATUS:CANCELLED
773UID:foobar
774SEQUENCE:1
775ORGANIZER;CN=Strunk:mailto:strunk@example.org
776ATTENDEE;CN=One:mailto:one@example.org
777DTSTART:20140716T120000Z
778END:VEVENT
779END:VCALENDAR
780ICS;
781
782
783        $newMessage = <<<ICS
784BEGIN:VCALENDAR
785VERSION:2.0
786BEGIN:VEVENT
787STATUS:CANCELLED
788UID:foobar
789SEQUENCE:1
790ORGANIZER;CN=Strunk:mailto:strunk@example.org
791ATTENDEE;PARTSTAT=DECLINED;CN=One:mailto:one@example.org
792DTSTART:20140716T120000Z
793END:VEVENT
794END:VCALENDAR
795ICS;
796
797        $version = \Sabre\VObject\Version::VERSION;
798
799        $expected = array();
800
801        $result = $this->parse($oldMessage, $newMessage, $expected);
802
803    }
804
805    /**
806     * In this test, a new exception is created by an attendee as well.
807     *
808     * Except in this case, there was already an overridden event, and the
809     * overridden event was marked as cancelled by the attendee.
810     *
811     * For any other attendence status, the new status would have been
812     * declined, but for this, no message should we sent.
813     */
814    function testDontCreateReplyWhenEventWasDeclined() {
815
816
817        $oldMessage = <<<ICS
818BEGIN:VCALENDAR
819VERSION:2.0
820BEGIN:VEVENT
821UID:foobar
822SEQUENCE:1
823DTSTART:20140811T200000Z
824RRULE:FREQ=WEEKLY
825ORGANIZER:mailto:organizer@example.org
826ATTENDEE:mailto:one@example.org
827END:VEVENT
828BEGIN:VEVENT
829RECURRENCE-ID:20140818T200000Z
830UID:foobar
831SEQUENCE:1
832DTSTART:20140818T200000Z
833RRULE:FREQ=WEEKLY
834ORGANIZER:mailto:organizer@example.org
835ATTENDEE;PARTSTAT=DECLINED:mailto:one@example.org
836END:VEVENT
837END:VCALENDAR
838ICS;
839
840        $newMessage = <<<ICS
841BEGIN:VCALENDAR
842VERSION:2.0
843BEGIN:VEVENT
844UID:foobar
845SEQUENCE:1
846DTSTART:20140811T200000Z
847RRULE:FREQ=WEEKLY
848ORGANIZER:mailto:organizer@example.org
849ATTENDEE:mailto:one@example.org
850EXDATE:20140818T200000Z
851END:VEVENT
852END:VCALENDAR
853ICS;
854
855        $version = \Sabre\VObject\Version::VERSION;
856        $expected = array();
857
858        $result = $this->parse($oldMessage, $newMessage, $expected);
859
860    }
861
862    function testScheduleAgentOnOrganizer() {
863
864        $oldMessage = <<<ICS
865BEGIN:VCALENDAR
866VERSION:2.0
867BEGIN:VEVENT
868UID:foobar
869SEQUENCE:1
870ORGANIZER;CN=Strunk:mailto:strunk@example.org
871ATTENDEE;CN=One:mailto:one@example.org
872DTSTART:20140716T120000Z
873END:VEVENT
874END:VCALENDAR
875ICS;
876
877
878        $newMessage = <<<ICS
879BEGIN:VCALENDAR
880VERSION:2.0
881BEGIN:VEVENT
882UID:foobar
883SEQUENCE:1
884ORGANIZER;SCHEDULE-AGENT=CLIENT;CN=Strunk:mailto:strunk@example.org
885ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
886DTSTART:20140716T120000Z
887END:VEVENT
888END:VCALENDAR
889ICS;
890
891        $version = \Sabre\VObject\Version::VERSION;
892
893        $expected = array();
894        $result = $this->parse($oldMessage, $newMessage, $expected);
895
896    }
897
898    function testAcceptedAllDay() {
899
900        $oldMessage = <<<ICS
901BEGIN:VCALENDAR
902VERSION:2.0
903BEGIN:VEVENT
904UID:foobar
905SEQUENCE:1
906ORGANIZER;CN=Strunk:mailto:strunk@example.org
907ATTENDEE;CN=One:mailto:one@example.org
908DTSTART;VALUE=DATE:20140716
909END:VEVENT
910END:VCALENDAR
911ICS;
912
913
914        $newMessage = <<<ICS
915BEGIN:VCALENDAR
916VERSION:2.0
917BEGIN:VEVENT
918UID:foobar
919SEQUENCE:1
920ORGANIZER;CN=Strunk:mailto:strunk@example.org
921ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
922DTSTART;VALUE=DATE:20140716
923END:VEVENT
924END:VCALENDAR
925ICS;
926
927        $version = \Sabre\VObject\Version::VERSION;
928
929        $expected = array(
930            array(
931                'uid' => 'foobar',
932                'method' => 'REPLY',
933                'component' => 'VEVENT',
934                'sender' => 'mailto:one@example.org',
935                'senderName' => 'One',
936                'recipient' => 'mailto:strunk@example.org',
937                'recipientName' => 'Strunk',
938                'message' => <<<ICS
939BEGIN:VCALENDAR
940VERSION:2.0
941PRODID:-//Sabre//Sabre VObject $version//EN
942CALSCALE:GREGORIAN
943METHOD:REPLY
944BEGIN:VEVENT
945UID:foobar
946SEQUENCE:1
947DTSTART;VALUE=DATE:20140716
948ORGANIZER;CN=Strunk:mailto:strunk@example.org
949ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
950END:VEVENT
951END:VCALENDAR
952ICS
953
954            ),
955
956        );
957
958        $result = $this->parse($oldMessage, $newMessage, $expected);
959
960    }
961
962    /**
963     * This function tests an attendee updating their status to an event where
964     * they don't have the master event of.
965     *
966     * This is possible in cases an organizer created a recurring event, and
967     * invited an attendee for one instance of the event.
968     */
969    function testReplyNoMasterEvent() {
970
971        $oldMessage = <<<ICS
972BEGIN:VCALENDAR
973VERSION:2.0
974BEGIN:VEVENT
975UID:foobar
976SEQUENCE:1
977ORGANIZER;CN=Strunk:mailto:strunk@example.org
978ATTENDEE;CN=One:mailto:one@example.org
979RECURRENCE-ID:20140724T120000Z
980DTSTART:20140724T120000Z
981SUMMARY:Daily sprint
982END:VEVENT
983END:VCALENDAR
984ICS;
985
986
987        $newMessage = <<<ICS
988BEGIN:VCALENDAR
989VERSION:2.0
990BEGIN:VEVENT
991UID:foobar
992SEQUENCE:1
993ORGANIZER;CN=Strunk:mailto:strunk@example.org
994ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
995RECURRENCE-ID:20140724T120000Z
996DTSTART:20140724T120000Z
997SUMMARY:Daily sprint
998END:VEVENT
999END:VCALENDAR
1000ICS;
1001
1002        $version = \Sabre\VObject\Version::VERSION;
1003
1004        $expected = array(
1005            array(
1006                'uid' => 'foobar',
1007                'method' => 'REPLY',
1008                'component' => 'VEVENT',
1009                'sender' => 'mailto:one@example.org',
1010                'senderName' => 'One',
1011                'recipient' => 'mailto:strunk@example.org',
1012                'recipientName' => 'Strunk',
1013                'message' => <<<ICS
1014BEGIN:VCALENDAR
1015VERSION:2.0
1016CALSCALE:GREGORIAN
1017METHOD:REPLY
1018BEGIN:VEVENT
1019UID:foobar
1020SEQUENCE:1
1021DTSTART:20140724T120000Z
1022SUMMARY:Daily sprint
1023RECURRENCE-ID:20140724T120000Z
1024ORGANIZER;CN=Strunk:mailto:strunk@example.org
1025ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
1026END:VEVENT
1027END:VCALENDAR
1028ICS
1029
1030            ),
1031
1032        );
1033
1034        $result = $this->parse($oldMessage, $newMessage, $expected);
1035
1036    }
1037
1038    /**
1039     * A party crasher is an attendee that accepted an event, but was not in
1040     * any original invite.
1041     *
1042     * @depends testAccepted
1043     */
1044    function testPartyCrasher() {
1045
1046        $oldMessage = <<<ICS
1047BEGIN:VCALENDAR
1048VERSION:2.0
1049BEGIN:VEVENT
1050UID:foobar
1051SUMMARY:B-day party
1052SEQUENCE:1
1053ORGANIZER;CN=Strunk:mailto:strunk@example.org
1054DTSTART:20140716T120000Z
1055RRULE:FREQ=DAILY
1056END:VEVENT
1057BEGIN:VEVENT
1058UID:foobar
1059RECURRENCE-ID:20140717T120000Z
1060SUMMARY:B-day party
1061SEQUENCE:1
1062ORGANIZER;CN=Strunk:mailto:strunk@example.org
1063DTSTART:20140717T120000Z
1064RRULE:FREQ=DAILY
1065END:VEVENT
1066END:VCALENDAR
1067ICS;
1068
1069
1070        $newMessage = <<<ICS
1071BEGIN:VCALENDAR
1072VERSION:2.0
1073BEGIN:VEVENT
1074UID:foobar
1075SUMMARY:B-day party
1076SEQUENCE:1
1077ORGANIZER;CN=Strunk:mailto:strunk@example.org
1078DTSTART:20140716T120000Z
1079RRULE:FREQ=DAILY
1080END:VEVENT
1081BEGIN:VEVENT
1082UID:foobar
1083RECURRENCE-ID:20140717T120000Z
1084SUMMARY:B-day party
1085SEQUENCE:1
1086ORGANIZER;CN=Strunk:mailto:strunk@example.org
1087ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
1088DTSTART:20140717T120000Z
1089RRULE:FREQ=DAILY
1090END:VEVENT
1091END:VCALENDAR
1092ICS;
1093
1094        $version = \Sabre\VObject\Version::VERSION;
1095
1096        $expected = array(
1097            array(
1098                'uid' => 'foobar',
1099                'method' => 'REPLY',
1100                'component' => 'VEVENT',
1101                'sender' => 'mailto:one@example.org',
1102                'senderName' => 'One',
1103                'recipient' => 'mailto:strunk@example.org',
1104                'recipientName' => 'Strunk',
1105                'message' => <<<ICS
1106BEGIN:VCALENDAR
1107VERSION:2.0
1108CALSCALE:GREGORIAN
1109METHOD:REPLY
1110BEGIN:VEVENT
1111UID:foobar
1112SEQUENCE:1
1113DTSTART:20140717T120000Z
1114SUMMARY:B-day party
1115RECURRENCE-ID:20140717T120000Z
1116ORGANIZER;CN=Strunk:mailto:strunk@example.org
1117ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
1118END:VEVENT
1119END:VCALENDAR
1120
1121ICS
1122
1123            ),
1124
1125        );
1126
1127        $result = $this->parse($oldMessage, $newMessage, $expected);
1128
1129    }
1130}
1131