Second part of refactoring; should be runnable again, yet not thoroughly tested

pull/76/merge
Tobias Hößl 2012-08-11 08:07:19 +00:00
parent b8234a1cb8
commit 6186153f68
88 changed files with 2135 additions and 1186 deletions

View File

@ -14,6 +14,7 @@
only used for informational purposes.
* BC Break: The DAV: namespace is no longer converted to urn:DAV. This was
a workaround for a bug in older PHP versions (pre-5.3).
* Changed: The Sabre_VObject library now spawned into it's own project!
* New feature: Support for caldav notifications!
* Changed: Responsibility for dealing with the calendar-query is now
moved from the CalDAV plugin to the CalDAV backends. This allows for
@ -33,13 +34,14 @@
* Fixed: Uploaded VCards without a UID are now rejected. (thanks Dominik!)
* Fixed: Rejecting calendar objects if they are not in the
supported-calendar-component list. (thanks Armin!)
* Fixed: Workaround for 10.8 Mountain Lion vCards, as it needs \r line
endings to parse them correctly.
* Fixed: Issue 219: serialize() now reorders correctly.
* Fixed: Sabre_DAV_XMLUtil no longer returns empty $dom->childNodes
if there is whitespace in $dom.
1.6.4-stable (2012-??-??)
1.6.5-stable (2012-??-??)
* Fixed: Workaround for line-ending bug OS X 10.8 addressbook has.
1.6.4-stable (2012-08-02)
* Fixed: Issue 220: Calendar-query filters may fail when filtering on
alarms, if an overridden event has it's alarm removed.
* Fixed: Compatibility for OS/X 10.8 iCal in the IMipHandler.
@ -56,6 +58,8 @@
exactly on the start of a time-range.
* Fixed: HTTP basic auth did not correctly deal with passwords containing
colons on some servers.
* Fixed: Issue 228: DTEND is now non-inclusive for all-day events in the
calendar-query REPORT and free-busy calculations.
1.6.3-stable (2012-06-12)
* Added: It's now possible to specify in Sabre_DAV_Client which type of

View File

