METHOD = 'PUBLISH'; $gen = new FreeBusyGenerator(); $gen->setObjects([]); $gen->setBaseObject($obj); $result = $gen->getResult(); $this->assertEquals('PUBLISH', $result->METHOD->getValue()); } /** * @expectedException InvalidArgumentException */ function testInvalidArg() { $gen = new FreeBusyGenerator( new \DateTime('2012-01-01'), new \DateTime('2012-12-31'), new \StdClass() ); } /** * This function takes a list of objects (icalendar objects), and turns * them into a freebusy report. * * Then it takes the expected output and compares it to what we actually * got. * * It only generates the freebusy report for the following time-range: * 2011-01-01 11:00:00 until 2011-01-03 11:11:11 * * @param string $expected * @param array $input * @param string|null $timeZone * @param string $vavailability * @return void */ function assertFreeBusyReport($expected, $input, $timeZone = null, $vavailability = null) { $gen = new FreeBusyGenerator( new \DateTime('20110101T110000Z', new \DateTimeZone('UTC')), new \DateTime('20110103T110000Z', new \DateTimeZone('UTC')), $input, $timeZone ); if ($vavailability) { if (is_string($vavailability)) { $vavailability = Reader::read($vavailability); } $gen->setVAvailability($vavailability); } $output = $gen->getResult(); // Removing DTSTAMP because it changes every time. unset($output->VFREEBUSY->DTSTAMP); $expected = <<assertVObjectEqualsVObject($expected, $output); } function testSimple() { $blob = <<assertFreeBusyReport( "FREEBUSY:20110101T120000Z/20110101T130000Z", $blob ); } function testSource() { $blob = <<assertFreeBusyReport( "FREEBUSY:20110101T120000Z/20110101T130000Z", $h ); } /** * Testing TRANSP:OPAQUE */ function testOpaque() { $blob = <<assertFreeBusyReport( "FREEBUSY:20110101T130000Z/20110101T140000Z", $blob ); } /** * Testing TRANSP:TRANSPARENT */ function testTransparent() { // transparent, hidden $blob = <<assertFreeBusyReport( "", $blob ); } /** * Testing STATUS:CANCELLED */ function testCancelled() { // transparent, hidden $blob = <<assertFreeBusyReport( "", $blob ); } /** * Testing STATUS:TENTATIVE */ function testTentative() { // tentative, shows up $blob = <<assertFreeBusyReport( 'FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T180000Z/20110101T190000Z', $blob ); } /** * Testing an event that falls outside of the report time-range. */ function testOutsideTimeRange() { // outside of time-range, hidden $blob = <<assertFreeBusyReport( '', $blob ); } /** * Testing an event that falls outside of the report time-range. */ function testOutsideTimeRange2() { // outside of time-range, hidden $blob = <<assertFreeBusyReport( '', $blob ); } /** * Testing an event that uses DURATION */ function testDuration() { // using duration, shows up $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T190000Z/20110101T200000Z', $blob ); } /** * Testing an all-day event */ function testAllDay() { // Day-long event, shows up $blob = <<assertFreeBusyReport( 'FREEBUSY:20110102T000000Z/20110103T000000Z', $blob ); } /** * Testing an event that has no end or duration. */ function testNoDuration() { // No duration, does not show up $blob = <<assertFreeBusyReport( '', $blob ); } /** * Testing feeding the freebusy generator an object instead of a string. */ function testObject() { // encoded as object, shows up $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T210000Z/20110101T220000Z', Reader::read($blob) ); } /** * Testing feeding VFREEBUSY objects instead of VEVENT */ function testVFreeBusy() { // Freebusy. Some parts show up $blob = <<assertFreeBusyReport( "FREEBUSY:20110103T010000Z/20110103T020000Z\n" . 'FREEBUSY:20110103T030000Z/20110103T060000Z', $blob ); } function testYearlyRecurrence() { // Yearly recurrence rule, shows up $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T220000Z/20110101T230000Z', $blob ); } function testYearlyRecurrenceDuration() { // Yearly recurrence rule + duration, shows up $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T230000Z/20110102T000000Z', $blob ); } function testFloatingTime() { // Floating time, no timezone $blob = <<assertFreeBusyReport( "FREEBUSY:20110101T120000Z/20110101T130000Z", $blob ); } function testFloatingTimeReferenceTimeZone() { // Floating time + reference timezone $blob = <<assertFreeBusyReport( "FREEBUSY:20110101T170000Z/20110101T180000Z", $blob, new \DateTimeZone('America/Toronto') ); } function testAllDay2() { // All-day event, slightly outside of the VFREEBUSY range. $blob = <<assertFreeBusyReport( "FREEBUSY:20110101T110000Z/20110102T000000Z", $blob ); } function testAllDayReferenceTimeZone() { // All-day event + reference timezone $blob = <<assertFreeBusyReport( "FREEBUSY:20110101T110000Z/20110102T050000Z", $blob, new \DateTimeZone('America/Toronto') ); } function testNoValidInstances() { // Recurrence rule with no valid instances $blob = <<assertFreeBusyReport( "", $blob ); } /** * This VAVAILABILITY object overlaps with the time-range, but we're just * busy the entire time. */ function testVAvailabilitySimple() { $blob = <<assertFreeBusyReport( "FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:20110101T110000Z/20110101T120000Z\n" . "FREEBUSY:20110101T120000Z/20110101T130000Z\n" . "FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:20110101T130000Z/20110103T110000Z", $blob, null, $vavail ); } /** * This VAVAILABILITY object does not overlap at all with the freebusy * report, so it should be ignored. */ function testVAvailabilityIrrelevant() { $blob = <<assertFreeBusyReport( "FREEBUSY:20110101T120000Z/20110101T130000Z", $blob, null, $vavail ); } /** * This VAVAILABILITY object has a 9am-5pm AVAILABLE object for office * hours. */ function testVAvailabilityOfficeHours() { $blob = <<assertFreeBusyReport( "FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T110000Z/20110101T120000Z\n" . "FREEBUSY:20110101T120000Z/20110101T130000Z\n" . "FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T130000Z/20110103T090000Z\n", $blob, null, $vavail ); } /** * This test has the same office hours, but has a vacation blocked off for * the relevant time, using a higher priority. (lower number). */ function testVAvailabilityOfficeHoursVacation() { $blob = <<assertFreeBusyReport( "FREEBUSY:20110101T110000Z/20110103T110000Z", $blob, null, $vavail ); } /** * This test has the same input as the last, except somebody mixed up the * PRIORITY values. * * The end-result is that the vacation VAVAILABILITY is completely ignored. */ function testVAvailabilityOfficeHoursVacation2() { $blob = <<assertFreeBusyReport( "FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T110000Z/20110101T120000Z\n" . "FREEBUSY:20110101T120000Z/20110101T130000Z\n" . "FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T130000Z/20110103T090000Z\n", $blob, null, $vavail ); } }