ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
FreeBusyGeneratorTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\VObject;
4 
6 
7 class FreeBusyGeneratorTest extends TestCase {
8 
10 
12 
13  $obj = new Component\VCalendar();
14  $obj->METHOD = 'PUBLISH';
15 
16  $gen = new FreeBusyGenerator();
17  $gen->setObjects([]);
18  $gen->setBaseObject($obj);
19 
20  $result = $gen->getResult();
21 
22  $this->assertEquals('PUBLISH', $result->METHOD->getValue());
23 
24  }
25 
29  function testInvalidArg() {
30 
31  $gen = new FreeBusyGenerator(
32  new \DateTime('2012-01-01'),
33  new \DateTime('2012-12-31'),
34  new \StdClass()
35  );
36 
37  }
38 
55  function assertFreeBusyReport($expected, $input, $timeZone = null, $vavailability = null) {
56 
57  $gen = new FreeBusyGenerator(
58  new \DateTime('20110101T110000Z', new \DateTimeZone('UTC')),
59  new \DateTime('20110103T110000Z', new \DateTimeZone('UTC')),
60  $input,
61  $timeZone
62  );
63 
64  if ($vavailability) {
65  if (is_string($vavailability)) {
66  $vavailability = Reader::read($vavailability);
67  }
68  $gen->setVAvailability($vavailability);
69  }
70 
71  $output = $gen->getResult();
72 
73  // Removing DTSTAMP because it changes every time.
74  unset($output->VFREEBUSY->DTSTAMP);
75 
76  $expected = <<<ICS
77 BEGIN:VCALENDAR
78 VERSION:2.0
79 BEGIN:VFREEBUSY
80 DTSTART:20110101T110000Z
81 DTEND:20110103T110000Z
82 $expected
83 END:VFREEBUSY
84 END:VCALENDAR
85 ICS;
86 
87  $this->assertVObjectEqualsVObject($expected, $output);
88 
89  }
90 
91  function testSimple() {
92 
93  $blob = <<<ICS
94 BEGIN:VCALENDAR
95 BEGIN:VEVENT
96 UID:foobar
97 DTSTART:20110101T120000Z
98 DTEND:20110101T130000Z
99 END:VEVENT
100 END:VCALENDAR
101 ICS;
102 
103 
104  $this->assertFreeBusyReport(
105  "FREEBUSY:20110101T120000Z/20110101T130000Z",
106  $blob
107  );
108 
109  }
110 
111  function testSource() {
112 
113  $blob = <<<ICS
114 BEGIN:VCALENDAR
115 BEGIN:VEVENT
116 UID:foobar
117 DTSTART:20110101T120000Z
118 DTEND:20110101T130000Z
119 END:VEVENT
120 END:VCALENDAR
121 ICS;
122  $h = fopen('php://memory', 'r+');
123  fwrite($h, $blob);
124  rewind($h);
125 
126 
127  $this->assertFreeBusyReport(
128  "FREEBUSY:20110101T120000Z/20110101T130000Z",
129  $h
130  );
131 
132  }
133 
137  function testOpaque() {
138 
139  $blob = <<<ICS
140 BEGIN:VCALENDAR
141 BEGIN:VEVENT
142 UID:foobar2
143 TRANSP:OPAQUE
144 DTSTART:20110101T130000Z
145 DTEND:20110101T140000Z
146 END:VEVENT
147 END:VCALENDAR
148 ICS;
149 
150  $this->assertFreeBusyReport(
151  "FREEBUSY:20110101T130000Z/20110101T140000Z",
152  $blob
153  );
154 
155  }
156 
160  function testTransparent() {
161 
162  // transparent, hidden
163  $blob = <<<ICS
164 BEGIN:VCALENDAR
165 BEGIN:VEVENT
166 UID:foobar3
167 TRANSP:TRANSPARENT
168 DTSTART:20110101T140000Z
169 DTEND:20110101T150000Z
170 END:VEVENT
171 END:VCALENDAR
172 ICS;
173 
174  $this->assertFreeBusyReport(
175  "",
176  $blob
177  );
178 
179  }
180 
184  function testCancelled() {
185 
186  // transparent, hidden
187  $blob = <<<ICS
188 BEGIN:VCALENDAR
189 BEGIN:VEVENT
190 UID:foobar4
191 STATUS:CANCELLED
192 DTSTART:20110101T160000Z
193 DTEND:20110101T170000Z
194 END:VEVENT
195 END:VCALENDAR
196 ICS;
197 
198  $this->assertFreeBusyReport(
199  "",
200  $blob
201  );
202 
203  }
204 
208  function testTentative() {
209 
210  // tentative, shows up
211  $blob = <<<ICS
212 BEGIN:VCALENDAR
213 BEGIN:VEVENT
214 UID:foobar5
215 STATUS:TENTATIVE
216 DTSTART:20110101T180000Z
217 DTEND:20110101T190000Z
218 END:VEVENT
219 END:VCALENDAR
220 ICS;
221 
222  $this->assertFreeBusyReport(
223  'FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T180000Z/20110101T190000Z',
224  $blob
225  );
226 
227  }
228 
232  function testOutsideTimeRange() {
233 
234  // outside of time-range, hidden
235  $blob = <<<ICS
236 BEGIN:VCALENDAR
237 BEGIN:VEVENT
238 UID:foobar6
239 DTSTART:20110101T090000Z
240 DTEND:20110101T100000Z
241 END:VEVENT
242 END:VCALENDAR
243 ICS;
244 
245  $this->assertFreeBusyReport(
246  '',
247  $blob
248  );
249 
250  }
251 
256 
257  // outside of time-range, hidden
258  $blob = <<<ICS
259 BEGIN:VCALENDAR
260 BEGIN:VEVENT
261 UID:foobar7
262 DTSTART:20110104T090000Z
263 DTEND:20110104T100000Z
264 END:VEVENT
265 END:VCALENDAR
266 ICS;
267 
268  $this->assertFreeBusyReport(
269  '',
270  $blob
271  );
272 
273  }
274 
278  function testDuration() {
279 
280  // using duration, shows up
281  $blob = <<<ICS
282 BEGIN:VCALENDAR
283 BEGIN:VEVENT
284 UID:foobar8
285 DTSTART:20110101T190000Z
286 DURATION:PT1H
287 END:VEVENT
288 END:VCALENDAR
289 ICS;
290 
291  $this->assertFreeBusyReport(
292  'FREEBUSY:20110101T190000Z/20110101T200000Z',
293  $blob
294  );
295 
296  }
297 
301  function testAllDay() {
302 
303  // Day-long event, shows up
304  $blob = <<<ICS
305 BEGIN:VCALENDAR
306 BEGIN:VEVENT
307 UID:foobar9
308 DTSTART;VALUE=DATE:20110102
309 END:VEVENT
310 END:VCALENDAR
311 ICS;
312 
313  $this->assertFreeBusyReport(
314  'FREEBUSY:20110102T000000Z/20110103T000000Z',
315  $blob
316  );
317 
318  }
319 
323  function testNoDuration() {
324 
325  // No duration, does not show up
326  $blob = <<<ICS
327 BEGIN:VCALENDAR
328 BEGIN:VEVENT
329 UID:foobar10
330 DTSTART:20110101T200000Z
331 END:VEVENT
332 END:VCALENDAR
333 ICS;
334 
335  $this->assertFreeBusyReport(
336  '',
337  $blob
338  );
339 
340  }
341 
345  function testObject() {
346 
347  // encoded as object, shows up
348  $blob = <<<ICS
349 BEGIN:VCALENDAR
350 BEGIN:VEVENT
351 UID:foobar11
352 DTSTART:20110101T210000Z
353 DURATION:PT1H
354 END:VEVENT
355 END:VCALENDAR
356 ICS;
357 
358  $this->assertFreeBusyReport(
359  'FREEBUSY:20110101T210000Z/20110101T220000Z',
360  Reader::read($blob)
361  );
362 
363 
364  }
365 
369  function testVFreeBusy() {
370 
371  // Freebusy. Some parts show up
372  $blob = <<<ICS
373 BEGIN:VCALENDAR
374 BEGIN:VFREEBUSY
375 FREEBUSY:20110103T010000Z/20110103T020000Z
376 FREEBUSY;FBTYPE=FREE:20110103T020000Z/20110103T030000Z
377 FREEBUSY:20110103T030000Z/20110103T040000Z,20110103T040000Z/20110103T050000Z
378 FREEBUSY:20120101T000000Z/20120101T010000Z
379 FREEBUSY:20110103T050000Z/PT1H
380 END:VFREEBUSY
381 END:VCALENDAR
382 ICS;
383 
384  $this->assertFreeBusyReport(
385  "FREEBUSY:20110103T010000Z/20110103T020000Z\n" .
386  'FREEBUSY:20110103T030000Z/20110103T060000Z',
387  $blob
388  );
389 
390  }
391 
392  function testYearlyRecurrence() {
393 
394  // Yearly recurrence rule, shows up
395  $blob = <<<ICS
396 BEGIN:VCALENDAR
397 BEGIN:VEVENT
398 UID:foobar13
399 DTSTART:20100101T220000Z
400 DTEND:20100101T230000Z
401 RRULE:FREQ=YEARLY
402 END:VEVENT
403 END:VCALENDAR
404 ICS;
405 
406  $this->assertFreeBusyReport(
407  'FREEBUSY:20110101T220000Z/20110101T230000Z',
408  $blob
409  );
410 
411  }
412 
414 
415  // Yearly recurrence rule + duration, shows up
416  $blob = <<<ICS
417 BEGIN:VCALENDAR
418 BEGIN:VEVENT
419 UID:foobar14
420 DTSTART:20100101T230000Z
421 DURATION:PT1H
422 RRULE:FREQ=YEARLY
423 END:VEVENT
424 END:VCALENDAR
425 ICS;
426 
427  $this->assertFreeBusyReport(
428  'FREEBUSY:20110101T230000Z/20110102T000000Z',
429  $blob
430  );
431 
432  }
433 
434  function testFloatingTime() {
435 
436  // Floating time, no timezone
437  $blob = <<<ICS
438 BEGIN:VCALENDAR
439 BEGIN:VEVENT
440 UID:foobar
441 DTSTART:20110101T120000
442 DTEND:20110101T130000
443 END:VEVENT
444 END:VCALENDAR
445 ICS;
446 
447  $this->assertFreeBusyReport(
448  "FREEBUSY:20110101T120000Z/20110101T130000Z",
449  $blob
450  );
451 
452  }
453 
455 
456  // Floating time + reference timezone
457  $blob = <<<ICS
458 BEGIN:VCALENDAR
459 BEGIN:VEVENT
460 UID:foobar
461 DTSTART:20110101T120000
462 DTEND:20110101T130000
463 END:VEVENT
464 END:VCALENDAR
465 ICS;
466 
467  $this->assertFreeBusyReport(
468  "FREEBUSY:20110101T170000Z/20110101T180000Z",
469  $blob,
470  new \DateTimeZone('America/Toronto')
471  );
472 
473  }
474 
475  function testAllDay2() {
476 
477  // All-day event, slightly outside of the VFREEBUSY range.
478  $blob = <<<ICS
479 BEGIN:VCALENDAR
480 BEGIN:VEVENT
481 UID:foobar
482 DTSTART;VALUE=DATE:20110101
483 END:VEVENT
484 END:VCALENDAR
485 ICS;
486 
487  $this->assertFreeBusyReport(
488  "FREEBUSY:20110101T110000Z/20110102T000000Z",
489  $blob
490  );
491 
492  }
493 
495 
496  // All-day event + reference timezone
497  $blob = <<<ICS
498 BEGIN:VCALENDAR
499 BEGIN:VEVENT
500 UID:foobar
501 DTSTART;VALUE=DATE:20110101
502 END:VEVENT
503 END:VCALENDAR
504 ICS;
505 
506  $this->assertFreeBusyReport(
507  "FREEBUSY:20110101T110000Z/20110102T050000Z",
508  $blob,
509  new \DateTimeZone('America/Toronto')
510  );
511 
512  }
513 
514  function testNoValidInstances() {
515 
516  // Recurrence rule with no valid instances
517  $blob = <<<ICS
518 BEGIN:VCALENDAR
519 BEGIN:VEVENT
520 UID:foobar
521 DTSTART:20110101T100000Z
522 DTEND:20110103T120000Z
523 RRULE:FREQ=WEEKLY;COUNT=1
524 EXDATE:20110101T100000Z
525 END:VEVENT
526 END:VCALENDAR
527 ICS;
528 
529  $this->assertFreeBusyReport(
530  "",
531  $blob
532  );
533 
534  }
535 
541 
542  $blob = <<<ICS
543 BEGIN:VCALENDAR
544 BEGIN:VEVENT
545 UID:lalala
546 DTSTART:20110101T120000Z
547 DTEND:20110101T130000Z
548 END:VEVENT
549 END:VCALENDAR
550 ICS;
551 
552  $vavail = <<<ICS
553 BEGIN:VCALENDAR
554 BEGIN:VAVAILABILITY
555 DTSTART:20110101T000000Z
556 DTEND:20120101T000000Z
557 BEGIN:AVAILABLE
558 DTSTART:20110101T000000Z
559 DTEND:20110101T010000Z
560 END:AVAILABLE
561 END:VAVAILABILITY
562 END:VCALENDAR
563 ICS;
564 
565  $this->assertFreeBusyReport(
566  "FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:20110101T110000Z/20110101T120000Z\n" .
567  "FREEBUSY:20110101T120000Z/20110101T130000Z\n" .
568  "FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:20110101T130000Z/20110103T110000Z",
569  $blob,
570  null,
571  $vavail
572  );
573 
574  }
575 
581 
582  $blob = <<<ICS
583 BEGIN:VCALENDAR
584 BEGIN:VEVENT
585 UID:lalala
586 DTSTART:20110101T120000Z
587 DTEND:20110101T130000Z
588 END:VEVENT
589 END:VCALENDAR
590 ICS;
591 
592  $vavail = <<<ICS
593 BEGIN:VCALENDAR
594 BEGIN:VAVAILABILITY
595 DTSTART:20150101T000000Z
596 DTEND:20160101T000000Z
597 BEGIN:AVAILABLE
598 DTSTART:20150101T000000Z
599 DTEND:20150101T010000Z
600 END:AVAILABLE
601 END:VAVAILABILITY
602 END:VCALENDAR
603 ICS;
604 
605  $this->assertFreeBusyReport(
606  "FREEBUSY:20110101T120000Z/20110101T130000Z",
607  $blob,
608  null,
609  $vavail
610  );
611 
612  }
613 
619 
620  $blob = <<<ICS
621 BEGIN:VCALENDAR
622 BEGIN:VEVENT
623 UID:lalala
624 DTSTART:20110101T120000Z
625 DTEND:20110101T130000Z
626 END:VEVENT
627 END:VCALENDAR
628 ICS;
629 
630  $vavail = <<<ICS
631 BEGIN:VCALENDAR
632 BEGIN:VAVAILABILITY
633 DTSTART:20100101T000000Z
634 DTEND:20120101T000000Z
635 BUSYTYPE:BUSY-TENTATIVE
636 BEGIN:AVAILABLE
637 DTSTART:20101213T090000Z
638 DTEND:20101213T170000Z
639 RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR
640 END:AVAILABLE
641 END:VAVAILABILITY
642 END:VCALENDAR
643 ICS;
644 
645  $this->assertFreeBusyReport(
646  "FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T110000Z/20110101T120000Z\n" .
647  "FREEBUSY:20110101T120000Z/20110101T130000Z\n" .
648  "FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T130000Z/20110103T090000Z\n",
649  $blob,
650  null,
651  $vavail
652  );
653 
654  }
655 
661 
662  $blob = <<<ICS
663 BEGIN:VCALENDAR
664 BEGIN:VEVENT
665 UID:lalala
666 DTSTART:20110101T120000Z
667 DTEND:20110101T130000Z
668 END:VEVENT
669 END:VCALENDAR
670 ICS;
671 
672  $vavail = <<<ICS
673 BEGIN:VCALENDAR
674 BEGIN:VAVAILABILITY
675 DTSTART:20100101T000000Z
676 DTEND:20120101T000000Z
677 BUSYTYPE:BUSY-TENTATIVE
678 PRIORITY:2
679 BEGIN:AVAILABLE
680 DTSTART:20101213T090000Z
681 DTEND:20101213T170000Z
682 RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR
683 END:AVAILABLE
684 END:VAVAILABILITY
685 BEGIN:VAVAILABILITY
686 PRIORITY:1
687 DTSTART:20101214T000000Z
688 DTEND:20110107T000000Z
689 BUSYTYPE:BUSY
690 END:VAVAILABILITY
691 END:VCALENDAR
692 ICS;
693 
694  $this->assertFreeBusyReport(
695  "FREEBUSY:20110101T110000Z/20110103T110000Z",
696  $blob,
697  null,
698  $vavail
699  );
700 
701  }
702 
710 
711  $blob = <<<ICS
712 BEGIN:VCALENDAR
713 BEGIN:VEVENT
714 UID:lalala
715 DTSTART:20110101T120000Z
716 DTEND:20110101T130000Z
717 END:VEVENT
718 END:VCALENDAR
719 ICS;
720 
721  $vavail = <<<ICS
722 BEGIN:VCALENDAR
723 BEGIN:VAVAILABILITY
724 DTSTART:20100101T000000Z
725 DTEND:20120101T000000Z
726 BUSYTYPE:BUSY-TENTATIVE
727 PRIORITY:1
728 BEGIN:AVAILABLE
729 DTSTART:20101213T090000Z
730 DTEND:20101213T170000Z
731 RRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR
732 END:AVAILABLE
733 END:VAVAILABILITY
734 BEGIN:VAVAILABILITY
735 PRIORITY:2
736 DTSTART:20101214T000000Z
737 DTEND:20110107T000000Z
738 BUSYTYPE:BUSY
739 END:VAVAILABILITY
740 END:VCALENDAR
741 ICS;
742 
743  $this->assertFreeBusyReport(
744  "FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T110000Z/20110101T120000Z\n" .
745  "FREEBUSY:20110101T120000Z/20110101T130000Z\n" .
746  "FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T130000Z/20110103T090000Z\n",
747  $blob,
748  null,
749  $vavail
750  );
751 
752  }
753 }
testVFreeBusy()
Testing feeding VFREEBUSY objects instead of VEVENT.
testOutsideTimeRange2()
Testing an event that falls outside of the report time-range.
testVAvailabilityOfficeHoursVacation()
This test has the same office hours, but has a vacation blocked off for the relevant time...
$result
$h
This class helps with generating FREEBUSY reports based on existing sets of objects.
if($argc< 3) $input
testTransparent()
Testing TRANSP:TRANSPARENT.
testVAvailabilityIrrelevant()
This VAVAILABILITY object does not overlap at all with the freebusy report, so it should be ignored...
assertFreeBusyReport($expected, $input, $timeZone=null, $vavailability=null)
This function takes a list of objects (icalendar objects), and turns them into a freebusy report...
testInvalidArg()
InvalidArgumentException
testTentative()
Testing STATUS:TENTATIVE.
testVAvailabilitySimple()
This VAVAILABILITY object overlaps with the time-range, but we&#39;re just busy the entire time...
testOutsideTimeRange()
Testing an event that falls outside of the report time-range.
testDuration()
Testing an event that uses DURATION.
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
testVAvailabilityOfficeHoursVacation2()
This test has the same input as the last, except somebody mixed up the PRIORITY values.
testObject()
Testing feeding the freebusy generator an object instead of a string.
testCancelled()
Testing STATUS:CANCELLED.
testNoDuration()
Testing an event that has no end or duration.
testVAvailabilityOfficeHours()
This VAVAILABILITY object has a 9am-5pm AVAILABLE object for office hours.
testAllDay()
Testing an all-day event.