/**
  * Different bug, also likely an infinite loop.
  */
 function testYearlyByMonthLoop()
 {
     $ev = Sabre_VObject_Component::create('VEVENT');
     $ev->UID = 'uuid';
     $ev->DTSTART = '20120101T154500';
     $ev->DTSTART['TZID'] = 'Europe/Berlin';
     $ev->RRULE = 'FREQ=YEARLY;INTERVAL=1;UNTIL=20120203T225959Z;BYMONTH=2;BYSETPOS=1;BYDAY=SU,MO,TU,WE,TH,FR,SA';
     $ev->DTEND = '20120101T164500';
     $ev->DTEND['TZID'] = 'Europe/Berlin';
     // This recurrence rule by itself is a yearly rule that should happen
     // every february.
     //
     // The BYDAY part expands this to every day of the month, but the
     // BYSETPOS limits this to only the 1st day of the month. Very crazy
     // way to specify this, and could have certainly been a lot easier.
     $cal = Sabre_VObject_Component::create('VCALENDAR');
     $cal->add($ev);
     $it = new Sabre_VObject_RecurrenceIterator($cal, 'uuid');
     $it->fastForward(new DateTime('2012-01-29 23:00:00', new DateTimeZone('UTC')));
     $collect = array();
     while ($it->valid()) {
         $collect[] = $it->getDTSTART();
         if ($it->getDTSTART() > new DateTime('2013-02-05 22:59:59', new DateTimeZone('UTC'))) {
             break;
         }
         $it->next();
     }
     $this->assertEquals(array(new DateTime('2012-02-01 15:45:00', new DateTimeZone('Europe/Berlin'))), $collect);
 }
 function testAlarmWayBefore()
 {
     $vevent = Sabre_VObject_Component::create('VEVENT');
     $vevent->DTSTART = '20120101T120000Z';
     $vevent->UID = 'bla';
     $valarm = Sabre_VObject_Component::create('VALARM');
     $valarm->TRIGGER = '-P2W1D';
     $vevent->add($valarm);
     $vcalendar = Sabre_VObject_Component::create('VCALENDAR');
     $vcalendar->add($vevent);
     $filter = array('name' => 'VCALENDAR', 'is-not-defined' => false, 'time-range' => null, 'prop-filters' => array(), 'comp-filters' => array(array('name' => 'VEVENT', 'is-not-defined' => false, 'time-range' => null, 'prop-filters' => array(), 'comp-filters' => array(array('name' => 'VALARM', 'is-not-defined' => false, 'prop-filters' => array(), 'comp-filters' => array(), 'time-range' => array('start' => new DateTime('2011-12-10'), 'end' => new DateTime('2011-12-20')))))));
     $validator = new Sabre_CalDAV_CalendarQueryValidator();
     $this->assertTrue($validator->validate($vcalendar, $filter));
 }
Ejemplo n.º 3
0
 /**
  * Reads and parses a single line.
  *
  * This method receives the full array of lines. The array pointer is used
  * to traverse.
  *
  * @param array $lines
  * @return Sabre_VObject_Element
  */
 private static function readLine(&$lines)
 {
     $line = current($lines);
     $lineNr = key($lines);
     next($lines);
     // Components
     if (stripos($line, "BEGIN:") === 0) {
         $componentName = strtoupper(substr($line, 6));
         $obj = Sabre_VObject_Component::create($componentName);
         $nextLine = current($lines);
         while (stripos($nextLine, "END:") !== 0) {
             $obj->add(self::readLine($lines));
             $nextLine = current($lines);
             if ($nextLine === false) {
                 throw new Sabre_VObject_ParseException('Invalid VObject. Document ended prematurely.');
             }
         }
         // Checking component name of the 'END:' line.
         if (substr($nextLine, 4) !== $obj->name) {
             throw new Sabre_VObject_ParseException('Invalid VObject, expected: "END:' . $obj->name . '" got: "' . $nextLine . '"');
         }
         next($lines);
         return $obj;
     }
     // Properties
     //$result = preg_match('/(?P<name>[A-Z0-9-]+)(?:;(?P<parameters>^(?<!:):))(.*)$/',$line,$matches);
     $token = '[A-Z0-9-\\.]+';
     $parameters = "(?:;(?P<parameters>([^:^\"]|\"([^\"]*)\")*))?";
     $regex = "/^(?P<name>{$token}){$parameters}:(?P<value>.*)\$/i";
     $result = preg_match($regex, $line, $matches);
     if (!$result) {
         throw new Sabre_VObject_ParseException('Invalid VObject, line ' . ($lineNr + 1) . ' did not follow the icalendar/vcard format');
     }
     $propertyName = strtoupper($matches['name']);
     $propertyValue = preg_replace_callback('#(\\\\(\\\\|N|n|;|,))#', function ($matches) {
         if ($matches[2] === 'n' || $matches[2] === 'N') {
             return "\n";
         } else {
             return $matches[2];
         }
     }, $matches['value']);
     $obj = Sabre_VObject_Property::create($propertyName, $propertyValue);
     if ($matches['parameters']) {
         foreach (self::readParameters($matches['parameters']) as $param) {
             $obj->add($param);
         }
     }
     return $obj;
 }
