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