1<?php
2
3namespace Sabre\VObject\ITip;
4
5class BrokerNewEventTest extends BrokerTester {
6
7    function testNoAttendee() {
8
9        $message = <<<ICS
10BEGIN:VCALENDAR
11BEGIN:VEVENT
12UID:foobar
13DTSTART:20140811T220000Z
14DTEND:20140811T230000Z
15END:VEVENT
16END:VCALENDAR
17ICS;
18
19        $result = $this->parse(null, $message, []);
20
21    }
22
23    function testVTODO() {
24
25        $message = <<<ICS
26BEGIN:VCALENDAR
27BEGIN:VTODO
28UID:foobar
29END:VTODO
30END:VCALENDAR
31ICS;
32
33        $result = $this->parse(null, $message, []);
34
35    }
36
37    function testSimpleInvite() {
38
39        $message = <<<ICS
40BEGIN:VCALENDAR
41VERSION:2.0
42BEGIN:VEVENT
43UID:foobar
44DTSTART:20140811T220000Z
45DTEND:20140811T230000Z
46ORGANIZER;CN=Strunk:mailto:strunk@example.org
47ATTENDEE;CN=White:mailto:white@example.org
48END:VEVENT
49END:VCALENDAR
50ICS;
51
52        $version = \Sabre\VObject\Version::VERSION;
53        $expectedMessage = <<<ICS
54BEGIN:VCALENDAR
55VERSION:2.0
56PRODID:-//Sabre//Sabre VObject $version//EN
57CALSCALE:GREGORIAN
58METHOD:REQUEST
59BEGIN:VEVENT
60UID:foobar
61DTSTART:20140811T220000Z
62DTEND:20140811T230000Z
63ORGANIZER;CN=Strunk:mailto:strunk@example.org
64ATTENDEE;CN=White;PARTSTAT=NEEDS-ACTION:mailto:white@example.org
65END:VEVENT
66END:VCALENDAR
67ICS;
68
69        $expected = [
70            [
71                'uid'           => 'foobar',
72                'method'        => 'REQUEST',
73                'component'     => 'VEVENT',
74                'sender'        => 'mailto:strunk@example.org',
75                'senderName'    => 'Strunk',
76                'recipient'     => 'mailto:white@example.org',
77                'recipientName' => 'White',
78                'message'       => $expectedMessage,
79            ],
80        ];
81
82        $this->parse(null, $message, $expected, 'mailto:strunk@example.org');
83
84    }
85
86    /**
87     * @expectedException \Sabre\VObject\ITip\ITipException
88     */
89    function testBrokenEventUIDMisMatch() {
90
91        $message = <<<ICS
92BEGIN:VCALENDAR
93VERSION:2.0
94BEGIN:VEVENT
95UID:foobar
96ORGANIZER;CN=Strunk:mailto:strunk@example.org
97ATTENDEE;CN=White:mailto:white@example.org
98END:VEVENT
99BEGIN:VEVENT
100UID:foobar2
101ORGANIZER;CN=Strunk:mailto:strunk@example.org
102ATTENDEE;CN=White:mailto:white@example.org
103END:VEVENT
104END:VCALENDAR
105ICS;
106
107        $this->parse(null, $message, [], 'mailto:strunk@example.org');
108
109    }
110    /**
111     * @expectedException \Sabre\VObject\ITip\ITipException
112     */
113    function testBrokenEventOrganizerMisMatch() {
114
115        $message = <<<ICS
116BEGIN:VCALENDAR
117VERSION:2.0
118BEGIN:VEVENT
119UID:foobar
120ORGANIZER;CN=Strunk:mailto:strunk@example.org
121ATTENDEE;CN=White:mailto:white@example.org
122END:VEVENT
123BEGIN:VEVENT
124UID:foobar
125ORGANIZER:mailto:foo@example.org
126ATTENDEE;CN=White:mailto:white@example.org
127END:VEVENT
128END:VCALENDAR
129ICS;
130
131        $this->parse(null, $message, [], 'mailto:strunk@example.org');
132
133    }
134
135    function testRecurrenceInvite() {
136
137        $message = <<<ICS
138BEGIN:VCALENDAR
139VERSION:2.0
140BEGIN:VEVENT
141UID:foobar
142ORGANIZER;CN=Strunk:mailto:strunk@example.org
143ATTENDEE;CN=One:mailto:one@example.org
144ATTENDEE;CN=Two:mailto:two@example.org
145DTSTART:20140716T120000Z
146DURATION:PT1H
147RRULE:FREQ=DAILY
148EXDATE:20140717T120000Z
149END:VEVENT
150BEGIN:VEVENT
151UID:foobar
152RECURRENCE-ID:20140718T120000Z
153ORGANIZER;CN=Strunk:mailto:strunk@example.org
154ATTENDEE;CN=Two:mailto:two@example.org
155ATTENDEE;CN=Three:mailto:three@example.org
156DTSTART:20140718T120000Z
157DURATION:PT1H
158END:VEVENT
159END:VCALENDAR
160ICS;
161
162        $version = \Sabre\VObject\Version::VERSION;
163
164        $expected = [
165            [
166                'uid'           => 'foobar',
167                'method'        => 'REQUEST',
168                'component'     => 'VEVENT',
169                'sender'        => 'mailto:strunk@example.org',
170                'senderName'    => 'Strunk',
171                'recipient'     => 'mailto:one@example.org',
172                'recipientName' => 'One',
173                'message'       => <<<ICS
174BEGIN:VCALENDAR
175VERSION:2.0
176PRODID:-//Sabre//Sabre VObject $version//EN
177CALSCALE:GREGORIAN
178METHOD:REQUEST
179BEGIN:VEVENT
180UID:foobar
181ORGANIZER;CN=Strunk:mailto:strunk@example.org
182ATTENDEE;CN=One;PARTSTAT=NEEDS-ACTION:mailto:one@example.org
183ATTENDEE;CN=Two;PARTSTAT=NEEDS-ACTION:mailto:two@example.org
184DTSTART:20140716T120000Z
185DURATION:PT1H
186RRULE:FREQ=DAILY
187EXDATE:20140717T120000Z,20140718T120000Z
188END:VEVENT
189END:VCALENDAR
190ICS
191
192            ],
193            [
194                'uid'           => 'foobar',
195                'method'        => 'REQUEST',
196                'component'     => 'VEVENT',
197                'sender'        => 'mailto:strunk@example.org',
198                'senderName'    => 'Strunk',
199                'recipient'     => 'mailto:two@example.org',
200                'recipientName' => 'Two',
201                'message'       => <<<ICS
202BEGIN:VCALENDAR
203VERSION:2.0
204PRODID:-//Sabre//Sabre VObject $version//EN
205CALSCALE:GREGORIAN
206METHOD:REQUEST
207BEGIN:VEVENT
208UID:foobar
209ORGANIZER;CN=Strunk:mailto:strunk@example.org
210ATTENDEE;CN=One;PARTSTAT=NEEDS-ACTION:mailto:one@example.org
211ATTENDEE;CN=Two;PARTSTAT=NEEDS-ACTION:mailto:two@example.org
212DTSTART:20140716T120000Z
213DURATION:PT1H
214RRULE:FREQ=DAILY
215EXDATE:20140717T120000Z
216END:VEVENT
217BEGIN:VEVENT
218UID:foobar
219RECURRENCE-ID:20140718T120000Z
220ORGANIZER;CN=Strunk:mailto:strunk@example.org
221ATTENDEE;CN=Two:mailto:two@example.org
222ATTENDEE;CN=Three:mailto:three@example.org
223DTSTART:20140718T120000Z
224DURATION:PT1H
225END:VEVENT
226END:VCALENDAR
227ICS
228
229            ],
230            [
231                'uid'           => 'foobar',
232                'method'        => 'REQUEST',
233                'component'     => 'VEVENT',
234                'sender'        => 'mailto:strunk@example.org',
235                'senderName'    => 'Strunk',
236                'recipient'     => 'mailto:three@example.org',
237                'recipientName' => 'Three',
238                'message'       => <<<ICS
239BEGIN:VCALENDAR
240VERSION:2.0
241PRODID:-//Sabre//Sabre VObject $version//EN
242CALSCALE:GREGORIAN
243METHOD:REQUEST
244BEGIN:VEVENT
245UID:foobar
246RECURRENCE-ID:20140718T120000Z
247ORGANIZER;CN=Strunk:mailto:strunk@example.org
248ATTENDEE;CN=Two:mailto:two@example.org
249ATTENDEE;CN=Three:mailto:three@example.org
250DTSTART:20140718T120000Z
251DURATION:PT1H
252END:VEVENT
253END:VCALENDAR
254ICS
255
256            ],
257        ];
258
259        $this->parse(null, $message, $expected, 'mailto:strunk@example.org');
260
261    }
262
263    function testRecurrenceInvite2() {
264
265        // This method tests a nearly identical path, but in this case the
266        // master event does not have an EXDATE.
267        $message = <<<ICS
268BEGIN:VCALENDAR
269VERSION:2.0
270BEGIN:VEVENT
271UID:foobar
272ORGANIZER;CN=Strunk:mailto:strunk@example.org
273ATTENDEE;CN=One:mailto:one@example.org
274ATTENDEE;CN=Two:mailto:two@example.org
275DTSTART:20140716T120000Z
276DTEND:20140716T130000Z
277RRULE:FREQ=DAILY
278END:VEVENT
279BEGIN:VEVENT
280UID:foobar
281RECURRENCE-ID:20140718T120000Z
282ORGANIZER;CN=Strunk:mailto:strunk@example.org
283ATTENDEE;CN=Two:mailto:two@example.org
284ATTENDEE;CN=Three:mailto:three@example.org
285DTSTART:20140718T120000Z
286DTEND:20140718T130000Z
287END:VEVENT
288END:VCALENDAR
289ICS;
290
291        $version = \Sabre\VObject\Version::VERSION;
292
293        $expected = [
294            [
295                'uid'           => 'foobar',
296                'method'        => 'REQUEST',
297                'component'     => 'VEVENT',
298                'sender'        => 'mailto:strunk@example.org',
299                'senderName'    => 'Strunk',
300                'recipient'     => 'mailto:one@example.org',
301                'recipientName' => 'One',
302                'message'       => <<<ICS
303BEGIN:VCALENDAR
304VERSION:2.0
305PRODID:-//Sabre//Sabre VObject $version//EN
306CALSCALE:GREGORIAN
307METHOD:REQUEST
308BEGIN:VEVENT
309UID:foobar
310ORGANIZER;CN=Strunk:mailto:strunk@example.org
311ATTENDEE;CN=One;PARTSTAT=NEEDS-ACTION:mailto:one@example.org
312ATTENDEE;CN=Two;PARTSTAT=NEEDS-ACTION:mailto:two@example.org
313DTSTART:20140716T120000Z
314DTEND:20140716T130000Z
315RRULE:FREQ=DAILY
316EXDATE:20140718T120000Z
317END:VEVENT
318END:VCALENDAR
319ICS
320
321            ],
322            [
323                'uid'           => 'foobar',
324                'method'        => 'REQUEST',
325                'component'     => 'VEVENT',
326                'sender'        => 'mailto:strunk@example.org',
327                'senderName'    => 'Strunk',
328                'recipient'     => 'mailto:two@example.org',
329                'recipientName' => 'Two',
330                'message'       => <<<ICS
331BEGIN:VCALENDAR
332VERSION:2.0
333PRODID:-//Sabre//Sabre VObject $version//EN
334CALSCALE:GREGORIAN
335METHOD:REQUEST
336BEGIN:VEVENT
337UID:foobar
338ORGANIZER;CN=Strunk:mailto:strunk@example.org
339ATTENDEE;CN=One;PARTSTAT=NEEDS-ACTION:mailto:one@example.org
340ATTENDEE;CN=Two;PARTSTAT=NEEDS-ACTION:mailto:two@example.org
341DTSTART:20140716T120000Z
342DTEND:20140716T130000Z
343RRULE:FREQ=DAILY
344END:VEVENT
345BEGIN:VEVENT
346UID:foobar
347RECURRENCE-ID:20140718T120000Z
348ORGANIZER;CN=Strunk:mailto:strunk@example.org
349ATTENDEE;CN=Two:mailto:two@example.org
350ATTENDEE;CN=Three:mailto:three@example.org
351DTSTART:20140718T120000Z
352DTEND:20140718T130000Z
353END:VEVENT
354END:VCALENDAR
355ICS
356
357            ],
358            [
359                'uid'           => 'foobar',
360                'method'        => 'REQUEST',
361                'component'     => 'VEVENT',
362                'sender'        => 'mailto:strunk@example.org',
363                'senderName'    => 'Strunk',
364                'recipient'     => 'mailto:three@example.org',
365                'recipientName' => 'Three',
366                'message'       => <<<ICS
367BEGIN:VCALENDAR
368VERSION:2.0
369PRODID:-//Sabre//Sabre VObject $version//EN
370CALSCALE:GREGORIAN
371METHOD:REQUEST
372BEGIN:VEVENT
373UID:foobar
374RECURRENCE-ID:20140718T120000Z
375ORGANIZER;CN=Strunk:mailto:strunk@example.org
376ATTENDEE;CN=Two:mailto:two@example.org
377ATTENDEE;CN=Three:mailto:three@example.org
378DTSTART:20140718T120000Z
379DTEND:20140718T130000Z
380END:VEVENT
381END:VCALENDAR
382ICS
383
384            ],
385        ];
386
387        $this->parse(null, $message, $expected, 'mailto:strunk@example.org');
388
389    }
390
391    function testScheduleAgentClient() {
392
393        $message = <<<ICS
394BEGIN:VCALENDAR
395VERSION:2.0
396BEGIN:VEVENT
397UID:foobar
398DTSTART:20140811T220000Z
399DTEND:20140811T230000Z
400ORGANIZER;CN=Strunk:mailto:strunk@example.org
401ATTENDEE;CN=White;SCHEDULE-AGENT=CLIENT:mailto:white@example.org
402END:VEVENT
403END:VCALENDAR
404ICS;
405
406        $version = \Sabre\VObject\Version::VERSION;
407
408        $this->parse(null, $message, [], 'mailto:strunk@example.org');
409
410    }
411
412    /**
413     * @expectedException Sabre\VObject\ITip\ITipException
414     */
415    function testMultipleUID() {
416
417        $message = <<<ICS
418BEGIN:VCALENDAR
419VERSION:2.0
420BEGIN:VEVENT
421UID:foobar
422ORGANIZER;CN=Strunk:mailto:strunk@example.org
423ATTENDEE;CN=One:mailto:one@example.org
424ATTENDEE;CN=Two:mailto:two@example.org
425DTSTART:20140716T120000Z
426DTEND:20140716T130000Z
427RRULE:FREQ=DAILY
428END:VEVENT
429BEGIN:VEVENT
430UID:foobar2
431RECURRENCE-ID:20140718T120000Z
432ORGANIZER;CN=Strunk:mailto:strunk@example.org
433ATTENDEE;CN=Two:mailto:two@example.org
434ATTENDEE;CN=Three:mailto:three@example.org
435DTSTART:20140718T120000Z
436DTEND:20140718T130000Z
437END:VEVENT
438END:VCALENDAR
439ICS;
440
441        $version = \Sabre\VObject\Version::VERSION;
442        $this->parse(null, $message, [], 'mailto:strunk@example.org');
443
444    }
445
446    /**
447     * @expectedException Sabre\VObject\ITip\SameOrganizerForAllComponentsException
448     */
449    function testChangingOrganizers() {
450
451        $message = <<<ICS
452BEGIN:VCALENDAR
453VERSION:2.0
454BEGIN:VEVENT
455UID:foobar
456ORGANIZER;CN=Strunk:mailto:strunk@example.org
457ATTENDEE;CN=One:mailto:one@example.org
458ATTENDEE;CN=Two:mailto:two@example.org
459DTSTART:20140716T120000Z
460DTEND:20140716T130000Z
461RRULE:FREQ=DAILY
462END:VEVENT
463BEGIN:VEVENT
464UID:foobar
465RECURRENCE-ID:20140718T120000Z
466ORGANIZER;CN=Strunk:mailto:ew@example.org
467ATTENDEE;CN=Two:mailto:two@example.org
468ATTENDEE;CN=Three:mailto:three@example.org
469DTSTART:20140718T120000Z
470DTEND:20140718T130000Z
471END:VEVENT
472END:VCALENDAR
473ICS;
474
475        $version = \Sabre\VObject\Version::VERSION;
476        $this->parse(null, $message, [], 'mailto:strunk@example.org');
477
478    }
479    function testNoOrganizerHasAttendee() {
480
481        $message = <<<ICS
482BEGIN:VCALENDAR
483BEGIN:VEVENT
484UID:foobar
485DTSTART:20140811T220000Z
486DTEND:20140811T230000Z
487ATTENDEE;CN=Two:mailto:two@example.org
488END:VEVENT
489END:VCALENDAR
490ICS;
491
492        $this->parse(null, $message, [], 'mailto:strunk@example.org');
493
494    }
495
496}
497