@ -1,21 +1,30 @@
{
"name": "evert/sabredav",
"name": "sabre/dav",
"type": "library",
"description": "WebDAV Framework for PHP",
"keywords": ["Framework", "WebDAV", "CalDAV", "CardDAV", "iCalendar"],
"homepage": "http://code.google.com/p/sabredav/",
"license": "New BSD License",
"license" : "BSD-3-Clause",
"authors": [
{
"name": "Evert Pot",
"email": "evert@rooftopsolutions.nl",
"homepage" : "http://www.rooftopsolutions.nl/"
"homepage" : "http://www.rooftopsolutions.nl/",
"role" : "Developer"
}
],
"require": {
"php": ">=5.3.1"
"php": ">=5.3.1",
"sabre/vobject" : "master-dev"
},
"provide" : {
"evert/sabredav" : "2.0.0"
},
"autoload": {
"psr-0": { "Sabre": "lib/" }
},
"support" : {
"forum" : "https://groups.google.com/group/sabredav-discuss",
"source" : "https://github.com/evert/sabredav"
}
}

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
/**
* Abstract Calendaring backend. Extend this class to create your own backends.
*
@ -140,7 +142,7 @@ abstract class Sabre_CalDAV_Backend_Abstract implements Sabre_CalDAV_Backend_Bac
$object = $this->getCalendarObject($object['calendarid'], $object['uri']);
}
$vObject = Sabre_VObject_Reader::read($object['calendardata']);
$vObject = VObject\Reader::read($object['calendardata']);
$validator = new Sabre_CalDAV_CalendarQueryValidator();
return $validator->validate($vObject, $filters);

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
/**
* PDO CalDAV backend
*
@ -462,7 +464,7 @@ class Sabre_CalDAV_Backend_PDO extends Sabre_CalDAV_Backend_Abstract {
*/
protected function getDenormalizedData($calendarData) {
$vObject = Sabre_VObject_Reader::read($calendarData);
$vObject = VObject\Reader::read($calendarData);
$componentType = null;
$component = null;
$firstOccurence = null;
@ -484,9 +486,9 @@ class Sabre_CalDAV_Backend_PDO extends Sabre_CalDAV_Backend_Abstract {
$lastOccurence = $component->DTEND->getDateTime()->getTimeStamp();
} elseif (isset($component->DURATION)) {
$endDate = clone $component->DTSTART->getDateTime();
$endDate->add(Sabre_VObject_DateTimeParser::parse($component->DURATION->value));
$endDate->add(VObject\DateTimeParser::parse($component->DURATION->value));
$lastOccurence = $endDate->getTimeStamp();
} elseif ($component->DTSTART->getDateType()===Sabre_VObject_Property_DateTime::DATE) {
} elseif ($component->DTSTART->getDateType()===VObject\Property\DateTime::DATE) {
$endDate = clone $component->DTSTART->getDateTime();
$endDate->modify('+1 day');
$lastOccurence = $endDate->getTimeStamp();
@ -494,7 +496,7 @@ class Sabre_CalDAV_Backend_PDO extends Sabre_CalDAV_Backend_Abstract {
$lastOccurence = $firstOccurence;
}
} else {
$it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->UID);
$it = new VObject\RecurrenceIterator($vObject, (string)$component->UID);
$maxDate = new DateTime(self::MAX_DATE);
if ($it->isInfinite()) {
$lastOccurence = $maxDate->getTimeStamp();

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
/**
* Parses the calendar-query report request body.
*
@ -241,12 +243,12 @@ class Sabre_CalDAV_CalendarQueryParser {
$timeRangeNode = $timeRangeNodes->item(0);
if ($start = $timeRangeNode->getAttribute('start')) {
$start = Sabre_VObject_DateTimeParser::parseDateTime($start);
$start = VObject\DateTimeParser::parseDateTime($start);
} else {
$start = null;
}
if ($end = $timeRangeNode->getAttribute('end')) {
$end = Sabre_VObject_DateTimeParser::parseDateTime($end);
$end = VObject\DateTimeParser::parseDateTime($end);
} else {
$end = null;
}
@ -274,13 +276,13 @@ class Sabre_CalDAV_CalendarQueryParser {
if(!$start) {
throw new Sabre_DAV_Exception_BadRequest('The "start" attribute is required for the CALDAV:expand element');
}
$start = Sabre_VObject_DateTimeParser::parseDateTime($start);
$start = VObject\DateTimeParser::parseDateTime($start);
$end = $parentNode->getAttribute('end');
if(!$end) {
throw new Sabre_DAV_Exception_BadRequest('The "end" attribute is required for the CALDAV:expand element');
}
$end = Sabre_VObject_DateTimeParser::parseDateTime($end);
$end = VObject\DateTimeParser::parseDateTime($end);
if ($end <= $start) {
throw new Sabre_DAV_Exception_BadRequest('The end-date must be larger than the start-date in the expand element.');

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
/**
* CalendarQuery Validator
*
@ -22,11 +24,11 @@ class Sabre_CalDAV_CalendarQueryValidator {
*
* The list of filters must be formatted as parsed by Sabre_CalDAV_CalendarQueryParser
*
* @param Sabre_VObject_Component $vObject
* @param VObject\Component $vObject
* @param array $filters
* @return bool
*/
public function validate(Sabre_VObject_Component $vObject,array $filters) {
public function validate(VObject\Component $vObject,array $filters) {
// The top level object is always a component filter.
// We'll parse it manually, as it's pretty simple.
@ -48,11 +50,11 @@ class Sabre_CalDAV_CalendarQueryValidator {
* component we're checking should be specified, not the component to check
* itself.
*
* @param Sabre_VObject_Component $parent
* @param VObject\Component $parent
* @param array $filters
* @return bool
*/
protected function validateCompFilters(Sabre_VObject_Component $parent, array $filters) {
protected function validateCompFilters(VObject\Component $parent, array $filters) {
foreach($filters as $filter) {
@ -117,11 +119,11 @@ class Sabre_CalDAV_CalendarQueryValidator {
* property we're checking should be specified, not the property to check
* itself.
*
* @param Sabre_VObject_Component $parent
* @param VObject\Component $parent
* @param array $filters
* @return bool
*/
protected function validatePropFilters(Sabre_VObject_Component $parent, array $filters) {
protected function validatePropFilters(VObject\Component $parent, array $filters) {
foreach($filters as $filter) {
@ -187,11 +189,11 @@ class Sabre_CalDAV_CalendarQueryValidator {
* parameter we're checking should be specified, not the parameter to check
* itself.
*
* @param Sabre_VObject_Property $parent
* @param VObject\Property $parent
* @param array $filters
* @return bool
*/
protected function validateParamFilters(Sabre_VObject_Property $parent, array $filters) {
protected function validateParamFilters(VObject\Property $parent, array $filters) {
foreach($filters as $filter) {
@ -243,11 +245,11 @@ class Sabre_CalDAV_CalendarQueryValidator {
* A single text-match should be specified as well as the specific property
* or parameter we need to validate.
*
* @param Sabre_VObject_Node $parent
* @param VObject\Node $parent
* @param array $textMatch
* @return bool
*/
protected function validateTextMatch(Sabre_VObject_Node $parent, array $textMatch) {
protected function validateTextMatch(VObject\Node $parent, array $textMatch) {
$value = (string)$parent;
@ -263,12 +265,12 @@ class Sabre_CalDAV_CalendarQueryValidator {
* This is all based on the rules specified in rfc4791, which are quite
* complex.
*
* @param Sabre_VObject_Node $component
* @param VObject\Node $component
* @param DateTime $start
* @param DateTime $end
* @return bool
*/
protected function validateTimeRange(Sabre_VObject_Node $component, $start, $end) {
protected function validateTimeRange(VObject\Node $component, $start, $end) {
if (is_null($start)) {
$start = new DateTime('1900-01-01');
@ -296,7 +298,7 @@ class Sabre_CalDAV_CalendarQueryValidator {
if ($component->parent->name === 'VEVENT' && $component->parent->RRULE) {
// Fire up the iterator!
$it = new Sabre_VObject_RecurrenceIterator($component->parent->parent, (string)$component->parent->UID);
$it = new VObject\RecurrenceIterator($component->parent->parent, (string)$component->parent->UID);
while($it->valid()) {
$expandedEvent = $it->getEventObject();

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
/**
* ICS Exporter
*
@ -82,7 +84,7 @@ class Sabre_CalDAV_ICSExportPlugin extends Sabre_DAV_ServerPlugin {
*/
public function generateICS(array $nodes) {
$calendar = new Sabre_VObject_Component('vcalendar');
$calendar = new VObject\Component('vcalendar');
$calendar->version = '2.0';
if (Sabre_DAV_Server::$exposeVersion) {
$calendar->prodid = '-//SabreDAV//SabreDAV ' . Sabre_DAV_Version::VERSION . '//EN';
@ -103,7 +105,7 @@ class Sabre_CalDAV_ICSExportPlugin extends Sabre_DAV_ServerPlugin {
}
$nodeData = $node[200]['{' . Sabre_CalDAV_Plugin::NS_CALDAV . '}calendar-data'];
$nodeComp = Sabre_VObject_Reader::read($nodeData);
$nodeComp = VObject\Reader::read($nodeData);
foreach($nodeComp->children() as $child) {

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
/**
* CalDAV plugin
*
@ -456,8 +458,8 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
if(!$start || !$end) {
throw new Sabre_DAV_Exception_BadRequest('The "start" and "end" attributes are required for the CALDAV:expand element');
}
$start = Sabre_VObject_DateTimeParser::parseDateTime($start);
$end = Sabre_VObject_DateTimeParser::parseDateTime($end);
$start = VObject\DateTimeParser::parseDateTime($start);
$end = VObject\DateTimeParser::parseDateTime($end);
if ($end <= $start) {
throw new Sabre_DAV_Exception_BadRequest('The end-date must be larger than the start-date in the expand element.');
@ -476,7 +478,7 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
list($objProps) = $this->server->getPropertiesForPath($uri,$properties);
if ($expand && isset($objProps[200]['{' . self::NS_CALDAV . '}calendar-data'])) {
$vObject = Sabre_VObject_Reader::read($objProps[200]['{' . self::NS_CALDAV . '}calendar-data']);
$vObject = VObject\Reader::read($objProps[200]['{' . self::NS_CALDAV . '}calendar-data']);
$vObject->expand($start, $end);
$objProps[200]['{' . self::NS_CALDAV . '}calendar-data'] = $vObject->serialize();
}
@ -543,7 +545,7 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
if (isset($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data'])) {
$validator = new Sabre_CalDAV_CalendarQueryValidator();
$vObject = Sabre_VObject_Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
$vObject = VObject\Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
if ($validator->validate($vObject,$parser->filters)) {
// If the client didn't require the calendar-data property,
@ -577,7 +579,7 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
if ($parser->expand) {
// We need to do some post-processing
$vObject = Sabre_VObject_Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
$vObject = VObject\Reader::read($properties[200]['{urn:ietf:params:xml:ns:caldav}calendar-data']);
$vObject->expand($parser->expand['start'], $parser->expand['end']);
$properties[200]['{' . self::NS_CALDAV . '}calendar-data'] = $vObject->serialize();
}
@ -617,10 +619,10 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
}
if ($start) {
$start = Sabre_VObject_DateTimeParser::parseDateTime($start);
$start = VObject\DateTimeParser::parseDateTime($start);
}
if ($end) {
$end = Sabre_VObject_DateTimeParser::parseDateTime($end);
$end = VObject\DateTimeParser::parseDateTime($end);
}
if (!$start && !$end) {
@ -647,7 +649,7 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
return $obj;
}, $calendar->getChildren());
$generator = new Sabre_VObject_FreeBusyGenerator();
$generator = new VObject\FreeBusyGenerator();
$generator->setObjects($objects);
$generator->setTimeRange($start, $end);
$result = $generator->getResult();
@ -763,9 +765,9 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
try {
$vobj = Sabre_VObject_Reader::read($data);
$vobj = VObject\Reader::read($data);
} catch (Sabre_VObject_ParseException $e) {
} catch (VObject\ParseException $e) {
throw new Sabre_DAV_Exception_UnsupportedMediaType('This resource only supports valid iCalendar 2.0 data. Parse error: ' . $e->getMessage());
@ -868,8 +870,8 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
}
try {
$vObject = Sabre_VObject_Reader::read($this->server->httpRequest->getBody(true));
} catch (Sabre_VObject_ParseException $e) {
$vObject = VObject\Reader::read($this->server->httpRequest->getBody(true));
} catch (VObject\ParseException $e) {
throw new Sabre_DAV_Exception_BadRequest('The request body must be a valid iCalendar object. Parse error: ' . $e->getMessage());
}
@ -920,10 +922,10 @@ class Sabre_CalDAV_Plugin extends Sabre_DAV_ServerPlugin {
*
* @param string $originator
* @param array $recipients
* @param Sabre_VObject_Component $vObject
* @param Sabre\VObject\Component $vObject
* @return array
*/
protected function iMIPMessage($originator, array $recipients, Sabre_VObject_Component $vObject, $principal) {
protected function iMIPMessage($originator, array $recipients, VObject\Component $vObject, $principal) {
if (!$this->imipHandler) {
$resultStatus = '5.2;This server does not support this operation';

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
/**
* iMIP handler.
*
@ -44,11 +46,11 @@ class Sabre_CalDAV_Schedule_IMip {
*
* @param string $originator Originator Email
* @param array $recipients Array of email addresses
* @param Sabre_VObject_Component $vObject
* @param Sabre\VObject\Component $vObject
* @param string $principal Principal Url of the originator
* @return void
*/
public function sendMessage($originator, array $recipients, Sabre_VObject_Component $vObject, $principal) {
public function sendMessage($originator, array $recipients, VObject\Component $vObject, $principal) {
foreach($recipients as $recipient) {

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
/**
* CardDAV plugin
*
@ -345,9 +347,9 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin {
try {
$vobj = Sabre_VObject_Reader::read($data);
$vobj = VObject\Reader::read($data);
} catch (Sabre_VObject_ParseException $e) {
} catch (VObject\ParseException $e) {
throw new Sabre_DAV_Exception_UnsupportedMediaType('This resource only supports valid vcard data. Parse error: ' . $e->getMessage());
@ -441,7 +443,7 @@ class Sabre_CardDAV_Plugin extends Sabre_DAV_ServerPlugin {
*/
public function validateFilters($vcardData, array $filters, $test) {
$vcard = Sabre_VObject_Reader::read($vcardData);
$vcard = VObject\Reader::read($vcardData);
if (!$filters) return true;

View File

@ -1,39 +0,0 @@
<?php
/**
* Sabre_VObject includes file
*
* Including this file will automatically include all files from the VObject
* package.
*
* This often allows faster loadtimes, as autoload-speed is often quite slow.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
// Begin includes
include __DIR__ . '/DateTimeParser.php';
include __DIR__ . '/ElementList.php';
include __DIR__ . '/FreeBusyGenerator.php';
include __DIR__ . '/Node.php';
include __DIR__ . '/Parameter.php';
include __DIR__ . '/ParseException.php';
include __DIR__ . '/Reader.php';
include __DIR__ . '/RecurrenceIterator.php';
include __DIR__ . '/TimeZoneUtil.php';
include __DIR__ . '/Version.php';
include __DIR__ . '/Element.php';
include __DIR__ . '/Property.php';
include __DIR__ . '/Component.php';
include __DIR__ . '/Property/DateTime.php';
include __DIR__ . '/Property/MultiDateTime.php';
include __DIR__ . '/Component/VAlarm.php';
include __DIR__ . '/Component/VCalendar.php';
include __DIR__ . '/Component/VEvent.php';
include __DIR__ . '/Component/VJournal.php';
include __DIR__ . '/Component/VTodo.php';
// End includes

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
class Sabre_CalDAV_CalendarQueryVAlarmTest extends PHPUnit_Framework_TestCase {
/**
@ -8,16 +10,16 @@ class Sabre_CalDAV_CalendarQueryVAlarmTest extends PHPUnit_Framework_TestCase {
*/
function testValarm() {
$vevent = Sabre_VObject_Component::create('VEVENT');
$vevent = VObject\Component::create('VEVENT');
$vevent->RRULE = 'FREQ=MONTHLY';
$vevent->DTSTART = '20120101T120000Z';
$vevent->UID = 'bla';
$valarm = Sabre_VObject_Component::create('VALARM');
$valarm = VObject\Component::create('VALARM');
$valarm->TRIGGER = '-P15D';
$vevent->add($valarm);
$vcalendar = Sabre_VObject_Component::create('VCALENDAR');
$vcalendar = VObject\Component::create('VCALENDAR');
$vcalendar->add($vevent);
$filter = array(
@ -52,16 +54,16 @@ class Sabre_CalDAV_CalendarQueryVAlarmTest extends PHPUnit_Framework_TestCase {
// A limited recurrence rule, should return false
$vevent = Sabre_VObject_Component::create('VEVENT');
$vevent = VObject\Component::create('VEVENT');
$vevent->RRULE = 'FREQ=MONTHLY;COUNT=1';
$vevent->DTSTART = '20120101T120000Z';
$vevent->UID = 'bla';
$valarm = Sabre_VObject_Component::create('VALARM');
$valarm = VObject\Component::create('VALARM');
$valarm->TRIGGER = '-P15D';
$vevent->add($valarm);
$vcalendar = Sabre_VObject_Component::create('VCALENDAR');
$vcalendar = VObject\Component::create('VCALENDAR');
$vcalendar->add($vevent);
$this->assertFalse($validator->validate($vcalendar, $filter));
@ -69,15 +71,15 @@ class Sabre_CalDAV_CalendarQueryVAlarmTest extends PHPUnit_Framework_TestCase {
function testAlarmWayBefore() {
$vevent = Sabre_VObject_Component::create('VEVENT');
$vevent = VObject\Component::create('VEVENT');
$vevent->DTSTART = '20120101T120000Z';
$vevent->UID = 'bla';
$valarm = Sabre_VObject_Component::create('VALARM');
$valarm = VObject\Component::create('VALARM');
$valarm->TRIGGER = '-P2W1D';
$vevent->add($valarm);
$vcalendar = Sabre_VObject_Component::create('VCALENDAR');
$vcalendar = VObject\Component::create('VCALENDAR');
$vcalendar->add($vevent);
$filter = array(

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
class Sabre_CalDAV_CalendarQueryValidatorTest extends PHPUnit_Framework_TestCase {
/**
@ -19,7 +21,7 @@ class Sabre_CalDAV_CalendarQueryValidatorTest extends PHPUnit_Framework_TestCase
'time-range' => null,
);
$vObject = Sabre_VObject_Reader::read($icalObject);
$vObject = VObject\Reader::read($icalObject);
switch($outcome) {
case 0 :
@ -31,7 +33,7 @@ class Sabre_CalDAV_CalendarQueryValidatorTest extends PHPUnit_Framework_TestCase
case -1 :
try {
$validator->validate($vObject, $filters);
} catch (Sabre_DAV_Exception $e) {
} catch (Exception $e) {
// Success
}
break;

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
/**
* This unittests is created to find out why recurring events have wrong DTSTART value
*
@ -83,13 +85,13 @@ END:VCALENDAR
);
$body = str_replace('&#13;','',$body);
$vObject = Sabre_VObject_Reader::read($body);
$vObject = VObject\Reader::read($body);
// check if DTSTARTs and DTENDs are correct
foreach ($vObject->VEVENT as $vevent) {
/** @var $vevent Sabre_VObject_Component_VEvent */
/** @var $vevent Sabre\VObject\Component_VEvent */
foreach ($vevent->children as $child) {
/** @var $child Sabre_VObject_Property */
/** @var $child Sabre\VObject\Property */
if ($child->name == 'DTSTART') {
// DTSTART has to be one of three valid values

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
/**
* This unittests is created to find out why recurring events have wrong DTSTART value
*
@ -75,15 +77,15 @@ END:VCALENDAR
);
$body = str_replace('&#13;','',$body);
$vObject = Sabre_VObject_Reader::read($body);
$vObject = VObject\Reader::read($body);
$this->assertEquals(2, count($vObject->VEVENT));
// check if DTSTARTs and DTENDs are correct
foreach ($vObject->VEVENT as $vevent) {
/** @var $vevent Sabre_VObject_Component_VEvent */
/** @var $vevent Sabre\VObject\Component\VEvent */
foreach ($vevent->children as $child) {
/** @var $child Sabre_VObject_Property */
/** @var $child Sabre\VObject\Property */
if ($child->name == 'DTSTART') {
// DTSTART has to be one of two valid values

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
/**
* This unittests is created to find out why certain events show up twice.
*
@ -85,7 +87,7 @@ END:VCALENDAR
);
$body = str_replace('&#13;','',$body);
$vObject = Sabre_VObject_Reader::read($body);
$vObject = VObject\Reader::read($body);
// We only expect 3 events
$this->assertEquals(3, count($vObject->VEVENT),'We got 6 events instead of 3. Output: ' . $body);

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
/**
* This unittest is created to check if queries for time-range include the start timestamp or not
*
@ -82,7 +84,7 @@ END:VCALENDAR
);
$body = str_replace('&#13;','',$body);
$vObject = Sabre_VObject_Reader::read($body);
$vObject = VObject\Reader::read($body);
// We expect 1 event
$this->assertEquals(1, count($vObject->VEVENT), 'We got 0 events instead of 1. Output: ' . $body);

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
require_once 'Sabre/CalDAV/TestUtil.php';
require_once 'Sabre/DAV/Auth/MockBackend.php';
require_once 'Sabre/HTTP/ResponseMock.php';
@ -49,7 +51,7 @@ class Sabre_CalDAV_ICSExportPluginTest extends PHPUnit_Framework_TestCase {
'Content-Type' => 'text/calendar',
), $s->httpResponse->headers);
$obj = Sabre_VObject_Reader::read($s->httpResponse->body);
$obj = VObject\Reader::read($s->httpResponse->body);
$this->assertEquals(5,count($obj->children()));
$this->assertEquals(1,count($obj->VERSION));
@ -98,7 +100,7 @@ class Sabre_CalDAV_ICSExportPluginTest extends PHPUnit_Framework_TestCase {
'Content-Type' => 'text/calendar',
), $s->httpResponse->headers);
$obj = Sabre_VObject_Reader::read($s->httpResponse->body);
$obj = VObject\Reader::read($s->httpResponse->body);
$this->assertEquals(5,count($obj->children()));
$this->assertEquals(1,count($obj->VERSION));
@ -211,7 +213,7 @@ class Sabre_CalDAV_ICSExportPluginTest extends PHPUnit_Framework_TestCase {
'Content-Type' => 'text/calendar',
), $s->httpResponse->headers);
$obj = Sabre_VObject_Reader::read($s->httpResponse->body);
$obj = VObject\Reader::read($s->httpResponse->body);
$this->assertEquals(5,count($obj->children()));
$this->assertEquals(1,count($obj->VERSION));

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
class Sabre_CalDAV_Issue166Test extends PHPUnit_Framework_TestCase {
function testFlaw() {
@ -51,7 +53,7 @@ HI;
'is-not-defined' => false,
'time-range' => null,
);
$input = Sabre_VObject_Reader::read($input);
$input = VObject\Reader::read($input);
$this->assertTrue($validator->validate($input,$filters));
}

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
class Sabre_CalDAV_Issue172Test extends PHPUnit_Framework_TestCase {
// DateTimeZone() native name: America/Los_Angeles (GMT-8 in January)
@ -30,7 +32,7 @@ HI;
),
'prop-filters' => array(),
);
$input = Sabre_VObject_Reader::read($input);
$input = VObject\Reader::read($input);
$this->assertTrue($validator->validate($input,$filters));
}
@ -77,7 +79,7 @@ HI;
),
'prop-filters' => array(),
);
$input = Sabre_VObject_Reader::read($input);
$input = VObject\Reader::read($input);
$this->assertTrue($validator->validate($input,$filters));
}
@ -125,7 +127,7 @@ HI;
),
'prop-filters' => array(),
);
$input = Sabre_VObject_Reader::read($input);
$input = VObject\Reader::read($input);
$this->assertTrue($validator->validate($input,$filters));
}
}

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
/**
* This unittest is created to find out why an overwritten DAILY event has wrong DTSTART, DTEND, SUMMARY and RECURRENCEID
*
@ -88,7 +90,7 @@ END:VCALENDAR
);
$body = str_replace('&#13;','',$body);
$vObject = Sabre_VObject_Reader::read($body);
$vObject = VObject\Reader::read($body);
$this->assertEquals(2, count($vObject->VEVENT));
@ -113,10 +115,10 @@ END:VCALENDAR
$matching = false;
foreach ($vObject->VEVENT as $vevent) {
/** @var $vevent Sabre_VObject_Component_VEvent */
/** @var $vevent Sabre\VObject\Component\VEvent */
foreach ($vevent->children as $child) {
/** @var $child Sabre_VObject_Property */
/** @var $child Sabre\VObject\Property */
if (isset($expectedEvent[$child->name])) {
if ($expectedEvent[$child->name] != $child->value) {

View File

@ -1,5 +1,7 @@
<?php
use Sabre\VObject;
/**
* This unittest is created to check if a VALARM TRIGGER of PT0S is supported
*
@ -86,7 +88,7 @@ END:VCALENDAR
);
$body = str_replace('&#13;','',$body);
$vObject = Sabre_VObject_Reader::read($body);
$vObject = VObject\Reader::read($body);
$this->assertEquals(1, count($vObject->VEVENT));

View File

@ -0,0 +1,75 @@
<?php
/**
* This unittest is created to check if the time-range filter is working correctly with all-day-events
*
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_CalDAV_Issue228Test extends Sabre_DAVServerTest {
protected $setupCalDAV = true;
protected $caldavCalendars = array(
array(
'id' => 1,
'name' => 'Calendar',
'principaluri' => 'principals/user1',
'uri' => 'calendar1',
)
);
protected $caldavCalendarObjects = array(
1 => array(
'event.ics' => array(
'calendardata' => 'BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
UID:20120730T113415CEST-6804EGphkd@xxxxxx.de
DTSTAMP:20120730T093415Z
DTSTART;VALUE=DATE:20120729
DTEND;VALUE=DATE:20120730
SUMMARY:sunday event
TRANSP:TRANSPARENT
END:VEVENT
END:VCALENDAR
',
),
),
);
function testIssue228() {
$request = new Sabre_HTTP_Request(array(
'REQUEST_METHOD' => 'REPORT',
'HTTP_CONTENT_TYPE' => 'application/xml',
'REQUEST_URI' => '/calendars/user1/calendar1',
'HTTP_DEPTH' => '1',
));
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
<D:prop>
<C:calendar-data>
<C:expand start="20120730T095609Z"
end="20120813T095609Z"/>
</C:calendar-data>
<D:getetag/>
</D:prop>
<C:filter>
<C:comp-filter name="VCALENDAR">
<C:comp-filter name="VEVENT">
<C:time-range start="20120730T095609Z" end="20120813T095609Z"/>
</C:comp-filter>
</C:comp-filter>
</C:filter>
</C:calendar-query>');
$response = $this->request($request);
// We must check if absolutely nothing was returned from this query.
$this->assertFalse(strpos($response->body, 'BEGIN:VCALENDAR'));
}
}

View File

@ -1,69 +0,0 @@
<?php
class Sabre_VObject_Component_VEventTest extends PHPUnit_Framework_TestCase {
/**
* @dataProvider timeRangeTestData
*/
public function testInTimeRange(Sabre_VObject_Component_VEvent $vevent,$start,$end,$outcome) {
$this->assertEquals($outcome, $vevent->isInTimeRange($start, $end));
}
public function timeRangeTestData() {
$tests = array();
$vevent = new Sabre_VObject_Component_VEvent('VEVENT');
$vevent->DTSTART = '20111223T120000Z';
$tests[] = array($vevent, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
$tests[] = array($vevent, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
$vevent2 = clone $vevent;
$vevent2->DTEND = '20111225T120000Z';
$tests[] = array($vevent2, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
$tests[] = array($vevent2, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
$vevent3 = clone $vevent;
$vevent3->DURATION = 'P1D';
$tests[] = array($vevent3, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
$tests[] = array($vevent3, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
$vevent4 = clone $vevent;
$vevent4->DTSTART = '20111225';
$vevent4->DTSTART['VALUE'] = 'DATE';
$tests[] = array($vevent4, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
$tests[] = array($vevent4, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
// Event with no end date should be treated as lasting the entire day.
$tests[] = array($vevent4, new DateTime('2011-12-25 16:00:00'), new DateTime('2011-12-25 17:00:00'), true);
$vevent5 = clone $vevent;
$vevent5->DURATION = 'P1D';
$vevent5->RRULE = 'FREQ=YEARLY';
$tests[] = array($vevent5, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
$tests[] = array($vevent5, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
$tests[] = array($vevent5, new DateTime('2013-12-01'), new DateTime('2013-12-31'), true);
$vevent6 = clone $vevent;
$vevent6->DTSTART = '20111225';
$vevent6->DTSTART['VALUE'] = 'DATE';
$vevent6->DTEND = '20111225';
$vevent6->DTEND['VALUE'] = 'DATE';
$tests[] = array($vevent6, new DateTime('2011-01-01'), new DateTime('2012-01-01'), true);
$tests[] = array($vevent6, new DateTime('2011-01-01'), new DateTime('2011-11-01'), false);
// Added this test to ensure that recurrence rules with no DTEND also
// get checked for the entire day.
$vevent7 = clone $vevent;
$vevent7->DTSTART = '20120101';
$vevent7->DTSTART['VALUE'] = 'DATE';
$vevent7->RRULE = 'FREQ=MONTHLY';
$tests[] = array($vevent7, new DateTime('2012-02-01 15:00:00'), new DateTime('2012-02-02'), true);
return $tests;
}
}

View File

@ -1,37 +0,0 @@
<?php
class Sabre_VObject_Component_VJournalTest extends PHPUnit_Framework_TestCase {
/**
* @dataProvider timeRangeTestData
*/
public function testInTimeRange(Sabre_VObject_Component_VJournal $vtodo,$start,$end,$outcome) {
$this->assertEquals($outcome, $vtodo->isInTimeRange($start, $end));
}
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;
}
}

View File

@ -1,63 +0,0 @@
<?php
class Sabre_VObject_Component_VTodoTest extends PHPUnit_Framework_TestCase {
/**
* @dataProvider timeRangeTestData
*/
public function testInTimeRange(Sabre_VObject_Component_VTodo $vtodo,$start,$end,$outcome) {
$this->assertEquals($outcome, $vtodo->isInTimeRange($start, $end));
}
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;
}
}

View File

@ -1,117 +0,0 @@
<?php
require_once 'Sabre/CalDAV/TestUtil.php';
class Sabre_VObject_DateTimeParserTest extends PHPUnit_Framework_TestCase {
function testParseICalendarDuration() {
$this->assertEquals('+1 weeks', Sabre_VObject_DateTimeParser::parseDuration('P1W',true));
$this->assertEquals('+5 days', Sabre_VObject_DateTimeParser::parseDuration('P5D',true));
$this->assertEquals('+5 days 3 hours 50 minutes 12 seconds', Sabre_VObject_DateTimeParser::parseDuration('P5DT3H50M12S',true));
$this->assertEquals('-1 weeks 50 minutes', Sabre_VObject_DateTimeParser::parseDuration('-P1WT50M',true));
$this->assertEquals('+50 days 3 hours 2 seconds', Sabre_VObject_DateTimeParser::parseDuration('+P50DT3H2S',true));
$this->assertEquals(new DateInterval('PT0S'), Sabre_VObject_DateTimeParser::parseDuration('PT0S'));
}
function testParseICalendarDurationDateInterval() {
$expected = new DateInterval('P7D');
$this->assertEquals($expected, Sabre_VObject_DateTimeParser::parseDuration('P1W'));
$this->assertEquals($expected, Sabre_VObject_DateTimeParser::parse('P1W'));
$expected = new DateInterval('PT3M');
$expected->invert = true;
$this->assertEquals($expected, Sabre_VObject_DateTimeParser::parseDuration('-PT3M'));
}
/**
* @expectedException Sabre_DAV_Exception_BadRequest
*/
function testParseICalendarDurationFail() {
Sabre_VObject_DateTimeParser::parseDuration('P1X',true);
}
function testParseICalendarDateTime() {
$dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20100316T141405');
$compare = new DateTime('2010-03-16 14:14:05',new DateTimeZone('UTC'));
$this->assertEquals($compare, $dateTime);
}
/**
* @depends testParseICalendarDateTime
* @expectedException Sabre_DAV_Exception_BadRequest
*/
function testParseICalendarDateTimeBadFormat() {
$dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20100316T141405 ');
}
/**
* @depends testParseICalendarDateTime
*/
function testParseICalendarDateTimeUTC() {
$dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20100316T141405Z');
$compare = new DateTime('2010-03-16 14:14:05',new DateTimeZone('UTC'));
$this->assertEquals($compare, $dateTime);
}
/**
* @depends testParseICalendarDateTime
*/
function testParseICalendarDateTimeUTC2() {
$dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20101211T160000Z');
$compare = new DateTime('2010-12-11 16:00:00',new DateTimeZone('UTC'));
$this->assertEquals($compare, $dateTime);
}
/**
* @depends testParseICalendarDateTime
*/
function testParseICalendarDateTimeCustomTimeZone() {
$dateTime = Sabre_VObject_DateTimeParser::parseDateTime('20100316T141405', new DateTimeZone('Europe/Amsterdam'));
$compare = new DateTime('2010-03-16 13:14:05',new DateTimeZone('UTC'));
$this->assertEquals($compare, $dateTime);
}
function testParseICalendarDate() {
$dateTime = Sabre_VObject_DateTimeParser::parseDate('20100316');
$expected = new DateTime('2010-03-16 00:00:00',new DateTimeZone('UTC'));
$this->assertEquals($expected, $dateTime);
$dateTime = Sabre_VObject_DateTimeParser::parse('20100316');
$this->assertEquals($expected, $dateTime);
}
/**
* @depends testParseICalendarDate
* @expectedException Sabre_DAV_Exception_BadRequest
*/
function testParseICalendarDateBadFormat() {
$dateTime = Sabre_VObject_DateTimeParser::parseDate('20100316T141405');
}
}

View File

@ -1,12 +0,0 @@
<?php
class Sabre_VObject_Issue153Test extends PHPUnit_Framework_TestCase {
function testRead() {
$obj = Sabre_VObject_Reader::read(file_get_contents(dirname(__FILE__) . '/issue153.vcf'));
$this->assertEquals('Test Benutzer', (string)$obj->fn);
}
}

View File

@ -4,9 +4,9 @@ define('SABRE_MYSQLDSN','mysql:host=127.0.0.1;dbname=sabredav');
define('SABRE_MYSQLUSER','root');
define('SABRE_MYSQLPASS','');
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . dirname(__FILE__) . '/../lib/' . PATH_SEPARATOR . get_include_path());
set_include_path(__DIR__ . '/../lib/' . PATH_SEPARATOR . __DIR__ . PATH_SEPARATOR . get_include_path());
include 'Sabre/autoload.php';
include __DIR__ . '/../vendor/autoload.php';
include 'Sabre/DAVServerTest.php';
date_default_timezone_set('GMT');

View File

@ -298,7 +298,7 @@ function dav_get_current_user_calendars(&$server, $with_privilege = "")
* @param Sabre_CalDAV_Calendar $calendar
* @param string $calendarobject_uri
* @param string $with_privilege
* @return null|Sabre_VObject_Component_VCalendar
* @return null|Sabre\VObject\Component\VCalendar
*/
function dav_get_current_user_calendarobject(&$server, &$calendar, $calendarobject_uri, $with_privilege = "")
{
@ -314,7 +314,7 @@ function dav_get_current_user_calendarobject(&$server, &$calendar, $calendarobje
if (!$aclplugin->checkPrivileges($uri, $with_privilege, Sabre_DAVACL_Plugin::R_PARENT, false)) return null;
$data = $obj->get();
$vObject = Sabre_VObject_Reader::read($data);
$vObject = Sabre\VObject\Reader::read($data);
return $vObject;
}
@ -342,20 +342,20 @@ function dav_get_current_user_calendar_by_id(&$server, $id, $with_privilege = ""
/**
* @param string $uid
* @return Sabre_VObject_Component_VCalendar $vObject
* @return Sabre\VObject\Component\VCalendar $vObject
*/
function dav_create_empty_vevent($uid = "")
{
$a = get_app();
if ($uid == "") $uid = uniqid();
return Sabre_VObject_Reader::read("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//" . DAV_APPNAME . "//DAV-Plugin//EN\r\nBEGIN:VEVENT\r\nUID:" . $uid . "@" . dav_compat_get_hostname() .
return Sabre\VObject\Reader::read("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//" . DAV_APPNAME . "//DAV-Plugin//EN\r\nBEGIN:VEVENT\r\nUID:" . $uid . "@" . dav_compat_get_hostname() .
"\r\nDTSTAMP:" . date("Ymd") . "T" . date("His") . "Z\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
}
/**
* @param Sabre_VObject_Component_VCalendar $vObject
* @return Sabre_VObject_Component_VEvent|null
* @param Sabre\VObject\Component\VCalendar $vObject
* @return Sabre\VObject\Component\VEvent|null
*/
function dav_get_eventComponent(&$vObject)
{

View File

@ -3,8 +3,8 @@
/**
* @param Sabre_VObject_Component_VAlarm $alarm
* @param Sabre_VObject_Component_VEvent|Sabre_VObject_Component_VTodo $parent
* @param Sabre\VObject\Component\VAlarm $alarm
* @param Sabre\VObject\Component\VEvent|Sabre\VObject\Component\VTodo $parent
* @return DateTime|null
* @throws Sabre_DAV_Exception
*/
@ -12,12 +12,12 @@ function renderCalDavEntry_calcalarm(&$alarm, &$parent)
{
$trigger = $alarm->__get("TRIGGER");
if (!isset($trigger['VALUE']) || strtoupper($trigger['VALUE']) === 'DURATION') {
$triggerDuration = Sabre_VObject_DateTimeParser::parseDuration($trigger->value);
$triggerDuration = Sabre\VObject\DateTimeParser::parseDuration($trigger->value);
$related = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'END' : 'START';
if ($related === 'START') {
/** @var Sabre_VObject_Property_DateTime $dtstart */
/** @var Sabre\VObject\Property\DateTime $dtstart */
$dtstart = $parent->__get("DTSTART");
$effectiveTrigger = $dtstart->getDateTime();
$effectiveTrigger->add($triggerDuration);
@ -28,14 +28,14 @@ function renderCalDavEntry_calcalarm(&$alarm, &$parent)
$endProp = 'DTEND';
}
/** @var Sabre_VObject_Property_DateTime $dtstart */
/** @var Sabre\VObject\Property\DateTime $dtstart */
$dtstart = $parent->__get("DTSTART");
if (isset($parent->$endProp)) {
$effectiveTrigger = clone $parent->$endProp->getDateTime();
$effectiveTrigger->add($triggerDuration);
} elseif ($parent->__get("DURATION") != "") {
$effectiveTrigger = clone $dtstart->getDateTime();
$duration = Sabre_VObject_DateTimeParser::parseDuration($parent->__get("DURATION"));
$duration = Sabre\VObject\DateTimeParser::parseDuration($parent->__get("DURATION"));
$effectiveTrigger->add($duration);
$effectiveTrigger->add($triggerDuration);
} else {
@ -58,10 +58,10 @@ function renderCalDavEntry_calcalarm(&$alarm, &$parent)
*/
function renderCalDavEntry_data(&$calendar, &$calendarobject)
{
/** @var Sabre_VObject_Component_VCalendar $vObject */
$vObject = Sabre_VObject_Reader::read($calendarobject["calendardata"]);
/** @var Sabre\VObject\Component\VCalendar $vObject */
$vObject = Sabre\VObject\Reader::read($calendarobject["calendardata"]);
$componentType = null;
/** @var Sabre_VObject_Component_VEvent $component */
/** @var Sabre\VObject\Component\VEvent $component */
$component = null;
foreach ($vObject->getComponents() as $component) {
if ($component->name !== 'VTIMEZONE') {
@ -86,18 +86,18 @@ function renderCalDavEntry_data(&$calendar, &$calendarobject)
);
$recurring = ($component->__get("RRULE") ? 1 : 0);
/** @var Sabre_VObject_Property_DateTime $dtstart */
/** @var Sabre\VObject\Property\DateTime $dtstart */
$dtstart = $component->__get("DTSTART");
$allday = ($dtstart->getDateType() == Sabre_VObject_Property_DateTime::DATE ? 1 : 0);
$allday = ($dtstart->getDateType() == Sabre\VObject\Property\DateTime::DATE ? 1 : 0);
/** @var array|Sabre_VObject_Component_VAlarm[] $alarms */
/** @var array|Sabre\VObject\Component\VAlarm[] $alarms */
$alarms = array();
foreach ($component->getComponents() as $a_component) if ($a_component->name == "VALARM") {
/** var Sabre_VObject_Component_VAlarm $component */
/** var Sabre\VObject\Component\VAlarm $component */
$alarms[] = $a_component;
}
$it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID"));
$it = new Sabre\VObject\RecurrenceIterator($vObject, (string)$component->__get("UID"));
$last_end = 0;
$max_ts = mktime(0, 0, 0, 1, 1, CALDAV_MAX_YEAR * 1);
$first = true;

View File

@ -81,22 +81,22 @@ abstract class Sabre_CalDAV_Backend_Common extends Sabre_CalDAV_Backend_Abstract
/**
* @static
* @param Sabre_VObject_Component_VEvent $component
* @param Sabre\VObject\Component\VEvent $component
* @return int
*/
public static function getDtEndTimeStamp(&$component)
{
/** @var Sabre_VObject_Property_DateTime $dtstart */
/** @var Sabre\VObject\Property\DateTime $dtstart */
$dtstart = $component->__get("DTSTART");
if ($component->__get("DTEND")) {
/** @var Sabre_VObject_Property_DateTime $dtend */
/** @var Sabre\VObject\Property\DateTime $dtend */
$dtend = $component->__get("DTEND");
return $dtend->getDateTime()->getTimeStamp();
} elseif ($component->__get("DURATION")) {
$endDate = clone $dtstart->getDateTime();
$endDate->add(Sabre_VObject_DateTimeParser::parse($component->__get("DURATION")->value));
$endDate->add(Sabre\VObject\DateTimeParser::parse($component->__get("DURATION")->value));
return $endDate->getTimeStamp();
} elseif ($dtstart->getDateType() === Sabre_VObject_Property_DateTime::DATE) {
} elseif ($dtstart->getDateType() === Sabre\VObject\Property\DateTime::DATE) {
$endDate = clone $dtstart->getDateTime();
$endDate->modify('+1 day');
return $endDate->getTimeStamp();
@ -124,8 +124,8 @@ abstract class Sabre_CalDAV_Backend_Common extends Sabre_CalDAV_Backend_Abstract
*/
protected function getDenormalizedData($calendarData)
{
/** @var Sabre_VObject_Component_VEvent $vObject */
$vObject = Sabre_VObject_Reader::read($calendarData);
/** @var Sabre\VObject\Component\VEvent $vObject */
$vObject = Sabre\VObject\Reader::read($calendarData);
$componentType = null;
$component = null;
$firstOccurence = null;
@ -141,15 +141,15 @@ abstract class Sabre_CalDAV_Backend_Common extends Sabre_CalDAV_Backend_Abstract
throw new Sabre_DAV_Exception_BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component');
}
if ($componentType === 'VEVENT') {
/** @var Sabre_VObject_Component_VEvent $component */
/** @var Sabre_VObject_Property_DateTime $dtstart */
/** @var Sabre\VObject\Component\VEvent $component */
/** @var Sabre\VObject\Property\DateTime $dtstart */
$dtstart = $component->__get("DTSTART");
$firstOccurence = $dtstart->getDateTime()->getTimeStamp();
// Finding the last occurence is a bit harder
if (!$component->__get("RRULE")) {
$lastOccurence = self::getDtEndTimeStamp($component);
} else {
$it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$component->__get("UID"));
$it = new Sabre\VObject\RecurrenceIterator($vObject, (string)$component->__get("UID"));
$maxDate = new DateTime(CALDAV_MAX_YEAR . "-01-01");
if ($it->isInfinite()) {
$lastOccurence = $maxDate->getTimeStamp();

View File

@ -97,12 +97,12 @@ function wdcal_print_feed($base_path = "")
$component = dav_get_eventComponent($item);
$component->add("SUMMARY", icalendar_sanitize_string(dav_compat_parse_text_serverside("CalendarTitle")));
if (isset($_REQUEST["allday"])) $type = Sabre_VObject_Property_DateTime::DATE;
else $type = Sabre_VObject_Property_DateTime::LOCALTZ;
if (isset($_REQUEST["allday"])) $type = Sabre\VObject\Property\DateTime::DATE;
else $type = Sabre\VObject\Property\DateTime::LOCALTZ;
$datetime_start = new Sabre_VObject_Property_DateTime("DTSTART");
$datetime_start = new Sabre\VObject\Property\DateTime("DTSTART");
$datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarStartTime"]))), $type);
$datetime_end = new Sabre_VObject_Property_DateTime("DTEND");
$datetime_end = new Sabre\VObject\Property\DateTime("DTEND");
$datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarEndTime"]))), $type);
$component->add($datetime_start);
@ -179,12 +179,12 @@ function wdcal_print_feed($base_path = "")
killme();
}
if (isset($_REQUEST["allday"])) $type = Sabre_VObject_Property_DateTime::DATE;
else $type = Sabre_VObject_Property_DateTime::LOCALTZ;
if (isset($_REQUEST["allday"])) $type = Sabre\VObject\Property\DateTime::DATE;
else $type = Sabre\VObject\Property\DateTime::LOCALTZ;
$datetime_start = new Sabre_VObject_Property_DateTime("DTSTART");
$datetime_start = new Sabre\VObject\Property\DateTime("DTSTART");
$datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarStartTime"]))), $type);
$datetime_end = new Sabre_VObject_Property_DateTime("DTEND");
$datetime_end = new Sabre\VObject\Property\DateTime("DTEND");
$datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", IntVal($_REQUEST["CalendarEndTime"]))), $type);
$component->__unset("DTSTART");

View File

@ -82,11 +82,11 @@ class Sabre_CalDAV_Backend_Friendica extends Sabre_CalDAV_Backend_Virtual
$ts_end = wdcal_mySql2PhpTime($start);
$allday = (strpos($start, "00:00:00") !== false && strpos($finish, "00:00:00") !== false);
$type = ($allday ? Sabre_VObject_Property_DateTime::DATE : Sabre_VObject_Property_DateTime::LOCALTZ);
$type = ($allday ? Sabre\VObject\Property\DateTime::DATE : Sabre\VObject\Property\DateTime::LOCALTZ);
$datetime_start = new Sabre_VObject_Property_DateTime("DTSTART");
$datetime_start = new Sabre\VObject\Property\DateTime("DTSTART");
$datetime_start->setDateTime(new DateTime(date("Y-m-d H:i:s", $ts_start)), $type);
$datetime_end = new Sabre_VObject_Property_DateTime("DTEND");
$datetime_end = new Sabre\VObject\Property\DateTime("DTEND");
$datetime_end->setDateTime(new DateTime(date("Y-m-d H:i:s", $ts_end)), $type);
$component->add($datetime_start);

View File

@ -86,12 +86,12 @@ function wdcal_import_user_ics($calendar_id) {
if ($_FILES["ics_file"]["tmp_name"] != "" && is_uploaded_file($_FILES["ics_file"]["tmp_name"])) try {
$text = file_get_contents($_FILES["ics_file"]["tmp_name"]);
/** @var Sabre_VObject_Component_VCalendar $vObject */
$vObject = Sabre_VObject_Reader::read($text);
/** @var Sabre\VObject\Component\VCalendar $vObject */
$vObject = Sabre\VObject\Reader::read($text);
$comp = $vObject->getComponents();
$imported = array();
foreach ($comp as $c) try {
/** @var Sabre_VObject_Component_VEvent $c */
/** @var Sabre\VObject\Component\VEvent $c */
$uid = $c->__get("UID")->value;
if (!isset($imported[$uid])) $imported[$uid] = "";
$imported[$uid] .= $c->serialize();

View File

@ -28,6 +28,27 @@ function dav_include_files()
{
require_once (__DIR__ . "/../SabreDAV/lib/Sabre/autoload.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Node.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Element.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/DateTimeParser.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/ElementList.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/FreeBusyGenerator.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Parameter.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/ParseException.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Property.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Reader.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/RecurrenceIterator.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/TimeZoneUtil.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Version.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Property/DateTime.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Property/MultiDateTime.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VAlarm.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VCalendar.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VEvent.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VJournal.php");
require_once (__DIR__ . "/../sabre-vobject/lib/Sabre/VObject/Component/VTodo.php");
require_once (__DIR__ . "/../common/calendar.fnk.php");
require_once (__DIR__ . "/../common/calendar_rendering.fnk.php");
@ -109,7 +130,7 @@ function dav_init(&$a)
}
$server = dav_create_server();
$server = dav_create_server();
$browser = new Sabre_DAV_Browser_Plugin();
$server->addPlugin($browser);
@ -293,8 +314,7 @@ function dav_plugin_admin_post(&$a = null, &$o = null)
if (count($errs) == 0) {
renderAllCalDavEntries();
info(t('The database tables have been updated.') . EOL);
}
else notice(t("An error occurred during the update.") . EOL);
} else notice(t("An error occurred during the update.") . EOL);
}
}

View File

@ -0,0 +1,8 @@
language: php
php:
- 5.3
- 5.4
script: phpunit --configuration tests/phpunit.xml
before_script: composer install

View File

@ -0,0 +1,7 @@
2.0.0-stable (2012-08-08)
* VObject is now a separate project from SabreDAV. See the SabreDAV
changelog for version information before 2.0.
* New: VObject library now uses PHP 5.3 namespaces.
* New: It's possible to specify lists of parameters when constructing
properties.
* New: made it easier to construct the FreeBusyGenerator.

27
dav/sabre-vobject/LICENSE Normal file
View File

@ -0,0 +1,27 @@
Copyright (C) 2007-2012 Rooftop Solutions.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the Sabre nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

388
dav/sabre-vobject/README.md Normal file
View File

@ -0,0 +1,388 @@
# SabreTooth VObject library
[![Build Status](https://secure.travis-ci.org/evert/sabre-vobject.png?branch=master)](http://travis-ci.org/evert/sabre-vobject)
The VObject library allows you to easily parse and manipulate [iCalendar](https://tools.ietf.org/html/rfc5545)
and [vCard](https://tools.ietf.org/html/rfc6350) objects using PHP.
The goal of the VObject library is to create a very complete library, with an easy to use API.
This project is a spin-off from [SabreDAV](http://code.google.com/p/sabredav/), where it has
been used for several years. The VObject library has 100% unittest coverage.
# Installation
VObject requires PHP 5.3, and should be installed using composer.
The general composer instructions can be found on the [composer website](http://getcomposer.org/doc/00-intro.md composer website).
After that, just declare the vobject dependency as follows:
```
"require" : {
"sabre/vobject" : "dev-master"
}
```
Then, run `composer.phar update` and you should be good. As soon as the first release is out, you should switch `dev-master` to `2.0.*` though.
# Usage
## Parsing
For our example, we will be using the following vcard:
```
BEGIN:VCARD
VERSION:3.0
PRODID:-//Sabre//Sabre VObject 2.0//EN
N:Planck;Max;;;
FN:Max Planck
EMAIL;TYPE=WORK:mplanck@example.org
item1.TEL;TYPE=CELL:(+49)3144435678
item1.X-ABLabel:Private cell
item2.TEL;TYPE=WORK:(+49)5554564744
item2.X-ABLabel:Work
END:VCARD
```
If we want to just print out Max' full name, you can just use property access:
```php
use Sabre\VObject;
$card = VObject\Reader::read($data);
echo $card->FN;
```
## Changing properties
Creating properties is pretty similar. If we like to add his birthday, we just
set the property:
```php
$card->BDAY = '1858-04-23';
```
Note that in the previous example, we're actually updating any existing BDAY that
may already exist. If we want to add a new property, without overwriting the previous
we can do this with the `add` method.
```php
$card->add('EMAIL','max@example.org');
```
## Parameters
If we want to also specify that this is max' home email addresses, we can do this with
a third parameter:
```
$card->add('EMAIL', 'max@example'org', array('type' => 'HOME'));
```
If we want to read out all the email addresses and their type, this would look something
like this:
```
foreach($card->EMAIL as $email) {
echo $email['TYPE'], ' - ', $email;
}
```
## Groups
In our example, you can see that the TEL properties are prefixed. These are 'groups' and
allow you to group multiple related properties together. The group can be any user-defined
name.
This particular example as generated by the OS X addressbook, which uses the `X-ABLabel`
to allow the user to specify custom labels for properties. OS X addressbook uses groups
to tie the label to the property.
The VObject library simply ignores the group if you don't specify it, so this will work:
```php
foreach($card->TEL as $tel) {
echo $tel, "\n";
}
```
But if you would like to target a specific group + property, this is possible too:
```php
echo $card->{'ITEM1.TEL'};
```
So if you would like to show all the phone numbers, along with their custom label, the
following syntax is used:
```
foreach($card->TEL as $tel) {
echo $card->{$tel->group . '.X-ABLABEL'}, ": ";
echo $tel, "\n";
}
```
## Serializing / Saving
If you want to generate your updated VObject, you can simply call the serialize() method.
```
echo $card->serialize();
```
## Components
iCalendar, unlike vCards always have sub-components. Where vCards are often just a flat
list, iCalendar objects tend to have a tree-like structure. For the following paragraphs,
we will use the following object as the example:
```
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Sabre//Sabre VObject 2.0//EN
BEGIN:VEVENT
SUMMARY:Curiosity landing
DTSTART:20120806T051439Z
LOCATION:Mars
END:VEVENT
END:VCALENDAR
```
Since events, tasks and journals are always in a sub component, this is also how we
access them.
```php
use Sabre\VObject;
$calendar = VObject\Reader::read($data);
echo $calendar->VEVENT->SUMMARY;
```
Adding components to a calendar is done with a factory method:
```php
$event = VObject\Component::create('VEVENT');
$calendar->add($event);
$event->SUMMARY = 'Curiosity launch';
$event->DTSTART = '20111126T150202Z';
$event->LOCATION = 'Cape Carnival';
```
By the way.. cloning also works as expected, as the entire structure is cloned along with it:
```php
$clonedEvent = clone $calendar->VEVENT[0];
$calendar->add($clonedEvent);
```
## Date and time handling
If you ever had to deal with iCalendar timezones, you know it can be complicated.
The way timezones are specified is flawed, which is something I may write an essay about some
day. VObject does its best to determine the correct timezone. Many standard formats
have been tested and verified, and special code has been implemented for special-casing
microsoft generated timezone information, and others.
To get a real php `DateTime` object, you can request this as follows:
```
$event = $calendar->VEVENT;
$start = $event->DTSTART->getDateTime();
echo $start->format(\DateTime::W3C);
```
To set the property with a DateTime object, you can use the following syntax:
```
$dateTime = new \DateTime('2012-08-07 23:53:00', new DateTimeZone('Europe/Amsterdam'));
$event->DTSTART->setDateTime($dateTime, VObject\Property\DateTime::DATE);
```
The second argument specifies the type of date you're setting. The following three
options exist:
1. `LOCAL` This is a floating time, with no timezone information. This basically specifies that the event happens in whatever the timezone's currently in. This would be encoded as `DTSTART;VALUE=DATE-TIME:20120807235300`
2. `UTC` This specifies that the time should be encoded as a UTC time. This is encoded as `DTSTART;VALUE=DATE-TIME:20120807205300Z`. Note the extra Z and the fact that it's two hours 'earlier'.
3. `LOCALTZ` specifies that it's supposed to be encoded in its local timezone. For example `DTSTART;VALUE=DATE-TIME;TZID=Europe/Amsterdam:20120807235300`.
4. `DATE` This is a date-only, and does not contain the time. In this case this would be encoded as `DTSTART;VALUE=DATE:20120807`.
A few important notes:
* When a `TZID` is specified, there should also be a matching `VTIMEZONE` object with all the timezone information. VObject cannot currently automatically embed this. However, in reality other clients seem to do fine without this information. Yet, for completeness, this will be added in the future.
* As mentioned, the timezone-determination process may sometimes fail. Report any issues you find, and I'll be quick to add workarounds!
## Recurrence rules
Recurrence rules allow events to recur, for example for a weekly meeting, or an anniversary.
This is done with the `RRULE` property. The `RRULE` property allows for a LOT of different
rules. VObject only implements the ones that actually appear in calendar software.
To read more about `RRULE` and all the options, check out [RFC5545](https://tools.ietf.org/html/rfc5545#section-3.8.5).
VObject supports the following options:
1. `UNTIL` for an end date.
2. `INTERVAL` for for example "every 2 days".
3. `COUNT` to stop recurring after x items.
4. `FREQ=DAILY` to recur every day, and `BYDAY` to limit it to certain days.
5. `FREQ=WEEKLY` to recur every week, `BYDAY` to expand this to multiple weekdays in every week and `WKST` to specify on which day the week starts.
6. `FREQ=MONTHLY` to recur every month, `BYMONTHDAY` to expand this to certain days in a month, `BYDAY` to expand it to certain weekdays occuring in a month, and `BYSETPOS` to limit the last two expansions.
7. `FREQ=YEARLY` to recur every year, `BYMONTH` to expand that to certain months in a year, and `BYDAY` and `BYWEEKDAY` to expand the `BYMONTH` rule even further.
VObject supports the `EXDATE` property for exclusions, but not yet the `RDATE` and `EXRULE`
properties. If you're interested in this, please file a github issue, as this will put it
on my radar.
This is a bit of a complex subject to go in excruciating detail. The
[RFC](https://tools.ietf.org/html/rfc5545#section-3.8.5) has a lot of examples though.
The hard part is not to write the RRULE, it is to expand them. The most complex and
hard-to-read code is hidden in this component. Dragons be here.
So, if we have a meeting every 2nd monday of the month, this would be specified as such:
```
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
UID:1102c450-e0d7-11e1-9b23-0800200c9a66
DTSTART:20120109T140000Z
RRULE:FREQ=MONTHLY;BYDAY=MO;BYSETPOS=2
END:VEVENT
END:VCALENDAR
```
Note that normally it's not allowed to indent the object like this, but it does make
it easier to read. This is also the first time I added in a UID, which is required
for all VEVENT, VTODO and VJOURNAL objects!
To figure out all the meetings for this year, we can use the following syntax:
```php
use Sabre\VObject;
$calendar = VObject\Reader::read($data);
$calendar->expand(new DateTime('2012-01-01'), new DateTime('2012-12-31'));
```
What the expand method does, is look at its inner events, and expand the recurring
rule. Our calendar now contains 12 events. The first will have its RRULE stripped,
and every subsequent VEVENT has the correct meeting date and a `RECURRENCE-ID` set.
This results in something like this:
```
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
UID:1102c450-e0d7-11e1-9b23-0800200c9a66
DTSTART:20120109T140000Z
END:VEVENT
BEGIN:VEVENT
UID:1102c450-e0d7-11e1-9b23-0800200c9a66
RECURRENCE-ID:20120213T140000Z
DTSTART:20120213T140000Z
END:VEVENT
BEGIN:VEVENT
UID:1102c450-e0d7-11e1-9b23-0800200c9a66
RECURRENCE-ID:20120312T140000Z
DTSTART:20120312T140000Z
END:VEVENT
..etc..
END:VCALENDAR
```
To show the list of dates, we would do this as such:
```
foreach($calendar->VEVENT as $event) {
echo $event->DTSTART->getDateTime()->format(\DateTime::ATOM);
}
```
In a recurring event, single instances can also be overriden. VObject also takes these
into consideration. The reason we needed to specify a start and end-date, is because
some recurrence rules can be 'never ending'.
You should make sure you pick a sane date-range. Because if you pick a 50 year
time-range, for a daily recurring event; this would result in over 18K objects.
# Free-busy report generation
Some calendaring software can make use of FREEBUSY reports to show when people are
available.
You can automatically generate these reports from calendars using the `FreeBusyGenerator`.
Example based on our last event:
```
// We're giving it the calendar object. It's also possible to specify multiple objects,
// by setting them as an array.
//
// We must also specify a start and end date, because recurring events are expanded.
$fbGenerator = new VObject\FreeBusyGenerator(
new DateTime('2012-01-01'),
new DateTime('2012-12-31'),
$calendar
);
// Grabbing the report
$freebusy = $fbGenerator->result();
// The freebusy report is another VCALENDAR object, so we can serialize it as usual:
echo $freebusy->serialize();
```
The output of this script will look like this:
```
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Sabre//Sabre VObject 2.0//EN
CALSCALE:GREGORIAN
BEGIN:VFREEBUSY
DTSTART;VALUE=DATE-TIME:20111231T230000Z
DTEND;VALUE=DATE-TIME:20111231T230000Z
DTSTAMP;VALUE=DATE-TIME:20120808T131628Z
FREEBUSY;FBTYPE=BUSY:20120109T140000Z/20120109T140000Z
FREEBUSY;FBTYPE=BUSY:20120213T140000Z/20120213T140000Z
FREEBUSY;FBTYPE=BUSY:20120312T140000Z/20120312T140000Z
FREEBUSY;FBTYPE=BUSY:20120409T140000Z/20120409T140000Z
FREEBUSY;FBTYPE=BUSY:20120514T140000Z/20120514T140000Z
FREEBUSY;FBTYPE=BUSY:20120611T140000Z/20120611T140000Z
FREEBUSY;FBTYPE=BUSY:20120709T140000Z/20120709T140000Z
FREEBUSY;FBTYPE=BUSY:20120813T140000Z/20120813T140000Z
FREEBUSY;FBTYPE=BUSY:20120910T140000Z/20120910T140000Z
FREEBUSY;FBTYPE=BUSY:20121008T140000Z/20121008T140000Z
FREEBUSY;FBTYPE=BUSY:20121112T140000Z/20121112T140000Z
FREEBUSY;FBTYPE=BUSY:20121210T140000Z/20121210T140000Z
END:VFREEBUSY
END:VCALENDAR
```

View File

@ -0,0 +1,27 @@
{
"name": "sabre/vobject",
"description" : "The VObject library for PHP allows you to easily parse and manipulate iCalendar and vCard objects",
"keywords" : [ "VObject", "iCalendar", "vCard" ],
"homepage" : "https://github.com/evert/sabre-vobject",
"license" : "BSD-3-Clause",
"require" : {
"php" : ">=5.3.1"
},
"authors" : [
{
"name" : "Evert Pot",
"email" : "evert@rooftopsolutions.nl",
"homepage" : "http://www.rooftopsolutions.nl/",
"role" : "Developer"
}
],
"support" : {
"forum" : "https://groups.google.com/group/sabredav-discuss",
"source" : "https://github.com/evert/sabre-vobject"
},
"autoload" : {
"psr-0" : {
"Sabre\\VObject" : "lib/"
}
}
}

View File

@ -1,5 +1,7 @@
<?php
namespace Sabre\VObject;
/**
* VObject Component
*
@ -7,13 +9,11 @@
* VEVENT, VTODO and also VCALENDAR. It starts with BEGIN:COMPONENTNAME and
* ends with END:COMPONENTNAME
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_Component extends Sabre_VObject_Element {
class Component extends Element {
/**
* Name, for example VEVENT
@ -29,6 +29,11 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
*/
public $children = array();
/**
* The following constants are used by the validate() method.
*/
const REPAIR = 1;
/**
* If components are added to this map, they will be automatically mapped
* to their respective classes, if parsed by the reader or constructed with
@ -37,11 +42,12 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
* @var array
*/
static public $classMap = array(
'VCALENDAR' => 'Sabre_VObject_Component_VCalendar',
'VEVENT' => 'Sabre_VObject_Component_VEvent',
'VTODO' => 'Sabre_VObject_Component_VTodo',
'VJOURNAL' => 'Sabre_VObject_Component_VJournal',
'VALARM' => 'Sabre_VObject_Component_VAlarm',
'VALARM' => 'Sabre\\VObject\\Component\\VAlarm',
'VCALENDAR' => 'Sabre\\VObject\\Component\\VCalendar',
'VCARD' => 'Sabre\\VObject\\Component\\VCard',
'VEVENT' => 'Sabre\\VObject\\Component\\VEvent',
'VJOURNAL' => 'Sabre\\VObject\\Component\\VJournal',
'VTODO' => 'Sabre\\VObject\\Component\\VTodo',
);
/**
@ -50,7 +56,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
*
* @param string $name
* @param string $value
* @return Sabre_VObject_Component
* @return Component
*/
static public function create($name, $value = null) {
@ -71,9 +77,9 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
* be overridden with the iterator argument
*
* @param string $name
* @param Sabre_VObject_ElementList $iterator
* @param ElementList $iterator
*/
public function __construct($name, Sabre_VObject_ElementList $iterator = null) {
public function __construct($name, ElementList $iterator = null) {
$this->name = strtoupper($name);
if (!is_null($iterator)) $this->iterator = $iterator;
@ -100,12 +106,13 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
* preserve the original relative order of elements.
*
* @param int $key
* @param Sabre_VObject $array
* @param array $array
* @return int
*/
$sortScore = function($key, $array) {
if ($array[$key] instanceof Sabre_VObject_Component) {
if ($array[$key] instanceof Component) {
// We want to encode VTIMEZONE first, this is a personal
// preference.
if ($array[$key]->name === 'VTIMEZONE') {
@ -118,7 +125,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
} else {
// Properties get encoded first
// VCARD version 4.0 wants the VERSION property to appear first
if ($array[$key] instanceof Sabre_VObject_Property) {
if ($array[$key] instanceof Property) {
if ($array[$key]->name === 'VERSION') {
$score=100000000;
return $score+$key;
@ -129,7 +136,6 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
}
}
}
next($children);
};
@ -157,8 +163,8 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
*
* You can call this method with the following syntaxes:
*
* add(Sabre_VObject_Element $element)
* add(string $name, $value)
* add(Element $element)
* add(string $name, $value, array $parameters = array())
*
* The first version adds an Element
* The second adds a property as a string.
@ -167,26 +173,26 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
* @param mixed $itemValue
* @return void
*/
public function add($item, $itemValue = null) {
public function add($item, $itemValue = null, array $parameters = array()) {
if ($item instanceof Sabre_VObject_Element) {
if ($item instanceof Element) {
if (!is_null($itemValue)) {
throw new InvalidArgumentException('The second argument must not be specified, when passing a VObject');
throw new \InvalidArgumentException('The second argument must not be specified, when passing a VObject');
}
$item->parent = $this;
$this->children[] = $item;
} elseif(is_string($item)) {
if (!is_scalar($itemValue)) {
throw new InvalidArgumentException('The second argument must be scalar');
throw new \InvalidArgumentException('The second argument must be scalar');
}
$item = Sabre_VObject_Property::create($item,$itemValue);
$item = Property::create($item,$itemValue, $parameters);
$item->parent = $this;
$this->children[] = $item;
} else {
throw new InvalidArgumentException('The first argument must either be a Sabre_VObject_Element or a string');
throw new \InvalidArgumentException('The first argument must either be a \\Sabre\\VObject\\Element or a string');
}
@ -195,11 +201,11 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
/**
* Returns an iterable list of children
*
* @return Sabre_VObject_ElementList
* @return ElementList
*/
public function children() {
return new Sabre_VObject_ElementList($this->children);
return new ElementList($this->children);
}
@ -232,7 +238,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
if (
strtoupper($child->name) === $name &&
(is_null($group) || ( $child instanceof Sabre_VObject_Property && strtoupper($child->group) === $group))
(is_null($group) || ( $child instanceof Property && strtoupper($child->group) === $group))
) {
$result[$key] = $child;
@ -255,7 +261,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
$result = array();
foreach($this->children as $child) {
if ($child instanceof Sabre_VObject_Component) {
if ($child instanceof Component) {
$result[] = $child;
}
}
@ -266,6 +272,11 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
/**
* Validates the node for correctness.
*
* The following options are supported:
* - Component::REPAIR - If something is broken, and automatic repair may
* be attempted.
*
* An array is returned with warnings.
*
* Every item in the array has the following properties:
@ -273,9 +284,10 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
* * message - (human readable message)
* * node - (reference to the offending node)
*
* @param int $options
* @return array
*/
public function validate() {
public function validate($options = 0) {
$result = array();
foreach($this->children as $child) {
@ -294,7 +306,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
* null is returned.
*
* @param string $name
* @return Sabre_VObject_Property
* @return Property
*/
public function __get($name) {
@ -303,8 +315,8 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
return null;
} else {
$firstMatch = current($matches);
/** @var $firstMatch Sabre_VObject_Property */
$firstMatch->setIterator(new Sabre_VObject_ElementList(array_values($matches)));
/** @var $firstMatch Property */
$firstMatch->setIterator(new ElementList(array_values($matches)));
return $firstMatch;
}
@ -326,7 +338,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
/**
* Using the setter method you can add properties or subcomponents
*
* You can either pass a Sabre_VObject_Component, Sabre_VObject_Property
* You can either pass a Component, Property
* object, or a string to automatically create a Property.
*
* If the item already exists, it will be removed. If you want to add
@ -341,7 +353,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
$matches = $this->select($name);
$overWrite = count($matches)?key($matches):null;
if ($value instanceof Sabre_VObject_Component || $value instanceof Sabre_VObject_Property) {
if ($value instanceof Component || $value instanceof Property) {
$value->parent = $this;
if (!is_null($overWrite)) {
$this->children[$overWrite] = $value;
@ -349,7 +361,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
$this->children[] = $value;
}
} elseif (is_scalar($value)) {
$property = Sabre_VObject_Property::create($name,$value);
$property = Property::create($name,$value);
$property->parent = $this;
if (!is_null($overWrite)) {
$this->children[$overWrite] = $property;
@ -357,7 +369,7 @@ class Sabre_VObject_Component extends Sabre_VObject_Element {
$this->children[] = $property;
}
} else {
throw new InvalidArgumentException('You must pass a Sabre_VObject_Component, Sabre_VObject_Property or scalar type');
throw new \InvalidArgumentException('You must pass a \\Sabre\\VObject\\Component, \\Sabre\\VObject\\Property or scalar type');
}
}

View File

@ -1,17 +1,18 @@
<?php
namespace Sabre\VObject\Component;
use Sabre\VObject;
/**
* VAlarm component
*
* This component contains some additional functionality specific for VALARMs.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_Component_VAlarm extends Sabre_VObject_Component {
class VAlarm extends VObject\Component {
/**
* Returns a DateTime object when this alarm is going to trigger.
@ -24,7 +25,7 @@ class Sabre_VObject_Component_VAlarm extends Sabre_VObject_Component {
$trigger = $this->TRIGGER;
if(!isset($trigger['VALUE']) || strtoupper($trigger['VALUE']) === 'DURATION') {
$triggerDuration = Sabre_VObject_DateTimeParser::parseDuration($this->TRIGGER);
$triggerDuration = VObject\DateTimeParser::parseDuration($this->TRIGGER);
$related = (isset($trigger['RELATED']) && strtoupper($trigger['RELATED']) == 'END') ? 'END' : 'START';
$parentComponent = $this->parent;
@ -37,7 +38,7 @@ class Sabre_VObject_Component_VAlarm extends Sabre_VObject_Component {
} elseif ($parentComponent->name === 'VEVENT') {
$endProp = 'DTEND';
} else {
throw new Sabre_DAV_Exception('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT');
throw new \LogicException('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT');
}
if (isset($parentComponent->$endProp)) {
@ -45,7 +46,7 @@ class Sabre_VObject_Component_VAlarm extends Sabre_VObject_Component {
$effectiveTrigger->add($triggerDuration);
} elseif (isset($parentComponent->DURATION)) {
$effectiveTrigger = clone $parentComponent->DTSTART->getDateTime();
$duration = Sabre_VObject_DateTimeParser::parseDuration($parentComponent->DURATION);
$duration = VObject\DateTimeParser::parseDuration($parentComponent->DURATION);
$effectiveTrigger->add($duration);
$effectiveTrigger->add($triggerDuration);
} else {
@ -67,22 +68,22 @@ class Sabre_VObject_Component_VAlarm extends Sabre_VObject_Component {
* The rules used to determine if an event falls within the specified
* time-range is based on the CalDAV specification.
*
* @param DateTime $start
* @param DateTime $end
* @param \DateTime $start
* @param \DateTime $end
* @return bool
*/
public function isInTimeRange(DateTime $start, DateTime $end) {
public function isInTimeRange(\DateTime $start, \DateTime $end) {
$effectiveTrigger = $this->getEffectiveTriggerTime();
if (isset($this->DURATION)) {
$duration = Sabre_VObject_DateTimeParser::parseDuration($this->DURATION);
$duration = VObject\DateTimeParser::parseDuration($this->DURATION);
$repeat = (string)$this->repeat;
if (!$repeat) {
$repeat = 1;
}
$period = new DatePeriod($effectiveTrigger, $duration, (int)$repeat);
$period = new \DatePeriod($effectiveTrigger, $duration, (int)$repeat);
foreach($period as $occurrence) {

View File

@ -1,17 +1,19 @@
<?php
namespace Sabre\VObject\Component;
use Sabre\VObject;
/**
* The VCalendar component
*
* This component adds functionality to a component, specific for a VCALENDAR.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
class VCalendar extends VObject\Component {
/**
* Returns a list of all 'base components'. For instance, if an Event has
@ -28,7 +30,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
$components = array();
foreach($this->children as $component) {
if (!$component instanceof Sabre_VObject_Component)
if (!$component instanceof VObject\Component)
continue;
if (isset($component->{'RECURRENCE-ID'}))
@ -69,7 +71,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
* @param DateTime $end
* @return void
*/
public function expand(DateTime $start, DateTime $end) {
public function expand(\DateTime $start, \DateTime $end) {
$newEvents = array();
@ -91,10 +93,10 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
$uid = (string)$vevent->uid;
if (!$uid) {
throw new LogicException('Event did not have a UID!');
throw new \LogicException('Event did not have a UID!');
}
$it = new Sabre_VObject_RecurrenceIterator($this, $vevent->uid);
$it = new VObject\RecurrenceIterator($this, $vevent->uid);
$it->fastForward($start);
while($it->valid() && $it->getDTStart() < $end) {
@ -114,9 +116,9 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
foreach($newEvents as $newEvent) {
foreach($newEvent->children as $child) {
if ($child instanceof Sabre_VObject_Property_DateTime &&
$child->getDateType() == Sabre_VObject_Property_DateTime::LOCALTZ) {
$child->setDateTime($child->getDateTime(),Sabre_VObject_Property_DateTime::UTC);
if ($child instanceof VObject\Property\DateTime &&
$child->getDateType() == VObject\Property\DateTime::LOCALTZ) {
$child->setDateTime($child->getDateTime(),VObject\Property\DateTime::UTC);
}
}
@ -140,6 +142,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
*
* @return array
*/
/*
public function validate() {
$warnings = array();
@ -198,7 +201,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
);
$componentsFound = 0;
foreach($this->children as $child) {
if($child instanceof Sabre_VObject_Component) {
if($child instanceof Component) {
$componentsFound++;
if (!in_array($child->name, $allowedComponents)) {
$warnings[] = array(
@ -208,7 +211,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
);
}
}
if ($child instanceof Sabre_VObject_Property) {
if ($child instanceof Property) {
if (!in_array($child->name, $allowedProperties)) {
$warnings[] = array(
'level' => 2,
@ -233,6 +236,7 @@ class Sabre_VObject_Component_VCalendar extends Sabre_VObject_Component {
);
}
*/
}

View File

@ -0,0 +1,105 @@
<?php
namespace Sabre\VObject\Component;
use Sabre\VObject;
/**
* The VCard component
*
* This component represents the BEGIN:VCARD and END:VCARD found in every
* vcard.
*
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class VCard extends VObject\Component {
/**
* VCards with version 2.1, 3.0 and 4.0 are found.
*
* If the VCARD doesn't know its version, 4.0 is assumed.
*/
const DEFAULT_VERSION = '4.0';
/**
* Validates the node for correctness.
*
* The following options are supported:
* - Component::REPAIR - If something is broken, and automatic repair may
* be attempted.
*
* An array is returned with warnings.
*
* Every item in the array has the following properties:
* * level - (number between 1 and 3 with severity information)
* * message - (human readable message)
* * node - (reference to the offending node)
*
* @param int $options
* @return array
*/
public function validate($options = 0) {
$warnings = array();
$version = $this->select('VERSION');
if (count($version)!==1) {
$warnings[] = array(
'level' => 1,
'message' => 'The VERSION property must appear in the VCARD component exactly 1 time',
'node' => $this,
);
if ($options & self::REPAIR) {
$this->VERSION = self::DEFAULT_VERSION;
}
} else {
$version = (string)$this->VERSION;
if ($version!=='2.1' && $version!=='3.0' && $version!=='4.0') {
$warnings[] = array(
'level' => 1,
'message' => 'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.',
'node' => $this,
);
if ($options & self::REPAIR) {
$this->VERSION = '4.0';
}
}
}
$version = $this->select('FN');
if (count($version)!==1) {
$warnings[] = array(
'level' => 1,
'message' => 'The FN property must appear in the VCARD component exactly 1 time',
'node' => $this,
);
if (($options & self::REPAIR) && count($version) === 0) {
// We're going to try to see if we can use the contents of the
// N property.
if (isset($this->N)) {
$value = explode(';', (string)$this->N);
if (isset($value[1]) && $value[1]) {
$this->FN = $value[1] . ' ' . $value[0];
} else {
$this->FN = $value[0];
}
// Otherwise, the ORG property may work
} elseif (isset($this->ORG)) {
$this->FN = (string)$this->ORG;
}
}
}
return array_merge(
parent::validate($options),
$warnings
);
}
}

View File

@ -1,17 +1,18 @@
<?php
namespace Sabre\VObject\Component;
use Sabre\VObject;
/**
* VEvent component
*
* This component contains some additional functionality specific for VEVENT's.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_Component_VEvent extends Sabre_VObject_Component {
class VEvent extends VObject\Component {
/**
* Returns true or false depending on if the event falls in the specified
@ -20,14 +21,14 @@ class Sabre_VObject_Component_VEvent extends Sabre_VObject_Component {
* The rules used to determine if an event falls within the specified
* time-range is based on the CalDAV specification.
*
* @param DateTime $start
* @param DateTime $end
* @param \DateTime $start
* @param \DateTime $end
* @return bool
*/
public function isInTimeRange(DateTime $start, DateTime $end) {
public function isInTimeRange(\DateTime $start, \DateTime $end) {
if ($this->RRULE) {
$it = new Sabre_VObject_RecurrenceIterator($this);
$it = new VObject\RecurrenceIterator($this);
$it->fastForward($start);
// We fast-forwarded to a spot where the end-time of the
@ -42,18 +43,19 @@ class Sabre_VObject_Component_VEvent extends Sabre_VObject_Component {
$effectiveStart = $this->DTSTART->getDateTime();
if (isset($this->DTEND)) {
// The DTEND property is considered non inclusive. So for a 3 day
// event in july, dtstart and dtend would have to be July 1st and
// July 4th respectively.
//
// See:
// http://tools.ietf.org/html/rfc5545#page-54
$effectiveEnd = $this->DTEND->getDateTime();
// If this was an all-day event, we should just increase the
// end-date by 1. Otherwise the event will last until the second
// the date changed, by increasing this by 1 day the event lasts
// all of the last day as well.
if ($this->DTSTART->getDateType() == Sabre_VObject_Property_DateTime::DATE) {
$effectiveEnd->modify('+1 day');
}
} elseif (isset($this->DURATION)) {
$effectiveEnd = clone $effectiveStart;
$effectiveEnd->add( Sabre_VObject_DateTimeParser::parseDuration($this->DURATION) );
} elseif ($this->DTSTART->getDateType() == Sabre_VObject_Property_DateTime::DATE) {
$effectiveEnd->add( VObject\DateTimeParser::parseDuration($this->DURATION) );
} elseif ($this->DTSTART->getDateType() == VObject\Property\DateTime::DATE) {
$effectiveEnd = clone $effectiveStart;
$effectiveEnd->modify('+1 day');
} else {

View File

@ -1,17 +1,19 @@
<?php
namespace Sabre\VObject\Component;
use Sabre\VObject;
/**
* VJournal component
*
* This component contains some additional functionality specific for VJOURNALs.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_Component_VJournal extends Sabre_VObject_Component {
class VJournal extends VObject\Component {
/**
* Returns true or false depending on if the event falls in the specified
@ -24,12 +26,12 @@ class Sabre_VObject_Component_VJournal extends Sabre_VObject_Component {
* @param DateTime $end
* @return bool
*/
public function isInTimeRange(DateTime $start, DateTime $end) {
public function isInTimeRange(\DateTime $start, \DateTime $end) {
$dtstart = isset($this->DTSTART)?$this->DTSTART->getDateTime():null;
if ($dtstart) {
$effectiveEnd = clone $dtstart;
if ($this->DTSTART->getDateType() == Sabre_VObject_Property_DateTime::DATE) {
if ($this->DTSTART->getDateType() == VObject\Property\DateTime::DATE) {
$effectiveEnd->modify('+1 day');
}

View File

@ -1,17 +1,19 @@
<?php
namespace Sabre\VObject\Component;
use Sabre\VObject;
/**
* VTodo component
*
* This component contains some additional functionality specific for VTODOs.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_Component_VTodo extends Sabre_VObject_Component {
class VTodo extends VObject\Component {
/**
* Returns true or false depending on if the event falls in the specified
@ -24,10 +26,10 @@ class Sabre_VObject_Component_VTodo extends Sabre_VObject_Component {
* @param DateTime $end
* @return bool
*/
public function isInTimeRange(DateTime $start, DateTime $end) {
public function isInTimeRange(\DateTime $start, \DateTime $end) {
$dtstart = isset($this->DTSTART)?$this->DTSTART->getDateTime():null;
$duration = isset($this->DURATION)?Sabre_VObject_DateTimeParser::parseDuration($this->DURATION):null;
$duration = isset($this->DURATION)?VObject\DateTimeParser::parseDuration($this->DURATION):null;
$due = isset($this->DUE)?$this->DUE->getDateTime():null;
$completed = isset($this->COMPLETED)?$this->COMPLETED->getDateTime():null;
$created = isset($this->CREATED)?$this->CREATED->getDateTime():null;

View File

@ -1,18 +1,18 @@
<?php
namespace Sabre\VObject;
/**
* DateTimeParser
*
* This class is responsible for parsing the several different date and time
* formats iCalendar and vCards have.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_DateTimeParser {
class DateTimeParser {
/**
* Parses an iCalendar (rfc5545) formatted datetime and returns a DateTime object
@ -25,22 +25,22 @@ class Sabre_VObject_DateTimeParser {
* @param DateTimeZone $tz
* @return DateTime
*/
static public function parseDateTime($dt,DateTimeZone $tz = null) {
static public function parseDateTime($dt,\DateTimeZone $tz = null) {
// Format is YYYYMMDD + "T" + hhmmss
$result = preg_match('/^([1-3][0-9]{3})([0-1][0-9])([0-3][0-9])T([0-2][0-9])([0-5][0-9])([0-5][0-9])([Z]?)$/',$dt,$matches);
if (!$result) {
throw new Sabre_DAV_Exception_BadRequest('The supplied iCalendar datetime value is incorrect: ' . $dt);
throw new \LogicException('The supplied iCalendar datetime value is incorrect: ' . $dt);
}
if ($matches[7]==='Z' || is_null($tz)) {
$tz = new DateTimeZone('UTC');
$tz = new \DateTimeZone('UTC');
}
$date = new DateTime($matches[1] . '-' . $matches[2] . '-' . $matches[3] . ' ' . $matches[4] . ':' . $matches[5] .':' . $matches[6], $tz);
$date = new \DateTime($matches[1] . '-' . $matches[2] . '-' . $matches[3] . ' ' . $matches[4] . ':' . $matches[5] .':' . $matches[6], $tz);
// Still resetting the timezone, to normalize everything to UTC
$date->setTimeZone(new DateTimeZone('UTC'));
$date->setTimeZone(new \DateTimeZone('UTC'));
return $date;
}
@ -57,10 +57,10 @@ class Sabre_VObject_DateTimeParser {
$result = preg_match('/^([1-3][0-9]{3})([0-1][0-9])([0-3][0-9])$/',$date,$matches);
if (!$result) {
throw new Sabre_DAV_Exception_BadRequest('The supplied iCalendar date value is incorrect: ' . $date);
throw new \LogicException('The supplied iCalendar date value is incorrect: ' . $date);
}
$date = new DateTime($matches[1] . '-' . $matches[2] . '-' . $matches[3], new DateTimeZone('UTC'));
$date = new \DateTime($matches[1] . '-' . $matches[2] . '-' . $matches[3], new \DateTimeZone('UTC'));
return $date;
}
@ -79,7 +79,7 @@ class Sabre_VObject_DateTimeParser {
$result = preg_match('/^(?P<plusminus>\+|-)?P((?P<week>\d+)W)?((?P<day>\d+)D)?(T((?P<hour>\d+)H)?((?P<minute>\d+)M)?((?P<second>\d+)S)?)?$/', $duration, $matches);
if (!$result) {
throw new Sabre_DAV_Exception_BadRequest('The supplied iCalendar duration value is incorrect: ' . $duration);
throw new \LogicException('The supplied iCalendar duration value is incorrect: ' . $duration);
}
if (!$asString) {
@ -128,7 +128,7 @@ class Sabre_VObject_DateTimeParser {
if ($duration==='P') {
$duration = 'PT0S';
}
$iv = new DateInterval($duration);
$iv = new \DateInterval($duration);
if ($invert) $iv->invert = true;
return $iv;

View File

@ -1,15 +1,15 @@
<?php
namespace Sabre\VObject;
/**
* Base class for all elements
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_VObject_Element extends Sabre_VObject_Node {
abstract class Element extends Node {
public $parent = null;

View File

@ -1,18 +1,18 @@
<?php
namespace Sabre\VObject;
/**
* VObject ElementList
*
* This class represents a list of elements. Lists are the result of queries,
* such as doing $vcalendar->vevent where there's multiple VEVENT objects.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_ElementList implements Iterator, Countable, ArrayAccess {
class ElementList implements \Iterator, \Countable, \ArrayAccess {
/**
* Inner elements
@ -44,7 +44,7 @@ class Sabre_VObject_ElementList implements Iterator, Countable, ArrayAccess {
/**
* Returns current item in iteration
*
* @return Sabre_VObject_Element
* @return Element
*/
public function current() {
@ -149,7 +149,7 @@ class Sabre_VObject_ElementList implements Iterator, Countable, ArrayAccess {
*/
public function offsetSet($offset,$value) {
throw new LogicException('You can not add new objects to an ElementList');
throw new \LogicException('You can not add new objects to an ElementList');
}
@ -163,7 +163,7 @@ class Sabre_VObject_ElementList implements Iterator, Countable, ArrayAccess {
*/
public function offsetUnset($offset) {
throw new LogicException('You can not remove objects from an ElementList');
throw new \LogicException('You can not remove objects from an ElementList');
}

View File

@ -1,5 +1,7 @@
<?php
namespace Sabre\VObject;
/**
* This class helps with generating FREEBUSY reports based on existing sets of
* objects.
@ -10,13 +12,11 @@
* VFREEBUSY components are described in RFC5545, The rules for what should
* go in a single freebusy report is taken from RFC4791, section 7.10.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_FreeBusyGenerator {
class FreeBusyGenerator {
/**
* Input objects
@ -42,10 +42,33 @@ class Sabre_VObject_FreeBusyGenerator {
/**
* VCALENDAR object
*
* @var Sabre_VObject_Component
* @var Component
*/
protected $baseObject;
/**
* Creates the generator.
*
* Check the setTimeRange and setObjects methods for details about the
* arguments.
*
* @param DateTime $start
* @param DateTime $end
* @param mixed $objects
* @return void
*/
public function __construct(\DateTime $start = null, \DateTime $end = null, $objects = null) {
if ($start && $end) {
$this->setTimeRange($start, $end);
}
if ($objects) {
$this->setObjects($objects);
}
}
/**
* Sets the VCALENDAR object.
*
@ -54,10 +77,10 @@ class Sabre_VObject_FreeBusyGenerator {
*
* The VFREEBUSY object will be automatically added though.
*
* @param Sabre_VObject_Component $vcalendar
* @param Component $vcalendar
* @return void
*/
public function setBaseObject(Sabre_VObject_Component $vcalendar) {
public function setBaseObject(Component $vcalendar) {
$this->baseObject = $vcalendar;
@ -66,22 +89,28 @@ class Sabre_VObject_FreeBusyGenerator {
/**
* Sets the input objects
*
* Every object must either be a string or a Sabre_VObject_Component.
* You must either specify a valendar object as a strong, or as the parse
* Component.
* It's also possible to specify multiple objects as an array.
*
* @param array $objects
* @param mixed $objects
* @return void
*/
public function setObjects(array $objects) {
public function setObjects($objects) {
if (!is_array($objects)) {
$objects = array($objects);
}
$this->objects = array();
foreach($objects as $object) {
if (is_string($object)) {
$this->objects[] = Sabre_VObject_Reader::read($object);
} elseif ($object instanceof Sabre_VObject_Component) {
$this->objects[] = Reader::read($object);
} elseif ($object instanceof Component) {
$this->objects[] = $object;
} else {
throw new InvalidArgumentException('You can only pass strings or Sabre_VObject_Component arguments to setObjects');
throw new \InvalidArgumentException('You can only pass strings or \\Sabre\\VObject\\Component arguments to setObjects');
}
}
@ -97,7 +126,7 @@ class Sabre_VObject_FreeBusyGenerator {
* @param DateTime $end
* @return void
*/
public function setTimeRange(DateTime $start = null, DateTime $end = null) {
public function setTimeRange(\DateTime $start = null, \DateTime $end = null) {
$this->start = $start;
$this->end = $end;
@ -108,7 +137,7 @@ class Sabre_VObject_FreeBusyGenerator {
* Parses the input data and returns a correct VFREEBUSY object, wrapped in
* a VCALENDAR.
*
* @return Sabre_VObject_Component
* @return Component
*/
public function getResult() {
@ -140,7 +169,7 @@ class Sabre_VObject_FreeBusyGenerator {
if ($component->RRULE) {
$iterator = new Sabre_VObject_RecurrenceIterator($object, (string)$component->uid);
$iterator = new RecurrenceIterator($object, (string)$component->uid);
if ($this->start) {
$iterator->fastForward($this->start);
}
@ -172,10 +201,10 @@ class Sabre_VObject_FreeBusyGenerator {
if (isset($component->DTEND)) {
$endTime = $component->DTEND->getDateTime();
} elseif (isset($component->DURATION)) {
$duration = Sabre_VObject_DateTimeParser::parseDuration((string)$component->DURATION);
$duration = DateTimeParser::parseDuration((string)$component->DURATION);
$endTime = clone $startTime;
$endTime->add($duration);
} elseif ($component->DTSTART->getDateType() === Sabre_VObject_Property_DateTime::DATE) {
} elseif ($component->DTSTART->getDateType() === Property\DateTime::DATE) {
$endTime = clone $startTime;
$endTime->modify('+1 day');
} else {
@ -212,14 +241,14 @@ class Sabre_VObject_FreeBusyGenerator {
$values = explode(',', $freebusy);
foreach($values as $value) {
list($startTime, $endTime) = explode('/', $value);
$startTime = Sabre_VObject_DateTimeParser::parseDateTime($startTime);
$startTime = DateTimeParser::parseDateTime($startTime);
if (substr($endTime,0,1)==='P' || substr($endTime,0,2)==='-P') {
$duration = Sabre_VObject_DateTimeParser::parseDuration($endTime);
$duration = DateTimeParser::parseDuration($endTime);
$endTime = clone $startTime;
$endTime->add($duration);
} else {
$endTime = Sabre_VObject_DateTimeParser::parseDateTime($endTime);
$endTime = DateTimeParser::parseDateTime($endTime);
}
if($this->start && $this->start > $endTime) continue;
@ -248,39 +277,35 @@ class Sabre_VObject_FreeBusyGenerator {
if ($this->baseObject) {
$calendar = $this->baseObject;
} else {
$calendar = new Sabre_VObject_Component('VCALENDAR');
$calendar = new Component('VCALENDAR');
$calendar->version = '2.0';
if (Sabre_DAV_Server::$exposeVersion) {
$calendar->prodid = '-//SabreDAV//Sabre VObject ' . Sabre_VObject_Version::VERSION . '//EN';
} else {
$calendar->prodid = '-//SabreDAV//Sabre VObject//EN';
}
$calendar->prodid = '-//Sabre//Sabre VObject ' . Version::VERSION . '//EN';
$calendar->calscale = 'GREGORIAN';
}
$vfreebusy = new Sabre_VObject_Component('VFREEBUSY');
$vfreebusy = new Component('VFREEBUSY');
$calendar->add($vfreebusy);
if ($this->start) {
$dtstart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtstart->setDateTime($this->start,Sabre_VObject_Property_DateTime::UTC);
$dtstart = new Property\DateTime('DTSTART');
$dtstart->setDateTime($this->start,Property\DateTime::UTC);
$vfreebusy->add($dtstart);
}
if ($this->end) {
$dtend = new Sabre_VObject_Property_DateTime('DTEND');
$dtend->setDateTime($this->start,Sabre_VObject_Property_DateTime::UTC);
$dtend = new Property\DateTime('DTEND');
$dtend->setDateTime($this->start,Property\DateTime::UTC);
$vfreebusy->add($dtend);
}
$dtstamp = new Sabre_VObject_Property_DateTime('DTSTAMP');
$dtstamp->setDateTime(new DateTime('now'), Sabre_VObject_Property_DateTime::UTC);
$dtstamp = new Property\DateTime('DTSTAMP');
$dtstamp->setDateTime(new \DateTime('now'), Property\DateTime::UTC);
$vfreebusy->add($dtstamp);
foreach($busyTimes as $busyTime) {
$busyTime[0]->setTimeZone(new DateTimeZone('UTC'));
$busyTime[1]->setTimeZone(new DateTimeZone('UTC'));
$busyTime[0]->setTimeZone(new \DateTimeZone('UTC'));
$busyTime[1]->setTimeZone(new \DateTimeZone('UTC'));
$prop = new Sabre_VObject_Property(
$prop = new Property(
'FREEBUSY',
$busyTime[0]->format('Ymd\\THis\\Z') . '/' . $busyTime[1]->format('Ymd\\THis\\Z')
);

View File

@ -1,15 +1,15 @@
<?php
namespace Sabre\VObject;
/**
* Base class for all nodes
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
abstract class Sabre_VObject_Node implements IteratorAggregate, ArrayAccess, Countable {
abstract class Node implements \IteratorAggregate, \ArrayAccess, \Countable {
/**
* Turns the object back into a serialized blob.
@ -21,14 +21,14 @@ abstract class Sabre_VObject_Node implements IteratorAggregate, ArrayAccess, Cou
/**
* Iterator override
*
* @var Sabre_VObject_ElementList
* @var ElementList
*/
protected $iterator = null;
/**
* A link to the parent node
*
* @var Sabre_VObject_Node
* @var Node
*/
public $parent = null;
@ -54,14 +54,14 @@ abstract class Sabre_VObject_Node implements IteratorAggregate, ArrayAccess, Cou
/**
* Returns the iterator for this object
*
* @return Sabre_VObject_ElementList
* @return ElementList
*/
public function getIterator() {
if (!is_null($this->iterator))
return $this->iterator;
return new Sabre_VObject_ElementList(array($this));
return new ElementList(array($this));
}
@ -70,10 +70,10 @@ abstract class Sabre_VObject_Node implements IteratorAggregate, ArrayAccess, Cou
*
* Note that this is not actually part of the iterator interface
*
* @param Sabre_VObject_ElementList $iterator
* @param ElementList $iterator
* @return void
*/
public function setIterator(Sabre_VObject_ElementList $iterator) {
public function setIterator(ElementList $iterator) {
$this->iterator = $iterator;

View File

@ -1,5 +1,7 @@
<?php
namespace Sabre\VObject;
/**
* VObject Parameter
*
@ -8,13 +10,11 @@
* DTSTART;VALUE=DATE:20101108
* VALUE=DATE would be the parameter name and value.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_Parameter extends Sabre_VObject_Node {
class Parameter extends Node {
/**
* Parameter name

View File

@ -1,12 +1,12 @@
<?php
namespace Sabre\VObject;
/**
* Exception thrown by Sabre_VObject_Reader if an invalid object was attempted to be parsed.
* Exception thrown by Reader if an invalid object was attempted to be parsed.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_ParseException extends Exception { }
class ParseException extends \Exception { }

View File

@ -1,5 +1,7 @@
<?php
namespace Sabre\VObject;
/**
* VObject Property
*
@ -11,13 +13,11 @@
*
* Parameters can be accessed using the ArrayAccess interface.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_Property extends Sabre_VObject_Element {
class Property extends Element {
/**
* Propertyname
@ -57,27 +57,33 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
* @var array
*/
static public $classMap = array(
'COMPLETED' => 'Sabre_VObject_Property_DateTime',
'CREATED' => 'Sabre_VObject_Property_DateTime',
'DTEND' => 'Sabre_VObject_Property_DateTime',
'DTSTAMP' => 'Sabre_VObject_Property_DateTime',
'DTSTART' => 'Sabre_VObject_Property_DateTime',
'DUE' => 'Sabre_VObject_Property_DateTime',
'EXDATE' => 'Sabre_VObject_Property_MultiDateTime',
'LAST-MODIFIED' => 'Sabre_VObject_Property_DateTime',
'RECURRENCE-ID' => 'Sabre_VObject_Property_DateTime',
'TRIGGER' => 'Sabre_VObject_Property_DateTime',
'COMPLETED' => 'Sabre\\VObject\\Property\\DateTime',
'CREATED' => 'Sabre\\VObject\\Property\\DateTime',
'DTEND' => 'Sabre\\VObject\\Property\\DateTime',
'DTSTAMP' => 'Sabre\\VObject\\Property\\DateTime',
'DTSTART' => 'Sabre\\VObject\\Property\\DateTime',
'DUE' => 'Sabre\\VObject\\Property\\DateTime',
'EXDATE' => 'Sabre\\VObject\\Property\\MultiDateTime',
'LAST-MODIFIED' => 'Sabre\\VObject\\Property\\DateTime',
'RECURRENCE-ID' => 'Sabre\\VObject\\Property\\DateTime',
'TRIGGER' => 'Sabre\\VObject\\Property\\DateTime',
);
/**
* Creates the new property by name, but in addition will also see if
* there's a class mapped to the property name.
*
* Parameters can be specified with the optional third argument. Parameters
* must be a key->value map of the parameter name, and value. If the value
* is specified as an array, it is assumed that multiple parameters with
* the same name should be added.
*
* @param string $name
* @param string $value
* @return Sabre_VObject_Property
* @param array $parameters
* @return Property
*/
static public function create($name, $value = null) {
static public function create($name, $value = null, array $parameters = array()) {
$name = strtoupper($name);
$shortName = $name;
@ -87,9 +93,9 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
}
if (isset(self::$classMap[$shortName])) {
return new self::$classMap[$shortName]($name, $value);
return new self::$classMap[$shortName]($name, $value, $parameters);
} else {
return new self($name, $value);
return new self($name, $value, $parameters);
}
}
@ -97,14 +103,16 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
/**
* Creates a new property object
*
* By default this object will iterate over its own children, but this can
* be overridden with the iterator argument
* Parameters can be specified with the optional third argument. Parameters
* must be a key->value map of the parameter name, and value. If the value
* is specified as an array, it is assumed that multiple parameters with
* the same name should be added.
*
* @param string $name
* @param string $value
* @param Sabre_VObject_ElementList $iterator
* @param array $parameters
*/
public function __construct($name, $value = null, $iterator = null) {
public function __construct($name, $value = null, array $parameters = array()) {
$name = strtoupper($name);
$group = null;
@ -113,13 +121,22 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
}
$this->name = $name;
$this->group = $group;
if (!is_null($iterator)) $this->iterator = $iterator;
$this->setValue($value);
foreach($parameters as $paramName => $paramValues) {
if (!is_array($paramValues)) {
$paramValues = array($paramValues);
}
foreach($paramValues as $paramValue) {
$this->add($paramName, $paramValue);
}
}
}
/**
* Updates the internal value
*
@ -180,7 +197,7 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
*
* You can call this method with the following syntaxes:
*
* add(Sabre_VObject_Parameter $element)
* add(Parameter $element)
* add(string $name, $value)
*
* The first version adds an Parameter
@ -192,24 +209,24 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
*/
public function add($item, $itemValue = null) {
if ($item instanceof Sabre_VObject_Parameter) {
if ($item instanceof Parameter) {
if (!is_null($itemValue)) {
throw new InvalidArgumentException('The second argument must not be specified, when passing a VObject');
throw new \InvalidArgumentException('The second argument must not be specified, when passing a VObject');
}
$item->parent = $this;
$this->parameters[] = $item;
} elseif(is_string($item)) {
if (!is_scalar($itemValue) && !is_null($itemValue)) {
throw new InvalidArgumentException('The second argument must be scalar');
throw new \InvalidArgumentException('The second argument must be scalar');
}
$parameter = new Sabre_VObject_Parameter($item,$itemValue);
$parameter = new Parameter($item,$itemValue);
$parameter->parent = $this;
$this->parameters[] = $parameter;
} else {
throw new InvalidArgumentException('The first argument must either be a Sabre_VObject_Element or a string');
throw new \InvalidArgumentException('The first argument must either be a Element or a string');
}
@ -240,7 +257,7 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
* Returns a parameter, or parameter list.
*
* @param string $name
* @return Sabre_VObject_Element
* @return Element
*/
public function offsetGet($name) {
@ -258,7 +275,7 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
} elseif (count($result)===1) {
return $result[0];
} else {
$result[0]->setIterator(new Sabre_VObject_ElementList($result));
$result[0]->setIterator(new ElementList($result));
return $result[0];
}
@ -277,21 +294,21 @@ class Sabre_VObject_Property extends Sabre_VObject_Element {
if (is_scalar($value)) {
if (!is_string($name))
throw new InvalidArgumentException('A parameter name must be specified. This means you cannot use the $array[]="string" to add parameters.');
throw new \InvalidArgumentException('A parameter name must be specified. This means you cannot use the $array[]="string" to add parameters.');
$this->offsetUnset($name);
$parameter = new Sabre_VObject_Parameter($name, $value);
$parameter = new Parameter($name, $value);
$parameter->parent = $this;
$this->parameters[] = $parameter;
} elseif ($value instanceof Sabre_VObject_Parameter) {
} elseif ($value instanceof Parameter) {
if (!is_null($name))
throw new InvalidArgumentException('Don\'t specify a parameter name if you\'re passing a Sabre_VObject_Parameter. Add using $array[]=$parameterObject.');
throw new \InvalidArgumentException('Don\'t specify a parameter name if you\'re passing a \\Sabre\\VObject\\Parameter. Add using $array[]=$parameterObject.');
$value->parent = $this;
$this->parameters[] = $value;
} else {
throw new InvalidArgumentException('You can only add parameters to the property object');
throw new \InvalidArgumentException('You can only add parameters to the property object');
}
}

View File

@ -1,5 +1,9 @@
<?php
namespace Sabre\VObject\Property;
use Sabre\VObject;
/**
* DateTime property
*
@ -13,13 +17,11 @@
* If you use the 'value' or properties directly, this object does not keep
* reference and results might appear incorrectly.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
class DateTime extends VObject\Property {
/**
* Local 'floating' time
@ -44,7 +46,7 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
/**
* DateTime representation
*
* @var DateTime
* @var \DateTime
*/
protected $dateTime;
@ -58,11 +60,11 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
/**
* Updates the Date and Time.
*
* @param DateTime $dt
* @param \DateTime $dt
* @param int $dateType
* @return void
*/
public function setDateTime(DateTime $dt, $dateType = self::LOCALTZ) {
public function setDateTime(\DateTime $dt, $dateType = self::LOCALTZ) {
switch($dateType) {
@ -73,7 +75,7 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
$this->offsetSet('VALUE','DATE-TIME');
break;
case self::UTC :
$dt->setTimeZone(new DateTimeZone('UTC'));
$dt->setTimeZone(new \DateTimeZone('UTC'));
$this->setValue($dt->format('Ymd\\THis\\Z'));
$this->offsetUnset('VALUE');
$this->offsetUnset('TZID');
@ -93,7 +95,7 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
$this->offsetSet('VALUE','DATE');
break;
default :
throw new InvalidArgumentException('You must pass a valid dateType constant');
throw new \InvalidArgumentException('You must pass a valid dateType constant');
}
$this->dateTime = $dt;
@ -106,7 +108,7 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
*
* If no value was set, this method returns null.
*
* @return DateTime|null
* @return \DateTime|null
*/
public function getDateTime() {
@ -152,11 +154,11 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
*
* @param string|null $propertyValue The string to parse (yymmdd or
* ymmddThhmmss, etc..)
* @param Sabre_VObject_Property|null $property The instance of the
* @param \Sabre\VObject\Property|null $property The instance of the
* property we're parsing.
* @return array
*/
static public function parseData($propertyValue, Sabre_VObject_Property $property = null) {
static public function parseData($propertyValue, VObject\Property $property = null) {
if (is_null($propertyValue)) {
return array(null, null);
@ -167,14 +169,14 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
$regex = "/^$date(T$time(?P<isutc>Z)?)?$/";
if (!preg_match($regex, $propertyValue, $matches)) {
throw new InvalidArgumentException($propertyValue . ' is not a valid DateTime or Date string');
throw new \InvalidArgumentException($propertyValue . ' is not a valid \DateTime or Date string');
}
if (!isset($matches['hour'])) {
// Date-only
return array(
self::DATE,
new DateTime($matches['year'] . '-' . $matches['month'] . '-' . $matches['date'] . ' 00:00:00'),
new \DateTime($matches['year'] . '-' . $matches['month'] . '-' . $matches['date'] . ' 00:00:00', new \DateTimeZone('UTC')),
);
}
@ -187,8 +189,8 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
$matches['second'];
if (isset($matches['isutc'])) {
$dt = new DateTime($dateStr,new DateTimeZone('UTC'));
$dt->setTimeZone(new DateTimeZone('UTC'));
$dt = new \DateTime($dateStr,new \DateTimeZone('UTC'));
$dt->setTimeZone(new \DateTimeZone('UTC'));
return array(
self::UTC,
$dt
@ -198,9 +200,12 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
// Finding the timezone.
$tzid = $property['TZID'];
if (!$tzid) {
// This was a floating time string. This implies we use the
// timezone from date_default_timezone_set / date.timezone ini
// setting.
return array(
self::LOCAL,
new DateTime($dateStr)
new \DateTime($dateStr)
);
}
@ -210,12 +215,12 @@ class Sabre_VObject_Property_DateTime extends Sabre_VObject_Property {
$root = $root->parent;
}
if ($root->name === 'VCALENDAR') {
$tz = Sabre_VObject_TimeZoneUtil::getTimeZone((string)$tzid, $root);
$tz = VObject\TimeZoneUtil::getTimeZone((string)$tzid, $root);
} else {
$tz = Sabre_VObject_TimeZoneUtil::getTimeZone((string)$tzid);
$tz = VObject\TimeZoneUtil::getTimeZone((string)$tzid);
}
$dt = new DateTime($dateStr, $tz);
$dt = new \DateTime($dateStr, $tz);
$dt->setTimeZone($tz);
return array(

View File

@ -1,5 +1,9 @@
<?php
namespace Sabre\VObject\Property;
use Sabre\VObject;
/**
* Multi-DateTime property
*
@ -13,13 +17,11 @@
* If you use the 'value' or properties directly, this object does not keep
* reference and results might appear incorrectly.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
class MultiDateTime extends VObject\Property {
/**
* DateTime representation
@ -31,7 +33,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
/**
* dateType
*
* This is one of the Sabre_VObject_Property_DateTime constants.
* This is one of the Sabre\VObject\Property\DateTime constants.
*
* @var int
*/
@ -44,17 +46,17 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
* @param int $dateType
* @return void
*/
public function setDateTimes(array $dt, $dateType = Sabre_VObject_Property_DateTime::LOCALTZ) {
public function setDateTimes(array $dt, $dateType = VObject\Property\DateTime::LOCALTZ) {
foreach($dt as $i)
if (!$i instanceof DateTime)
throw new InvalidArgumentException('You must pass an array of DateTime objects');
if (!$i instanceof \DateTime)
throw new \InvalidArgumentException('You must pass an array of DateTime objects');
$this->offsetUnset('VALUE');
$this->offsetUnset('TZID');
switch($dateType) {
case Sabre_VObject_Property_DateTime::LOCAL :
case DateTime::LOCAL :
$val = array();
foreach($dt as $i) {
$val[] = $i->format('Ymd\\THis');
@ -62,16 +64,16 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
$this->setValue(implode(',',$val));
$this->offsetSet('VALUE','DATE-TIME');
break;
case Sabre_VObject_Property_DateTime::UTC :
case DateTime::UTC :
$val = array();
foreach($dt as $i) {
$i->setTimeZone(new DateTimeZone('UTC'));
$i->setTimeZone(new \DateTimeZone('UTC'));
$val[] = $i->format('Ymd\\THis\\Z');
}
$this->setValue(implode(',',$val));
$this->offsetSet('VALUE','DATE-TIME');
break;
case Sabre_VObject_Property_DateTime::LOCALTZ :
case DateTime::LOCALTZ :
$val = array();
foreach($dt as $i) {
$val[] = $i->format('Ymd\\THis');
@ -80,7 +82,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
$this->offsetSet('VALUE','DATE-TIME');
$this->offsetSet('TZID', $dt[0]->getTimeZone()->getName());
break;
case Sabre_VObject_Property_DateTime::DATE :
case DateTime::DATE :
$val = array();
foreach($dt as $i) {
$val[] = $i->format('Ymd');
@ -89,7 +91,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
$this->offsetSet('VALUE','DATE');
break;
default :
throw new InvalidArgumentException('You must pass a valid dateType constant');
throw new \InvalidArgumentException('You must pass a valid dateType constant');
}
$this->dateTimes = $dt;
@ -121,7 +123,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
list(
$type,
$dt
) = Sabre_VObject_Property_DateTime::parseData($val, $this);
) = DateTime::parseData($val, $this);
$dts[] = $dt;
$this->dateType = $type;
}
@ -154,7 +156,7 @@ class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
list(
$type,
$dt
) = Sabre_VObject_Property_DateTime::parseData($val, $this);
) = DateTime::parseData($val, $this);
$dts[] = $dt;
$this->dateType = $type;
}

View File

@ -1,5 +1,7 @@
<?php
namespace Sabre\VObject;
/**
* VCALENDAR/VCARD reader
*
@ -8,19 +10,17 @@
* TODO: this class currently completely works 'statically'. This is pointless,
* and defeats OOP principals. Needs refactoring in a future version.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_Reader {
class Reader {
/**
* Parses the file and returns the top component
*
* @param string $data
* @return Sabre_VObject_Element
* @return Element
*/
static function read($data) {
@ -59,7 +59,7 @@ class Sabre_VObject_Reader {
* to traverse.
*
* @param array $lines
* @return Sabre_VObject_Element
* @return Element
*/
static private function readLine(&$lines) {
@ -71,7 +71,7 @@ class Sabre_VObject_Reader {
if (stripos($line,"BEGIN:")===0) {
$componentName = strtoupper(substr($line,6));
$obj = Sabre_VObject_Component::create($componentName);
$obj = Component::create($componentName);
$nextLine = current($lines);
@ -82,13 +82,13 @@ class Sabre_VObject_Reader {
$nextLine = current($lines);
if ($nextLine===false)
throw new Sabre_VObject_ParseException('Invalid VObject. Document ended prematurely.');
throw new 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 . '"');
throw new ParseException('Invalid VObject, expected: "END:' . $obj->name . '" got: "' . $nextLine . '"');
}
next($lines);
@ -107,7 +107,7 @@ class Sabre_VObject_Reader {
$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');
throw new ParseException('Invalid VObject, line ' . ($lineNr+1) . ' did not follow the icalendar/vcard format');
}
$propertyName = strtoupper($matches['name']);
@ -119,7 +119,7 @@ class Sabre_VObject_Reader {
}
}, $matches['value']);
$obj = Sabre_VObject_Property::create($propertyName, $propertyValue);
$obj = Property::create($propertyName, $propertyValue);
if ($matches['parameters']) {
@ -137,7 +137,7 @@ class Sabre_VObject_Reader {
/**
* Reads a parameter list from a property
*
* This method returns an array of Sabre_VObject_Parameter
* This method returns an array of Parameter
*
* @param string $parameters
* @return array
@ -171,7 +171,7 @@ class Sabre_VObject_Reader {
}
}, $value);
$params[] = new Sabre_VObject_Parameter($match['paramName'], $value);
$params[] = new Parameter($match['paramName'], $value);
}

View File

@ -1,5 +1,7 @@
<?php
namespace Sabre\VObject;
/**
* This class is used to determine new for a recurring event, when the next
* events occur.
@ -37,13 +39,11 @@
* you may get unexpected results. The effect is that in some applications the
* specified recurrence may look incorrect, or is missing.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_RecurrenceIterator implements Iterator {
class RecurrenceIterator implements \Iterator {
/**
* The initial event date
@ -82,7 +82,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
/**
* Base event
*
* @var Sabre_VObject_Component_VEvent
* @var Component\VEvent
*/
public $baseEvent;
@ -97,7 +97,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
/**
* list of events that are 'overridden'.
*
* This is an array of Sabre_VObject_Component_VEvent objects.
* This is an array of Component\VEvent objects.
*
* @var array
*/
@ -281,7 +281,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
* If the current iteration of the event is an overriden event, this
* property will hold the VObject
*
* @var Sabre_VObject_Component
* @var Component
*/
private $currentOverriddenEvent;
@ -300,14 +300,14 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
* You should pass a VCALENDAR component, as well as the UID of the event
* we're going to traverse.
*
* @param Sabre_VObject_Component $vcal
* @param Component $vcal
* @param string|null $uid
*/
public function __construct(Sabre_VObject_Component $vcal, $uid=null) {
public function __construct(Component $vcal, $uid=null) {
if (is_null($uid)) {
if ($vcal->name === 'VCALENDAR') {
throw new InvalidArgumentException('If you pass a VCALENDAR object, you must pass a uid argument as well');
throw new \InvalidArgumentException('If you pass a VCALENDAR object, you must pass a uid argument as well');
}
$components = array($vcal);
$uid = (string)$vcal->uid;
@ -325,7 +325,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
}
}
if (!$this->baseEvent) {
throw new InvalidArgumentException('Could not find a base event with uid: ' . $uid);
throw new \InvalidArgumentException('Could not find a base event with uid: ' . $uid);
}
$this->startDate = clone $this->baseEvent->DTSTART->getDateTime();
@ -336,8 +336,8 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
} else {
$this->endDate = clone $this->startDate;
if (isset($this->baseEvent->DURATION)) {
$this->endDate->add(Sabre_VObject_DateTimeParser::parse($this->baseEvent->DURATION->value));
} elseif ($this->baseEvent->DTSTART->getDateType()===Sabre_VObject_Property_DateTime::DATE) {
$this->endDate->add(DateTimeParser::parse($this->baseEvent->DURATION->value));
} elseif ($this->baseEvent->DTSTART->getDateType()===Property\DateTime::DATE) {
$this->endDate->modify('+1 day');
}
}
@ -362,14 +362,14 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
strtolower($value),
array('secondly','minutely','hourly','daily','weekly','monthly','yearly')
)) {
throw new InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value));
throw new \InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value));
}
$this->frequency = strtolower($value);
break;
case 'UNTIL' :
$this->until = Sabre_VObject_DateTimeParser::parse($value);
$this->until = DateTimeParser::parse($value);
break;
case 'COUNT' :
@ -431,7 +431,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
foreach(explode(',', (string)$exDate) as $exceptionDate) {
$this->exceptionDates[] =
Sabre_VObject_DateTimeParser::parse($exceptionDate, $this->startDate->getTimeZone());
DateTimeParser::parse($exceptionDate, $this->startDate->getTimeZone());
}
@ -489,7 +489,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
*
* This method always returns a cloned instance.
*
* @return Sabre_VObject_Component_VEvent
* @return Component\VEvent
*/
public function getEventObject() {
@ -565,7 +565,7 @@ class Sabre_VObject_RecurrenceIterator implements Iterator {
* @param DateTime $dt
* @return void
*/
public function fastForward(DateTime $dt) {
public function fastForward(\DateTime $dt) {
while($this->valid() && $this->getDTEnd() <= $dt) {
$this->next();

View File

@ -1,18 +1,18 @@
<?php
namespace Sabre\VObject;
/**
* Time zone name translation
*
* This file translates well-known time zone names into "Olson database" time zone names.
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Frank Edelhaeuser (fedel@users.sourceforge.net)
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_TimeZoneUtil {
class TimeZoneUtil {
public static $map = array(
@ -297,20 +297,20 @@ class Sabre_VObject_TimeZoneUtil {
* If the lookup fails, this method will return UTC.
*
* @param string $tzid
* @param Sabre_VObject_Component $vcalendar
* @param Sabre\VObject\Component $vcalendar
* @return DateTimeZone
*/
static public function getTimeZone($tzid, Sabre_VObject_Component $vcalendar = null) {
static public function getTimeZone($tzid, Component $vcalendar = null) {
// First we will just see if the tzid is a support timezone identifier.
try {
return new DateTimeZone($tzid);
return new \DateTimeZone($tzid);
} catch (\Exception $e) {
}
// Next, we check if the tzid is somewhere in our tzid map.
if (isset(self::$map[$tzid])) {
return new DateTimeZone(self::$map[$tzid]);
return new \DateTimeZone(self::$map[$tzid]);
}
if ($vcalendar) {
@ -323,7 +323,7 @@ class Sabre_VObject_TimeZoneUtil {
// Some clients add 'X-LIC-LOCATION' with the olson name.
if (isset($vtimezone->{'X-LIC-LOCATION'})) {
try {
return new DateTimeZone($vtimezone->{'X-LIC-LOCATION'});
return new \DateTimeZone($vtimezone->{'X-LIC-LOCATION'});
} catch (\Exception $e) {
}
@ -332,7 +332,7 @@ class Sabre_VObject_TimeZoneUtil {
// answer for.
if (isset($vtimezone->{'X-MICROSOFT-CDO-TZID'})) {
if (isset(self::$microsoftExchangeMap[(int)$vtimezone->{'X-MICROSOFT-CDO-TZID'}->value])) {
return new DateTimeZone(self::$microsoftExchangeMap[(int)$vtimezone->{'X-MICROSOFT-CDO-TZID'}->value]);
return new \DateTimeZone(self::$microsoftExchangeMap[(int)$vtimezone->{'X-MICROSOFT-CDO-TZID'}->value]);
}
}
}
@ -342,7 +342,7 @@ class Sabre_VObject_TimeZoneUtil {
}
// If we got all the way here, we default to UTC.
return new DateTimeZone(date_default_timezone_get());
return new \DateTimeZone(date_default_timezone_get());
}

View File

@ -1,20 +1,20 @@
<?php
namespace Sabre\VObject;
/**
* This class contains the version number for the VObject package
*
* @package Sabre
* @subpackage VObject
* @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
class Sabre_VObject_Version {
class Version {
/**
* Full version number
*/
const VERSION = '1.3.4';
const VERSION = '2.0';
/**
* Stability : alpha, beta, stable

View File

@ -1,11 +1,16 @@
<?php
class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject\Component;
use Sabre\VObject\Component;
use DateTime;
class VAlarmTest extends \PHPUnit_Framework_TestCase {
/**
* @dataProvider timeRangeTestData
*/
public function testInTimeRange(Sabre_VObject_Component_VAlarm $valarm,$start,$end,$outcome) {
public function testInTimeRange(VAlarm $valarm,$start,$end,$outcome) {
$this->assertEquals($outcome, $valarm->isInTimeRange($start, $end));
@ -16,7 +21,7 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase {
$tests = array();
// Hard date and time
$valarm1 = Sabre_VObject_Component::create('VALARM');
$valarm1 = Component::create('VALARM');
$valarm1->TRIGGER = '20120312T130000Z';
$valarm1->TRIGGER['VALUE'] = 'DATE-TIME';
@ -24,11 +29,11 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase {
$tests[] = array($valarm1, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-03-10 01:00:00'), false);
// Relation to start time of event
$valarm2 = Sabre_VObject_Component::create('VALARM');
$valarm2 = Component::create('VALARM');
$valarm2->TRIGGER = '-P1D';
$valarm2->TRIGGER['VALUE'] = 'DURATION';
$vevent2 = Sabre_VObject_Component::create('VEVENT');
$vevent2 = Component::create('VEVENT');
$vevent2->DTSTART = '20120313T130000Z';
$vevent2->add($valarm2);
@ -36,12 +41,12 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase {
$tests[] = array($valarm2, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-03-10 01:00:00'), false);
// Relation to end time of event
$valarm3 = Sabre_VObject_Component::create('VALARM');
$valarm3 = Component::create('VALARM');
$valarm3->TRIGGER = '-P1D';
$valarm3->TRIGGER['VALUE'] = 'DURATION';
$valarm3->TRIGGER['RELATED']= 'END';
$vevent3 = Sabre_VObject_Component::create('VEVENT');
$vevent3 = Component::create('VEVENT');
$vevent3->DTSTART = '20120301T130000Z';
$vevent3->DTEND = '20120401T130000Z';
$vevent3->add($valarm3);
@ -50,12 +55,12 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase {
$tests[] = array($valarm3, new DateTime('2012-03-25 01:00:00'), new DateTime('2012-04-05 01:00:00'), true);
// Relation to end time of todo
$valarm4 = Sabre_VObject_Component::create('VALARM');
$valarm4 = Component::create('VALARM');
$valarm4->TRIGGER = '-P1D';
$valarm4->TRIGGER['VALUE'] = 'DURATION';
$valarm4->TRIGGER['RELATED']= 'END';
$vtodo4 = Sabre_VObject_Component::create('VTODO');
$vtodo4 = Component::create('VTODO');
$vtodo4->DTSTART = '20120301T130000Z';
$vtodo4->DUE = '20120401T130000Z';
$vtodo4->add($valarm4);
@ -64,25 +69,25 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase {
$tests[] = array($valarm4, new DateTime('2012-03-25 01:00:00'), new DateTime('2012-04-05 01:00:00'), true);
// Relation to start time of event + repeat
$valarm5 = Sabre_VObject_Component::create('VALARM');
$valarm5 = Component::create('VALARM');
$valarm5->TRIGGER = '-P1D';
$valarm5->TRIGGER['VALUE'] = 'DURATION';
$valarm5->REPEAT = 10;
$valarm5->DURATION = 'P1D';
$vevent5 = Sabre_VObject_Component::create('VEVENT');
$vevent5 = Component::create('VEVENT');
$vevent5->DTSTART = '20120301T130000Z';
$vevent5->add($valarm5);
$tests[] = array($valarm5, new DateTime('2012-03-09 01:00:00'), new DateTime('2012-03-10 01:00:00'), true);
// Relation to start time of event + duration, but no repeat
$valarm6 = Sabre_VObject_Component::create('VALARM');
$valarm6 = Component::create('VALARM');
$valarm6->TRIGGER = '-P1D';
$valarm6->TRIGGER['VALUE'] = 'DURATION';
$valarm6->DURATION = 'P1D';
$vevent6 = Sabre_VObject_Component::create('VEVENT');
$vevent6 = Component::create('VEVENT');
$vevent6->DTSTART = '20120313T130000Z';
$vevent6->add($valarm6);
@ -91,12 +96,12 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase {
// Relation to end time of event (DURATION instead of DTEND)
$valarm7 = Sabre_VObject_Component::create('VALARM');
$valarm7 = Component::create('VALARM');
$valarm7->TRIGGER = '-P1D';
$valarm7->TRIGGER['VALUE'] = 'DURATION';
$valarm7->TRIGGER['RELATED']= 'END';
$vevent7 = Sabre_VObject_Component::create('VEVENT');
$vevent7 = Component::create('VEVENT');
$vevent7->DTSTART = '20120301T130000Z';
$vevent7->DURATION = 'P30D';
$vevent7->add($valarm7);
@ -105,12 +110,12 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase {
$tests[] = array($valarm7, new DateTime('2012-03-25 01:00:00'), new DateTime('2012-04-05 01:00:00'), true);
// Relation to end time of event (No DTEND or DURATION)
$valarm7 = Sabre_VObject_Component::create('VALARM');
$valarm7 = Component::create('VALARM');
$valarm7->TRIGGER = '-P1D';
$valarm7->TRIGGER['VALUE'] = 'DURATION';
$valarm7->TRIGGER['RELATED']= 'END';
$vevent7 = Sabre_VObject_Component::create('VEVENT');
$vevent7 = Component::create('VEVENT');
$vevent7->DTSTART = '20120301T130000Z';
$vevent7->add($valarm7);
@ -122,15 +127,15 @@ class Sabre_VObject_Component_VAlarmTest extends PHPUnit_Framework_TestCase {
}
/**
* @expectedException Sabre_DAV_Exception
* @expectedException LogicException
*/
public function testInTimeRangeInvalidComponent() {
$valarm = Sabre_VObject_Component::create('VALARM');
$valarm = Component::create('VALARM');
$valarm->TRIGGER = '-P1D';
$valarm->TRIGGER['RELATED'] = 'END';
$vjournal = Sabre_VObject_Component::create('VJOURNAL');
$vjournal = Component::create('VJOURNAL');
$vjournal->add($valarm);
$valarm->isInTimeRange(new DateTime('2012-02-25 01:00:00'), new DateTime('2012-03-05 01:00:00'));

View File

@ -1,20 +1,24 @@
<?php
class Sabre_VObject_Component_VCalendarTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject\Component;
use Sabre\VObject;
class VCalendarTest extends \PHPUnit_Framework_TestCase {
/**
* @dataProvider expandData
*/
public function testExpand($input, $output) {
$vcal = Sabre_VObject_Reader::read($input);
$vcal = VObject\Reader::read($input);
$vcal->expand(
new DateTime('2011-12-01'),
new DateTime('2011-12-31')
new \DateTime('2011-12-01'),
new \DateTime('2011-12-31')
);
// This will normalize the output
$output = Sabre_VObject_Reader::read($output)->serialize();
$output = VObject\Reader::read($output)->serialize();
$this->assertEquals($output, $vcal->serialize());
@ -229,10 +233,10 @@ DTSTART;VALUE=DATE:20111202
END:VEVENT
END:VCALENDAR
';
$vcal = Sabre_VObject_Reader::read($input);
$vcal = VObject\Reader::read($input);
$vcal->expand(
new DateTime('2011-12-01'),
new DateTime('2011-12-31')
new \DateTime('2011-12-01'),
new \DateTime('2011-12-31')
);
}

View File

@ -0,0 +1,100 @@
<?php
namespace Sabre\VObject\Component;
use Sabre\VObject;
class VCardTest extends \PHPUnit_Framework_TestCase {
/**
* @dataProvider validateData
*/
function testValidate($input, $expectedWarnings, $expectedRepairedOutput) {
$vcard = VObject\Reader::read($input);
$warnings = $vcard->validate();
$warnMsg = array();
foreach($warnings as $warning) {
$warnMsg[] = $warning['message'];
}
$this->assertEquals($expectedWarnings, $warnMsg);
$vcard->validate(VObject\Component::REPAIR);
$this->assertEquals(
$expectedRepairedOutput,
$vcard->serialize()
);
}
public function validateData() {
$tests = array();
// Correct
$tests[] = array(
"BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nEND:VCARD\r\n",
array(),
"BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nEND:VCARD\r\n",
);
// No VERSION
$tests[] = array(
"BEGIN:VCARD\r\nFN:John Doe\r\nEND:VCARD\r\n",
array(
'The VERSION property must appear in the VCARD component exactly 1 time',
),
"BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nEND:VCARD\r\n",
);
// Unknown version
$tests[] = array(
"BEGIN:VCARD\r\nVERSION:2.2\r\nFN:John Doe\r\nEND:VCARD\r\n",
array(
'Only vcard version 4.0 (RFC6350), version 3.0 (RFC2426) or version 2.1 (icm-vcard-2.1) are supported.',
),
"BEGIN:VCARD\r\nVERSION:4.0\r\nFN:John Doe\r\nEND:VCARD\r\n",
);
// No FN
$tests[] = array(
"BEGIN:VCARD\r\nVERSION:4.0\r\nEND:VCARD\r\n",
array(
'The FN property must appear in the VCARD component exactly 1 time',
),
"BEGIN:VCARD\r\nVERSION:4.0\r\nEND:VCARD\r\n",
);
// No FN, N fallback
$tests[] = array(
"BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;John;;;;;\r\nEND:VCARD\r\n",
array(
'The FN property must appear in the VCARD component exactly 1 time',
),
"BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;John;;;;;\r\nFN:John Doe\r\nEND:VCARD\r\n",
);
// No FN, N fallback, no first name
$tests[] = array(
"BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;;;;;;\r\nEND:VCARD\r\n",
array(
'The FN property must appear in the VCARD component exactly 1 time',
),
"BEGIN:VCARD\r\nVERSION:4.0\r\nN:Doe;;;;;;\r\nFN:Doe\r\nEND:VCARD\r\n",
);
// No FN, ORG fallback
$tests[] = array(
"BEGIN:VCARD\r\nVERSION:4.0\r\nORG:Acme Co.\r\nEND:VCARD\r\n",
array(
'The FN property must appear in the VCARD component exactly 1 time',
),
"BEGIN:VCARD\r\nVERSION:4.0\r\nORG:Acme Co.\r\nFN:Acme Co.\r\nEND:VCARD\r\n",
);
return $tests;
}
}

View File

@ -0,0 +1,74 @@
<?php
namespace Sabre\VObject\Component;
use Sabre\VObject;
class VEventTest extends \PHPUnit_Framework_TestCase {
/**
* @dataProvider timeRangeTestData
*/
public function testInTimeRange(VEvent $vevent,$start,$end,$outcome) {
$this->assertEquals($outcome, $vevent->isInTimeRange($start, $end));
}
public function timeRangeTestData() {
$tests = array();
$vevent = new VEvent('VEVENT');
$vevent->DTSTART = '20111223T120000Z';
$tests[] = array($vevent, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vevent, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
$vevent2 = clone $vevent;
$vevent2->DTEND = '20111225T120000Z';
$tests[] = array($vevent2, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vevent2, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
$vevent3 = clone $vevent;
$vevent3->DURATION = 'P1D';
$tests[] = array($vevent3, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vevent3, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
$vevent4 = clone $vevent;
$vevent4->DTSTART = '20111225';
$vevent4->DTSTART['VALUE'] = 'DATE';
$tests[] = array($vevent4, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vevent4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
// Event with no end date should be treated as lasting the entire day.
$tests[] = array($vevent4, new \DateTime('2011-12-25 16:00:00'), new \DateTime('2011-12-25 17:00:00'), true);
$vevent5 = clone $vevent;
$vevent5->DURATION = 'P1D';
$vevent5->RRULE = 'FREQ=YEARLY';
$tests[] = array($vevent5, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vevent5, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
$tests[] = array($vevent5, new \DateTime('2013-12-01'), new \DateTime('2013-12-31'), true);
$vevent6 = clone $vevent;
$vevent6->DTSTART = '20111225';
$vevent6->DTSTART['VALUE'] = 'DATE';
$vevent6->DTEND = '20111225';
$vevent6->DTEND['VALUE'] = 'DATE';
$tests[] = array($vevent6, new \DateTime('2011-01-01'), new \DateTime('2012-01-01'), true);
$tests[] = array($vevent6, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false);
// Added this test to ensure that recurrence rules with no DTEND also
// get checked for the entire day.
$vevent7 = clone $vevent;
$vevent7->DTSTART = '20120101';
$vevent7->DTSTART['VALUE'] = 'DATE';
$vevent7->RRULE = 'FREQ=MONTHLY';
$tests[] = array($vevent7, new \DateTime('2012-02-01 15:00:00'), new \DateTime('2012-02-02'), true);
return $tests;
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace Sabre\VObject\Component;
use Sabre\VObject\Component;
class VJournalTest extends \PHPUnit_Framework_TestCase {
/**
* @dataProvider timeRangeTestData
*/
public function testInTimeRange(VJournal $vtodo,$start,$end,$outcome) {
$this->assertEquals($outcome, $vtodo->isInTimeRange($start, $end));
}
public function timeRangeTestData() {
$tests = array();
$vjournal = 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 = 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 = 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;
}
}

View File

@ -0,0 +1,67 @@
<?php
namespace Sabre\VObject\Component;
use Sabre\VObject\Component;
class VTodoTest extends \PHPUnit_Framework_TestCase {
/**
* @dataProvider timeRangeTestData
*/
public function testInTimeRange(VTodo $vtodo,$start,$end,$outcome) {
$this->assertEquals($outcome, $vtodo->isInTimeRange($start, $end));
}
public function timeRangeTestData() {
$tests = array();
$vtodo = 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 = 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 = 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 = 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 = 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 = 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;
}
}

View File

@ -1,22 +1,24 @@
<?php
class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject;
class ComponentTest extends \PHPUnit_Framework_TestCase {
function testIterate() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$sub = new Sabre_VObject_Component('VEVENT');
$sub = new Component('VEVENT');
$comp->children[] = $sub;
$sub = new Sabre_VObject_Component('VTODO');
$sub = new Component('VTODO');
$comp->children[] = $sub;
$count = 0;
foreach($comp->children() as $key=>$subcomponent) {
$count++;
$this->assertInstanceOf('Sabre_VObject_Component',$subcomponent);
$this->assertInstanceOf('Sabre\\VObject\\Component',$subcomponent);
}
$this->assertEquals(2,$count);
@ -26,16 +28,16 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
function testMagicGet() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$sub = new Sabre_VObject_Component('VEVENT');
$sub = new Component('VEVENT');
$comp->children[] = $sub;
$sub = new Sabre_VObject_Component('VTODO');
$sub = new Component('VTODO');
$comp->children[] = $sub;
$event = $comp->vevent;
$this->assertInstanceOf('Sabre_VObject_Component', $event);
$this->assertInstanceOf('Sabre\\VObject\\Component', $event);
$this->assertEquals('VEVENT', $event->name);
$this->assertInternalType('null', $comp->vjournal);
@ -44,15 +46,15 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
function testMagicGetGroups() {
$comp = new Sabre_VObject_Component('VCARD');
$comp = new Component('VCARD');
$sub = new Sabre_VObject_Property('GROUP1.EMAIL','1@1.com');
$sub = new Property('GROUP1.EMAIL','1@1.com');
$comp->children[] = $sub;
$sub = new Sabre_VObject_Property('GROUP2.EMAIL','2@2.com');
$sub = new Property('GROUP2.EMAIL','2@2.com');
$comp->children[] = $sub;
$sub = new Sabre_VObject_Property('EMAIL','3@3.com');
$sub = new Property('EMAIL','3@3.com');
$comp->children[] = $sub;
$emails = $comp->email;
@ -70,12 +72,12 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
function testMagicIsset() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$sub = new Sabre_VObject_Component('VEVENT');
$sub = new Component('VEVENT');
$comp->children[] = $sub;
$sub = new Sabre_VObject_Component('VTODO');
$sub = new Component('VTODO');
$comp->children[] = $sub;
$this->assertTrue(isset($comp->vevent));
@ -86,10 +88,10 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
function testMagicSetScalar() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$comp->myProp = 'myValue';
$this->assertInstanceOf('Sabre_VObject_Property',$comp->MYPROP);
$this->assertInstanceOf('Sabre\\VObject\\Property',$comp->MYPROP);
$this->assertEquals('myValue',$comp->MYPROP->value);
@ -97,22 +99,22 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
function testMagicSetScalarTwice() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$comp->myProp = 'myValue';
$comp->myProp = 'myValue';
$this->assertEquals(1,count($comp->children));
$this->assertInstanceOf('Sabre_VObject_Property',$comp->MYPROP);
$this->assertInstanceOf('Sabre\\VObject\\Property',$comp->MYPROP);
$this->assertEquals('myValue',$comp->MYPROP->value);
}
function testMagicSetComponent() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
// Note that 'myProp' is ignored here.
$comp->myProp = new Sabre_VObject_Component('VEVENT');
$comp->myProp = new Component('VEVENT');
$this->assertEquals(1, count($comp->children));
@ -122,10 +124,10 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
function testMagicSetTwice() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$comp->VEVENT = new Sabre_VObject_Component('VEVENT');
$comp->VEVENT = new Sabre_VObject_Component('VEVENT');
$comp->VEVENT = new Component('VEVENT');
$comp->VEVENT = new Component('VEVENT');
$this->assertEquals(1, count($comp->children));
@ -135,9 +137,9 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
function testArrayAccessGet() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$event = new Sabre_VObject_Component('VEVENT');
$event = new Component('VEVENT');
$event->summary = 'Event 1';
$comp->add($event);
@ -148,16 +150,16 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
$comp->add($event2);
$this->assertEquals(2,count($comp->children()));
$this->assertTrue($comp->vevent[1] instanceof Sabre_VObject_Component);
$this->assertTrue($comp->vevent[1] instanceof Component);
$this->assertEquals('Event 2', (string)$comp->vevent[1]->summary);
}
function testArrayAccessExists() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$event = new Sabre_VObject_Component('VEVENT');
$event = new Component('VEVENT');
$event->summary = 'Event 1';
$comp->add($event);
@ -177,7 +179,7 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
*/
function testArrayAccessSet() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$comp['hey'] = 'hi there';
}
@ -186,30 +188,51 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
*/
function testArrayAccessUnset() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
unset($comp[0]);
}
function testAddScalar() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$comp->add('myprop','value');
$this->assertEquals(1, count($comp->children));
$this->assertTrue($comp->children[0] instanceof Sabre_VObject_Property);
$this->assertTrue($comp->children[0] instanceof Property);
$this->assertEquals('MYPROP',$comp->children[0]->name);
$this->assertEquals('value',$comp->children[0]->value);
}
function testAddScalarParams() {
$comp = Component::create('VCALENDAR');
$comp->add('myprop','value',array('param1'=>'value1'));
$this->assertEquals(1, count($comp->children));
$this->assertTrue($comp->children[0] instanceof Property);
$this->assertEquals('MYPROP',$comp->children[0]->name);
$this->assertEquals('value',$comp->children[0]->value);
$this->assertEquals(1, count($comp->children[0]->parameters));
$this->assertTrue($comp->children[0]->parameters[0] instanceof Parameter);
$this->assertEquals('PARAM1',$comp->children[0]->parameters[0]->name);
$this->assertEquals('value1',$comp->children[0]->parameters[0]->value);
}
function testAddComponent() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$comp->add(new Sabre_VObject_Component('VEVENT'));
$comp->add(new Component('VEVENT'));
$this->assertEquals(1, count($comp->children));
@ -219,10 +242,10 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
function testAddComponentTwice() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$comp->add(new Sabre_VObject_Component('VEVENT'));
$comp->add(new Sabre_VObject_Component('VEVENT'));
$comp->add(new Component('VEVENT'));
$comp->add(new Component('VEVENT'));
$this->assertEquals(2, count($comp->children));
@ -235,8 +258,8 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
*/
function testAddArgFail() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp->add(new Sabre_VObject_Component('VEVENT'),'hello');
$comp = new Component('VCALENDAR');
$comp->add(new Component('VEVENT'),'hello');
}
@ -245,7 +268,7 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
*/
function testAddArgFail2() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$comp->add(array());
}
@ -255,7 +278,7 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
*/
function testAddArgFail3() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$comp->add('hello',array());
}
@ -265,10 +288,10 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
*/
function testMagicSetInvalid() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
// Note that 'myProp' is ignored here.
$comp->myProp = new StdClass();
$comp->myProp = new \StdClass();
$this->assertEquals(1, count($comp->children));
@ -278,8 +301,8 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
function testMagicUnset() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp->add(new Sabre_VObject_Component('VEVENT'));
$comp = new Component('VCALENDAR');
$comp->add(new Component('VEVENT'));
unset($comp->vevent);
@ -290,34 +313,34 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
function testCount() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$this->assertEquals(1,$comp->count());
}
function testChildren() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
// Note that 'myProp' is ignored here.
$comp->children = array(
new Sabre_VObject_Component('VEVENT'),
new Sabre_VObject_Component('VTODO')
new Component('VEVENT'),
new Component('VTODO')
);
$r = $comp->children();
$this->assertTrue($r instanceof Sabre_VObject_ElementList);
$this->assertTrue($r instanceof ElementList);
$this->assertEquals(2,count($r));
}
function testGetComponents() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
// Note that 'myProp' is ignored here.
$comp->children = array(
new Sabre_VObject_Property('FOO','BAR'),
new Sabre_VObject_Component('VTODO')
new Property('FOO','BAR'),
new Component('VTODO')
);
$r = $comp->getComponents();
@ -328,17 +351,17 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
function testSerialize() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$this->assertEquals("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n", $comp->serialize());
}
function testSerializeChildren() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp = new Component('VCALENDAR');
$comp->children = array(
new Sabre_VObject_Component('VEVENT'),
new Sabre_VObject_Component('VTODO')
new Component('VEVENT'),
new Component('VTODO')
);
$str = $comp->serialize();
@ -349,11 +372,11 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
function testSerializeOrderCompAndProp() {
$comp = new Sabre_VObject_Component('VCALENDAR');
$comp->add(new Sabre_VObject_Component('VEVENT'));
$comp = new Component('VCALENDAR');
$comp->add(new Component('VEVENT'));
$comp->add('PROP1','BLABLA');
$comp->add('VERSION','2.0');
$comp->add(new Sabre_VObject_Component('VTIMEZONE'));
$comp->add(new Component('VTIMEZONE'));
$str = $comp->serialize();
@ -365,7 +388,7 @@ class Sabre_VObject_ComponentTest extends PHPUnit_Framework_TestCase {
$prop4s=array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10');
$comp = new Sabre_VObject_Component('VCARD');
$comp = new Component('VCARD');
$comp->__set('SOMEPROP','FOO');
$comp->__set('ANOTHERPROP','FOO');
$comp->__set('THIRDPROP','FOO');

View File

@ -0,0 +1,121 @@
<?php
namespace Sabre\VObject;
use DateTime;
use DateTimeZone;
use DateInterval;
class DateTimeParserTest extends \PHPUnit_Framework_TestCase {
function testParseICalendarDuration() {
$this->assertEquals('+1 weeks', DateTimeParser::parseDuration('P1W',true));
$this->assertEquals('+5 days', DateTimeParser::parseDuration('P5D',true));
$this->assertEquals('+5 days 3 hours 50 minutes 12 seconds', DateTimeParser::parseDuration('P5DT3H50M12S',true));
$this->assertEquals('-1 weeks 50 minutes', DateTimeParser::parseDuration('-P1WT50M',true));
$this->assertEquals('+50 days 3 hours 2 seconds', DateTimeParser::parseDuration('+P50DT3H2S',true));
$this->assertEquals(new DateInterval('PT0S'), DateTimeParser::parseDuration('PT0S'));
}
function testParseICalendarDurationDateInterval() {
$expected = new DateInterval('P7D');
$this->assertEquals($expected, DateTimeParser::parseDuration('P1W'));
$this->assertEquals($expected, DateTimeParser::parse('P1W'));
$expected = new DateInterval('PT3M');
$expected->invert = true;
$this->assertEquals($expected, DateTimeParser::parseDuration('-PT3M'));
}
/**
* @expectedException LogicException
*/
function testParseICalendarDurationFail() {
DateTimeParser::parseDuration('P1X',true);
}
function testParseICalendarDateTime() {
$dateTime = DateTimeParser::parseDateTime('20100316T141405');
$compare = new DateTime('2010-03-16 14:14:05',new DateTimeZone('UTC'));
$this->assertEquals($compare, $dateTime);
}
/**
* @depends testParseICalendarDateTime
* @expectedException LogicException
*/
function testParseICalendarDateTimeBadFormat() {
$dateTime = DateTimeParser::parseDateTime('20100316T141405 ');
}
/**
* @depends testParseICalendarDateTime
*/
function testParseICalendarDateTimeUTC() {
$dateTime = DateTimeParser::parseDateTime('20100316T141405Z');
$compare = new DateTime('2010-03-16 14:14:05',new DateTimeZone('UTC'));
$this->assertEquals($compare, $dateTime);
}
/**
* @depends testParseICalendarDateTime
*/
function testParseICalendarDateTimeUTC2() {
$dateTime = DateTimeParser::parseDateTime('20101211T160000Z');
$compare = new DateTime('2010-12-11 16:00:00',new DateTimeZone('UTC'));
$this->assertEquals($compare, $dateTime);
}
/**
* @depends testParseICalendarDateTime
*/
function testParseICalendarDateTimeCustomTimeZone() {
$dateTime = DateTimeParser::parseDateTime('20100316T141405', new DateTimeZone('Europe/Amsterdam'));
$compare = new DateTime('2010-03-16 13:14:05',new DateTimeZone('UTC'));
$this->assertEquals($compare, $dateTime);
}
function testParseICalendarDate() {
$dateTime = DateTimeParser::parseDate('20100316');
$expected = new DateTime('2010-03-16 00:00:00',new DateTimeZone('UTC'));
$this->assertEquals($expected, $dateTime);
$dateTime = DateTimeParser::parse('20100316');
$this->assertEquals($expected, $dateTime);
}
/**
* @depends testParseICalendarDate
* @expectedException LogicException
*/
function testParseICalendarDateBadFormat() {
$dateTime = DateTimeParser::parseDate('20100316T141405');
}
}

View File

@ -1,10 +1,12 @@
<?php
class Sabre_VObject_ElementListTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject;
class ElementListTest extends \PHPUnit_Framework_TestCase {
function testIterate() {
$sub = new Sabre_VObject_Component('VEVENT');
$sub = new Component('VEVENT');
$elems = array(
$sub,
@ -12,13 +14,13 @@ class Sabre_VObject_ElementListTest extends PHPUnit_Framework_TestCase {
clone $sub
);
$elemList = new Sabre_VObject_ElementList($elems);
$elemList = new ElementList($elems);
$count = 0;
foreach($elemList as $key=>$subcomponent) {
$count++;
$this->assertInstanceOf('Sabre_VObject_Component',$subcomponent);
$this->assertInstanceOf('Sabre\\VObject\\Component',$subcomponent);
}
$this->assertEquals(3,$count);

View File

@ -1,6 +1,8 @@
<?php
class Sabre_VObject_EmClientTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject;
class EmClientTest extends \PHPUnit_Framework_TestCase {
function testParseTz() {
@ -43,9 +45,9 @@ CLASS:PUBLIC
END:VEVENT
END:VCALENDAR';
$vObject = Sabre_VObject_Reader::read($str);
$vObject = Reader::read($str);
$dt = $vObject->VEVENT->DTSTART->getDateTime();
$this->assertEquals(new DateTime('2011-10-08 19:30:00', new DateTimeZone('America/Chicago')), $dt);
$this->assertEquals(new \DateTime('2011-10-08 19:30:00', new \DateTimeZone('America/Chicago')), $dt);
}

View File

@ -1,6 +1,8 @@
<?php
class Sabre_VObject_FreeBusyGeneratorTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject;
class FreeBusyGeneratorTest extends \PHPUnit_Framework_TestCase {
function getInput() {
@ -163,7 +165,7 @@ ICS;
$blob8,
$blob9,
$blob10,
Sabre_VObject_Reader::read($blob11),
Reader::read($blob11),
$blob12,
$blob13,
$blob14,
@ -173,11 +175,10 @@ ICS;
function testGenerator() {
$gen = new Sabre_VObject_FreeBusyGenerator();
$gen->setObjects($this->getInput());
$gen->setTimeRange(
new DateTime('20110101T110000Z'),
new DateTime('20110103T110000Z')
$gen = new FreeBusyGenerator(
new \DateTime('20110101T110000Z', new \DateTimeZone('UTC')),
new \DateTime('20110103T110000Z', new \DateTimeZone('UTC')),
$this->getInput()
);
$result = $gen->getResult();
@ -216,10 +217,10 @@ ICS;
function testGeneratorBaseObject() {
$obj = new Sabre_VObject_Component('VCALENDAR');
$obj = new Component('VCALENDAR');
$obj->METHOD = 'PUBLISH';
$gen = new Sabre_VObject_FreeBusyGenerator();
$gen = new FreeBusyGenerator();
$gen->setObjects(array());
$gen->setBaseObject($obj);
@ -227,20 +228,6 @@ ICS;
$this->assertEquals('PUBLISH', $result->METHOD->value);
}
function testGeneratorNoVersion() {
$v = Sabre_DAV_Server::$exposeVersion;
Sabre_DAV_Server::$exposeVersion = false;
$gen = new Sabre_VObject_FreeBusyGenerator();
$gen->setObjects(array());
$result = $gen->getResult();
Sabre_DAV_Server::$exposeVersion = $v;
$this->assertFalse(strpos($result->PRODID->value, Sabre_VObject_Version::VERSION));
}
/**
@ -248,8 +235,11 @@ ICS;
*/
function testInvalidArg() {
$gen = new Sabre_VObject_FreeBusyGenerator();
$gen->setObjects(array(new StdClass()));
$gen = new FreeBusyGenerator(
new \DateTime('2012-01-01'),
new \DateTime('2012-12-31'),
new \StdClass()
);
}

View File

@ -0,0 +1,14 @@
<?php
namespace Sabre\VObject;
class Issue153Test extends \PHPUnit_Framework_TestCase {
function testRead() {
$obj = Reader::read(file_get_contents(dirname(__FILE__) . '/issue153.vcf'));
$this->assertEquals('Test Benutzer', (string)$obj->fn);
}
}

View File

@ -1,10 +1,12 @@
<?php
class Sabre_VObject_Issue154Test extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject;
class Issue154Test extends \PHPUnit_Framework_TestCase {
function testStuff() {
$vcard = new Sabre_VObject_Component('VCARD');
$vcard = new Component('VCARD');
$vcard->VERSION = '3.0';
$vcard->PHOTO = base64_encode('random_stuff');
$vcard->PHOTO->add('BASE64',null);

View File

@ -1,10 +1,12 @@
<?php
class Sabre_VObject_ParameterTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject;
class ParameterTest extends \PHPUnit_Framework_TestCase {
function testSetup() {
$param = new Sabre_VObject_Parameter('name','value');
$param = new Parameter('name','value');
$this->assertEquals('NAME',$param->name);
$this->assertEquals('value',$param->value);
@ -12,7 +14,7 @@ class Sabre_VObject_ParameterTest extends PHPUnit_Framework_TestCase {
function testCastToString() {
$param = new Sabre_VObject_Parameter('name','value');
$param = new Parameter('name','value');
$this->assertEquals('value',$param->__toString());
$this->assertEquals('value',(string)$param);

View File

@ -1,14 +1,17 @@
<?php
class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject\Property;
use Sabre\VObject\Component;
class DateTimeTest extends \PHPUnit_Framework_TestCase {
function testSetDateTime() {
$tz = new DateTimeZone('Europe/Amsterdam');
$dt = new DateTime('1985-07-04 01:30:00', $tz);
$tz = new \DateTimeZone('Europe/Amsterdam');
$dt = new \DateTime('1985-07-04 01:30:00', $tz);
$dt->setTimeZone($tz);
$elem = new Sabre_VObject_Property_DateTime('DTSTART');
$elem = new DateTime('DTSTART');
$elem->setDateTime($dt);
$this->assertEquals('19850704T013000', $elem->value);
@ -19,12 +22,12 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase {
function testSetDateTimeLOCAL() {
$tz = new DateTimeZone('Europe/Amsterdam');
$dt = new DateTime('1985-07-04 01:30:00', $tz);
$tz = new \DateTimeZone('Europe/Amsterdam');
$dt = new \DateTime('1985-07-04 01:30:00', $tz);
$dt->setTimeZone($tz);
$elem = new Sabre_VObject_Property_DateTime('DTSTART');
$elem->setDateTime($dt, Sabre_VObject_Property_DateTime::LOCAL);
$elem = new DateTime('DTSTART');
$elem->setDateTime($dt, DateTime::LOCAL);
$this->assertEquals('19850704T013000', $elem->value);
$this->assertNull($elem['TZID']);
@ -34,12 +37,12 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase {
function testSetDateTimeUTC() {
$tz = new DateTimeZone('GMT');
$dt = new DateTime('1985-07-04 01:30:00', $tz);
$tz = new \DateTimeZone('GMT');
$dt = new \DateTime('1985-07-04 01:30:00', $tz);
$dt->setTimeZone($tz);
$elem = new Sabre_VObject_Property_DateTime('DTSTART');
$elem->setDateTime($dt, Sabre_VObject_Property_DateTime::UTC);
$elem = new DateTime('DTSTART');
$elem->setDateTime($dt, DateTime::UTC);
$this->assertEquals('19850704T013000Z', $elem->value);
$this->assertNull($elem['TZID']);
@ -49,12 +52,12 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase {
function testSetDateTimeLOCALTZ() {
$tz = new DateTimeZone('Europe/Amsterdam');
$dt = new DateTime('1985-07-04 01:30:00', $tz);
$tz = new \DateTimeZone('Europe/Amsterdam');
$dt = new \DateTime('1985-07-04 01:30:00', $tz);
$dt->setTimeZone($tz);
$elem = new Sabre_VObject_Property_DateTime('DTSTART');
$elem->setDateTime($dt, Sabre_VObject_Property_DateTime::LOCALTZ);
$elem = new DateTime('DTSTART');
$elem->setDateTime($dt, DateTime::LOCALTZ);
$this->assertEquals('19850704T013000', $elem->value);
$this->assertEquals('Europe/Amsterdam', (string)$elem['TZID']);
@ -64,12 +67,12 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase {
function testSetDateTimeDATE() {
$tz = new DateTimeZone('Europe/Amsterdam');
$dt = new DateTime('1985-07-04 01:30:00', $tz);
$tz = new \DateTimeZone('Europe/Amsterdam');
$dt = new \DateTime('1985-07-04 01:30:00', $tz);
$dt->setTimeZone($tz);
$elem = new Sabre_VObject_Property_DateTime('DTSTART');
$elem->setDateTime($dt, Sabre_VObject_Property_DateTime::DATE);
$elem = new DateTime('DTSTART');
$elem->setDateTime($dt, DateTime::DATE);
$this->assertEquals('19850704', $elem->value);
$this->assertNull($elem['TZID']);
@ -82,22 +85,22 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase {
*/
function testSetDateTimeInvalid() {
$tz = new DateTimeZone('Europe/Amsterdam');
$dt = new DateTime('1985-07-04 01:30:00', $tz);
$tz = new \DateTimeZone('Europe/Amsterdam');
$dt = new \DateTime('1985-07-04 01:30:00', $tz);
$dt->setTimeZone($tz);
$elem = new Sabre_VObject_Property_DateTime('DTSTART');
$elem = new DateTime('DTSTART');
$elem->setDateTime($dt, 7);
}
function testGetDateTimeCached() {
$tz = new DateTimeZone('Europe/Amsterdam');
$dt = new DateTime('1985-07-04 01:30:00', $tz);
$tz = new \DateTimeZone('Europe/Amsterdam');
$dt = new \DateTime('1985-07-04 01:30:00', $tz);
$dt->setTimeZone($tz);
$elem = new Sabre_VObject_Property_DateTime('DTSTART');
$elem = new DateTime('DTSTART');
$elem->setDateTime($dt);
$this->assertEquals($elem->getDateTime(), $dt);
@ -106,7 +109,7 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase {
function testGetDateTimeDateNULL() {
$elem = new Sabre_VObject_Property_DateTime('DTSTART');
$elem = new DateTime('DTSTART');
$dt = $elem->getDateTime();
$this->assertNull($dt);
@ -116,42 +119,42 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase {
function testGetDateTimeDateDATE() {
$elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704');
$elem = new DateTime('DTSTART','19850704');
$dt = $elem->getDateTime();
$this->assertInstanceOf('DateTime', $dt);
$this->assertEquals('1985-07-04 00:00:00', $dt->format('Y-m-d H:i:s'));
$this->assertEquals(Sabre_VObject_Property_DateTime::DATE, $elem->getDateType());
$this->assertEquals(DateTime::DATE, $elem->getDateType());
}
function testGetDateTimeDateLOCAL() {
$elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000');
$elem = new DateTime('DTSTART','19850704T013000');
$dt = $elem->getDateTime();
$this->assertInstanceOf('DateTime', $dt);
$this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s'));
$this->assertEquals(Sabre_VObject_Property_DateTime::LOCAL, $elem->getDateType());
$this->assertEquals(DateTime::LOCAL, $elem->getDateType());
}
function testGetDateTimeDateUTC() {
$elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000Z');
$elem = new DateTime('DTSTART','19850704T013000Z');
$dt = $elem->getDateTime();
$this->assertInstanceOf('DateTime', $dt);
$this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s'));
$this->assertEquals('UTC', $dt->getTimeZone()->getName());
$this->assertEquals(Sabre_VObject_Property_DateTime::UTC, $elem->getDateType());
$this->assertEquals(DateTime::UTC, $elem->getDateType());
}
function testGetDateTimeDateLOCALTZ() {
$elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000');
$elem = new DateTime('DTSTART','19850704T013000');
$elem['TZID'] = 'Europe/Amsterdam';
$dt = $elem->getDateTime();
@ -159,7 +162,7 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase {
$this->assertInstanceOf('DateTime', $dt);
$this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s'));
$this->assertEquals('Europe/Amsterdam', $dt->getTimeZone()->getName());
$this->assertEquals(Sabre_VObject_Property_DateTime::LOCALTZ, $elem->getDateType());
$this->assertEquals(DateTime::LOCALTZ, $elem->getDateType());
}
@ -168,25 +171,25 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase {
*/
function testGetDateTimeDateInvalid() {
$elem = new Sabre_VObject_Property_DateTime('DTSTART','bla');
$elem = new DateTime('DTSTART','bla');
$dt = $elem->getDateTime();
}
function testGetDateTimeWeirdTZ() {
$elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000');
$elem = new DateTime('DTSTART','19850704T013000');
$elem['TZID'] = '/freeassociation.sourceforge.net/Tzfile/Europe/Amsterdam';
$event = new Sabre_VObject_Component('VEVENT');
$event = new Component('VEVENT');
$event->add($elem);
$timezone = new Sabre_VObject_Component('VTIMEZONE');
$timezone = new Component('VTIMEZONE');
$timezone->TZID = '/freeassociation.sourceforge.net/Tzfile/Europe/Amsterdam';
$timezone->{'X-LIC-LOCATION'} = 'Europe/Amsterdam';
$calendar = new Sabre_VObject_Component('VCALENDAR');
$calendar = new Component('VCALENDAR');
$calendar->add($event);
$calendar->add($timezone);
@ -195,7 +198,7 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase {
$this->assertInstanceOf('DateTime', $dt);
$this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s'));
$this->assertEquals('Europe/Amsterdam', $dt->getTimeZone()->getName());
$this->assertEquals(Sabre_VObject_Property_DateTime::LOCALTZ, $elem->getDateType());
$this->assertEquals(DateTime::LOCALTZ, $elem->getDateType());
}
@ -204,18 +207,18 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase {
$default = date_default_timezone_get();
date_default_timezone_set('Canada/Eastern');
$elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000');
$elem = new DateTime('DTSTART','19850704T013000');
$elem['TZID'] = 'Moon';
$event = new Sabre_VObject_Component('VEVENT');
$event = new Component('VEVENT');
$event->add($elem);
$timezone = new Sabre_VObject_Component('VTIMEZONE');
$timezone = new Component('VTIMEZONE');
$timezone->TZID = 'Moon';
$timezone->{'X-LIC-LOCATION'} = 'Moon';
$calendar = new Sabre_VObject_Component('VCALENDAR');
$calendar = new Component('VCALENDAR');
$calendar->add($event);
$calendar->add($timezone);
@ -224,7 +227,7 @@ class Sabre_VObject_Property_DateTimeTest extends PHPUnit_Framework_TestCase {
$this->assertInstanceOf('DateTime', $dt);
$this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s'));
$this->assertEquals('Canada/Eastern', $dt->getTimeZone()->getName());
$this->assertEquals(Sabre_VObject_Property_DateTime::LOCALTZ, $elem->getDateType());
$this->assertEquals(DateTime::LOCALTZ, $elem->getDateType());
date_default_timezone_set($default);
}

View File

@ -1,16 +1,18 @@
<?php
class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject\Property;
class MultiDateTimeTest extends \PHPUnit_Framework_TestCase {
function testSetDateTime() {
$tz = new DateTimeZone('Europe/Amsterdam');
$dt1 = new DateTime('1985-07-04 01:30:00', $tz);
$dt2 = new DateTime('1986-07-04 01:30:00', $tz);
$tz = new \DateTimeZone('Europe/Amsterdam');
$dt1 = new \DateTime('1985-07-04 01:30:00', $tz);
$dt2 = new \DateTime('1986-07-04 01:30:00', $tz);
$dt1->setTimeZone($tz);
$dt2->setTimeZone($tz);
$elem = new Sabre_VObject_Property_MultiDateTime('DTSTART');
$elem = new MultiDateTime('DTSTART');
$elem->setDateTimes(array($dt1,$dt2));
$this->assertEquals('19850704T013000,19860704T013000', $elem->value);
@ -21,14 +23,14 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas
function testSetDateTimeLOCAL() {
$tz = new DateTimeZone('Europe/Amsterdam');
$dt1 = new DateTime('1985-07-04 01:30:00', $tz);
$dt2 = new DateTime('1986-07-04 01:30:00', $tz);
$tz = new \DateTimeZone('Europe/Amsterdam');
$dt1 = new \DateTime('1985-07-04 01:30:00', $tz);
$dt2 = new \DateTime('1986-07-04 01:30:00', $tz);
$dt1->setTimeZone($tz);
$dt2->setTimeZone($tz);
$elem = new Sabre_VObject_Property_MultiDateTime('DTSTART');
$elem->setDateTimes(array($dt1,$dt2), Sabre_VObject_Property_DateTime::LOCAL);
$elem = new MultiDateTime('DTSTART');
$elem->setDateTimes(array($dt1,$dt2), DateTime::LOCAL);
$this->assertEquals('19850704T013000,19860704T013000', $elem->value);
$this->assertNull($elem['TZID']);
@ -38,14 +40,14 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas
function testSetDateTimeUTC() {
$tz = new DateTimeZone('GMT');
$dt1 = new DateTime('1985-07-04 01:30:00', $tz);
$dt2 = new DateTime('1986-07-04 01:30:00', $tz);
$tz = new \DateTimeZone('GMT');
$dt1 = new \DateTime('1985-07-04 01:30:00', $tz);
$dt2 = new \DateTime('1986-07-04 01:30:00', $tz);
$dt1->setTimeZone($tz);
$dt2->setTimeZone($tz);
$elem = new Sabre_VObject_Property_MultiDateTime('DTSTART');
$elem->setDateTimes(array($dt1,$dt2), Sabre_VObject_Property_DateTime::UTC);
$elem = new MultiDateTime('DTSTART');
$elem->setDateTimes(array($dt1,$dt2), DateTime::UTC);
$this->assertEquals('19850704T013000Z,19860704T013000Z', $elem->value);
$this->assertNull($elem['TZID']);
@ -55,14 +57,14 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas
function testSetDateTimeLOCALTZ() {
$tz = new DateTimeZone('Europe/Amsterdam');
$dt1 = new DateTime('1985-07-04 01:30:00', $tz);
$dt2 = new DateTime('1986-07-04 01:30:00', $tz);
$tz = new \DateTimeZone('Europe/Amsterdam');
$dt1 = new \DateTime('1985-07-04 01:30:00', $tz);
$dt2 = new \DateTime('1986-07-04 01:30:00', $tz);
$dt1->setTimeZone($tz);
$dt2->setTimeZone($tz);
$elem = new Sabre_VObject_Property_MultiDateTime('DTSTART');
$elem->setDateTimes(array($dt1,$dt2), Sabre_VObject_Property_DateTime::LOCALTZ);
$elem = new MultiDateTime('DTSTART');
$elem->setDateTimes(array($dt1,$dt2), DateTime::LOCALTZ);
$this->assertEquals('19850704T013000,19860704T013000', $elem->value);
$this->assertEquals('Europe/Amsterdam', (string)$elem['TZID']);
@ -72,14 +74,14 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas
function testSetDateTimeDATE() {
$tz = new DateTimeZone('Europe/Amsterdam');
$dt1 = new datetime('1985-07-04 01:30:00', $tz);
$dt2 = new datetime('1986-07-04 01:30:00', $tz);
$tz = new \DateTimeZone('Europe/Amsterdam');
$dt1 = new \DateTime('1985-07-04 01:30:00', $tz);
$dt2 = new \DateTime('1986-07-04 01:30:00', $tz);
$dt1->settimezone($tz);
$dt2->settimezone($tz);
$elem = new Sabre_VObject_Property_MultiDateTime('DTSTART');
$elem->setDateTimes(array($dt1,$dt2), Sabre_VObject_Property_DateTime::DATE);
$elem = new MultiDateTime('DTSTART');
$elem->setDateTimes(array($dt1,$dt2), DateTime::DATE);
$this->assertEquals('19850704,19860704', $elem->value);
$this->assertNull($elem['TZID']);
@ -92,24 +94,24 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas
*/
function testSetDateTimeInvalid() {
$tz = new DateTimeZone('Europe/Amsterdam');
$dt = new DateTime('1985-07-04 01:30:00', $tz);
$tz = new \DateTimeZone('Europe/Amsterdam');
$dt = new \DateTime('1985-07-04 01:30:00', $tz);
$dt->setTimeZone($tz);
$elem = new Sabre_VObject_Property_MultiDateTime('DTSTART');
$elem = new MultiDateTime('DTSTART');
$elem->setDateTimes(array($dt), 7);
}
function testGetDateTimeCached() {
$tz = new DateTimeZone('Europe/Amsterdam');
$dt1 = new datetime('1985-07-04 01:30:00', $tz);
$dt2 = new datetime('1986-07-04 01:30:00', $tz);
$tz = new \DateTimeZone('Europe/Amsterdam');
$dt1 = new \DateTime('1985-07-04 01:30:00', $tz);
$dt2 = new \DateTime('1986-07-04 01:30:00', $tz);
$dt1->settimezone($tz);
$dt2->settimezone($tz);
$elem = new Sabre_VObject_Property_MultiDateTime('DTSTART');
$elem = new MultiDateTime('DTSTART');
$elem->setDateTimes(array($dt1,$dt2));
$this->assertEquals($elem->getDateTimes(), array($dt1,$dt2));
@ -118,7 +120,7 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas
function testGetDateTimeDateNULL() {
$elem = new Sabre_VObject_Property_MultiDateTime('DTSTART');
$elem = new MultiDateTime('DTSTART');
$dt = $elem->getDateTimes();
$this->assertNull($dt);
@ -128,20 +130,20 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas
function testGetDateTimeDateDATE() {
$elem = new Sabre_VObject_Property_MultiDateTime('DTSTART','19850704,19860704');
$elem = new MultiDateTime('DTSTART','19850704,19860704');
$dt = $elem->getDateTimes();
$this->assertEquals('1985-07-04 00:00:00', $dt[0]->format('Y-m-d H:i:s'));
$this->assertEquals('1986-07-04 00:00:00', $dt[1]->format('Y-m-d H:i:s'));
$this->assertEquals(Sabre_VObject_Property_DateTime::DATE, $elem->getDateType());
$this->assertEquals(DateTime::DATE, $elem->getDateType());
}
function testGetDateTimeDateDATEReverse() {
$elem = new Sabre_VObject_Property_MultiDateTime('DTSTART','19850704,19860704');
$elem = new MultiDateTime('DTSTART','19850704,19860704');
$this->assertEquals(Sabre_VObject_Property_DateTime::DATE, $elem->getDateType());
$this->assertEquals(DateTime::DATE, $elem->getDateType());
$dt = $elem->getDateTimes();
$this->assertEquals('1985-07-04 00:00:00', $dt[0]->format('Y-m-d H:i:s'));
@ -152,30 +154,30 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas
function testGetDateTimeDateLOCAL() {
$elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000');
$elem = new DateTime('DTSTART','19850704T013000');
$dt = $elem->getDateTime();
$this->assertInstanceOf('DateTime', $dt);
$this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s'));
$this->assertEquals(Sabre_VObject_Property_DateTime::LOCAL, $elem->getDateType());
$this->assertEquals(DateTime::LOCAL, $elem->getDateType());
}
function testGetDateTimeDateUTC() {
$elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000Z');
$elem = new DateTime('DTSTART','19850704T013000Z');
$dt = $elem->getDateTime();
$this->assertInstanceOf('DateTime', $dt);
$this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s'));
$this->assertEquals('UTC', $dt->getTimeZone()->getName());
$this->assertEquals(Sabre_VObject_Property_DateTime::UTC, $elem->getDateType());
$this->assertEquals(DateTime::UTC, $elem->getDateType());
}
function testGetDateTimeDateLOCALTZ() {
$elem = new Sabre_VObject_Property_DateTime('DTSTART','19850704T013000');
$elem = new DateTime('DTSTART','19850704T013000');
$elem['TZID'] = 'Europe/Amsterdam';
$dt = $elem->getDateTime();
@ -183,7 +185,7 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas
$this->assertInstanceOf('DateTime', $dt);
$this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s'));
$this->assertEquals('Europe/Amsterdam', $dt->getTimeZone()->getName());
$this->assertEquals(Sabre_VObject_Property_DateTime::LOCALTZ, $elem->getDateType());
$this->assertEquals(DateTime::LOCALTZ, $elem->getDateType());
}
@ -192,7 +194,7 @@ class Sabre_VObject_Property_MultiDateTimeTest extends PHPUnit_Framework_TestCas
*/
function testGetDateTimeDateInvalid() {
$elem = new Sabre_VObject_Property_DateTime('DTSTART','bla');
$elem = new DateTime('DTSTART','bla');
$dt = $elem->getDateTime();
}

View File

@ -1,10 +1,12 @@
<?php
class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject;
class PropertyTest extends \PHPUnit_Framework_TestCase {
public function testToString() {
$property = new Sabre_VObject_Property('propname','propvalue');
$property = new Property('propname','propvalue');
$this->assertEquals('PROPNAME', $property->name);
$this->assertEquals('propvalue', $property->value);
$this->assertEquals('propvalue', $property->__toString());
@ -14,8 +16,8 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
public function testParameterExists() {
$property = new Sabre_VObject_Property('propname','propvalue');
$property->parameters[] = new Sabre_VObject_Parameter('paramname','paramvalue');
$property = new Property('propname','propvalue');
$property->parameters[] = new Parameter('paramname','paramvalue');
$this->assertTrue(isset($property['PARAMNAME']));
$this->assertTrue(isset($property['paramname']));
@ -25,17 +27,17 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
public function testParameterGet() {
$property = new Sabre_VObject_Property('propname','propvalue');
$property->parameters[] = new Sabre_VObject_Parameter('paramname','paramvalue');
$property = new Property('propname','propvalue');
$property->parameters[] = new Parameter('paramname','paramvalue');
$this->assertInstanceOf('Sabre_VObject_Parameter',$property['paramname']);
$this->assertInstanceOf('Sabre\\VObject\\Parameter',$property['paramname']);
}
public function testParameterNotExists() {
$property = new Sabre_VObject_Property('propname','propvalue');
$property->parameters[] = new Sabre_VObject_Parameter('paramname','paramvalue');
$property = new Property('propname','propvalue');
$property->parameters[] = new Parameter('paramname','paramvalue');
$this->assertInternalType('null',$property['foo']);
@ -43,22 +45,22 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
public function testParameterMultiple() {
$property = new Sabre_VObject_Property('propname','propvalue');
$property->parameters[] = new Sabre_VObject_Parameter('paramname','paramvalue');
$property->parameters[] = new Sabre_VObject_Parameter('paramname','paramvalue');
$property = new Property('propname','propvalue');
$property->parameters[] = new Parameter('paramname','paramvalue');
$property->parameters[] = new Parameter('paramname','paramvalue');
$this->assertInstanceOf('Sabre_VObject_Parameter',$property['paramname']);
$this->assertInstanceOf('Sabre\\VObject\\Parameter',$property['paramname']);
$this->assertEquals(2,count($property['paramname']));
}
public function testSetParameterAsString() {
$property = new Sabre_VObject_Property('propname','propvalue');
$property = new Property('propname','propvalue');
$property['paramname'] = 'paramvalue';
$this->assertEquals(1,count($property->parameters));
$this->assertInstanceOf('Sabre_VObject_Parameter', $property->parameters[0]);
$this->assertInstanceOf('Sabre\\VObject\\Parameter', $property->parameters[0]);
$this->assertEquals('PARAMNAME',$property->parameters[0]->name);
$this->assertEquals('paramvalue',$property->parameters[0]->value);
@ -69,15 +71,15 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
*/
public function testSetParameterAsStringNoKey() {
$property = new Sabre_VObject_Property('propname','propvalue');
$property = new Property('propname','propvalue');
$property[] = 'paramvalue';
}
public function testSetParameterObject() {
$property = new Sabre_VObject_Property('propname','propvalue');
$param = new Sabre_VObject_Parameter('paramname','paramvalue');
$property = new Property('propname','propvalue');
$param = new Parameter('paramname','paramvalue');
$property[] = $param;
@ -91,8 +93,8 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
*/
public function testSetParameterObjectWithKey() {
$property = new Sabre_VObject_Property('propname','propvalue');
$param = new Sabre_VObject_Parameter('paramname','paramvalue');
$property = new Property('propname','propvalue');
$param = new Parameter('paramname','paramvalue');
$property['key'] = $param;
@ -104,15 +106,15 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
*/
public function testSetParameterObjectRandomObject() {
$property = new Sabre_VObject_Property('propname','propvalue');
$property[] = new StdClass();
$property = new Property('propname','propvalue');
$property[] = new \StdClass();
}
public function testUnsetParameter() {
$property = new Sabre_VObject_Property('propname','propvalue');
$param = new Sabre_VObject_Parameter('paramname','paramvalue');
$property = new Property('propname','propvalue');
$param = new Parameter('paramname','paramvalue');
$property->parameters[] = $param;
unset($property['PARAMNAME']);
@ -122,8 +124,8 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
public function testParamCount() {
$property = new Sabre_VObject_Property('propname','propvalue');
$param = new Sabre_VObject_Parameter('paramname','paramvalue');
$property = new Property('propname','propvalue');
$param = new Parameter('paramname','paramvalue');
$property->parameters[] = $param;
$property->parameters[] = clone $param;
@ -133,7 +135,7 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
public function testSerialize() {
$property = new Sabre_VObject_Property('propname','propvalue');
$property = new Property('propname','propvalue');
$this->assertEquals("PROPNAME:propvalue\r\n",$property->serialize());
@ -141,9 +143,9 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
public function testSerializeParam() {
$property = new Sabre_VObject_Property('propname','propvalue');
$property->parameters[] = new Sabre_VObject_Parameter('paramname','paramvalue');
$property->parameters[] = new Sabre_VObject_Parameter('paramname2','paramvalue2');
$property = new Property('propname','propvalue');
$property->parameters[] = new Parameter('paramname','paramvalue');
$property->parameters[] = new Parameter('paramname2','paramvalue2');
$this->assertEquals("PROPNAME;PARAMNAME=paramvalue;PARAMNAME2=paramvalue2:propvalue\r\n",$property->serialize());
@ -151,7 +153,7 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
public function testSerializeNewLine() {
$property = new Sabre_VObject_Property('propname',"line1\nline2");
$property = new Property('propname',"line1\nline2");
$this->assertEquals("PROPNAME:line1\\nline2\r\n",$property->serialize());
@ -160,7 +162,7 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
public function testSerializeLongLine() {
$value = str_repeat('!',200);
$property = new Sabre_VObject_Property('propname',$value);
$property = new Property('propname',$value);
$expected = "PROPNAME:" . str_repeat('!',66) . "\r\n " . str_repeat('!',74) . "\r\n " . str_repeat('!',60) . "\r\n";
@ -171,7 +173,7 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
public function testSerializeUTF8LineFold() {
$value = str_repeat('!',65) . "\xc3\xa4bla"; // inserted umlaut-a
$property = new Sabre_VObject_Property('propname', $value);
$property = new Property('propname', $value);
$expected = "PROPNAME:" . str_repeat('!',65) . "\r\n \xc3\xa4bla\r\n";
$this->assertEquals($expected, $property->serialize());
@ -179,8 +181,9 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
public function testGetIterator() {
$it = new Sabre_VObject_ElementList(array());
$property = new Sabre_VObject_Property('propname','propvalue', $it);
$it = new ElementList(array());
$property = new Property('propname','propvalue');
$property->setIterator($it);
$this->assertEquals($it,$property->getIterator());
}
@ -188,22 +191,22 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
public function testGetIteratorDefault() {
$property = new Sabre_VObject_Property('propname','propvalue');
$property = new Property('propname','propvalue');
$it = $property->getIterator();
$this->assertTrue($it instanceof Sabre_VObject_ElementList);
$this->assertTrue($it instanceof ElementList);
$this->assertEquals(1,count($it));
}
function testAddScalar() {
$property = new Sabre_VObject_Property('EMAIL');
$property = new Property('EMAIL');
$property->add('myparam','value');
$this->assertEquals(1, count($property->parameters));
$this->assertTrue($property->parameters[0] instanceof Sabre_VObject_Parameter);
$this->assertTrue($property->parameters[0] instanceof Parameter);
$this->assertEquals('MYPARAM',$property->parameters[0]->name);
$this->assertEquals('value',$property->parameters[0]->value);
@ -211,9 +214,9 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
function testAddParameter() {
$prop = new Sabre_VObject_Property('EMAIL');
$prop = new Property('EMAIL');
$prop->add(new Sabre_VObject_Parameter('MYPARAM','value'));
$prop->add(new Parameter('MYPARAM','value'));
$this->assertEquals(1, count($prop->parameters));
$this->assertEquals('MYPARAM',$prop['myparam']->name);
@ -222,10 +225,10 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
function testAddParameterTwice() {
$prop = new Sabre_VObject_Property('EMAIL');
$prop = new Property('EMAIL');
$prop->add(new Sabre_VObject_Parameter('MYPARAM', 'value1'));
$prop->add(new Sabre_VObject_Parameter('MYPARAM', 'value2'));
$prop->add(new Parameter('MYPARAM', 'value1'));
$prop->add(new Parameter('MYPARAM', 'value2'));
$this->assertEquals(2, count($prop->parameters));
@ -238,8 +241,8 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
*/
function testAddArgFail() {
$prop = new Sabre_VObject_Property('EMAIL');
$prop->add(new Sabre_VObject_Parameter('MPARAM'),'hello');
$prop = new Property('EMAIL');
$prop->add(new Parameter('MPARAM'),'hello');
}
@ -248,7 +251,7 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
*/
function testAddArgFail2() {
$property = new Sabre_VObject_Property('EMAIL','value');
$property = new Property('EMAIL','value');
$property->add(array());
}
@ -258,14 +261,14 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
*/
function testAddArgFail3() {
$property = new Sabre_VObject_Property('EMAIL','value');
$property = new Property('EMAIL','value');
$property->add('hello',array());
}
function testClone() {
$property = new Sabre_VObject_Property('EMAIL','value');
$property = new Property('EMAIL','value');
$property['FOO'] = 'BAR';
$property2 = clone $property;
@ -275,4 +278,16 @@ class Sabre_VObject_PropertyTest extends PHPUnit_Framework_TestCase {
}
function testCreateParams() {
$property = Property::create('X-PROP', 'value', array(
'param1' => 'value1',
'param2' => array('value2', 'value3')
));
$this->assertEquals(1, count($property['PARAM1']));
$this->assertEquals(2, count($property['PARAM2']));
}
}

View File

@ -1,14 +1,16 @@
<?php
class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject;
class ReaderTest extends \PHPUnit_Framework_TestCase {
function testReadComponent() {
$data = "BEGIN:VCALENDAR\r\nEND:VCALENDAR";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Component', $result);
$this->assertInstanceOf('Sabre\\VObject\\Component', $result);
$this->assertEquals('VCALENDAR', $result->name);
$this->assertEquals(0, count($result->children));
@ -18,9 +20,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
$data = "BEGIN:VCALENDAR\nEND:VCALENDAR";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Component', $result);
$this->assertInstanceOf('Sabre\\VObject\\Component', $result);
$this->assertEquals('VCALENDAR', $result->name);
$this->assertEquals(0, count($result->children));
@ -30,9 +32,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
$data = "BEGIN:VCALENDAR\rEND:VCALENDAR";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Component', $result);
$this->assertInstanceOf('Sabre\\VObject\\Component', $result);
$this->assertEquals('VCALENDAR', $result->name);
$this->assertEquals(0, count($result->children));
@ -42,31 +44,31 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
$data = "BEGIN:\r\n\tVCALENDAR\r\nE\r\n ND:VCALENDAR";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Component', $result);
$this->assertInstanceOf('Sabre\\VObject\\Component', $result);
$this->assertEquals('VCALENDAR', $result->name);
$this->assertEquals(0, count($result->children));
}
/**
* @expectedException Sabre_VObject_ParseException
* @expectedException Sabre\VObject\ParseException
*/
function testReadCorruptComponent() {
$data = "BEGIN:VCALENDAR\r\nEND:FOO";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
}
function testReadProperty() {
$data = "PROPNAME:propValue";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Property', $result);
$this->assertInstanceOf('Sabre\\VObject\\Property', $result);
$this->assertEquals('PROPNAME', $result->name);
$this->assertEquals('propValue', $result->value);
@ -75,9 +77,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
function testReadPropertyWithNewLine() {
$data = 'PROPNAME:Line1\\nLine2\\NLine3\\\\Not the 4th line!';
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Property', $result);
$this->assertInstanceOf('Sabre\\VObject\\Property', $result);
$this->assertEquals('PROPNAME', $result->name);
$this->assertEquals("Line1\nLine2\nLine3\\Not the 4th line!", $result->value);
@ -86,9 +88,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
function testReadMappedProperty() {
$data = "DTSTART:20110529";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Property_DateTime', $result);
$this->assertInstanceOf('Sabre\\VObject\\Property\\DateTime', $result);
$this->assertEquals('DTSTART', $result->name);
$this->assertEquals('20110529', $result->value);
@ -97,9 +99,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
function testReadMappedPropertyGrouped() {
$data = "foo.DTSTART:20110529";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Property_DateTime', $result);
$this->assertInstanceOf('Sabre\\VObject\\Property\\DateTime', $result);
$this->assertEquals('DTSTART', $result->name);
$this->assertEquals('20110529', $result->value);
@ -107,12 +109,12 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
/**
* @expectedException Sabre_VObject_ParseException
* @expectedException Sabre\VObject\ParseException
*/
function testReadBrokenLine() {
$data = "PROPNAME;propValue";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
}
@ -124,12 +126,12 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
"END:VCALENDAR"
);
$result = Sabre_VObject_Reader::read(implode("\r\n",$data));
$result = Reader::read(implode("\r\n",$data));
$this->assertInstanceOf('Sabre_VObject_Component', $result);
$this->assertInstanceOf('Sabre\\VObject\\Component', $result);
$this->assertEquals('VCALENDAR', $result->name);
$this->assertEquals(1, count($result->children));
$this->assertInstanceOf('Sabre_VObject_Property', $result->children[0]);
$this->assertInstanceOf('Sabre\\VObject\\Property', $result->children[0]);
$this->assertEquals('PROPNAME', $result->children[0]->name);
$this->assertEquals('propValue', $result->children[0]->value);
@ -146,15 +148,15 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
"END:VCALENDAR"
);
$result = Sabre_VObject_Reader::read(implode("\r\n",$data));
$result = Reader::read(implode("\r\n",$data));
$this->assertInstanceOf('Sabre_VObject_Component', $result);
$this->assertInstanceOf('Sabre\\VObject\\Component', $result);
$this->assertEquals('VCALENDAR', $result->name);
$this->assertEquals(1, count($result->children));
$this->assertInstanceOf('Sabre_VObject_Component', $result->children[0]);
$this->assertInstanceOf('Sabre\\VObject\\Component', $result->children[0]);
$this->assertEquals('VTIMEZONE', $result->children[0]->name);
$this->assertEquals(1, count($result->children[0]->children));
$this->assertInstanceOf('Sabre_VObject_Component', $result->children[0]->children[0]);
$this->assertInstanceOf('Sabre\\VObject\\Component', $result->children[0]->children[0]);
$this->assertEquals('DAYLIGHT', $result->children[0]->children[0]->name);
@ -163,9 +165,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
function testReadPropertyParameter() {
$data = "PROPNAME;PARAMNAME=paramvalue:propValue";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Property', $result);
$this->assertInstanceOf('Sabre\\VObject\\Property', $result);
$this->assertEquals('PROPNAME', $result->name);
$this->assertEquals('propValue', $result->value);
$this->assertEquals(1, count($result->parameters));
@ -177,9 +179,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
function testReadPropertyNoValue() {
$data = "PROPNAME;PARAMNAME:propValue";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Property', $result);
$this->assertInstanceOf('Sabre\\VObject\\Property', $result);
$this->assertEquals('PROPNAME', $result->name);
$this->assertEquals('propValue', $result->value);
$this->assertEquals(1, count($result->parameters));
@ -191,9 +193,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
function testReadPropertyParameterExtraColon() {
$data = "PROPNAME;PARAMNAME=paramvalue:propValue:anotherrandomstring";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Property', $result);
$this->assertInstanceOf('Sabre\\VObject\\Property', $result);
$this->assertEquals('PROPNAME', $result->name);
$this->assertEquals('propValue:anotherrandomstring', $result->value);
$this->assertEquals(1, count($result->parameters));
@ -205,9 +207,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
function testReadProperty2Parameters() {
$data = "PROPNAME;PARAMNAME=paramvalue;PARAMNAME2=paramvalue2:propValue";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Property', $result);
$this->assertInstanceOf('Sabre\\VObject\\Property', $result);
$this->assertEquals('PROPNAME', $result->name);
$this->assertEquals('propValue', $result->value);
$this->assertEquals(2, count($result->parameters));
@ -221,9 +223,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
function testReadPropertyParameterQuoted() {
$data = "PROPNAME;PARAMNAME=\"paramvalue\":propValue";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Property', $result);
$this->assertInstanceOf('Sabre\\VObject\\Property', $result);
$this->assertEquals('PROPNAME', $result->name);
$this->assertEquals('propValue', $result->value);
$this->assertEquals(1, count($result->parameters));
@ -234,9 +236,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
function testReadPropertyParameterNewLines() {
$data = "PROPNAME;PARAMNAME=paramvalue1\\nvalue2\\\\nvalue3:propValue";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Property', $result);
$this->assertInstanceOf('Sabre\\VObject\\Property', $result);
$this->assertEquals('PROPNAME', $result->name);
$this->assertEquals('propValue', $result->value);
@ -249,9 +251,9 @@ class Sabre_VObject_ReaderTest extends PHPUnit_Framework_TestCase {
function testReadPropertyParameterQuotedColon() {
$data = "PROPNAME;PARAMNAME=\"param:value\":propValue";
$result = Sabre_VObject_Reader::read($data);
$result = Reader::read($data);
$this->assertInstanceOf('Sabre_VObject_Property', $result);
$this->assertInstanceOf('Sabre\\VObject\\Property', $result);
$this->assertEquals('PROPNAME', $result->name);
$this->assertEquals('propValue', $result->value);
$this->assertEquals(1, count($result->parameters));

View File

@ -1,6 +1,8 @@
<?php
class Sabre_VObject_RecurrenceIteratorFifthTuesdayProblemTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject;
class RecurrenceIteratorFifthTuesdayProblemTest extends \PHPUnit_Framework_TestCase {
function testGetDTEnd() {
@ -26,8 +28,8 @@ END:VEVENT
END:VCALENDAR
ICS;
$vObject = Sabre_VObject_Reader::read($ics);
$it = new Sabre_VObject_RecurrenceIterator($vObject, (string)$vObject->VEVENT->UID);
$vObject = Reader::read($ics);
$it = new RecurrenceIterator($vObject, (string)$vObject->VEVENT->UID);
while($it->valid()) {
$it->next();

View File

@ -1,6 +1,11 @@
<?php
class Sabre_VObject_RecurrenceIteratorInfiniteLoopProblemTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject;
use DateTime;
use DateTimeZone;
class RecurrenceIteratorInfiniteLoopProblemTest extends \PHPUnit_Framework_TestCase {
/**
* This bug came from a Fruux customer. This would result in a never-ending
@ -8,7 +13,7 @@ class Sabre_VObject_RecurrenceIteratorInfiniteLoopProblemTest extends PHPUnit_Fr
*/
function testFastForwardTooFar() {
$ev = Sabre_VObject_Component::create('VEVENT');
$ev = Component::create('VEVENT');
$ev->DTSTART = '20090420T180000Z';
$ev->RRULE = 'FREQ=WEEKLY;BYDAY=MO;UNTIL=20090704T205959Z;INTERVAL=1';
@ -21,7 +26,7 @@ class Sabre_VObject_RecurrenceIteratorInfiniteLoopProblemTest extends PHPUnit_Fr
*/
function testYearlyByMonthLoop() {
$ev = Sabre_VObject_Component::create('VEVENT');
$ev = Component::create('VEVENT');
$ev->UID = 'uuid';
$ev->DTSTART = '20120101T154500';
$ev->DTSTART['TZID'] = 'Europe/Berlin';
@ -35,10 +40,10 @@ class Sabre_VObject_RecurrenceIteratorInfiniteLoopProblemTest extends PHPUnit_Fr
// 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 = Component::create('VCALENDAR');
$cal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($cal,'uuid');
$it = new RecurrenceIterator($cal,'uuid');
$it->fastForward(new DateTime('2012-01-29 23:00:00', new DateTimeZone('UTC')));
$collect = array();

View File

@ -1,21 +1,26 @@
<?php
class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject;
use DateTime;
use DateTimeZone;
class RecurrenceIteratorTest extends \PHPUnit_Framework_TestCase {
function testValues() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=DAILY;BYHOUR=10;BYMINUTE=5;BYSECOND=16;BYWEEKNO=32;BYYEARDAY=100,200';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-10-07'),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals(array(10), $it->byHour);
$this->assertEquals(array(5), $it->byMinute);
@ -31,17 +36,17 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testInvalidFreq() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->RRULE = 'FREQ=SMONTHLY;INTERVAL=3;UNTIL=20111025T000000Z';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-10-07'),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
}
@ -50,8 +55,8 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testVCalendarNoUID() {
$vcal = new Sabre_VObject_Component('VCALENDAR');
$it = new Sabre_VObject_RecurrenceIterator($vcal);
$vcal = new Component('VCALENDAR');
$it = new RecurrenceIterator($vcal);
}
@ -60,8 +65,8 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testVCalendarInvalidUID() {
$vcal = new Sabre_VObject_Component('VCALENDAR');
$it = new Sabre_VObject_RecurrenceIterator($vcal,'foo');
$vcal = new Component('VCALENDAR');
$it = new RecurrenceIterator($vcal,'foo');
}
@ -70,18 +75,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testDaily() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=DAILY;INTERVAL=3;UNTIL=20111025T000000Z';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,$ev->uid);
$it = new RecurrenceIterator($vcal,$ev->uid);
$this->assertEquals('daily', $it->frequency);
$this->assertEquals(3, $it->interval);
@ -121,17 +126,17 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testNoRRULE() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,$ev->uid);
$it = new RecurrenceIterator($vcal,$ev->uid);
$this->assertEquals('daily', $it->frequency);
$this->assertEquals(1, $it->interval);
@ -164,18 +169,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testDailyByDay() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=DAILY;INTERVAL=2;BYDAY=TU,WE,FR';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals('daily', $it->frequency);
$this->assertEquals(2, $it->interval);
@ -220,18 +225,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testWeekly() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;COUNT=10';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals('weekly', $it->frequency);
$this->assertEquals(2, $it->interval);
@ -274,18 +279,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testWeeklyByDay() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-10-07'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-10-07', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals('weekly', $it->frequency);
$this->assertEquals(2, $it->interval);
@ -331,18 +336,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testMonthly() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=MONTHLY;INTERVAL=3;COUNT=5';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-12-05'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-12-05', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals('monthly', $it->frequency);
$this->assertEquals(3, $it->interval);
@ -380,18 +385,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testMonthlyEndOfMonth() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=MONTHLY;INTERVAL=2;COUNT=12';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-12-31'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-12-31', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals('monthly', $it->frequency);
$this->assertEquals(2, $it->interval);
@ -436,18 +441,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testMonthlyByMonthDay() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=MONTHLY;INTERVAL=5;COUNT=9;BYMONTHDAY=1,31,-7';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-01-01'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-01-01', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals('monthly', $it->frequency);
$this->assertEquals(5, $it->interval);
@ -489,18 +494,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testMonthlyByDay() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=MONTHLY;INTERVAL=2;COUNT=16;BYDAY=MO,-2TU,+1WE,3TH';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-01-03'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-01-03', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals('monthly', $it->frequency);
$this->assertEquals(2, $it->interval);
@ -549,18 +554,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testMonthlyByDayByMonthDay() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO;BYMONTHDAY=1';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-08-01'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-08-01', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals('monthly', $it->frequency);
$this->assertEquals(1, $it->interval);
@ -604,18 +609,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testMonthlyByDayBySetPos() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1,-1';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-01-03'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-01-03', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals('monthly', $it->frequency);
$this->assertEquals(1, $it->interval);
@ -659,18 +664,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testYearly() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=YEARLY;COUNT=10;INTERVAL=3';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-01-01'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-01-01', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals('yearly', $it->frequency);
$this->assertEquals(3, $it->interval);
@ -712,18 +717,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testYearlyLeapYear() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=YEARLY;COUNT=3';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2012-02-29'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2012-02-29', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals('yearly', $it->frequency);
$this->assertEquals(3, $it->count);
@ -757,18 +762,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testYearlyByMonth() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=4;BYMONTH=4,10';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-04-07'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-04-07', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals('yearly', $it->frequency);
$this->assertEquals(4, $it->interval);
@ -809,18 +814,18 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testYearlyByMonthByDay() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-04-04'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-04-04', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals('yearly', $it->frequency);
$this->assertEquals(5, $it->interval);
@ -862,22 +867,22 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testFastForward() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-04-04'),Sabre_VObject_Property_DateTime::UTC);
$dtStart = new Property\DateTime('DTSTART');
$dtStart->setDateTime(new DateTime('2011-04-04', new DateTimeZone('UTC')),Property\DateTime::UTC);
$ev->add($dtStart);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
// The idea is that we're fast-forwarding too far in the future, so
// there will be no results left.
$it->fastForward(new DateTime('2020-05-05'));
$it->fastForward(new DateTime('2020-05-05', new DateTimeZone('UTC')));
$max = 20;
$result = array();
@ -901,27 +906,27 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testComplexExclusions() {
$ev = new Sabre_VObject_Component('VEVENT');
$ev = new Component('VEVENT');
$ev->UID = 'bla';
$ev->RRULE = 'FREQ=YEARLY;COUNT=10';
$dtStart = new Sabre_VObject_Property_DateTime('DTSTART');
$dtStart = new Property\DateTime('DTSTART');
$tz = new DateTimeZone('Canada/Eastern');
$dtStart->setDateTime(new DateTime('2011-01-01 13:50:20', $tz),Sabre_VObject_Property_DateTime::LOCALTZ);
$dtStart->setDateTime(new DateTime('2011-01-01 13:50:20', $tz),Property\DateTime::LOCALTZ);
$exDate1 = new Sabre_VObject_Property_MultiDateTime('EXDATE');
$exDate1->setDateTimes(array(new DateTime('2012-01-01 13:50:20', $tz), new DateTime('2014-01-01 13:50:20', $tz)), Sabre_VObject_Property_DateTime::LOCALTZ);
$exDate2 = new Sabre_VObject_Property_MultiDateTime('EXDATE');
$exDate2->setDateTimes(array(new DateTime('2016-01-01 13:50:20', $tz)), Sabre_VObject_Property_DateTime::LOCALTZ);
$exDate1 = new Property\MultiDateTime('EXDATE');
$exDate1->setDateTimes(array(new DateTime('2012-01-01 13:50:20', $tz), new DateTime('2014-01-01 13:50:20', $tz)), Property\DateTime::LOCALTZ);
$exDate2 = new Property\MultiDateTime('EXDATE');
$exDate2->setDateTimes(array(new DateTime('2016-01-01 13:50:20', $tz)), Property\DateTime::LOCALTZ);
$ev->add($dtStart);
$ev->add($exDate1);
$ev->add($exDate2);
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$vcal->add($ev);
$it = new Sabre_VObject_RecurrenceIterator($vcal,(string)$ev->uid);
$it = new RecurrenceIterator($vcal,(string)$ev->uid);
$this->assertEquals('yearly', $it->frequency);
$this->assertEquals(1, $it->interval);
@ -958,9 +963,9 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testOverridenEvent() {
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$ev1 = Sabre_VObject_Component::create('VEVENT');
$ev1 = Component::create('VEVENT');
$ev1->UID = 'overridden';
$ev1->RRULE = 'FREQ=DAILY;COUNT=10';
$ev1->DTSTART = '20120107T120000Z';
@ -969,7 +974,7 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
$vcal->add($ev1);
// ev2 overrides an event, and puts it on 2pm instead.
$ev2 = Sabre_VObject_Component::create('VEVENT');
$ev2 = Component::create('VEVENT');
$ev2->UID = 'overridden';
$ev2->{'RECURRENCE-ID'} = '20120110T120000Z';
$ev2->DTSTART = '20120110T140000Z';
@ -978,7 +983,7 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
$vcal->add($ev2);
// ev3 overrides an event, and puts it 2 days and 2 hours later
$ev3 = Sabre_VObject_Component::create('VEVENT');
$ev3 = Component::create('VEVENT');
$ev3->UID = 'overridden';
$ev3->{'RECURRENCE-ID'} = '20120113T120000Z';
$ev3->DTSTART = '20120115T140000Z';
@ -986,7 +991,7 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
$vcal->add($ev3);
$it = new Sabre_VObject_RecurrenceIterator($vcal,'overridden');
$it = new RecurrenceIterator($vcal,'overridden');
$dates = array();
$summaries = array();
@ -1032,9 +1037,9 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testOverridenEvent2() {
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$ev1 = Sabre_VObject_Component::create('VEVENT');
$ev1 = Component::create('VEVENT');
$ev1->UID = 'overridden';
$ev1->RRULE = 'FREQ=WEEKLY;COUNT=3';
$ev1->DTSTART = '20120112T120000Z';
@ -1043,7 +1048,7 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
$vcal->add($ev1);
// ev2 overrides an event, and puts it 6 days earlier instead.
$ev2 = Sabre_VObject_Component::create('VEVENT');
$ev2 = Component::create('VEVENT');
$ev2->UID = 'overridden';
$ev2->{'RECURRENCE-ID'} = '20120119T120000Z';
$ev2->DTSTART = '20120113T120000Z';
@ -1051,7 +1056,7 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
$vcal->add($ev2);
$it = new Sabre_VObject_RecurrenceIterator($vcal,'overridden');
$it = new RecurrenceIterator($vcal,'overridden');
$dates = array();
$summaries = array();
@ -1084,9 +1089,9 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
*/
function testOverridenEventNoValuesExpected() {
$vcal = Sabre_VObject_Component::create('VCALENDAR');
$vcal = Component::create('VCALENDAR');
$ev1 = Sabre_VObject_Component::create('VEVENT');
$ev1 = Component::create('VEVENT');
$ev1->UID = 'overridden';
$ev1->RRULE = 'FREQ=WEEKLY;COUNT=3';
$ev1->DTSTART = '20120124T120000Z';
@ -1095,7 +1100,7 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
$vcal->add($ev1);
// ev2 overrides an event, and puts it 6 days earlier instead.
$ev2 = Sabre_VObject_Component::create('VEVENT');
$ev2 = Component::create('VEVENT');
$ev2->UID = 'overridden';
$ev2->{'RECURRENCE-ID'} = '20120131T120000Z';
$ev2->DTSTART = '20120125T120000Z';
@ -1103,7 +1108,7 @@ class Sabre_VObject_RecurrenceIteratorTest extends PHPUnit_Framework_TestCase {
$vcal->add($ev2);
$it = new Sabre_VObject_RecurrenceIterator($vcal,'overridden');
$it = new RecurrenceIterator($vcal,'overridden');
$dates = array();
$summaries = array();

View File

@ -1,13 +1,15 @@
<?php
class Sabre_VObject_TimeZoneUtilTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject;
class TimezoneUtilTest extends \PHPUnit_Framework_TestCase {
/**
* @dataProvider getMapping
*/
function testCorrectTZ($timezoneName) {
$tz = new DateTimeZone($timezoneName);
$tz = new \DateTimeZone($timezoneName);
}
@ -18,7 +20,7 @@ class Sabre_VObject_TimeZoneUtilTest extends PHPUnit_Framework_TestCase {
function($value) {
return array($value);
},
Sabre_VObject_TimeZoneUtil::$map
TimeZoneUtil::$map
);
}
@ -58,9 +60,9 @@ END:VEVENT
END:VCALENDAR
HI;
$tz = Sabre_VObject_TimeZoneUtil::getTimeZone('foo', Sabre_VObject_Reader::read($vobj));
$tz = TimeZoneUtil::getTimeZone('foo', Reader::read($vobj));
$this->assertEquals(new DateTimeZone('Europe/Sarajevo'), $tz);
$this->assertEquals(new \DateTimeZone('Europe/Sarajevo'), $tz);
}
@ -99,16 +101,16 @@ END:VEVENT
END:VCALENDAR
HI;
$tz = Sabre_VObject_TimeZoneUtil::getTimeZone('foo', Sabre_VObject_Reader::read($vobj));
$tz = TimeZoneUtil::getTimeZone('foo', Reader::read($vobj));
$this->assertEquals(new DateTimeZone(date_default_timezone_get()), $tz);
$this->assertEquals(new \DateTimeZone(date_default_timezone_get()), $tz);
}
function testWindowsTimeZone() {
$tz = Sabre_VObject_TimeZoneUtil::getTimeZone('Eastern Standard Time');
$this->assertEquals(new DateTimeZone('America/New_York'), $tz);
$tz = TimeZoneUtil::getTimeZone('Eastern Standard Time');
$this->assertEquals(new \DateTimeZone('America/New_York'), $tz);
}
@ -144,9 +146,9 @@ UID:040000008200E00074C5B7101A82E0080000000010DA091DC31BCD01000000000000000
END:VEVENT
END:VCALENDAR
HI;
$tz = Sabre_VObject_TimeZoneUtil::getTimeZone('foo', Sabre_VObject_Reader::read($vobj));
$tz = TimeZoneUtil::getTimeZone('foo', Reader::read($vobj));
$this->assertEquals(new DateTimeZone(date_default_timezone_get()), $tz);
$this->assertEquals(new \DateTimeZone(date_default_timezone_get()), $tz);
}

View File

@ -1,13 +1,15 @@
<?php
class Sabre_VObject_VersionTest extends PHPUnit_Framework_TestCase {
namespace Sabre\VObject;
class VersionTest extends \PHPUnit_Framework_TestCase {
function testString() {
$v = Sabre_VObject_Version::VERSION;
$v = Version::VERSION;
$this->assertEquals(-1, version_compare('0.9.0',$v));
$s = Sabre_VObject_Version::STABILITY;
$s = Version::STABILITY;
$this->assertTrue($s == 'alpha' || $s == 'beta' || $s =='stable');
}

View File

@ -0,0 +1,4 @@
<?php
// Composer autoloader
include __DIR__ . '/../vendor/autoload.php';

View File

@ -0,0 +1,17 @@
<phpunit
colors="true"
bootstrap="bootstrap.php"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<testsuite name="Sabre_VObject">
<directory>Sabre/</directory>
</testsuite>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">../lib/</directory>
</whitelist>
</filter>
</phpunit>