ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ScheduleDeliverTest.php
Go to the documentation of this file.
1<?php
2
4
7
9
10 use VObject\PHPUnitAssertions;
11
12 public $setupCalDAV = true;
14 public $setupACL = true;
15 public $autoLogin = 'user1';
16
18 [
19 'principaluri' => 'principals/user1',
20 'uri' => 'cal',
21 ],
22 [
23 'principaluri' => 'principals/user2',
24 'uri' => 'cal',
25 ],
26 ];
27
28 function setUp() {
29
30 $this->calendarObjectUri = '/calendars/user1/cal/object.ics';
31
32 parent::setUp();
33
34 }
35
36 function testNewInvite() {
37
38 $newObject = <<<ICS
39BEGIN:VCALENDAR
40BEGIN:VEVENT
41UID:foo
42DTSTART:20140811T230000Z
43ORGANIZER:mailto:user1.sabredav@sabredav.org
44ATTENDEE:mailto:user2.sabredav@sabredav.org
45END:VEVENT
46END:VCALENDAR
47ICS;
48
49 $this->deliver(null, $newObject);
50 $this->assertItemsInInbox('user2', 1);
51
52 $expected = <<<ICS
53BEGIN:VCALENDAR
54VERSION:2.0
55BEGIN:VEVENT
56UID:foo
57DTSTART:20140811T230000Z
58ORGANIZER:mailto:user1.sabredav@sabredav.org
59ATTENDEE;SCHEDULE-STATUS=1.2:mailto:user2.sabredav@sabredav.org
60DTSTAMP:**ANY**
61END:VEVENT
62END:VCALENDAR
63ICS;
64
65 $this->assertVObjectEqualsVObject(
66 $expected,
67 $newObject
68 );
69
70 }
71
73
74 $newObject = <<<ICS
75BEGIN:VCALENDAR
76VERSION:2.0
77BEGIN:VEVENT
78UID:foo
79DTSTART:20140811T230000Z
80ORGANIZER:mailto:user1.sabredav@sabredav.org
81ATTENDEE:mailto:user2.sabredav@sabredav.org
82END:VEVENT
83END:VCALENDAR
84ICS;
85
86 $this->calendarObjectUri = '/calendars/user1/object.ics';
87 $this->deliver(null, $newObject);
88 $this->assertItemsInInbox('user2', 0);
89
90
91 }
93
94 $newObject = <<<ICS
95BEGIN:VCALENDAR
96BEGIN:VEVENT
97UID:foo
98DTSTART:20140811T230000Z
99ORGANIZER:mailto:user1.sabredav@sabredav.org
100ATTENDEE:mailto:user2.sabredav@sabredav.org
101END:VEVENT
102END:VCALENDAR
103ICS;
104
105 $this->deliver(null, $newObject, true);
106 $this->assertItemsInInbox('user2', 0);
107
108 }
109 function testUpdatedInvite() {
110
111 $newObject = <<<ICS
112BEGIN:VCALENDAR
113BEGIN:VEVENT
114UID:foo
115DTSTART:20140811T230000Z
116ORGANIZER:mailto:user1.sabredav@sabredav.org
117ATTENDEE:mailto:user2.sabredav@sabredav.org
118END:VEVENT
119END:VCALENDAR
120ICS;
121 $oldObject = <<<ICS
122BEGIN:VCALENDAR
123VERSION:2.0
124BEGIN:VEVENT
125UID:foo
126DTSTART:20140811T230000Z
127ORGANIZER:mailto:user1.sabredav@sabredav.org
128END:VEVENT
129END:VCALENDAR
130ICS;
131
132 $this->deliver($oldObject, $newObject);
133 $this->assertItemsInInbox('user2', 1);
134
135 $expected = <<<ICS
136BEGIN:VCALENDAR
137VERSION:2.0
138BEGIN:VEVENT
139UID:foo
140DTSTART:20140811T230000Z
141ORGANIZER:mailto:user1.sabredav@sabredav.org
142ATTENDEE;SCHEDULE-STATUS=1.2:mailto:user2.sabredav@sabredav.org
143DTSTAMP:**ANY**
144END:VEVENT
145END:VCALENDAR
146ICS;
147
148 $this->assertVObjectEqualsVObject(
149 $expected,
150 $newObject
151 );
152
153
154 }
156
157 $newObject = <<<ICS
158BEGIN:VCALENDAR
159BEGIN:VEVENT
160UID:foo
161DTSTART:20140811T230000Z
162ORGANIZER:mailto:user1.sabredav@sabredav.org
163ATTENDEE:mailto:user2.sabredav@sabredav.org
164END:VEVENT
165END:VCALENDAR
166ICS;
167 $oldObject = <<<ICS
168BEGIN:VCALENDAR
169BEGIN:VEVENT
170UID:foo
171DTSTART:20140811T230000Z
172ORGANIZER:mailto:user1.sabredav@sabredav.org
173END:VEVENT
174END:VCALENDAR
175ICS;
176
177 $this->deliver($oldObject, $newObject, true);
178 $this->assertItemsInInbox('user2', 0);
179
180 }
181
183
184 $newObject = <<<ICS
185BEGIN:VCALENDAR
186BEGIN:VEVENT
187UID:foo
188DTSTART:20140811T230000Z
189ORGANIZER:mailto:user1.sabredav@sabredav.org
190ATTENDEE:mailto:user2.sabredav@sabredav.org
191END:VEVENT
192END:VCALENDAR
193ICS;
194 $oldObject = <<<ICS
195BEGIN:VCALENDAR
196BEGIN:VEVENT
197UID:foo
198DTSTART:20140811T230000Z
199ORGANIZER:mailto:user1.sabredav@sabredav.org
200END:VEVENT
201END:VCALENDAR
202ICS;
203
204 $this->calendarObjectUri = '/calendars/user1/inbox/foo.ics';
205 $this->deliver($oldObject, $newObject);
206 $this->assertItemsInInbox('user2', 0);
207
208 }
209
210 function testDeletedInvite() {
211
212 $newObject = null;
213
214 $oldObject = <<<ICS
215BEGIN:VCALENDAR
216BEGIN:VEVENT
217UID:foo
218DTSTART:20140811T230000Z
219ORGANIZER:mailto:user1.sabredav@sabredav.org
220ATTENDEE:mailto:user2.sabredav@sabredav.org
221END:VEVENT
222END:VCALENDAR
223ICS;
224
225 $this->deliver($oldObject, $newObject);
226 $this->assertItemsInInbox('user2', 1);
227
228 }
229
231
232 $newObject = null;
233
234 $oldObject = <<<ICS
235BEGIN:VCALENDAR
236BEGIN:VEVENT
237UID:foo
238DTSTART:20140811T230000Z
239ORGANIZER:mailto:user1.sabredav@sabredav.org
240ATTENDEE:mailto:user2.sabredav@sabredav.org
241END:VEVENT
242END:VCALENDAR
243ICS;
244
245 $this->deliver($oldObject, $newObject, true);
246 $this->assertItemsInInbox('user2', 0);
247
248 }
249
257
258 $newObject = null;
259
260 $oldObject = <<<ICS
261BEGIN:VCALENDAR
262BEGIN:VEVENT
263UID:foo
264DTSTART:20140811T230000Z
265ORGANIZER:mailto:user1.sabredav@sabredav.org
266ATTENDEE:mailto:user2.sabredav@sabredav.org
267END:VEVENT
268END:VCALENDAR
269ICS;
270
271
272 $this->server->httpRequest->setMethod('MOVE');
273 $this->deliver($oldObject, $newObject);
274 $this->assertItemsInInbox('user2', 0);
275
276 }
277
279
280 $newObject = null;
281
282 $oldObject = <<<ICS
283BEGIN:VCALENDAR
284BEGIN:VEVENT
285UID:foo
286DTSTART:20140811T230000Z
287ORGANIZER:mailto:user1.sabredav@sabredav.org
288ATTENDEE:mailto:user2.sabredav@sabredav.org
289END:VEVENT
290END:VCALENDAR
291ICS;
292
293 $this->calendarObjectUri = '/calendars/user1/inbox/foo.ics';
294 $this->deliver($oldObject, $newObject);
295 $this->assertItemsInInbox('user2', 0);
296
297 }
298
299 function testReply() {
300
301 $oldObject = <<<ICS
302BEGIN:VCALENDAR
303BEGIN:VEVENT
304UID:foo
305DTSTART:20140811T230000Z
306ORGANIZER:mailto:user2.sabredav@sabredav.org
307ATTENDEE;PARTSTAT=ACCEPTED:mailto:user2.sabredav@sabredav.org
308ATTENDEE:mailto:user1.sabredav@sabredav.org
309ATTENDEE:mailto:user3.sabredav@sabredav.org
310END:VEVENT
311END:VCALENDAR
312ICS;
313
314 $newObject = <<<ICS
315BEGIN:VCALENDAR
316BEGIN:VEVENT
317UID:foo
318DTSTART:20140811T230000Z
319ORGANIZER:mailto:user2.sabredav@sabredav.org
320ATTENDEE;PARTSTAT=ACCEPTED:mailto:user2.sabredav@sabredav.org
321ATTENDEE;PARTSTAT=ACCEPTED:mailto:user1.sabredav@sabredav.org
322ATTENDEE:mailto:user3.sabredav@sabredav.org
323END:VEVENT
324END:VCALENDAR
325ICS;
326
327 $this->putPath('calendars/user2/cal/foo.ics', $oldObject);
328
329 $this->deliver($oldObject, $newObject);
330 $this->assertItemsInInbox('user2', 1);
331 $this->assertItemsInInbox('user1', 0);
332
333 $expected = <<<ICS
334BEGIN:VCALENDAR
335VERSION:2.0
336BEGIN:VEVENT
337UID:foo
338DTSTART:20140811T230000Z
339ORGANIZER;SCHEDULE-STATUS=1.2:mailto:user2.sabredav@sabredav.org
340ATTENDEE;PARTSTAT=ACCEPTED:mailto:user2.sabredav@sabredav.org
341ATTENDEE;PARTSTAT=ACCEPTED:mailto:user1.sabredav@sabredav.org
342ATTENDEE:mailto:user3.sabredav@sabredav.org
343DTSTAMP:**ANY**
344END:VEVENT
345END:VCALENDAR
346ICS;
347
348 $this->assertVObjectEqualsVObject(
349 $expected,
350 $newObject
351 );
352
353 }
354
355
356
358
359 $newObject = <<<ICS
360BEGIN:VCALENDAR
361BEGIN:VEVENT
362UID:foo
363DTSTART:20140811T230000Z
364ORGANIZER:mailto:user1.sabredav@sabredav.org
365ATTENDEE:mailto:user3.sabredav@sabredav.org
366END:VEVENT
367END:VCALENDAR
368ICS;
369
370 $this->deliver(null, $newObject);
371
372 $expected = <<<ICS
373BEGIN:VCALENDAR
374VERSION:2.0
375BEGIN:VEVENT
376UID:foo
377DTSTART:20140811T230000Z
378ORGANIZER:mailto:user1.sabredav@sabredav.org
379ATTENDEE;SCHEDULE-STATUS=3.7:mailto:user3.sabredav@sabredav.org
380DTSTAMP:**ANY**
381END:VEVENT
382END:VCALENDAR
383ICS;
384
385 $this->assertVObjectEqualsVObject(
386 $expected,
387 $newObject
388 );
389
390 }
391
393
394 $newObject = <<<ICS
395BEGIN:VCALENDAR
396BEGIN:VEVENT
397UID:foo
398DTSTART:20140811T230000Z
399ORGANIZER:mailto:user1.sabredav@sabredav.org
400ATTENDEE:mailto:user2.sabredav@sabredav.org
401END:VEVENT
402END:VCALENDAR
403ICS;
404
405 $this->server->on('propFind', function($propFind) {
406 $propFind->set('{' . Plugin::NS_CALDAV . '}schedule-inbox-URL', null, 403);
407 });
408 $this->deliver(null, $newObject);
409
410 $expected = <<<ICS
411BEGIN:VCALENDAR
412VERSION:2.0
413BEGIN:VEVENT
414UID:foo
415DTSTART:20140811T230000Z
416ORGANIZER:mailto:user1.sabredav@sabredav.org
417ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
418DTSTAMP:**ANY**
419END:VEVENT
420END:VCALENDAR
421ICS;
422
423 $this->assertVObjectEqualsVObject(
424 $expected,
425 $newObject
426 );
427
428 }
429
431
432 $newObject = <<<ICS
433BEGIN:VCALENDAR
434BEGIN:VEVENT
435UID:foo
436DTSTART:20140811T230000Z
437ORGANIZER:mailto:user1.sabredav@sabredav.org
438ATTENDEE:mailto:user2.sabredav@sabredav.org
439END:VEVENT
440END:VCALENDAR
441ICS;
442
443 $this->server->on('propFind', function($propFind) {
444 $propFind->set('{' . Plugin::NS_CALDAV . '}calendar-home-set', null, 403);
445 });
446 $this->deliver(null, $newObject);
447
448 $expected = <<<ICS
449BEGIN:VCALENDAR
450VERSION:2.0
451BEGIN:VEVENT
452UID:foo
453DTSTART:20140811T230000Z
454ORGANIZER:mailto:user1.sabredav@sabredav.org
455ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
456DTSTAMP:**ANY**
457END:VEVENT
458END:VCALENDAR
459ICS;
460
461 $this->assertVObjectEqualsVObject(
462 $expected,
463 $newObject
464 );
465
466 }
468
469 $newObject = <<<ICS
470BEGIN:VCALENDAR
471BEGIN:VEVENT
472UID:foo
473DTSTART:20140811T230000Z
474ORGANIZER:mailto:user1.sabredav@sabredav.org
475ATTENDEE:mailto:user2.sabredav@sabredav.org
476END:VEVENT
477END:VCALENDAR
478ICS;
479
480 $this->server->on('propFind', function($propFind) {
481 $propFind->set('{' . Plugin::NS_CALDAV . '}schedule-default-calendar-URL', null, 403);
482 });
483 $this->deliver(null, $newObject);
484
485 $expected = <<<ICS
486BEGIN:VCALENDAR
487VERSION:2.0
488BEGIN:VEVENT
489UID:foo
490DTSTART:20140811T230000Z
491ORGANIZER:mailto:user1.sabredav@sabredav.org
492ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
493DTSTAMP:**ANY**
494END:VEVENT
495END:VCALENDAR
496ICS;
497
498 $this->assertVObjectEqualsVObject(
499 $expected,
500 $newObject
501 );
502
503 }
505
506 $newObject = <<<ICS
507BEGIN:VCALENDAR
508BEGIN:VEVENT
509UID:foo
510DTSTART:20140811T230000Z
511ORGANIZER:mailto:user1.sabredav@sabredav.org
512ATTENDEE:mailto:user2.sabredav@sabredav.org
513END:VEVENT
514END:VCALENDAR
515ICS;
516
517 $this->server->removeAllListeners('schedule');
518 $this->deliver(null, $newObject);
519
520 $expected = <<<ICS
521BEGIN:VCALENDAR
522VERSION:2.0
523BEGIN:VEVENT
524UID:foo
525DTSTART:20140811T230000Z
526ORGANIZER:mailto:user1.sabredav@sabredav.org
527ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
528DTSTAMP:**ANY**
529END:VEVENT
530END:VCALENDAR
531ICS;
532
533 $this->assertVObjectEqualsVObject(
534 $expected,
535 $newObject
536 );
537
538 }
540
541 $this->setupACL = false;
542 parent::setUp();
543
544 $newObject = <<<ICS
545BEGIN:VCALENDAR
546BEGIN:VEVENT
547UID:foo
548DTSTART:20140811T230000Z
549ORGANIZER:mailto:user1.sabredav@sabredav.org
550ATTENDEE:mailto:user2.sabredav@sabredav.org
551END:VEVENT
552END:VCALENDAR
553ICS;
554
555 $this->deliver(null, $newObject);
556
557 $expected = <<<ICS
558BEGIN:VCALENDAR
559VERSION:2.0
560BEGIN:VEVENT
561UID:foo
562DTSTART:20140811T230000Z
563ORGANIZER:mailto:user1.sabredav@sabredav.org
564ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
565DTSTAMP:**ANY**
566END:VEVENT
567END:VCALENDAR
568ICS;
569
570 $this->assertVObjectEqualsVObject(
571 $expected,
572 $newObject
573 );
574
575 }
576
578
579 function deliver($oldObject, &$newObject, $disableScheduling = false) {
580
581 $this->server->httpRequest->setUrl($this->calendarObjectUri);
582 if ($disableScheduling) {
583 $this->server->httpRequest->setHeader('Schedule-Reply', 'F');
584 }
585
586 if ($oldObject && $newObject) {
587 // update
588 $this->putPath($this->calendarObjectUri, $oldObject);
589
590 $stream = fopen('php://memory', 'r+');
591 fwrite($stream, $newObject);
592 rewind($stream);
593 $modified = false;
594
595 $this->server->emit('beforeWriteContent', [
596 $this->calendarObjectUri,
597 $this->server->tree->getNodeForPath($this->calendarObjectUri),
598 &$stream,
599 &$modified
600 ]);
601 if ($modified) {
602 $newObject = $stream;
603 }
604
605 } elseif ($oldObject && !$newObject) {
606 // delete
607 $this->putPath($this->calendarObjectUri, $oldObject);
608
609 $this->caldavSchedulePlugin->beforeUnbind(
610 $this->calendarObjectUri
611 );
612 } else {
613
614 // create
615 $stream = fopen('php://memory', 'r+');
616 fwrite($stream, $newObject);
617 rewind($stream);
618 $modified = false;
619 $this->server->emit('beforeCreateFile', [
620 $this->calendarObjectUri,
621 &$stream,
622 $this->server->tree->getNodeForPath(dirname($this->calendarObjectUri)),
623 &$modified
624 ]);
625
626 if ($modified) {
627 $newObject = $stream;
628 }
629 }
630
631 }
632
633
644 function putPath($path, $data) {
645
646 list($parent, $base) = \Sabre\HTTP\UrlUtil::splitPath($path);
647 $parentNode = $this->server->tree->getNodeForPath($parent);
648
649 /*
650 if ($parentNode->childExists($base)) {
651 $childNode = $parentNode->getChild($base);
652 $childNode->put($data);
653 } else {*/
654 $parentNode->createFile($base, $data);
655 //}
656
657 }
658
659 function assertItemsInInbox($user, $count) {
660
661 $inboxNode = $this->server->tree->getNodeForPath('calendars/' . $user . '/inbox');
662 $this->assertEquals($count, count($inboxNode->getChildren()));
663
664 }
665
666}
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
const NS_CALDAV
This is the official CalDAV namespace.
Definition: Plugin.php:33
testUnbindIgnoredOnMove()
A MOVE request will trigger an unbind on a scheduling resource.
putPath($path, $data)
Creates or updates a node at the specified path.
deliver($oldObject, &$newObject, $disableScheduling=false)
This class may be used as a basis for other webdav-related unittests.
The Request class represents a single HTTP request.
Definition: Request.php:18
$base
Definition: index.php:4
$user
Definition: migrateto20.php:57
$stream
PHP stream implementation.
$data
Definition: bench.php:6