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