Ejemplo n.º 4
0
 public function timeRangeTestData()
 {
     $tests = array();
     $vjournal = Sabre_VObject_Component::create('VJOURNAL');
     $vjournal->DTSTART = '20111223T120000Z';
     $tests[] = array($vjournal, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
     $tests[] = array($vjournal, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
     $vjournal2 = Sabre_VObject_Component::create('VJOURNAL');
     $vjournal2->DTSTART = '20111223';
     $vjournal2->DTSTART['VALUE'] = 'DATE';
     $tests[] = array($vjournal2, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
     $tests[] = array($vjournal2, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
     $vjournal3 = Sabre_VObject_Component::create('VJOURNAL');
     $tests[] = array($vjournal3, new DateTime('2011-01-01'), new DateTime('2012-01-01'), false);
     $tests[] = array($vjournal3, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
     return $tests;
 }
Ejemplo n.º 5
0
 public function timeRangeTestData()
 {
     $tests = array();
     $vtodo = Sabre_VObject_Component::create('VTODO');
     $vtodo->DTSTART = '20111223T120000Z';
     $tests[] = array($vtodo, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
     $tests[] = array($vtodo, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
     $vtodo2 = clone $vtodo;
     $vtodo2->DURATION = 'P1D';
     $tests[] = array($vtodo2, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
     $tests[] = array($vtodo2, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
     $vtodo3 = clone $vtodo;
     $vtodo3->DUE = '20111225';
     $tests[] = array($vtodo3, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
     $tests[] = array($vtodo3, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
     $vtodo4 = Sabre_VObject_Component::create('VTODO');
     $vtodo4->DUE = '20111225';
     $tests[] = array($vtodo4, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
     $tests[] = array($vtodo4, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
     $vtodo5 = Sabre_VObject_Component::create('VTODO');
     $vtodo5->COMPLETED = '20111225';
     $tests[] = array($vtodo5, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
     $tests[] = array($vtodo5, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
     $vtodo6 = Sabre_VObject_Component::create('VTODO');
     $vtodo6->CREATED = '20111225';
     $tests[] = array($vtodo6, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
     $tests[] = array($vtodo6, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
     $vtodo7 = Sabre_VObject_Component::create('VTODO');
     $vtodo7->CREATED = '20111225';
     $vtodo7->COMPLETED = '20111226';
     $tests[] = array($vtodo7, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
     $tests[] = array($vtodo7, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
     $vtodo7 = Sabre_VObject_Component::create('VTODO');
     $tests[] = array($vtodo7, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
     $tests[] = array($vtodo7, new DateTime('2011-01-01'), new DateTime('2011-11-01'), true);
     return $tests;
 }
Ejemplo n.º 6
0
 /**
  * @expectedException Sabre_DAV_Exception
  */
 public function testInTimeRangeInvalidComponent()
 {
     $valarm = Sabre_VObject_Component::create('VALARM');
     $valarm->TRIGGER = '-P1D';
     $valarm->TRIGGER['RELATED'] = 'END';
     $vjournal = Sabre_VObject_Component::create('VJOURNAL');
     $vjournal->add($valarm);
     $valarm->isInTimeRange(new DateTime('2012-02-25 01:00:00'), new DateTime('2012-03-05 01:00:00'));
 }
 /**
  * @depends testValues
  */
 function testOverridenEventNoValuesExpected()
 {
     $vcal = Sabre_VObject_Component::create('VCALENDAR');
     $ev1 = Sabre_VObject_Component::create('VEVENT');
     $ev1->UID = 'overridden';
     $ev1->RRULE = 'FREQ=WEEKLY;COUNT=3';
     $ev1->DTSTART = '20120124T120000Z';
     $ev1->SUMMARY = 'baseEvent';
     $vcal->add($ev1);
     // ev2 overrides an event, and puts it 6 days earlier instead.
     $ev2 = Sabre_VObject_Component::create('VEVENT');
     $ev2->UID = 'overridden';
     $ev2->{'RECURRENCE-ID'} = '20120131T120000Z';
     $ev2->DTSTART = '20120125T120000Z';
     $ev2->SUMMARY = 'Override!';
     $vcal->add($ev2);
     $it = new Sabre_VObject_RecurrenceIterator($vcal, 'overridden');
     $dates = array();
     $summaries = array();
     // The reported problem was specifically related to the VCALENDAR
     // expansion. In this parcitular case, we had to forward to the 28th of
     // january.
     $it->fastForward(new DateTime('2012-01-28 23:00:00'));
     // We stop the loop when it hits the 6th of februari. Normally this
     // iterator would hit 24, 25 (overriden from 31) and 7 feb but because
     // we 'filter' from the 28th till the 6th, we should get 0 results.
     while ($it->valid() && $it->getDTSTart() < new DateTime('2012-02-06 23:00:00')) {
         $dates[] = $it->getDTStart();
         $summaries[] = (string) $it->getEventObject()->SUMMARY;
         $it->next();
     }
     $this->assertEquals(array(), $dates);
     $this->assertEquals(array(), $summaries);
 }