ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ScheduleDeliverTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\CalDAV\Schedule;
4 
6 use Sabre\VObject;
7 
9 
11 
12  public $setupCalDAV = true;
13  public $setupCalDAVScheduling = true;
14  public $setupACL = true;
15  public $autoLogin = 'user1';
16 
17  public $caldavCalendars = [
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
39 BEGIN:VCALENDAR
40 BEGIN:VEVENT
41 UID:foo
42 DTSTART:20140811T230000Z
43 ORGANIZER:mailto:user1.sabredav@sabredav.org
44 ATTENDEE:mailto:user2.sabredav@sabredav.org
45 END:VEVENT
46 END:VCALENDAR
47 ICS;
48 
49  $this->deliver(null, $newObject);
50  $this->assertItemsInInbox('user2', 1);
51 
52  $expected = <<<ICS
53 BEGIN:VCALENDAR
54 VERSION:2.0
55 BEGIN:VEVENT
56 UID:foo
57 DTSTART:20140811T230000Z
58 ORGANIZER:mailto:user1.sabredav@sabredav.org
59 ATTENDEE;SCHEDULE-STATUS=1.2:mailto:user2.sabredav@sabredav.org
60 DTSTAMP:**ANY**
61 END:VEVENT
62 END:VCALENDAR
63 ICS;
64 
65  $this->assertVObjectEqualsVObject(
66  $expected,
67  $newObject
68  );
69 
70  }
71 
73 
74  $newObject = <<<ICS
75 BEGIN:VCALENDAR
76 VERSION:2.0
77 BEGIN:VEVENT
78 UID:foo
79 DTSTART:20140811T230000Z
80 ORGANIZER:mailto:user1.sabredav@sabredav.org
81 ATTENDEE:mailto:user2.sabredav@sabredav.org
82 END:VEVENT
83 END:VCALENDAR
84 ICS;
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
95 BEGIN:VCALENDAR
96 BEGIN:VEVENT
97 UID:foo
98 DTSTART:20140811T230000Z
99 ORGANIZER:mailto:user1.sabredav@sabredav.org
100 ATTENDEE:mailto:user2.sabredav@sabredav.org
101 END:VEVENT
102 END:VCALENDAR
103 ICS;
104 
105  $this->deliver(null, $newObject, true);
106  $this->assertItemsInInbox('user2', 0);
107 
108  }
109  function testUpdatedInvite() {
110 
111  $newObject = <<<ICS
112 BEGIN:VCALENDAR
113 BEGIN:VEVENT
114 UID:foo
115 DTSTART:20140811T230000Z
116 ORGANIZER:mailto:user1.sabredav@sabredav.org
117 ATTENDEE:mailto:user2.sabredav@sabredav.org
118 END:VEVENT
119 END:VCALENDAR
120 ICS;
121  $oldObject = <<<ICS
122 BEGIN:VCALENDAR
123 VERSION:2.0
124 BEGIN:VEVENT
125 UID:foo
126 DTSTART:20140811T230000Z
127 ORGANIZER:mailto:user1.sabredav@sabredav.org
128 END:VEVENT
129 END:VCALENDAR
130 ICS;
131 
132  $this->deliver($oldObject, $newObject);
133  $this->assertItemsInInbox('user2', 1);
134 
135  $expected = <<<ICS
136 BEGIN:VCALENDAR
137 VERSION:2.0
138 BEGIN:VEVENT
139 UID:foo
140 DTSTART:20140811T230000Z
141 ORGANIZER:mailto:user1.sabredav@sabredav.org
142 ATTENDEE;SCHEDULE-STATUS=1.2:mailto:user2.sabredav@sabredav.org
143 DTSTAMP:**ANY**
144 END:VEVENT
145 END:VCALENDAR
146 ICS;
147 
148  $this->assertVObjectEqualsVObject(
149  $expected,
150  $newObject
151  );
152 
153 
154  }
156 
157  $newObject = <<<ICS
158 BEGIN:VCALENDAR
159 BEGIN:VEVENT
160 UID:foo
161 DTSTART:20140811T230000Z
162 ORGANIZER:mailto:user1.sabredav@sabredav.org
163 ATTENDEE:mailto:user2.sabredav@sabredav.org
164 END:VEVENT
165 END:VCALENDAR
166 ICS;
167  $oldObject = <<<ICS
168 BEGIN:VCALENDAR
169 BEGIN:VEVENT
170 UID:foo
171 DTSTART:20140811T230000Z
172 ORGANIZER:mailto:user1.sabredav@sabredav.org
173 END:VEVENT
174 END:VCALENDAR
175 ICS;
176 
177  $this->deliver($oldObject, $newObject, true);
178  $this->assertItemsInInbox('user2', 0);
179 
180  }
181 
183 
184  $newObject = <<<ICS
185 BEGIN:VCALENDAR
186 BEGIN:VEVENT
187 UID:foo
188 DTSTART:20140811T230000Z
189 ORGANIZER:mailto:user1.sabredav@sabredav.org
190 ATTENDEE:mailto:user2.sabredav@sabredav.org
191 END:VEVENT
192 END:VCALENDAR
193 ICS;
194  $oldObject = <<<ICS
195 BEGIN:VCALENDAR
196 BEGIN:VEVENT
197 UID:foo
198 DTSTART:20140811T230000Z
199 ORGANIZER:mailto:user1.sabredav@sabredav.org
200 END:VEVENT
201 END:VCALENDAR
202 ICS;
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
215 BEGIN:VCALENDAR
216 BEGIN:VEVENT
217 UID:foo
218 DTSTART:20140811T230000Z
219 ORGANIZER:mailto:user1.sabredav@sabredav.org
220 ATTENDEE:mailto:user2.sabredav@sabredav.org
221 END:VEVENT
222 END:VCALENDAR
223 ICS;
224 
225  $this->deliver($oldObject, $newObject);
226  $this->assertItemsInInbox('user2', 1);
227 
228  }
229 
231 
232  $newObject = null;
233 
234  $oldObject = <<<ICS
235 BEGIN:VCALENDAR
236 BEGIN:VEVENT
237 UID:foo
238 DTSTART:20140811T230000Z
239 ORGANIZER:mailto:user1.sabredav@sabredav.org
240 ATTENDEE:mailto:user2.sabredav@sabredav.org
241 END:VEVENT
242 END:VCALENDAR
243 ICS;
244 
245  $this->deliver($oldObject, $newObject, true);
246  $this->assertItemsInInbox('user2', 0);
247 
248  }
249 
257 
258  $newObject = null;
259 
260  $oldObject = <<<ICS
261 BEGIN:VCALENDAR
262 BEGIN:VEVENT
263 UID:foo
264 DTSTART:20140811T230000Z
265 ORGANIZER:mailto:user1.sabredav@sabredav.org
266 ATTENDEE:mailto:user2.sabredav@sabredav.org
267 END:VEVENT
268 END:VCALENDAR
269 ICS;
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
283 BEGIN:VCALENDAR
284 BEGIN:VEVENT
285 UID:foo
286 DTSTART:20140811T230000Z
287 ORGANIZER:mailto:user1.sabredav@sabredav.org
288 ATTENDEE:mailto:user2.sabredav@sabredav.org
289 END:VEVENT
290 END:VCALENDAR
291 ICS;
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
302 BEGIN:VCALENDAR
303 BEGIN:VEVENT
304 UID:foo
305 DTSTART:20140811T230000Z
306 ORGANIZER:mailto:user2.sabredav@sabredav.org
307 ATTENDEE;PARTSTAT=ACCEPTED:mailto:user2.sabredav@sabredav.org
308 ATTENDEE:mailto:user1.sabredav@sabredav.org
309 ATTENDEE:mailto:user3.sabredav@sabredav.org
310 END:VEVENT
311 END:VCALENDAR
312 ICS;
313 
314  $newObject = <<<ICS
315 BEGIN:VCALENDAR
316 BEGIN:VEVENT
317 UID:foo
318 DTSTART:20140811T230000Z
319 ORGANIZER:mailto:user2.sabredav@sabredav.org
320 ATTENDEE;PARTSTAT=ACCEPTED:mailto:user2.sabredav@sabredav.org
321 ATTENDEE;PARTSTAT=ACCEPTED:mailto:user1.sabredav@sabredav.org
322 ATTENDEE:mailto:user3.sabredav@sabredav.org
323 END:VEVENT
324 END:VCALENDAR
325 ICS;
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
334 BEGIN:VCALENDAR
335 VERSION:2.0
336 BEGIN:VEVENT
337 UID:foo
338 DTSTART:20140811T230000Z
339 ORGANIZER;SCHEDULE-STATUS=1.2:mailto:user2.sabredav@sabredav.org
340 ATTENDEE;PARTSTAT=ACCEPTED:mailto:user2.sabredav@sabredav.org
341 ATTENDEE;PARTSTAT=ACCEPTED:mailto:user1.sabredav@sabredav.org
342 ATTENDEE:mailto:user3.sabredav@sabredav.org
343 DTSTAMP:**ANY**
344 END:VEVENT
345 END:VCALENDAR
346 ICS;
347 
348  $this->assertVObjectEqualsVObject(
349  $expected,
350  $newObject
351  );
352 
353  }
354 
355 
356 
358 
359  $newObject = <<<ICS
360 BEGIN:VCALENDAR
361 BEGIN:VEVENT
362 UID:foo
363 DTSTART:20140811T230000Z
364 ORGANIZER:mailto:user1.sabredav@sabredav.org
365 ATTENDEE:mailto:user3.sabredav@sabredav.org
366 END:VEVENT
367 END:VCALENDAR
368 ICS;
369 
370  $this->deliver(null, $newObject);
371 
372  $expected = <<<ICS
373 BEGIN:VCALENDAR
374 VERSION:2.0
375 BEGIN:VEVENT
376 UID:foo
377 DTSTART:20140811T230000Z
378 ORGANIZER:mailto:user1.sabredav@sabredav.org
379 ATTENDEE;SCHEDULE-STATUS=3.7:mailto:user3.sabredav@sabredav.org
380 DTSTAMP:**ANY**
381 END:VEVENT
382 END:VCALENDAR
383 ICS;
384 
385  $this->assertVObjectEqualsVObject(
386  $expected,
387  $newObject
388  );
389 
390  }
391 
392  function testInviteNoInboxUrl() {
393 
394  $newObject = <<<ICS
395 BEGIN:VCALENDAR
396 BEGIN:VEVENT
397 UID:foo
398 DTSTART:20140811T230000Z
399 ORGANIZER:mailto:user1.sabredav@sabredav.org
400 ATTENDEE:mailto:user2.sabredav@sabredav.org
401 END:VEVENT
402 END:VCALENDAR
403 ICS;
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
411 BEGIN:VCALENDAR
412 VERSION:2.0
413 BEGIN:VEVENT
414 UID:foo
415 DTSTART:20140811T230000Z
416 ORGANIZER:mailto:user1.sabredav@sabredav.org
417 ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
418 DTSTAMP:**ANY**
419 END:VEVENT
420 END:VCALENDAR
421 ICS;
422 
423  $this->assertVObjectEqualsVObject(
424  $expected,
425  $newObject
426  );
427 
428  }
429 
431 
432  $newObject = <<<ICS
433 BEGIN:VCALENDAR
434 BEGIN:VEVENT
435 UID:foo
436 DTSTART:20140811T230000Z
437 ORGANIZER:mailto:user1.sabredav@sabredav.org
438 ATTENDEE:mailto:user2.sabredav@sabredav.org
439 END:VEVENT
440 END:VCALENDAR
441 ICS;
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
449 BEGIN:VCALENDAR
450 VERSION:2.0
451 BEGIN:VEVENT
452 UID:foo
453 DTSTART:20140811T230000Z
454 ORGANIZER:mailto:user1.sabredav@sabredav.org
455 ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
456 DTSTAMP:**ANY**
457 END:VEVENT
458 END:VCALENDAR
459 ICS;
460 
461  $this->assertVObjectEqualsVObject(
462  $expected,
463  $newObject
464  );
465 
466  }
468 
469  $newObject = <<<ICS
470 BEGIN:VCALENDAR
471 BEGIN:VEVENT
472 UID:foo
473 DTSTART:20140811T230000Z
474 ORGANIZER:mailto:user1.sabredav@sabredav.org
475 ATTENDEE:mailto:user2.sabredav@sabredav.org
476 END:VEVENT
477 END:VCALENDAR
478 ICS;
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
486 BEGIN:VCALENDAR
487 VERSION:2.0
488 BEGIN:VEVENT
489 UID:foo
490 DTSTART:20140811T230000Z
491 ORGANIZER:mailto:user1.sabredav@sabredav.org
492 ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
493 DTSTAMP:**ANY**
494 END:VEVENT
495 END:VCALENDAR
496 ICS;
497 
498  $this->assertVObjectEqualsVObject(
499  $expected,
500  $newObject
501  );
502 
503  }
505 
506  $newObject = <<<ICS
507 BEGIN:VCALENDAR
508 BEGIN:VEVENT
509 UID:foo
510 DTSTART:20140811T230000Z
511 ORGANIZER:mailto:user1.sabredav@sabredav.org
512 ATTENDEE:mailto:user2.sabredav@sabredav.org
513 END:VEVENT
514 END:VCALENDAR
515 ICS;
516 
517  $this->server->removeAllListeners('schedule');
518  $this->deliver(null, $newObject);
519 
520  $expected = <<<ICS
521 BEGIN:VCALENDAR
522 VERSION:2.0
523 BEGIN:VEVENT
524 UID:foo
525 DTSTART:20140811T230000Z
526 ORGANIZER:mailto:user1.sabredav@sabredav.org
527 ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
528 DTSTAMP:**ANY**
529 END:VEVENT
530 END:VCALENDAR
531 ICS;
532 
533  $this->assertVObjectEqualsVObject(
534  $expected,
535  $newObject
536  );
537 
538  }
540 
541  $this->setupACL = false;
542  parent::setUp();
543 
544  $newObject = <<<ICS
545 BEGIN:VCALENDAR
546 BEGIN:VEVENT
547 UID:foo
548 DTSTART:20140811T230000Z
549 ORGANIZER:mailto:user1.sabredav@sabredav.org
550 ATTENDEE:mailto:user2.sabredav@sabredav.org
551 END:VEVENT
552 END:VCALENDAR
553 ICS;
554 
555  $this->deliver(null, $newObject);
556 
557  $expected = <<<ICS
558 BEGIN:VCALENDAR
559 VERSION:2.0
560 BEGIN:VEVENT
561 UID:foo
562 DTSTART:20140811T230000Z
563 ORGANIZER:mailto:user1.sabredav@sabredav.org
564 ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
565 DTSTAMP:**ANY**
566 END:VEVENT
567 END:VCALENDAR
568 ICS;
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 }
testUnbindIgnoredOnMove()
A MOVE request will trigger an unbind on a scheduling resource.
$path
Definition: aliased.php:25
$stream
PHP stream implementation.
putPath($path, $data)
Creates or updates a node at the specified path.
$base
Definition: index.php:4
This class may be used as a basis for other webdav-related unittests.
$user
Definition: migrateto20.php:57
deliver($oldObject, &$newObject, $disableScheduling=false)
user2
Definition: basicauth.php:12
const NS_CALDAV
This is the official CalDAV namespace.
Definition: Plugin.php:33
$data
Definition: bench.php:6