METHOD = 'PUBLISH'; $gen = new FreeBusyGenerator(); $gen->setObjects([]); $gen->setBaseObject($obj); $result = $gen->getResult(); $this->assertEquals('PUBLISH', $result->METHOD->getValue()); } /** * @expectedException \InvalidArgumentException */ public 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 */ public 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); } public function testSimple() { $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T120000Z/20110101T130000Z', $blob ); } public function testSource() { $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T120000Z/20110101T130000Z', $h ); } /** * Testing TRANSP:OPAQUE. */ public function testOpaque() { $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T130000Z/20110101T140000Z', $blob ); } /** * Testing TRANSP:TRANSPARENT. */ public function testTransparent() { // transparent, hidden $blob = <<assertFreeBusyReport( '', $blob ); } /** * Testing STATUS:CANCELLED. */ public function testCancelled() { // transparent, hidden $blob = <<assertFreeBusyReport( '', $blob ); } /** * Testing STATUS:TENTATIVE. */ public 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. */ public function testOutsideTimeRange() { // outside of time-range, hidden $blob = <<assertFreeBusyReport( '', $blob ); } /** * Testing an event that falls outside of the report time-range. */ public function testOutsideTimeRange2() { // outside of time-range, hidden $blob = <<assertFreeBusyReport( '', $blob ); } /** * Testing an event that uses DURATION. */ public function testDuration() { // using duration, shows up $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T190000Z/20110101T200000Z', $blob ); } /** * Testing an all-day event. */ public function testAllDay() { // Day-long event, shows up $blob = <<assertFreeBusyReport( 'FREEBUSY:20110102T000000Z/20110103T000000Z', $blob ); } /** * Testing an event that has no end or duration. */ public function testNoDuration() { // No duration, does not show up $blob = <<assertFreeBusyReport( '', $blob ); } /** * Testing feeding the freebusy generator an object instead of a string. */ public function testObject() { // encoded as object, shows up $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T210000Z/20110101T220000Z', Reader::read($blob) ); } /** * Testing feeding VFREEBUSY objects instead of VEVENT. */ public function testVFreeBusy() { // Freebusy. Some parts show up $blob = <<assertFreeBusyReport( "FREEBUSY:20110103T010000Z/20110103T020000Z\n". 'FREEBUSY:20110103T030000Z/20110103T060000Z', $blob ); } public function testYearlyRecurrence() { // Yearly recurrence rule, shows up $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T220000Z/20110101T230000Z', $blob ); } public function testYearlyRecurrenceDuration() { // Yearly recurrence rule + duration, shows up $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T230000Z/20110102T000000Z', $blob ); } public function testFloatingTime() { // Floating time, no timezone $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T120000Z/20110101T130000Z', $blob ); } public function testFloatingTimeReferenceTimeZone() { // Floating time + reference timezone $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T170000Z/20110101T180000Z', $blob, new \DateTimeZone('America/Toronto') ); } public function testAllDay2() { // All-day event, slightly outside of the VFREEBUSY range. $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T110000Z/20110102T000000Z', $blob ); } public function testAllDayReferenceTimeZone() { // All-day event + reference timezone $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T110000Z/20110102T050000Z', $blob, new \DateTimeZone('America/Toronto') ); } public 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. */ public 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. */ public function testVAvailabilityIrrelevant() { $blob = <<assertFreeBusyReport( 'FREEBUSY:20110101T120000Z/20110101T130000Z', $blob, null, $vavail ); } /** * This VAVAILABILITY object has a 9am-5pm AVAILABLE object for office * hours. */ public 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). */ public 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. */ public 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 ); } }