VFreeBusyTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Sabre\VObject\Component;
  3. use Sabre\VObject;
  4. use Sabre\VObject\Reader;
  5. class VFreeBusyTest extends \PHPUnit_Framework_TestCase {
  6. function testIsFree() {
  7. $input = <<<BLA
  8. BEGIN:VCALENDAR
  9. BEGIN:VFREEBUSY
  10. FREEBUSY;FBTYPE=FREE:20120912T000500Z/PT1H
  11. FREEBUSY;FBTYPE=BUSY:20120912T010000Z/20120912T020000Z
  12. FREEBUSY;FBTYPE=BUSY-TENTATIVE:20120912T020000Z/20120912T030000Z
  13. FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:20120912T030000Z/20120912T040000Z
  14. FREEBUSY;FBTYPE=BUSY:20120912T050000Z/20120912T060000Z,20120912T080000Z/20120912T090000Z
  15. FREEBUSY;FBTYPE=BUSY:20120912T100000Z/PT1H
  16. END:VFREEBUSY
  17. END:VCALENDAR
  18. BLA;
  19. $obj = VObject\Reader::read($input);
  20. $vfb = $obj->VFREEBUSY;
  21. $tz = new \DateTimeZone('UTC');
  22. $this->assertFalse($vfb->isFree(new \DateTime('2012-09-12 01:15:00', $tz), new \DateTime('2012-09-12 01:45:00', $tz)));
  23. $this->assertFalse($vfb->isFree(new \DateTime('2012-09-12 08:05:00', $tz), new \DateTime('2012-09-12 08:10:00', $tz)));
  24. $this->assertFalse($vfb->isFree(new \DateTime('2012-09-12 10:15:00', $tz), new \DateTime('2012-09-12 10:45:00', $tz)));
  25. // Checking whether the end time is treated as non-inclusive
  26. $this->assertTrue($vfb->isFree(new \DateTime('2012-09-12 09:00:00', $tz), new \DateTime('2012-09-12 09:15:00', $tz)));
  27. $this->assertTrue($vfb->isFree(new \DateTime('2012-09-12 09:45:00', $tz), new \DateTime('2012-09-12 10:00:00', $tz)));
  28. $this->assertTrue($vfb->isFree(new \DateTime('2012-09-12 11:00:00', $tz), new \DateTime('2012-09-12 12:00:00', $tz)));
  29. }
  30. public function testValidate() {
  31. $input = <<<HI
  32. BEGIN:VCALENDAR
  33. VERSION:2.0
  34. PRODID:YoYo
  35. BEGIN:VFREEBUSY
  36. UID:some-random-id
  37. DTSTAMP:20140402T180200Z
  38. END:VFREEBUSY
  39. END:VCALENDAR
  40. HI;
  41. $obj = Reader::read($input);
  42. $warnings = $obj->validate();
  43. $messages = array();
  44. foreach($warnings as $warning) {
  45. $messages[] = $warning['message'];
  46. }
  47. $this->assertEquals(array(), $messages);
  48. }
  49. }