Removed unexpected files
This commit is contained in:
parent
e16b7fe1ee
commit
168e50a45b
File diff suppressed because it is too large
Load Diff
@ -1,178 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Backend;
|
||||
|
||||
use
|
||||
Sabre\DAV\PropPatch;
|
||||
|
||||
class AbstractTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function testUpdateCalendar() {
|
||||
|
||||
$abstract = new AbstractMock();
|
||||
$propPatch = new PropPatch(['{DAV:}displayname' => 'anything']);
|
||||
|
||||
$abstract->updateCalendar('randomid', $propPatch);
|
||||
$result = $propPatch->commit();
|
||||
|
||||
$this->assertFalse($result);
|
||||
|
||||
}
|
||||
|
||||
function testCalendarQuery() {
|
||||
|
||||
$abstract = new AbstractMock();
|
||||
$filters = [
|
||||
'name' => 'VCALENDAR',
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VEVENT',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
],
|
||||
],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
];
|
||||
|
||||
$this->assertEquals([
|
||||
'event1.ics',
|
||||
], $abstract->calendarQuery(1, $filters));
|
||||
|
||||
}
|
||||
|
||||
function testGetCalendarObjectByUID() {
|
||||
|
||||
$abstract = new AbstractMock();
|
||||
$this->assertNull(
|
||||
$abstract->getCalendarObjectByUID('principal1', 'zim')
|
||||
);
|
||||
$this->assertEquals(
|
||||
'cal1/event1.ics',
|
||||
$abstract->getCalendarObjectByUID('principal1', 'foo')
|
||||
);
|
||||
$this->assertNull(
|
||||
$abstract->getCalendarObjectByUID('principal3', 'foo')
|
||||
);
|
||||
$this->assertNull(
|
||||
$abstract->getCalendarObjectByUID('principal1', 'shared')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testGetMultipleCalendarObjects() {
|
||||
|
||||
$abstract = new AbstractMock();
|
||||
$result = $abstract->getMultipleCalendarObjects(1, [
|
||||
'event1.ics',
|
||||
'task1.ics',
|
||||
]);
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'id' => 1,
|
||||
'calendarid' => 1,
|
||||
'uri' => 'event1.ics',
|
||||
'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'calendarid' => 1,
|
||||
'uri' => 'task1.ics',
|
||||
'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n",
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class AbstractMock extends AbstractBackend {
|
||||
|
||||
function getCalendarsForUser($principalUri) {
|
||||
|
||||
return [
|
||||
[
|
||||
'id' => 1,
|
||||
'principaluri' => 'principal1',
|
||||
'uri' => 'cal1',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'principaluri' => 'principal1',
|
||||
'{http://sabredav.org/ns}owner-principal' => 'principal2',
|
||||
'uri' => 'cal1',
|
||||
],
|
||||
];
|
||||
|
||||
}
|
||||
function createCalendar($principalUri, $calendarUri, array $properties) { }
|
||||
function deleteCalendar($calendarId) { }
|
||||
function getCalendarObjects($calendarId) {
|
||||
|
||||
switch ($calendarId) {
|
||||
case 1:
|
||||
return [
|
||||
[
|
||||
'id' => 1,
|
||||
'calendarid' => 1,
|
||||
'uri' => 'event1.ics',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'calendarid' => 1,
|
||||
'uri' => 'task1.ics',
|
||||
],
|
||||
];
|
||||
case 2:
|
||||
return [
|
||||
[
|
||||
'id' => 3,
|
||||
'calendarid' => 2,
|
||||
'uri' => 'shared-event.ics',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getCalendarObject($calendarId, $objectUri) {
|
||||
|
||||
switch ($objectUri) {
|
||||
|
||||
case 'event1.ics' :
|
||||
return [
|
||||
'id' => 1,
|
||||
'calendarid' => 1,
|
||||
'uri' => 'event1.ics',
|
||||
'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
|
||||
];
|
||||
case 'task1.ics' :
|
||||
return [
|
||||
'id' => 2,
|
||||
'calendarid' => 1,
|
||||
'uri' => 'task1.ics',
|
||||
'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n",
|
||||
];
|
||||
case 'shared-event.ics' :
|
||||
return [
|
||||
'id' => 3,
|
||||
'calendarid' => 2,
|
||||
'uri' => 'event1.ics',
|
||||
'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:shared\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
function createCalendarObject($calendarId, $objectUri, $calendarData) { }
|
||||
function updateCalendarObject($calendarId, $objectUri, $calendarData) { }
|
||||
function deleteCalendarObject($calendarId, $objectUri) { }
|
||||
|
||||
}
|
||||
@ -1,258 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Backend;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\DAV;
|
||||
|
||||
class Mock extends AbstractBackend {
|
||||
|
||||
protected $calendarData;
|
||||
protected $calendars;
|
||||
|
||||
function __construct(array $calendars = [], array $calendarData = []) {
|
||||
|
||||
foreach ($calendars as &$calendar) {
|
||||
if (!isset($calendar['id'])) {
|
||||
$calendar['id'] = DAV\UUIDUtil::getUUID();
|
||||
}
|
||||
}
|
||||
|
||||
$this->calendars = $calendars;
|
||||
$this->calendarData = $calendarData;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of calendars for a principal.
|
||||
*
|
||||
* Every project is an array with the following keys:
|
||||
* * id, a unique id that will be used by other functions to modify the
|
||||
* calendar. This can be the same as the uri or a database key.
|
||||
* * uri, which the basename of the uri with which the calendar is
|
||||
* accessed.
|
||||
* * principalUri. The owner of the calendar. Almost always the same as
|
||||
* principalUri passed to this method.
|
||||
*
|
||||
* Furthermore it can contain webdav properties in clark notation. A very
|
||||
* common one is '{DAV:}displayname'.
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @return array
|
||||
*/
|
||||
function getCalendarsForUser($principalUri) {
|
||||
|
||||
$r = [];
|
||||
foreach ($this->calendars as $row) {
|
||||
if ($row['principaluri'] == $principalUri) {
|
||||
$r[] = $row;
|
||||
}
|
||||
}
|
||||
|
||||
return $r;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new calendar for a principal.
|
||||
*
|
||||
* If the creation was a success, an id must be returned that can be used to reference
|
||||
* this calendar in other methods, such as updateCalendar.
|
||||
*
|
||||
* This function must return a server-wide unique id that can be used
|
||||
* later to reference the calendar.
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @param string $calendarUri
|
||||
* @param array $properties
|
||||
* @return string|int
|
||||
*/
|
||||
function createCalendar($principalUri, $calendarUri, array $properties) {
|
||||
|
||||
$id = DAV\UUIDUtil::getUUID();
|
||||
$this->calendars[] = array_merge([
|
||||
'id' => $id,
|
||||
'principaluri' => $principalUri,
|
||||
'uri' => $calendarUri,
|
||||
'{' . CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet(['VEVENT', 'VTODO']),
|
||||
], $properties);
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates properties for a calendar.
|
||||
*
|
||||
* The list of mutations is stored in a Sabre\DAV\PropPatch object.
|
||||
* To do the actual updates, you must tell this object which properties
|
||||
* you're going to process with the handle() method.
|
||||
*
|
||||
* Calling the handle method is like telling the PropPatch object "I
|
||||
* promise I can handle updating this property".
|
||||
*
|
||||
* Read the PropPatch documentation for more info and examples.
|
||||
*
|
||||
* @param mixed $calendarId
|
||||
* @param \Sabre\DAV\PropPatch $propPatch
|
||||
* @return void
|
||||
*/
|
||||
function updateCalendar($calendarId, \Sabre\DAV\PropPatch $propPatch) {
|
||||
|
||||
$propPatch->handleRemaining(function($props) use ($calendarId) {
|
||||
|
||||
foreach ($this->calendars as $k => $calendar) {
|
||||
|
||||
if ($calendar['id'] === $calendarId) {
|
||||
foreach ($props as $propName => $propValue) {
|
||||
if (is_null($propValue)) {
|
||||
unset($this->calendars[$k][$propName]);
|
||||
} else {
|
||||
$this->calendars[$k][$propName] = $propValue;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a calendar and all it's objects
|
||||
*
|
||||
* @param string $calendarId
|
||||
* @return void
|
||||
*/
|
||||
function deleteCalendar($calendarId) {
|
||||
|
||||
foreach ($this->calendars as $k => $calendar) {
|
||||
if ($calendar['id'] === $calendarId) {
|
||||
unset($this->calendars[$k]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all calendar objects within a calendar object.
|
||||
*
|
||||
* Every item contains an array with the following keys:
|
||||
* * id - unique identifier which will be used for subsequent updates
|
||||
* * calendardata - The iCalendar-compatible calendar data
|
||||
* * uri - a unique key which will be used to construct the uri. This can be any arbitrary string.
|
||||
* * lastmodified - a timestamp of the last modification time
|
||||
* * etag - An arbitrary string, surrounded by double-quotes. (e.g.:
|
||||
* ' "abcdef"')
|
||||
* * calendarid - The calendarid as it was passed to this function.
|
||||
*
|
||||
* Note that the etag is optional, but it's highly encouraged to return for
|
||||
* speed reasons.
|
||||
*
|
||||
* The calendardata is also optional. If it's not returned
|
||||
* 'getCalendarObject' will be called later, which *is* expected to return
|
||||
* calendardata.
|
||||
*
|
||||
* @param string $calendarId
|
||||
* @return array
|
||||
*/
|
||||
function getCalendarObjects($calendarId) {
|
||||
|
||||
if (!isset($this->calendarData[$calendarId]))
|
||||
return [];
|
||||
|
||||
$objects = $this->calendarData[$calendarId];
|
||||
|
||||
foreach ($objects as $uri => &$object) {
|
||||
$object['calendarid'] = $calendarId;
|
||||
$object['uri'] = $uri;
|
||||
$object['lastmodified'] = null;
|
||||
}
|
||||
return $objects;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information from a single calendar object, based on it's object
|
||||
* uri.
|
||||
*
|
||||
* The object uri is only the basename, or filename and not a full path.
|
||||
*
|
||||
* The returned array must have the same keys as getCalendarObjects. The
|
||||
* 'calendardata' object is required here though, while it's not required
|
||||
* for getCalendarObjects.
|
||||
*
|
||||
* This method must return null if the object did not exist.
|
||||
*
|
||||
* @param mixed $calendarId
|
||||
* @param string $objectUri
|
||||
* @return array|null
|
||||
*/
|
||||
function getCalendarObject($calendarId, $objectUri) {
|
||||
|
||||
if (!isset($this->calendarData[$calendarId][$objectUri])) {
|
||||
return null;
|
||||
}
|
||||
$object = $this->calendarData[$calendarId][$objectUri];
|
||||
$object['calendarid'] = $calendarId;
|
||||
$object['uri'] = $objectUri;
|
||||
$object['lastmodified'] = null;
|
||||
return $object;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new calendar object.
|
||||
*
|
||||
* @param string $calendarId
|
||||
* @param string $objectUri
|
||||
* @param string $calendarData
|
||||
* @return void
|
||||
*/
|
||||
function createCalendarObject($calendarId, $objectUri, $calendarData) {
|
||||
|
||||
$this->calendarData[$calendarId][$objectUri] = [
|
||||
'calendardata' => $calendarData,
|
||||
'calendarid' => $calendarId,
|
||||
'uri' => $objectUri,
|
||||
];
|
||||
return '"' . md5($calendarData) . '"';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing calendarobject, based on it's uri.
|
||||
*
|
||||
* @param string $calendarId
|
||||
* @param string $objectUri
|
||||
* @param string $calendarData
|
||||
* @return void
|
||||
*/
|
||||
function updateCalendarObject($calendarId, $objectUri, $calendarData) {
|
||||
|
||||
$this->calendarData[$calendarId][$objectUri] = [
|
||||
'calendardata' => $calendarData,
|
||||
'calendarid' => $calendarId,
|
||||
'uri' => $objectUri,
|
||||
];
|
||||
return '"' . md5($calendarData) . '"';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing calendar object.
|
||||
*
|
||||
* @param string $calendarId
|
||||
* @param string $objectUri
|
||||
* @return void
|
||||
*/
|
||||
function deleteCalendarObject($calendarId, $objectUri) {
|
||||
|
||||
unset($this->calendarData[$calendarId][$objectUri]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,91 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Backend;
|
||||
|
||||
class MockScheduling extends Mock implements SchedulingSupport {
|
||||
|
||||
public $schedulingObjects = [];
|
||||
|
||||
/**
|
||||
* Returns a single scheduling object.
|
||||
*
|
||||
* The returned array should contain the following elements:
|
||||
* * uri - A unique basename for the object. This will be used to
|
||||
* construct a full uri.
|
||||
* * calendardata - The iCalendar object
|
||||
* * lastmodified - The last modification date. Can be an int for a unix
|
||||
* timestamp, or a PHP DateTime object.
|
||||
* * etag - A unique token that must change if the object changed.
|
||||
* * size - The size of the object, in bytes.
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @param string $objectUri
|
||||
* @return array
|
||||
*/
|
||||
function getSchedulingObject($principalUri, $objectUri) {
|
||||
|
||||
if (isset($this->schedulingObjects[$principalUri][$objectUri])) {
|
||||
return $this->schedulingObjects[$principalUri][$objectUri];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all scheduling objects for the inbox collection.
|
||||
*
|
||||
* These objects should be returned as an array. Every item in the array
|
||||
* should follow the same structure as returned from getSchedulingObject.
|
||||
*
|
||||
* The main difference is that 'calendardata' is optional.
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @return array
|
||||
*/
|
||||
function getSchedulingObjects($principalUri) {
|
||||
|
||||
if (isset($this->schedulingObjects[$principalUri])) {
|
||||
return array_values($this->schedulingObjects[$principalUri]);
|
||||
}
|
||||
return [];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a scheduling object
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @param string $objectUri
|
||||
* @return void
|
||||
*/
|
||||
function deleteSchedulingObject($principalUri, $objectUri) {
|
||||
|
||||
if (isset($this->schedulingObjects[$principalUri][$objectUri])) {
|
||||
unset($this->schedulingObjects[$principalUri][$objectUri]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new scheduling object. This should land in a users' inbox.
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @param string $objectUri
|
||||
* @param string $objectData;
|
||||
* @return void
|
||||
*/
|
||||
function createSchedulingObject($principalUri, $objectUri, $objectData) {
|
||||
|
||||
if (!isset($this->schedulingObjects[$principalUri])) {
|
||||
$this->schedulingObjects[$principalUri] = [];
|
||||
}
|
||||
$this->schedulingObjects[$principalUri][$objectUri] = [
|
||||
'uri' => $objectUri,
|
||||
'calendardata' => $objectData,
|
||||
'lastmodified' => null,
|
||||
'etag' => '"' . md5($objectData) . '"',
|
||||
'size' => strlen($objectData)
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,204 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Backend;
|
||||
|
||||
use Sabre\CalDAV\Xml\Notification\NotificationInterface;
|
||||
use Sabre\DAV;
|
||||
|
||||
class MockSharing extends Mock implements NotificationSupport, SharingSupport {
|
||||
|
||||
private $shares = [];
|
||||
private $notifications;
|
||||
|
||||
function __construct(array $calendars = [], array $calendarData = [], array $notifications = []) {
|
||||
|
||||
parent::__construct($calendars, $calendarData);
|
||||
$this->notifications = $notifications;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of calendars for a principal.
|
||||
*
|
||||
* Every project is an array with the following keys:
|
||||
* * id, a unique id that will be used by other functions to modify the
|
||||
* calendar. This can be the same as the uri or a database key.
|
||||
* * uri, which the basename of the uri with which the calendar is
|
||||
* accessed.
|
||||
* * principalUri. The owner of the calendar. Almost always the same as
|
||||
* principalUri passed to this method.
|
||||
*
|
||||
* Furthermore it can contain webdav properties in clark notation. A very
|
||||
* common one is '{DAV:}displayname'.
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @return array
|
||||
*/
|
||||
function getCalendarsForUser($principalUri) {
|
||||
|
||||
$calendars = parent::getCalendarsForUser($principalUri);
|
||||
foreach ($calendars as $k => $calendar) {
|
||||
|
||||
if (isset($calendar['share-access'])) {
|
||||
continue;
|
||||
}
|
||||
if (!empty($this->shares[$calendar['id']])) {
|
||||
$calendar['share-access'] = DAV\Sharing\Plugin::ACCESS_SHAREDOWNER;
|
||||
} else {
|
||||
$calendar['share-access'] = DAV\Sharing\Plugin::ACCESS_NOTSHARED;
|
||||
}
|
||||
$calendars[$k] = $calendar;
|
||||
|
||||
}
|
||||
return $calendars;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of notifications for a given principal url.
|
||||
*
|
||||
* The returned array should only consist of implementations of
|
||||
* Sabre\CalDAV\Notifications\INotificationType.
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @return array
|
||||
*/
|
||||
function getNotificationsForPrincipal($principalUri) {
|
||||
|
||||
if (isset($this->notifications[$principalUri])) {
|
||||
return $this->notifications[$principalUri];
|
||||
}
|
||||
return [];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This deletes a specific notifcation.
|
||||
*
|
||||
* This may be called by a client once it deems a notification handled.
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @param NotificationInterface $notification
|
||||
* @return void
|
||||
*/
|
||||
function deleteNotification($principalUri, NotificationInterface $notification) {
|
||||
|
||||
foreach ($this->notifications[$principalUri] as $key => $value) {
|
||||
if ($notification === $value) {
|
||||
unset($this->notifications[$principalUri][$key]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the list of shares.
|
||||
*
|
||||
* @param mixed $calendarId
|
||||
* @param \Sabre\DAV\Xml\Element\Sharee[] $sharees
|
||||
* @return void
|
||||
*/
|
||||
function updateInvites($calendarId, array $sharees) {
|
||||
|
||||
if (!isset($this->shares[$calendarId])) {
|
||||
$this->shares[$calendarId] = [];
|
||||
}
|
||||
|
||||
foreach ($sharees as $sharee) {
|
||||
|
||||
$existingKey = null;
|
||||
foreach ($this->shares[$calendarId] as $k => $existingSharee) {
|
||||
if ($sharee->href === $existingSharee->href) {
|
||||
$existingKey = $k;
|
||||
}
|
||||
}
|
||||
// Just making sure we're not affecting an existing copy.
|
||||
$sharee = clone $sharee;
|
||||
$sharee->inviteStatus = DAV\Sharing\Plugin::INVITE_NORESPONSE;
|
||||
|
||||
if ($sharee->access === DAV\Sharing\Plugin::ACCESS_NOACCESS) {
|
||||
// It's a removal
|
||||
unset($this->shares[$calendarId][$existingKey]);
|
||||
} elseif ($existingKey) {
|
||||
// It's an update
|
||||
$this->shares[$calendarId][$existingKey] = $sharee;
|
||||
} else {
|
||||
// It's an addition
|
||||
$this->shares[$calendarId][] = $sharee;
|
||||
}
|
||||
}
|
||||
|
||||
// Re-numbering keys
|
||||
$this->shares[$calendarId] = array_values($this->shares[$calendarId]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of people whom this calendar is shared with.
|
||||
*
|
||||
* Every item in the returned list must be a Sharee object with at
|
||||
* least the following properties set:
|
||||
* $href
|
||||
* $shareAccess
|
||||
* $inviteStatus
|
||||
*
|
||||
* and optionally:
|
||||
* $properties
|
||||
*
|
||||
* @param mixed $calendarId
|
||||
* @return \Sabre\DAV\Xml\Element\Sharee[]
|
||||
*/
|
||||
function getInvites($calendarId) {
|
||||
|
||||
if (!isset($this->shares[$calendarId])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->shares[$calendarId];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called when a user replied to a request to share.
|
||||
*
|
||||
* @param string href The sharee who is replying (often a mailto: address)
|
||||
* @param int status One of the \Sabre\DAV\Sharing\Plugin::INVITE_* constants
|
||||
* @param string $calendarUri The url to the calendar thats being shared
|
||||
* @param string $inReplyTo The unique id this message is a response to
|
||||
* @param string $summary A description of the reply
|
||||
* @return void
|
||||
*/
|
||||
function shareReply($href, $status, $calendarUri, $inReplyTo, $summary = null) {
|
||||
|
||||
// This operation basically doesn't do anything yet
|
||||
if ($status === DAV\Sharing\Plugin::INVITE_ACCEPTED) {
|
||||
return 'calendars/blabla/calendar';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Publishes a calendar
|
||||
*
|
||||
* @param mixed $calendarId
|
||||
* @param bool $value
|
||||
* @return void
|
||||
*/
|
||||
function setPublishStatus($calendarId, $value) {
|
||||
|
||||
foreach ($this->calendars as $k => $cal) {
|
||||
if ($cal['id'] === $calendarId) {
|
||||
if (!$value) {
|
||||
unset($cal['{http://calendarserver.org/ns/}publish-url']);
|
||||
} else {
|
||||
$cal['{http://calendarserver.org/ns/}publish-url'] = 'http://example.org/public/ ' . $calendarId . '.ics';
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new DAV\Exception('Calendar with id "' . $calendarId . '" not found');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,156 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Backend;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\DAV;
|
||||
|
||||
/**
|
||||
* This is a mock CalDAV backend that supports subscriptions.
|
||||
*
|
||||
* All data is retained in memory temporarily. It's primary purpose is
|
||||
* unit-tests.
|
||||
*
|
||||
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
class MockSubscriptionSupport extends Mock implements SubscriptionSupport {
|
||||
|
||||
/**
|
||||
* Subscription list
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $subs = [];
|
||||
|
||||
/**
|
||||
* Returns a list of subscriptions for a principal.
|
||||
*
|
||||
* Every subscription is an array with the following keys:
|
||||
* * id, a unique id that will be used by other functions to modify the
|
||||
* subscription. This can be the same as the uri or a database key.
|
||||
* * uri. This is just the 'base uri' or 'filename' of the subscription.
|
||||
* * principaluri. The owner of the subscription. Almost always the same as
|
||||
* principalUri passed to this method.
|
||||
* * source. Url to the actual feed
|
||||
*
|
||||
* Furthermore, all the subscription info must be returned too:
|
||||
*
|
||||
* 1. {DAV:}displayname
|
||||
* 2. {http://apple.com/ns/ical/}refreshrate
|
||||
* 3. {http://calendarserver.org/ns/}subscribed-strip-todos (omit if todos
|
||||
* should not be stripped).
|
||||
* 4. {http://calendarserver.org/ns/}subscribed-strip-alarms (omit if alarms
|
||||
* should not be stripped).
|
||||
* 5. {http://calendarserver.org/ns/}subscribed-strip-attachments (omit if
|
||||
* attachments should not be stripped).
|
||||
* 7. {http://apple.com/ns/ical/}calendar-color
|
||||
* 8. {http://apple.com/ns/ical/}calendar-order
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @return array
|
||||
*/
|
||||
function getSubscriptionsForUser($principalUri) {
|
||||
|
||||
if (isset($this->subs[$principalUri])) {
|
||||
return $this->subs[$principalUri];
|
||||
}
|
||||
return [];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new subscription for a principal.
|
||||
*
|
||||
* If the creation was a success, an id must be returned that can be used to reference
|
||||
* this subscription in other methods, such as updateSubscription.
|
||||
*
|
||||
* @param string $principalUri
|
||||
* @param string $uri
|
||||
* @param array $properties
|
||||
* @return mixed
|
||||
*/
|
||||
function createSubscription($principalUri, $uri, array $properties) {
|
||||
|
||||
$properties['uri'] = $uri;
|
||||
$properties['principaluri'] = $principalUri;
|
||||
$properties['source'] = $properties['{http://calendarserver.org/ns/}source']->getHref();
|
||||
|
||||
if (!isset($this->subs[$principalUri])) {
|
||||
$this->subs[$principalUri] = [];
|
||||
}
|
||||
|
||||
$id = [$principalUri, count($this->subs[$principalUri]) + 1];
|
||||
|
||||
$properties['id'] = $id;
|
||||
|
||||
$this->subs[$principalUri][] = array_merge($properties, [
|
||||
'id' => $id,
|
||||
]);
|
||||
|
||||
return $id;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a subscription
|
||||
*
|
||||
* The list of mutations is stored in a Sabre\DAV\PropPatch object.
|
||||
* To do the actual updates, you must tell this object which properties
|
||||
* you're going to process with the handle() method.
|
||||
*
|
||||
* Calling the handle method is like telling the PropPatch object "I
|
||||
* promise I can handle updating this property".
|
||||
*
|
||||
* Read the PropPatch documentation for more info and examples.
|
||||
*
|
||||
* @param mixed $subscriptionId
|
||||
* @param \Sabre\DAV\PropPatch $propPatch
|
||||
* @return void
|
||||
*/
|
||||
function updateSubscription($subscriptionId, DAV\PropPatch $propPatch) {
|
||||
|
||||
$found = null;
|
||||
foreach ($this->subs[$subscriptionId[0]] as &$sub) {
|
||||
|
||||
if ($sub['id'][1] === $subscriptionId[1]) {
|
||||
$found = & $sub;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!$found) return;
|
||||
|
||||
$propPatch->handleRemaining(function($mutations) use (&$found) {
|
||||
foreach ($mutations as $k => $v) {
|
||||
$found[$k] = $v;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a subscription
|
||||
*
|
||||
* @param mixed $subscriptionId
|
||||
* @return void
|
||||
*/
|
||||
function deleteSubscription($subscriptionId) {
|
||||
|
||||
foreach ($this->subs[$subscriptionId[0]] as $index => $sub) {
|
||||
|
||||
if ($sub['id'][1] === $subscriptionId[1]) {
|
||||
unset($this->subs[$subscriptionId[0]][$index]);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Backend;
|
||||
|
||||
class PDOMySQLTest extends AbstractPDOTest {
|
||||
|
||||
public $driver = 'mysql';
|
||||
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Backend;
|
||||
|
||||
class PDOPgSqlTest extends AbstractPDOTest {
|
||||
|
||||
public $driver = 'pgsql';
|
||||
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Backend;
|
||||
|
||||
class PDOSqliteTest extends AbstractPDOTest {
|
||||
|
||||
public $driver = 'sqlite';
|
||||
|
||||
}
|
||||
@ -1,445 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Backend;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\DAV;
|
||||
use Sabre\DAV\PropPatch;
|
||||
|
||||
class SimplePDOTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
protected $pdo;
|
||||
|
||||
function setUp() {
|
||||
|
||||
if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
|
||||
|
||||
if (file_exists(SABRE_TEMPDIR . '/testdb.sqlite'))
|
||||
unlink(SABRE_TEMPDIR . '/testdb.sqlite');
|
||||
|
||||
$pdo = new \PDO('sqlite:' . SABRE_TEMPDIR . '/testdb.sqlite');
|
||||
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$pdo->exec(<<<SQL
|
||||
CREATE TABLE simple_calendars (
|
||||
id INTEGER PRIMARY KEY ASC NOT NULL,
|
||||
uri TEXT NOT NULL,
|
||||
principaluri TEXT NOT NULL
|
||||
)
|
||||
SQL
|
||||
);
|
||||
$pdo->exec(<<<SQL
|
||||
CREATE TABLE simple_calendarobjects (
|
||||
id INTEGER PRIMARY KEY ASC NOT NULL,
|
||||
calendarid INT UNSIGNED NOT NULL,
|
||||
uri TEXT NOT NULL,
|
||||
calendardata TEXT
|
||||
);
|
||||
SQL
|
||||
);
|
||||
|
||||
$this->pdo = $pdo;
|
||||
|
||||
}
|
||||
|
||||
function testConstruct() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$this->assertTrue($backend instanceof SimplePDO);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testConstruct
|
||||
*/
|
||||
function testGetCalendarsForUserNoCalendars() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$calendars = $backend->getCalendarsForUser('principals/user2');
|
||||
$this->assertEquals([], $calendars);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testConstruct
|
||||
*/
|
||||
function testCreateCalendarAndFetch() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$returnedId = $backend->createCalendar('principals/user2', 'somerandomid', [
|
||||
'{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet(['VEVENT']),
|
||||
'{DAV:}displayname' => 'Hello!',
|
||||
'{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp('transparent'),
|
||||
]);
|
||||
$calendars = $backend->getCalendarsForUser('principals/user2');
|
||||
|
||||
$elementCheck = [
|
||||
'uri' => 'somerandomid',
|
||||
];
|
||||
|
||||
$this->assertInternalType('array', $calendars);
|
||||
$this->assertEquals(1, count($calendars));
|
||||
|
||||
foreach ($elementCheck as $name => $value) {
|
||||
|
||||
$this->assertArrayHasKey($name, $calendars[0]);
|
||||
$this->assertEquals($value, $calendars[0][$name]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testConstruct
|
||||
*/
|
||||
function testUpdateCalendarAndFetch() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
|
||||
//Creating a new calendar
|
||||
$newId = $backend->createCalendar('principals/user2', 'somerandomid', []);
|
||||
|
||||
$propPatch = new PropPatch([
|
||||
'{DAV:}displayname' => 'myCalendar',
|
||||
'{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp('transparent'),
|
||||
]);
|
||||
|
||||
// Updating the calendar
|
||||
$backend->updateCalendar($newId, $propPatch);
|
||||
$result = $propPatch->commit();
|
||||
|
||||
// Verifying the result of the update
|
||||
$this->assertFalse($result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCalendarAndFetch
|
||||
*/
|
||||
function testDeleteCalendar() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$returnedId = $backend->createCalendar('principals/user2', 'somerandomid', [
|
||||
'{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet(['VEVENT']),
|
||||
'{DAV:}displayname' => 'Hello!',
|
||||
]);
|
||||
|
||||
$backend->deleteCalendar($returnedId);
|
||||
|
||||
$calendars = $backend->getCalendarsForUser('principals/user2');
|
||||
$this->assertEquals([], $calendars);
|
||||
|
||||
}
|
||||
|
||||
function testCreateCalendarObject() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []);
|
||||
|
||||
$object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
|
||||
|
||||
$backend->createCalendarObject($returnedId, 'random-id', $object);
|
||||
|
||||
$result = $this->pdo->query('SELECT calendardata FROM simple_calendarobjects WHERE uri = "random-id"');
|
||||
$this->assertEquals([
|
||||
'calendardata' => $object,
|
||||
], $result->fetch(\PDO::FETCH_ASSOC));
|
||||
|
||||
}
|
||||
function testGetMultipleObjects() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []);
|
||||
|
||||
$object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
|
||||
|
||||
$backend->createCalendarObject($returnedId, 'id-1', $object);
|
||||
$backend->createCalendarObject($returnedId, 'id-2', $object);
|
||||
|
||||
$check = [
|
||||
[
|
||||
'id' => 1,
|
||||
'etag' => '"' . md5($object) . '"',
|
||||
'uri' => 'id-1',
|
||||
'size' => strlen($object),
|
||||
'calendardata' => $object,
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'etag' => '"' . md5($object) . '"',
|
||||
'uri' => 'id-2',
|
||||
'size' => strlen($object),
|
||||
'calendardata' => $object,
|
||||
],
|
||||
];
|
||||
|
||||
$result = $backend->getMultipleCalendarObjects($returnedId, ['id-1', 'id-2']);
|
||||
|
||||
foreach ($check as $index => $props) {
|
||||
|
||||
foreach ($props as $key => $value) {
|
||||
|
||||
if ($key !== 'lastmodified') {
|
||||
$this->assertEquals($value, $result[$index][$key]);
|
||||
} else {
|
||||
$this->assertTrue(isset($result[$index][$key]));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCalendarObject
|
||||
*/
|
||||
function testGetCalendarObjects() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []);
|
||||
|
||||
$object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
|
||||
$backend->createCalendarObject($returnedId, 'random-id', $object);
|
||||
|
||||
$data = $backend->getCalendarObjects($returnedId);
|
||||
|
||||
$this->assertEquals(1, count($data));
|
||||
$data = $data[0];
|
||||
|
||||
$this->assertEquals('random-id', $data['uri']);
|
||||
$this->assertEquals(strlen($object), $data['size']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCalendarObject
|
||||
*/
|
||||
function testGetCalendarObjectByUID() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []);
|
||||
|
||||
$object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
|
||||
$backend->createCalendarObject($returnedId, 'random-id', $object);
|
||||
|
||||
$this->assertNull(
|
||||
$backend->getCalendarObjectByUID('principals/user2', 'bar')
|
||||
);
|
||||
$this->assertEquals(
|
||||
'somerandomid/random-id',
|
||||
$backend->getCalendarObjectByUID('principals/user2', 'foo')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCalendarObject
|
||||
*/
|
||||
function testUpdateCalendarObject() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []);
|
||||
|
||||
$object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
|
||||
$object2 = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20130101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
|
||||
$backend->createCalendarObject($returnedId, 'random-id', $object);
|
||||
$backend->updateCalendarObject($returnedId, 'random-id', $object2);
|
||||
|
||||
$data = $backend->getCalendarObject($returnedId, 'random-id');
|
||||
|
||||
$this->assertEquals($object2, $data['calendardata']);
|
||||
$this->assertEquals('random-id', $data['uri']);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @depends testCreateCalendarObject
|
||||
*/
|
||||
function testDeleteCalendarObject() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$returnedId = $backend->createCalendar('principals/user2', 'somerandomid', []);
|
||||
|
||||
$object = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n";
|
||||
$backend->createCalendarObject($returnedId, 'random-id', $object);
|
||||
$backend->deleteCalendarObject($returnedId, 'random-id');
|
||||
|
||||
$data = $backend->getCalendarObject($returnedId, 'random-id');
|
||||
$this->assertNull($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testCalendarQueryNoResult() {
|
||||
|
||||
$abstract = new SimplePDO($this->pdo);
|
||||
$filters = [
|
||||
'name' => 'VCALENDAR',
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VJOURNAL',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
],
|
||||
],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
];
|
||||
|
||||
$this->assertEquals([
|
||||
], $abstract->calendarQuery(1, $filters));
|
||||
|
||||
}
|
||||
|
||||
function testCalendarQueryTodo() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$backend->createCalendarObject(1, "todo", "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n");
|
||||
$backend->createCalendarObject(1, "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
|
||||
|
||||
$filters = [
|
||||
'name' => 'VCALENDAR',
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VTODO',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
],
|
||||
],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
];
|
||||
|
||||
$this->assertEquals([
|
||||
"todo",
|
||||
], $backend->calendarQuery(1, $filters));
|
||||
|
||||
}
|
||||
function testCalendarQueryTodoNotMatch() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$backend->createCalendarObject(1, "todo", "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n");
|
||||
$backend->createCalendarObject(1, "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
|
||||
|
||||
$filters = [
|
||||
'name' => 'VCALENDAR',
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VTODO',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [
|
||||
[
|
||||
'name' => 'summary',
|
||||
'text-match' => null,
|
||||
'time-range' => null,
|
||||
'param-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
],
|
||||
],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
],
|
||||
],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
];
|
||||
|
||||
$this->assertEquals([
|
||||
], $backend->calendarQuery(1, $filters));
|
||||
|
||||
}
|
||||
|
||||
function testCalendarQueryNoFilter() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$backend->createCalendarObject(1, "todo", "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n");
|
||||
$backend->createCalendarObject(1, "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
|
||||
|
||||
$filters = [
|
||||
'name' => 'VCALENDAR',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
];
|
||||
|
||||
$result = $backend->calendarQuery(1, $filters);
|
||||
$this->assertTrue(in_array('todo', $result));
|
||||
$this->assertTrue(in_array('event', $result));
|
||||
|
||||
}
|
||||
|
||||
function testCalendarQueryTimeRange() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$backend->createCalendarObject(1, "todo", "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n");
|
||||
$backend->createCalendarObject(1, "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
|
||||
$backend->createCalendarObject(1, "event2", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART;VALUE=DATE:20120103\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
|
||||
|
||||
$filters = [
|
||||
'name' => 'VCALENDAR',
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VEVENT',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('20120103'),
|
||||
'end' => new \DateTime('20120104'),
|
||||
],
|
||||
],
|
||||
],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
];
|
||||
|
||||
$this->assertEquals([
|
||||
"event2",
|
||||
], $backend->calendarQuery(1, $filters));
|
||||
|
||||
}
|
||||
function testCalendarQueryTimeRangeNoEnd() {
|
||||
|
||||
$backend = new SimplePDO($this->pdo);
|
||||
$backend->createCalendarObject(1, "todo", "BEGIN:VCALENDAR\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n");
|
||||
$backend->createCalendarObject(1, "event", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120101\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
|
||||
$backend->createCalendarObject(1, "event2", "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nDTSTART:20120103\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
|
||||
|
||||
$filters = [
|
||||
'name' => 'VCALENDAR',
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VEVENT',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('20120102'),
|
||||
'end' => null,
|
||||
],
|
||||
],
|
||||
],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
];
|
||||
|
||||
$this->assertEquals([
|
||||
"event2",
|
||||
], $backend->calendarQuery(1, $filters));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
class CalendarHomeNotificationsTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function testGetChildrenNoSupport() {
|
||||
|
||||
$backend = new Backend\Mock();
|
||||
$calendarHome = new CalendarHome($backend, ['uri' => 'principals/user']);
|
||||
|
||||
$this->assertEquals(
|
||||
[],
|
||||
$calendarHome->getChildren()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\NotFound
|
||||
*/
|
||||
function testGetChildNoSupport() {
|
||||
|
||||
$backend = new Backend\Mock();
|
||||
$calendarHome = new CalendarHome($backend, ['uri' => 'principals/user']);
|
||||
$calendarHome->getChild('notifications');
|
||||
|
||||
}
|
||||
|
||||
function testGetChildren() {
|
||||
|
||||
$backend = new Backend\MockSharing();
|
||||
$calendarHome = new CalendarHome($backend, ['uri' => 'principals/user']);
|
||||
|
||||
$result = $calendarHome->getChildren();
|
||||
$this->assertEquals('notifications', $result[0]->getName());
|
||||
|
||||
}
|
||||
|
||||
function testGetChild() {
|
||||
|
||||
$backend = new Backend\MockSharing();
|
||||
$calendarHome = new CalendarHome($backend, ['uri' => 'principals/user']);
|
||||
$result = $calendarHome->getChild('notifications');
|
||||
$this->assertEquals('notifications', $result->getName());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,80 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\DAV;
|
||||
|
||||
class CalendarHomeSharedCalendarsTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
protected $backend;
|
||||
|
||||
function getInstance() {
|
||||
|
||||
$calendars = [
|
||||
[
|
||||
'id' => 1,
|
||||
'principaluri' => 'principals/user1',
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/cal1',
|
||||
'{http://sabredav.org/ns}owner-principal' => 'principal/owner',
|
||||
'{http://sabredav.org/ns}read-only' => false,
|
||||
'principaluri' => 'principals/user1',
|
||||
],
|
||||
];
|
||||
|
||||
$this->backend = new Backend\MockSharing(
|
||||
$calendars,
|
||||
[],
|
||||
[]
|
||||
);
|
||||
|
||||
return new CalendarHome($this->backend, [
|
||||
'uri' => 'principals/user1'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$instance = $this->getInstance();
|
||||
$this->assertEquals('user1', $instance->getName());
|
||||
|
||||
}
|
||||
|
||||
function testGetChildren() {
|
||||
|
||||
$instance = $this->getInstance();
|
||||
$children = $instance->getChildren();
|
||||
$this->assertEquals(3, count($children));
|
||||
|
||||
// Testing if we got all the objects back.
|
||||
$sharedCalendars = 0;
|
||||
$hasOutbox = false;
|
||||
$hasNotifications = false;
|
||||
|
||||
foreach ($children as $child) {
|
||||
|
||||
if ($child instanceof ISharedCalendar) {
|
||||
$sharedCalendars++;
|
||||
}
|
||||
if ($child instanceof Notifications\ICollection) {
|
||||
$hasNotifications = true;
|
||||
}
|
||||
|
||||
}
|
||||
$this->assertEquals(2, $sharedCalendars);
|
||||
$this->assertTrue($hasNotifications);
|
||||
|
||||
}
|
||||
|
||||
function testShareReply() {
|
||||
|
||||
$instance = $this->getInstance();
|
||||
$result = $instance->shareReply('uri', DAV\Sharing\Plugin::INVITE_DECLINED, 'curi', '1');
|
||||
$this->assertNull($result);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,85 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\DAV\MkCol;
|
||||
|
||||
class CalendarHomeSubscriptionsTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
protected $backend;
|
||||
|
||||
function getInstance() {
|
||||
|
||||
$props = [
|
||||
'{DAV:}displayname' => 'baz',
|
||||
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/test.ics'),
|
||||
];
|
||||
$principal = [
|
||||
'uri' => 'principals/user1'
|
||||
];
|
||||
$this->backend = new Backend\MockSubscriptionSupport([], []);
|
||||
$this->backend->createSubscription('principals/user1', 'uri', $props);
|
||||
|
||||
return new CalendarHome($this->backend, $principal);
|
||||
|
||||
}
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$instance = $this->getInstance();
|
||||
$this->assertEquals('user1', $instance->getName());
|
||||
|
||||
}
|
||||
|
||||
function testGetChildren() {
|
||||
|
||||
$instance = $this->getInstance();
|
||||
$children = $instance->getChildren();
|
||||
$this->assertEquals(1, count($children));
|
||||
foreach ($children as $child) {
|
||||
if ($child instanceof Subscriptions\Subscription) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
$this->fail('There were no subscription nodes in the calendar home');
|
||||
|
||||
}
|
||||
|
||||
function testCreateSubscription() {
|
||||
|
||||
$instance = $this->getInstance();
|
||||
$rt = ['{DAV:}collection', '{http://calendarserver.org/ns/}subscribed'];
|
||||
|
||||
$props = [
|
||||
'{DAV:}displayname' => 'baz',
|
||||
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/test2.ics'),
|
||||
];
|
||||
$instance->createExtendedCollection('sub2', new MkCol($rt, $props));
|
||||
|
||||
$children = $instance->getChildren();
|
||||
$this->assertEquals(2, count($children));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\InvalidResourceType
|
||||
*/
|
||||
function testNoSubscriptionSupport() {
|
||||
|
||||
$principal = [
|
||||
'uri' => 'principals/user1'
|
||||
];
|
||||
$backend = new Backend\Mock([], []);
|
||||
$uC = new CalendarHome($backend, $principal);
|
||||
|
||||
$rt = ['{DAV:}collection', '{http://calendarserver.org/ns/}subscribed'];
|
||||
|
||||
$props = [
|
||||
'{DAV:}displayname' => 'baz',
|
||||
'{http://calendarserver.org/ns/}source' => new \Sabre\DAV\Xml\Property\Href('http://example.org/test2.ics'),
|
||||
];
|
||||
$uC->createExtendedCollection('sub2', new MkCol($rt, $props));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,215 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\DAV;
|
||||
use Sabre\DAV\MkCol;
|
||||
|
||||
class CalendarHomeTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Sabre\CalDAV\CalendarHome
|
||||
*/
|
||||
protected $usercalendars;
|
||||
|
||||
/**
|
||||
* @var Backend\BackendInterface
|
||||
*/
|
||||
protected $backend;
|
||||
|
||||
function setup() {
|
||||
|
||||
$this->backend = TestUtil::getBackend();
|
||||
$this->usercalendars = new CalendarHome($this->backend, [
|
||||
'uri' => 'principals/user1'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$this->assertEquals('user1', $this->usercalendars->getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\NotFound
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testGetChildNotFound() {
|
||||
|
||||
$this->usercalendars->getChild('randomname');
|
||||
|
||||
}
|
||||
|
||||
function testChildExists() {
|
||||
|
||||
$this->assertFalse($this->usercalendars->childExists('foo'));
|
||||
$this->assertTrue($this->usercalendars->childExists('UUID-123467'));
|
||||
|
||||
}
|
||||
|
||||
function testGetOwner() {
|
||||
|
||||
$this->assertEquals('principals/user1', $this->usercalendars->getOwner());
|
||||
|
||||
}
|
||||
|
||||
function testGetGroup() {
|
||||
|
||||
$this->assertNull($this->usercalendars->getGroup());
|
||||
|
||||
}
|
||||
|
||||
function testGetACL() {
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}write',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}write',
|
||||
'principal' => 'principals/user1/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1/calendar-proxy-read',
|
||||
'protected' => true,
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expected, $this->usercalendars->getACL());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testSetACL() {
|
||||
|
||||
$this->usercalendars->setACL([]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\Forbidden
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testSetName() {
|
||||
|
||||
$this->usercalendars->setName('bla');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\Forbidden
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testDelete() {
|
||||
|
||||
$this->usercalendars->delete();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testGetLastModified() {
|
||||
|
||||
$this->assertNull($this->usercalendars->getLastModified());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\MethodNotAllowed
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testCreateFile() {
|
||||
|
||||
$this->usercalendars->createFile('bla');
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testCreateDirectory() {
|
||||
|
||||
$this->usercalendars->createDirectory('bla');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testCreateExtendedCollection() {
|
||||
|
||||
$mkCol = new MkCol(
|
||||
['{DAV:}collection', '{urn:ietf:params:xml:ns:caldav}calendar'],
|
||||
[]
|
||||
);
|
||||
$result = $this->usercalendars->createExtendedCollection('newcalendar', $mkCol);
|
||||
$this->assertNull($result);
|
||||
$cals = $this->backend->getCalendarsForUser('principals/user1');
|
||||
$this->assertEquals(3, count($cals));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\InvalidResourceType
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testCreateExtendedCollectionBadResourceType() {
|
||||
|
||||
$mkCol = new MkCol(
|
||||
['{DAV:}collection', '{DAV:}blabla'],
|
||||
[]
|
||||
);
|
||||
$this->usercalendars->createExtendedCollection('newcalendar', $mkCol);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\InvalidResourceType
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testCreateExtendedCollectionNotACalendar() {
|
||||
|
||||
$mkCol = new MkCol(
|
||||
['{DAV:}collection'],
|
||||
[]
|
||||
);
|
||||
$this->usercalendars->createExtendedCollection('newcalendar', $mkCol);
|
||||
|
||||
}
|
||||
|
||||
function testGetSupportedPrivilegesSet() {
|
||||
|
||||
$this->assertNull($this->usercalendars->getSupportedPrivilegeSet());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\NotImplemented
|
||||
*/
|
||||
function testShareReplyFail() {
|
||||
|
||||
$this->usercalendars->shareReply('uri', DAV\Sharing\Plugin::INVITE_DECLINED, 'curi', '1');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,383 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
require_once 'Sabre/CalDAV/TestUtil.php';
|
||||
|
||||
class CalendarObjectTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Sabre\CalDAV\Backend_PDO
|
||||
*/
|
||||
protected $backend;
|
||||
/**
|
||||
* @var Sabre\CalDAV\Calendar
|
||||
*/
|
||||
protected $calendar;
|
||||
protected $principalBackend;
|
||||
|
||||
function setup() {
|
||||
|
||||
$this->backend = TestUtil::getBackend();
|
||||
|
||||
$calendars = $this->backend->getCalendarsForUser('principals/user1');
|
||||
$this->assertEquals(2, count($calendars));
|
||||
$this->calendar = new Calendar($this->backend, $calendars[0]);
|
||||
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
|
||||
unset($this->calendar);
|
||||
unset($this->backend);
|
||||
|
||||
}
|
||||
|
||||
function testSetup() {
|
||||
|
||||
$children = $this->calendar->getChildren();
|
||||
$this->assertTrue($children[0] instanceof CalendarObject);
|
||||
|
||||
$this->assertInternalType('string', $children[0]->getName());
|
||||
$this->assertInternalType('string', $children[0]->get());
|
||||
$this->assertInternalType('string', $children[0]->getETag());
|
||||
$this->assertEquals('text/calendar; charset=utf-8', $children[0]->getContentType());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
function testInvalidArg1() {
|
||||
|
||||
$obj = new CalendarObject(
|
||||
new Backend\Mock([], []),
|
||||
[],
|
||||
[]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
function testInvalidArg2() {
|
||||
|
||||
$obj = new CalendarObject(
|
||||
new Backend\Mock([], []),
|
||||
[],
|
||||
['calendarid' => '1']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSetup
|
||||
*/
|
||||
function testPut() {
|
||||
|
||||
$children = $this->calendar->getChildren();
|
||||
$this->assertTrue($children[0] instanceof CalendarObject);
|
||||
$newData = TestUtil::getTestCalendarData();
|
||||
|
||||
$children[0]->put($newData);
|
||||
$this->assertEquals($newData, $children[0]->get());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSetup
|
||||
*/
|
||||
function testPutStream() {
|
||||
|
||||
$children = $this->calendar->getChildren();
|
||||
$this->assertTrue($children[0] instanceof CalendarObject);
|
||||
$newData = TestUtil::getTestCalendarData();
|
||||
|
||||
$stream = fopen('php://temp', 'r+');
|
||||
fwrite($stream, $newData);
|
||||
rewind($stream);
|
||||
$children[0]->put($stream);
|
||||
$this->assertEquals($newData, $children[0]->get());
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @depends testSetup
|
||||
*/
|
||||
function testDelete() {
|
||||
|
||||
$children = $this->calendar->getChildren();
|
||||
$this->assertTrue($children[0] instanceof CalendarObject);
|
||||
|
||||
$obj = $children[0];
|
||||
$obj->delete();
|
||||
|
||||
$children2 = $this->calendar->getChildren();
|
||||
$this->assertEquals(count($children) - 1, count($children2));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSetup
|
||||
*/
|
||||
function testGetLastModified() {
|
||||
|
||||
$children = $this->calendar->getChildren();
|
||||
$this->assertTrue($children[0] instanceof CalendarObject);
|
||||
|
||||
$obj = $children[0];
|
||||
|
||||
$lastMod = $obj->getLastModified();
|
||||
$this->assertTrue(is_int($lastMod) || ctype_digit($lastMod) || is_null($lastMod));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSetup
|
||||
*/
|
||||
function testGetSize() {
|
||||
|
||||
$children = $this->calendar->getChildren();
|
||||
$this->assertTrue($children[0] instanceof CalendarObject);
|
||||
|
||||
$obj = $children[0];
|
||||
|
||||
$size = $obj->getSize();
|
||||
$this->assertInternalType('int', $size);
|
||||
|
||||
}
|
||||
|
||||
function testGetOwner() {
|
||||
|
||||
$children = $this->calendar->getChildren();
|
||||
$this->assertTrue($children[0] instanceof CalendarObject);
|
||||
|
||||
$obj = $children[0];
|
||||
$this->assertEquals('principals/user1', $obj->getOwner());
|
||||
|
||||
}
|
||||
|
||||
function testGetGroup() {
|
||||
|
||||
$children = $this->calendar->getChildren();
|
||||
$this->assertTrue($children[0] instanceof CalendarObject);
|
||||
|
||||
$obj = $children[0];
|
||||
$this->assertNull($obj->getGroup());
|
||||
|
||||
}
|
||||
|
||||
function testGetACL() {
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1/calendar-proxy-read',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}write',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}write',
|
||||
'principal' => 'principals/user1/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$children = $this->calendar->getChildren();
|
||||
$this->assertTrue($children[0] instanceof CalendarObject);
|
||||
|
||||
$obj = $children[0];
|
||||
$this->assertEquals($expected, $obj->getACL());
|
||||
|
||||
}
|
||||
|
||||
function testDefaultACL() {
|
||||
|
||||
$backend = new Backend\Mock([], []);
|
||||
$calendarObject = new CalendarObject($backend, ['principaluri' => 'principals/user1'], ['calendarid' => 1, 'uri' => 'foo']);
|
||||
$expected = [
|
||||
[
|
||||
'privilege' => '{DAV:}all',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}all',
|
||||
'principal' => 'principals/user1/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1/calendar-proxy-read',
|
||||
'protected' => true,
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expected, $calendarObject->getACL());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testSetACL() {
|
||||
|
||||
$children = $this->calendar->getChildren();
|
||||
$this->assertTrue($children[0] instanceof CalendarObject);
|
||||
|
||||
$obj = $children[0];
|
||||
$obj->setACL([]);
|
||||
|
||||
}
|
||||
|
||||
function testGet() {
|
||||
|
||||
$children = $this->calendar->getChildren();
|
||||
$this->assertTrue($children[0] instanceof CalendarObject);
|
||||
|
||||
$obj = $children[0];
|
||||
|
||||
$expected = "BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//Apple Inc.//iCal 4.0.1//EN
|
||||
CALSCALE:GREGORIAN
|
||||
BEGIN:VTIMEZONE
|
||||
TZID:Asia/Seoul
|
||||
BEGIN:DAYLIGHT
|
||||
TZOFFSETFROM:+0900
|
||||
RRULE:FREQ=YEARLY;UNTIL=19880507T150000Z;BYMONTH=5;BYDAY=2SU
|
||||
DTSTART:19870510T000000
|
||||
TZNAME:GMT+09:00
|
||||
TZOFFSETTO:+1000
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
TZOFFSETFROM:+1000
|
||||
DTSTART:19881009T000000
|
||||
TZNAME:GMT+09:00
|
||||
TZOFFSETTO:+0900
|
||||
END:STANDARD
|
||||
END:VTIMEZONE
|
||||
BEGIN:VEVENT
|
||||
CREATED:20100225T154229Z
|
||||
UID:39A6B5ED-DD51-4AFE-A683-C35EE3749627
|
||||
TRANSP:TRANSPARENT
|
||||
SUMMARY:Something here
|
||||
DTSTAMP:20100228T130202Z
|
||||
DTSTART;TZID=Asia/Seoul:20100223T060000
|
||||
DTEND;TZID=Asia/Seoul:20100223T070000
|
||||
ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com
|
||||
SEQUENCE:2
|
||||
END:VEVENT
|
||||
END:VCALENDAR";
|
||||
|
||||
|
||||
|
||||
$this->assertEquals($expected, $obj->get());
|
||||
|
||||
}
|
||||
|
||||
function testGetRefetch() {
|
||||
|
||||
$backend = new Backend\Mock([], [
|
||||
1 => [
|
||||
'foo' => [
|
||||
'calendardata' => 'foo',
|
||||
'uri' => 'foo'
|
||||
],
|
||||
]
|
||||
]);
|
||||
$obj = new CalendarObject($backend, ['id' => 1], ['uri' => 'foo']);
|
||||
|
||||
$this->assertEquals('foo', $obj->get());
|
||||
|
||||
}
|
||||
|
||||
function testGetEtag1() {
|
||||
|
||||
$objectInfo = [
|
||||
'calendardata' => 'foo',
|
||||
'uri' => 'foo',
|
||||
'etag' => 'bar',
|
||||
'calendarid' => 1
|
||||
];
|
||||
|
||||
$backend = new Backend\Mock([], []);
|
||||
$obj = new CalendarObject($backend, [], $objectInfo);
|
||||
|
||||
$this->assertEquals('bar', $obj->getETag());
|
||||
|
||||
}
|
||||
|
||||
function testGetEtag2() {
|
||||
|
||||
$objectInfo = [
|
||||
'calendardata' => 'foo',
|
||||
'uri' => 'foo',
|
||||
'calendarid' => 1
|
||||
];
|
||||
|
||||
$backend = new Backend\Mock([], []);
|
||||
$obj = new CalendarObject($backend, [], $objectInfo);
|
||||
|
||||
$this->assertEquals('"' . md5('foo') . '"', $obj->getETag());
|
||||
|
||||
}
|
||||
|
||||
function testGetSupportedPrivilegesSet() {
|
||||
|
||||
$objectInfo = [
|
||||
'calendardata' => 'foo',
|
||||
'uri' => 'foo',
|
||||
'calendarid' => 1
|
||||
];
|
||||
|
||||
$backend = new Backend\Mock([], []);
|
||||
$obj = new CalendarObject($backend, [], $objectInfo);
|
||||
$this->assertNull($obj->getSupportedPrivilegeSet());
|
||||
|
||||
}
|
||||
|
||||
function testGetSize1() {
|
||||
|
||||
$objectInfo = [
|
||||
'calendardata' => 'foo',
|
||||
'uri' => 'foo',
|
||||
'calendarid' => 1
|
||||
];
|
||||
|
||||
$backend = new Backend\Mock([], []);
|
||||
$obj = new CalendarObject($backend, [], $objectInfo);
|
||||
$this->assertEquals(3, $obj->getSize());
|
||||
|
||||
}
|
||||
|
||||
function testGetSize2() {
|
||||
|
||||
$objectInfo = [
|
||||
'uri' => 'foo',
|
||||
'calendarid' => 1,
|
||||
'size' => 4,
|
||||
];
|
||||
|
||||
$backend = new Backend\Mock([], []);
|
||||
$obj = new CalendarObject($backend, [], $objectInfo);
|
||||
$this->assertEquals(4, $obj->getSize());
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,122 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
class CalendarQueryVAlarmTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* This test is specifically for a time-range query on a VALARM, contained
|
||||
* in a VEVENT that's recurring
|
||||
*/
|
||||
function testValarm() {
|
||||
|
||||
$vcalendar = new VObject\Component\VCalendar();
|
||||
|
||||
$vevent = $vcalendar->createComponent('VEVENT');
|
||||
$vevent->RRULE = 'FREQ=MONTHLY';
|
||||
$vevent->DTSTART = '20120101T120000Z';
|
||||
$vevent->UID = 'bla';
|
||||
|
||||
$valarm = $vcalendar->createComponent('VALARM');
|
||||
$valarm->TRIGGER = '-P15D';
|
||||
$vevent->add($valarm);
|
||||
|
||||
|
||||
$vcalendar->add($vevent);
|
||||
|
||||
$filter = [
|
||||
'name' => 'VCALENDAR',
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
'prop-filters' => [],
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VEVENT',
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
'prop-filters' => [],
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VALARM',
|
||||
'is-not-defined' => false,
|
||||
'prop-filters' => [],
|
||||
'comp-filters' => [],
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2012-05-10'),
|
||||
'end' => new \DateTime('2012-05-20'),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$validator = new CalendarQueryValidator();
|
||||
$this->assertTrue($validator->validate($vcalendar, $filter));
|
||||
|
||||
$vcalendar = new VObject\Component\VCalendar();
|
||||
|
||||
// A limited recurrence rule, should return false
|
||||
$vevent = $vcalendar->createComponent('VEVENT');
|
||||
$vevent->RRULE = 'FREQ=MONTHLY;COUNT=1';
|
||||
$vevent->DTSTART = '20120101T120000Z';
|
||||
$vevent->UID = 'bla';
|
||||
|
||||
$valarm = $vcalendar->createComponent('VALARM');
|
||||
$valarm->TRIGGER = '-P15D';
|
||||
$vevent->add($valarm);
|
||||
|
||||
$vcalendar->add($vevent);
|
||||
|
||||
$this->assertFalse($validator->validate($vcalendar, $filter));
|
||||
}
|
||||
|
||||
function testAlarmWayBefore() {
|
||||
|
||||
$vcalendar = new VObject\Component\VCalendar();
|
||||
|
||||
$vevent = $vcalendar->createComponent('VEVENT');
|
||||
$vevent->DTSTART = '20120101T120000Z';
|
||||
$vevent->UID = 'bla';
|
||||
|
||||
$valarm = $vcalendar->createComponent('VALARM');
|
||||
$valarm->TRIGGER = '-P2W1D';
|
||||
$vevent->add($valarm);
|
||||
|
||||
$vcalendar->add($vevent);
|
||||
|
||||
$filter = [
|
||||
'name' => 'VCALENDAR',
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
'prop-filters' => [],
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VEVENT',
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
'prop-filters' => [],
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VALARM',
|
||||
'is-not-defined' => false,
|
||||
'prop-filters' => [],
|
||||
'comp-filters' => [],
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2011-12-10'),
|
||||
'end' => new \DateTime('2011-12-20'),
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$validator = new CalendarQueryValidator();
|
||||
$this->assertTrue($validator->validate($vcalendar, $filter));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,829 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
class CalendarQueryValidatorTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function testTopLevelFail() {
|
||||
|
||||
$validator = new CalendarQueryValidator();
|
||||
$vcal = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
$vcal = VObject\Reader::read($vcal);
|
||||
$this->assertFalse($validator->validate($vcal, ['name' => 'VFOO']));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $icalObject
|
||||
* @param array $filters
|
||||
* @param int $outcome
|
||||
* @dataProvider provider
|
||||
*/
|
||||
function testValid($icalObject, $filters, $outcome) {
|
||||
|
||||
$validator = new CalendarQueryValidator();
|
||||
|
||||
// Wrapping filter in a VCALENDAR component filter, as this is always
|
||||
// there anyway.
|
||||
$filters = [
|
||||
'name' => 'VCALENDAR',
|
||||
'comp-filters' => [$filters],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
];
|
||||
|
||||
$vObject = VObject\Reader::read($icalObject);
|
||||
|
||||
switch ($outcome) {
|
||||
case 0 :
|
||||
$this->assertFalse($validator->validate($vObject, $filters));
|
||||
break;
|
||||
case 1 :
|
||||
$this->assertTrue($validator->validate($vObject, $filters));
|
||||
break;
|
||||
case -1 :
|
||||
try {
|
||||
$validator->validate($vObject, $filters);
|
||||
$this->fail('This test was supposed to fail');
|
||||
} catch (\Exception $e) {
|
||||
// We need to test something to be valid for phpunit strict
|
||||
// mode.
|
||||
$this->assertTrue(true);
|
||||
} catch (\Throwable $e) {
|
||||
// PHP7
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function provider() {
|
||||
|
||||
$blob1 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:hi
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob2 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:hi
|
||||
BEGIN:VALARM
|
||||
ACTION:DISPLAY
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob3 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
SUMMARY:hi
|
||||
DTSTART;VALUE=DATE:20110704
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
$blob4 = <<<yow
|
||||
BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
FN:Evert
|
||||
END:VCARD
|
||||
yow;
|
||||
|
||||
$blob5 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20110101T120000Z
|
||||
DTEND:20110102T120000Z
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob6 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20110101T120000Z
|
||||
DURATION:PT5H
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob7 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART;VALUE=DATE:20110101
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob8 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20110101T120000Z
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob9 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VTODO
|
||||
DTSTART:20110101T120000Z
|
||||
DURATION:PT1H
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
$blob10 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VTODO
|
||||
DTSTART:20110101T120000Z
|
||||
DUE:20110101T130000Z
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
$blob11 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VTODO
|
||||
DTSTART:20110101T120000Z
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob12 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VTODO
|
||||
DUE:20110101T130000Z
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob13 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VTODO
|
||||
COMPLETED:20110101T130000Z
|
||||
CREATED:20110101T110000Z
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob14 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VTODO
|
||||
COMPLETED:20110101T130000Z
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob15 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VTODO
|
||||
CREATED:20110101T110000Z
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
|
||||
$blob16 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VTODO
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob17 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VJOURNAL
|
||||
END:VJOURNAL
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob18 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VJOURNAL
|
||||
DTSTART:20110101T120000Z
|
||||
END:VJOURNAL
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob19 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VJOURNAL
|
||||
DTSTART;VALUE=DATE:20110101
|
||||
END:VJOURNAL
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob20 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VFREEBUSY
|
||||
END:VFREEBUSY
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob21 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20110101T120000Z
|
||||
BEGIN:VALARM
|
||||
TRIGGER:-PT1H
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob22 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20110101T120000Z
|
||||
BEGIN:VALARM
|
||||
TRIGGER;VALUE=DURATION:-PT1H
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob23 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20110101T120000Z
|
||||
BEGIN:VALARM
|
||||
TRIGGER;VALUE=DURATION;RELATED=END:-PT1H
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob24 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20110101T120000Z
|
||||
DTEND:20110101T130000Z
|
||||
BEGIN:VALARM
|
||||
TRIGGER;VALUE=DURATION;RELATED=END:-PT2H
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob25 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20110101T120000Z
|
||||
DURATION:PT1H
|
||||
BEGIN:VALARM
|
||||
TRIGGER;VALUE=DURATION;RELATED=END:-PT2H
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob26 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20110101T120000Z
|
||||
DURATION:PT1H
|
||||
BEGIN:VALARM
|
||||
TRIGGER;VALUE=DATE-TIME:20110101T110000Z
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
|
||||
$blob27 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VTODO
|
||||
DTSTART:20110101T120000Z
|
||||
DUE:20110101T130000Z
|
||||
BEGIN:VALARM
|
||||
TRIGGER;VALUE=DURATION;RELATED=END:-PT2H
|
||||
END:VALARM
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob28 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VJOURNAL
|
||||
DTSTART:20110101T120000Z
|
||||
BEGIN:VALARM
|
||||
TRIGGER;VALUE=DURATION;RELATED=END:-PT2H
|
||||
END:VALARM
|
||||
END:VJOURNAL
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob29 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20110101T120000Z
|
||||
DURATION:PT1H
|
||||
BEGIN:VALARM
|
||||
TRIGGER;VALUE=DATE-TIME:20110101T090000Z
|
||||
REPEAT:2
|
||||
DURATION:PT1H
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob30 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20110101T120000Z
|
||||
DURATION:PT1H
|
||||
BEGIN:VALARM
|
||||
TRIGGER;VALUE=DATE-TIME:20110101T090000Z
|
||||
DURATION:PT1H
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob31 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foobar
|
||||
DTSTART:20080101T120000Z
|
||||
DURATION:PT1H
|
||||
RRULE:FREQ=YEARLY
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$blob32 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foobar
|
||||
DTSTART:20080102T120000Z
|
||||
DURATION:PT1H
|
||||
RRULE:FREQ=YEARLY
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
$blob33 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foobar
|
||||
DTSTART;VALUE=DATE:20120628
|
||||
RRULE:FREQ=DAILY
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
$blob34 = <<<yow
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foobar
|
||||
DTSTART;VALUE=DATE:20120628
|
||||
RRULE:FREQ=DAILY
|
||||
BEGIN:VALARM
|
||||
TRIGGER:P52W
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
yow;
|
||||
|
||||
$filter1 = [
|
||||
'name' => 'VEVENT',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
];
|
||||
$filter2 = $filter1;
|
||||
$filter2['name'] = 'VTODO';
|
||||
|
||||
$filter3 = $filter1;
|
||||
$filter3['is-not-defined'] = true;
|
||||
|
||||
$filter4 = $filter1;
|
||||
$filter4['name'] = 'VTODO';
|
||||
$filter4['is-not-defined'] = true;
|
||||
|
||||
$filter5 = $filter1;
|
||||
$filter5['comp-filters'] = [
|
||||
[
|
||||
'name' => 'VALARM',
|
||||
'is-not-defined' => false,
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'time-range' => null,
|
||||
],
|
||||
];
|
||||
$filter6 = $filter1;
|
||||
$filter6['prop-filters'] = [
|
||||
[
|
||||
'name' => 'SUMMARY',
|
||||
'is-not-defined' => false,
|
||||
'param-filters' => [],
|
||||
'time-range' => null,
|
||||
'text-match' => null,
|
||||
],
|
||||
];
|
||||
$filter7 = $filter6;
|
||||
$filter7['prop-filters'][0]['name'] = 'DESCRIPTION';
|
||||
|
||||
$filter8 = $filter6;
|
||||
$filter8['prop-filters'][0]['is-not-defined'] = true;
|
||||
|
||||
$filter9 = $filter7;
|
||||
$filter9['prop-filters'][0]['is-not-defined'] = true;
|
||||
|
||||
$filter10 = $filter5;
|
||||
$filter10['prop-filters'] = $filter6['prop-filters'];
|
||||
|
||||
// Param filters
|
||||
$filter11 = $filter1;
|
||||
$filter11['prop-filters'] = [
|
||||
[
|
||||
'name' => 'DTSTART',
|
||||
'is-not-defined' => false,
|
||||
'param-filters' => [
|
||||
[
|
||||
'name' => 'VALUE',
|
||||
'is-not-defined' => false,
|
||||
'text-match' => null,
|
||||
],
|
||||
],
|
||||
'time-range' => null,
|
||||
'text-match' => null,
|
||||
],
|
||||
];
|
||||
|
||||
$filter12 = $filter11;
|
||||
$filter12['prop-filters'][0]['param-filters'][0]['name'] = 'TZID';
|
||||
|
||||
$filter13 = $filter11;
|
||||
$filter13['prop-filters'][0]['param-filters'][0]['is-not-defined'] = true;
|
||||
|
||||
$filter14 = $filter12;
|
||||
$filter14['prop-filters'][0]['param-filters'][0]['is-not-defined'] = true;
|
||||
|
||||
// Param text filter
|
||||
$filter15 = $filter11;
|
||||
$filter15['prop-filters'][0]['param-filters'][0]['text-match'] = [
|
||||
'collation' => 'i;ascii-casemap',
|
||||
'value' => 'dAtE',
|
||||
'negate-condition' => false,
|
||||
];
|
||||
$filter16 = $filter15;
|
||||
$filter16['prop-filters'][0]['param-filters'][0]['text-match']['collation'] = 'i;octet';
|
||||
|
||||
$filter17 = $filter15;
|
||||
$filter17['prop-filters'][0]['param-filters'][0]['text-match']['negate-condition'] = true;
|
||||
|
||||
$filter18 = $filter15;
|
||||
$filter18['prop-filters'][0]['param-filters'][0]['text-match']['negate-condition'] = true;
|
||||
$filter18['prop-filters'][0]['param-filters'][0]['text-match']['collation'] = 'i;octet';
|
||||
|
||||
// prop + text
|
||||
$filter19 = $filter5;
|
||||
$filter19['comp-filters'][0]['prop-filters'] = [
|
||||
[
|
||||
'name' => 'action',
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
'param-filters' => [],
|
||||
'text-match' => [
|
||||
'collation' => 'i;ascii-casemap',
|
||||
'value' => 'display',
|
||||
'negate-condition' => false,
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// Time range
|
||||
$filter20 = [
|
||||
'name' => 'VEVENT',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2011-01-01 10:00:00', new \DateTimeZone('GMT')),
|
||||
'end' => new \DateTime('2011-01-01 13:00:00', new \DateTimeZone('GMT')),
|
||||
],
|
||||
];
|
||||
// Time range, no end date
|
||||
$filter21 = $filter20;
|
||||
$filter21['time-range']['end'] = null;
|
||||
|
||||
// Time range, no start date
|
||||
$filter22 = $filter20;
|
||||
$filter22['time-range']['start'] = null;
|
||||
|
||||
// Time range, other dates
|
||||
$filter23 = $filter20;
|
||||
$filter23['time-range'] = [
|
||||
'start' => new \DateTime('2011-02-01 10:00:00', new \DateTimeZone('GMT')),
|
||||
'end' => new \DateTime('2011-02-01 13:00:00', new \DateTimeZone('GMT')),
|
||||
];
|
||||
// Time range
|
||||
$filter24 = [
|
||||
'name' => 'VTODO',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2011-01-01 12:45:00', new \DateTimeZone('GMT')),
|
||||
'end' => new \DateTime('2011-01-01 13:15:00', new \DateTimeZone('GMT')),
|
||||
],
|
||||
];
|
||||
// Time range, other dates (1 month in the future)
|
||||
$filter25 = $filter24;
|
||||
$filter25['time-range'] = [
|
||||
'start' => new \DateTime('2011-02-01 10:00:00', new \DateTimeZone('GMT')),
|
||||
'end' => new \DateTime('2011-02-01 13:00:00', new \DateTimeZone('GMT')),
|
||||
];
|
||||
$filter26 = $filter24;
|
||||
$filter26['time-range'] = [
|
||||
'start' => new \DateTime('2011-01-01 11:45:00', new \DateTimeZone('GMT')),
|
||||
'end' => new \DateTime('2011-01-01 12:15:00', new \DateTimeZone('GMT')),
|
||||
];
|
||||
|
||||
// Time range for VJOURNAL
|
||||
$filter27 = [
|
||||
'name' => 'VJOURNAL',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2011-01-01 12:45:00', new \DateTimeZone('GMT')),
|
||||
'end' => new \DateTime('2011-01-01 13:15:00', new \DateTimeZone('GMT')),
|
||||
],
|
||||
];
|
||||
$filter28 = $filter27;
|
||||
$filter28['time-range'] = [
|
||||
'start' => new \DateTime('2011-01-01 11:45:00', new \DateTimeZone('GMT')),
|
||||
'end' => new \DateTime('2011-01-01 12:15:00', new \DateTimeZone('GMT')),
|
||||
];
|
||||
// Time range for VFREEBUSY
|
||||
$filter29 = [
|
||||
'name' => 'VFREEBUSY',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2011-01-01 12:45:00', new \DateTimeZone('GMT')),
|
||||
'end' => new \DateTime('2011-01-01 13:15:00', new \DateTimeZone('GMT')),
|
||||
],
|
||||
];
|
||||
// Time range filter on property
|
||||
$filter30 = [
|
||||
'name' => 'VEVENT',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [
|
||||
[
|
||||
'name' => 'DTSTART',
|
||||
'is-not-defined' => false,
|
||||
'param-filters' => [],
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2011-01-01 10:00:00', new \DateTimeZone('GMT')),
|
||||
'end' => new \DateTime('2011-01-01 13:00:00', new \DateTimeZone('GMT')),
|
||||
],
|
||||
'text-match' => null,
|
||||
],
|
||||
],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
];
|
||||
|
||||
// Time range for alarm
|
||||
$filter31 = [
|
||||
'name' => 'VEVENT',
|
||||
'prop-filters' => [],
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VALARM',
|
||||
'is-not-defined' => false,
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2011-01-01 10:45:00', new \DateTimeZone('GMT')),
|
||||
'end' => new \DateTime('2011-01-01 11:15:00', new \DateTimeZone('GMT')),
|
||||
],
|
||||
'text-match' => null,
|
||||
],
|
||||
],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
];
|
||||
$filter32 = $filter31;
|
||||
$filter32['comp-filters'][0]['time-range'] = [
|
||||
'start' => new \DateTime('2011-01-01 11:45:00', new \DateTimeZone('GMT')),
|
||||
'end' => new \DateTime('2011-01-01 12:15:00', new \DateTimeZone('GMT')),
|
||||
];
|
||||
|
||||
$filter33 = $filter31;
|
||||
$filter33['name'] = 'VTODO';
|
||||
$filter34 = $filter32;
|
||||
$filter34['name'] = 'VTODO';
|
||||
$filter35 = $filter31;
|
||||
$filter35['name'] = 'VJOURNAL';
|
||||
$filter36 = $filter32;
|
||||
$filter36['name'] = 'VJOURNAL';
|
||||
|
||||
// Time range filter on non-datetime property
|
||||
$filter37 = [
|
||||
'name' => 'VEVENT',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [
|
||||
[
|
||||
'name' => 'SUMMARY',
|
||||
'is-not-defined' => false,
|
||||
'param-filters' => [],
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2011-01-01 10:00:00', new \DateTimeZone('GMT')),
|
||||
'end' => new \DateTime('2011-01-01 13:00:00', new \DateTimeZone('GMT')),
|
||||
],
|
||||
'text-match' => null,
|
||||
],
|
||||
],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
];
|
||||
|
||||
$filter38 = [
|
||||
'name' => 'VEVENT',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2012-07-01 00:00:00', new \DateTimeZone('UTC')),
|
||||
'end' => new \DateTime('2012-08-01 00:00:00', new \DateTimeZone('UTC')),
|
||||
]
|
||||
];
|
||||
$filter39 = [
|
||||
'name' => 'VEVENT',
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VALARM',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2012-09-01 00:00:00', new \DateTimeZone('UTC')),
|
||||
'end' => new \DateTime('2012-10-01 00:00:00', new \DateTimeZone('UTC')),
|
||||
]
|
||||
],
|
||||
],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
];
|
||||
|
||||
return [
|
||||
|
||||
// Component check
|
||||
|
||||
[$blob1, $filter1, 1],
|
||||
[$blob1, $filter2, 0],
|
||||
[$blob1, $filter3, 0],
|
||||
[$blob1, $filter4, 1],
|
||||
|
||||
// Subcomponent check (4)
|
||||
[$blob1, $filter5, 0],
|
||||
[$blob2, $filter5, 1],
|
||||
|
||||
// Property checki (6)
|
||||
[$blob1, $filter6, 1],
|
||||
[$blob1, $filter7, 0],
|
||||
[$blob1, $filter8, 0],
|
||||
[$blob1, $filter9, 1],
|
||||
|
||||
// Subcomponent + property (10)
|
||||
[$blob2, $filter10, 1],
|
||||
|
||||
// Param filter (11)
|
||||
[$blob3, $filter11, 1],
|
||||
[$blob3, $filter12, 0],
|
||||
[$blob3, $filter13, 0],
|
||||
[$blob3, $filter14, 1],
|
||||
|
||||
// Param + text (15)
|
||||
[$blob3, $filter15, 1],
|
||||
[$blob3, $filter16, 0],
|
||||
[$blob3, $filter17, 0],
|
||||
[$blob3, $filter18, 1],
|
||||
|
||||
// Prop + text (19)
|
||||
[$blob2, $filter19, 1],
|
||||
|
||||
// Incorrect object (vcard) (20)
|
||||
[$blob4, $filter1, -1],
|
||||
|
||||
// Time-range for event (21)
|
||||
[$blob5, $filter20, 1],
|
||||
[$blob6, $filter20, 1],
|
||||
[$blob7, $filter20, 1],
|
||||
[$blob8, $filter20, 1],
|
||||
|
||||
[$blob5, $filter21, 1],
|
||||
[$blob5, $filter22, 1],
|
||||
|
||||
[$blob5, $filter23, 0],
|
||||
[$blob6, $filter23, 0],
|
||||
[$blob7, $filter23, 0],
|
||||
[$blob8, $filter23, 0],
|
||||
|
||||
// Time-range for todo (31)
|
||||
[$blob9, $filter24, 1],
|
||||
[$blob9, $filter25, 0],
|
||||
[$blob9, $filter26, 1],
|
||||
[$blob10, $filter24, 1],
|
||||
[$blob10, $filter25, 0],
|
||||
[$blob10, $filter26, 1],
|
||||
|
||||
[$blob11, $filter24, 0],
|
||||
[$blob11, $filter25, 0],
|
||||
[$blob11, $filter26, 1],
|
||||
|
||||
[$blob12, $filter24, 1],
|
||||
[$blob12, $filter25, 0],
|
||||
[$blob12, $filter26, 0],
|
||||
|
||||
[$blob13, $filter24, 1],
|
||||
[$blob13, $filter25, 0],
|
||||
[$blob13, $filter26, 1],
|
||||
|
||||
[$blob14, $filter24, 1],
|
||||
[$blob14, $filter25, 0],
|
||||
[$blob14, $filter26, 0],
|
||||
|
||||
[$blob15, $filter24, 1],
|
||||
[$blob15, $filter25, 1],
|
||||
[$blob15, $filter26, 1],
|
||||
|
||||
[$blob16, $filter24, 1],
|
||||
[$blob16, $filter25, 1],
|
||||
[$blob16, $filter26, 1],
|
||||
|
||||
// Time-range for journals (55)
|
||||
[$blob17, $filter27, 0],
|
||||
[$blob17, $filter28, 0],
|
||||
[$blob18, $filter27, 0],
|
||||
[$blob18, $filter28, 1],
|
||||
[$blob19, $filter27, 1],
|
||||
[$blob19, $filter28, 1],
|
||||
|
||||
// Time-range for free-busy (61)
|
||||
[$blob20, $filter29, -1],
|
||||
|
||||
// Time-range on property (62)
|
||||
[$blob5, $filter30, 1],
|
||||
[$blob3, $filter37, -1],
|
||||
[$blob3, $filter30, 0],
|
||||
|
||||
// Time-range on alarm in vevent (65)
|
||||
[$blob21, $filter31, 1],
|
||||
[$blob21, $filter32, 0],
|
||||
[$blob22, $filter31, 1],
|
||||
[$blob22, $filter32, 0],
|
||||
[$blob23, $filter31, 1],
|
||||
[$blob23, $filter32, 0],
|
||||
[$blob24, $filter31, 1],
|
||||
[$blob24, $filter32, 0],
|
||||
[$blob25, $filter31, 1],
|
||||
[$blob25, $filter32, 0],
|
||||
[$blob26, $filter31, 1],
|
||||
[$blob26, $filter32, 0],
|
||||
|
||||
// Time-range on alarm for vtodo (77)
|
||||
[$blob27, $filter33, 1],
|
||||
[$blob27, $filter34, 0],
|
||||
|
||||
// Time-range on alarm for vjournal (79)
|
||||
[$blob28, $filter35, -1],
|
||||
[$blob28, $filter36, -1],
|
||||
|
||||
// Time-range on alarm with duration (81)
|
||||
[$blob29, $filter31, 1],
|
||||
[$blob29, $filter32, 0],
|
||||
[$blob30, $filter31, 0],
|
||||
[$blob30, $filter32, 0],
|
||||
|
||||
// Time-range with RRULE (85)
|
||||
[$blob31, $filter20, 1],
|
||||
[$blob32, $filter20, 0],
|
||||
|
||||
// Bug reported on mailing list, related to all-day events (87)
|
||||
//array($blob33, $filter38, 1),
|
||||
|
||||
// Event in timerange, but filtered alarm is in the far future (88).
|
||||
[$blob34, $filter39, 0],
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,256 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\DAV\PropPatch;
|
||||
|
||||
require_once 'Sabre/CalDAV/TestUtil.php';
|
||||
|
||||
class CalendarTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Sabre\CalDAV\Backend\PDO
|
||||
*/
|
||||
protected $backend;
|
||||
protected $principalBackend;
|
||||
/**
|
||||
* @var Sabre\CalDAV\Calendar
|
||||
*/
|
||||
protected $calendar;
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $calendars;
|
||||
|
||||
function setup() {
|
||||
|
||||
$this->backend = TestUtil::getBackend();
|
||||
|
||||
$this->calendars = $this->backend->getCalendarsForUser('principals/user1');
|
||||
$this->assertEquals(2, count($this->calendars));
|
||||
$this->calendar = new Calendar($this->backend, $this->calendars[0]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
|
||||
unset($this->backend);
|
||||
|
||||
}
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$this->assertEquals($this->calendars[0]['uri'], $this->calendar->getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testUpdateProperties() {
|
||||
|
||||
$propPatch = new PropPatch([
|
||||
'{DAV:}displayname' => 'NewName',
|
||||
]);
|
||||
|
||||
$result = $this->calendar->propPatch($propPatch);
|
||||
$result = $propPatch->commit();
|
||||
|
||||
$this->assertEquals(true, $result);
|
||||
|
||||
$calendars2 = $this->backend->getCalendarsForUser('principals/user1');
|
||||
$this->assertEquals('NewName', $calendars2[0]['{DAV:}displayname']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testGetProperties() {
|
||||
|
||||
$question = [
|
||||
'{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set',
|
||||
];
|
||||
|
||||
$result = $this->calendar->getProperties($question);
|
||||
|
||||
foreach ($question as $q) $this->assertArrayHasKey($q, $result);
|
||||
|
||||
$this->assertEquals(['VEVENT', 'VTODO'], $result['{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set']->getValue());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\NotFound
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testGetChildNotFound() {
|
||||
|
||||
$this->calendar->getChild('randomname');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testGetChildren() {
|
||||
|
||||
$children = $this->calendar->getChildren();
|
||||
$this->assertEquals(1, count($children));
|
||||
|
||||
$this->assertTrue($children[0] instanceof CalendarObject);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetChildren
|
||||
*/
|
||||
function testChildExists() {
|
||||
|
||||
$this->assertFalse($this->calendar->childExists('foo'));
|
||||
|
||||
$children = $this->calendar->getChildren();
|
||||
$this->assertTrue($this->calendar->childExists($children[0]->getName()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
|
||||
*/
|
||||
function testCreateDirectory() {
|
||||
|
||||
$this->calendar->createDirectory('hello');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
|
||||
*/
|
||||
function testSetName() {
|
||||
|
||||
$this->calendar->setName('hello');
|
||||
|
||||
}
|
||||
|
||||
function testGetLastModified() {
|
||||
|
||||
$this->assertNull($this->calendar->getLastModified());
|
||||
|
||||
}
|
||||
|
||||
function testCreateFile() {
|
||||
|
||||
$file = fopen('php://memory', 'r+');
|
||||
fwrite($file, TestUtil::getTestCalendarData());
|
||||
rewind($file);
|
||||
|
||||
$this->calendar->createFile('hello', $file);
|
||||
|
||||
$file = $this->calendar->getChild('hello');
|
||||
$this->assertTrue($file instanceof CalendarObject);
|
||||
|
||||
}
|
||||
|
||||
function testCreateFileNoSupportedComponents() {
|
||||
|
||||
$file = fopen('php://memory', 'r+');
|
||||
fwrite($file, TestUtil::getTestCalendarData());
|
||||
rewind($file);
|
||||
|
||||
$calendar = new Calendar($this->backend, $this->calendars[1]);
|
||||
$calendar->createFile('hello', $file);
|
||||
|
||||
$file = $calendar->getChild('hello');
|
||||
$this->assertTrue($file instanceof CalendarObject);
|
||||
|
||||
}
|
||||
|
||||
function testDelete() {
|
||||
|
||||
$this->calendar->delete();
|
||||
|
||||
$calendars = $this->backend->getCalendarsForUser('principals/user1');
|
||||
$this->assertEquals(1, count($calendars));
|
||||
}
|
||||
|
||||
function testGetOwner() {
|
||||
|
||||
$this->assertEquals('principals/user1', $this->calendar->getOwner());
|
||||
|
||||
}
|
||||
|
||||
function testGetGroup() {
|
||||
|
||||
$this->assertNull($this->calendar->getGroup());
|
||||
|
||||
}
|
||||
|
||||
function testGetACL() {
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1/calendar-proxy-read',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
|
||||
'principal' => '{DAV:}authenticated',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}write',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}write',
|
||||
'principal' => 'principals/user1/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expected, $this->calendar->getACL());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testSetACL() {
|
||||
|
||||
$this->calendar->setACL([]);
|
||||
|
||||
}
|
||||
|
||||
function testGetSyncToken() {
|
||||
|
||||
$this->assertNull($this->calendar->getSyncToken());
|
||||
|
||||
}
|
||||
|
||||
function testGetSyncTokenNoSyncSupport() {
|
||||
|
||||
$calendar = new Calendar(new Backend\Mock([], []), []);
|
||||
$this->assertNull($calendar->getSyncToken());
|
||||
|
||||
}
|
||||
|
||||
function testGetChanges() {
|
||||
|
||||
$this->assertNull($this->calendar->getChanges(1, 1));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,113 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\HTTP;
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* This unittests is created to find out why recurring events have wrong DTSTART value
|
||||
*
|
||||
*
|
||||
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
class ExpandEventsDTSTARTandDTENDTest extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
|
||||
protected $caldavCalendars = [
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => 'Calendar',
|
||||
'principaluri' => 'principals/user1',
|
||||
'uri' => 'calendar1',
|
||||
]
|
||||
];
|
||||
|
||||
protected $caldavCalendarObjects = [
|
||||
1 => [
|
||||
'event.ics' => [
|
||||
'calendardata' => 'BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foobar
|
||||
DTEND;TZID=Europe/Berlin:20120207T191500
|
||||
RRULE:FREQ=DAILY;INTERVAL=1;COUNT=3
|
||||
SUMMARY:RecurringEvents 3 times
|
||||
DTSTART;TZID=Europe/Berlin:20120207T181500
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
CREATED:20120207T111900Z
|
||||
UID:foobar
|
||||
DTEND;TZID=Europe/Berlin:20120208T191500
|
||||
SUMMARY:RecurringEvents 3 times OVERWRITTEN
|
||||
DTSTART;TZID=Europe/Berlin:20120208T181500
|
||||
RECURRENCE-ID;TZID=Europe/Berlin:20120208T181500
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
function testExpand() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'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="20120205T230000Z" end="20120212T225959Z"/>
|
||||
</C:calendar-data>
|
||||
<D:getetag/>
|
||||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT">
|
||||
<C:time-range start="20120205T230000Z" end="20120212T225959Z"/>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
</C:calendar-query>');
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
// Everts super awesome xml parser.
|
||||
$body = substr(
|
||||
$response->body,
|
||||
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
|
||||
strpos($response->body, 'END:VCALENDAR') - $start + 13
|
||||
);
|
||||
$body = str_replace(' ', '', $body);
|
||||
|
||||
try {
|
||||
$vObject = VObject\Reader::read($body);
|
||||
} catch (VObject\ParseException $e) {
|
||||
$this->fail('Could not parse object. Error:' . $e->getMessage() . ' full object: ' . $response->getBodyAsString());
|
||||
}
|
||||
|
||||
// check if DTSTARTs and DTENDs are correct
|
||||
foreach ($vObject->VEVENT as $vevent) {
|
||||
/** @var $vevent Sabre\VObject\Component\VEvent */
|
||||
foreach ($vevent->children() as $child) {
|
||||
/** @var $child Sabre\VObject\Property */
|
||||
if ($child->name == 'DTSTART') {
|
||||
// DTSTART has to be one of three valid values
|
||||
$this->assertContains($child->getValue(), ['20120207T171500Z', '20120208T171500Z', '20120209T171500Z'], 'DTSTART is not a valid value: ' . $child->getValue());
|
||||
} elseif ($child->name == 'DTEND') {
|
||||
// DTEND has to be one of three valid values
|
||||
$this->assertContains($child->getValue(), ['20120207T181500Z', '20120208T181500Z', '20120209T181500Z'], 'DTEND is not a valid value: ' . $child->getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\HTTP;
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* This unittests is created to find out why recurring events have wrong DTSTART value
|
||||
*
|
||||
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
class ExpandEventsDTSTARTandDTENDbyDayTest extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
|
||||
protected $caldavCalendars = [
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => 'Calendar',
|
||||
'principaluri' => 'principals/user1',
|
||||
'uri' => 'calendar1',
|
||||
]
|
||||
];
|
||||
|
||||
protected $caldavCalendarObjects = [
|
||||
1 => [
|
||||
'event.ics' => [
|
||||
'calendardata' => 'BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foobar
|
||||
DTEND;TZID=Europe/Berlin:20120207T191500
|
||||
RRULE:FREQ=WEEKLY;INTERVAL=1;BYDAY=TU,TH
|
||||
SUMMARY:RecurringEvents on tuesday and thursday
|
||||
DTSTART;TZID=Europe/Berlin:20120207T181500
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
function testExpandRecurringByDayEvent() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'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="20120210T230000Z" end="20120217T225959Z"/>
|
||||
</C:calendar-data>
|
||||
<D:getetag/>
|
||||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT">
|
||||
<C:time-range start="20120210T230000Z" end="20120217T225959Z"/>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
</C:calendar-query>');
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
// Everts super awesome xml parser.
|
||||
$body = substr(
|
||||
$response->body,
|
||||
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
|
||||
strpos($response->body, 'END:VCALENDAR') - $start + 13
|
||||
);
|
||||
$body = str_replace(' ', '', $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 */
|
||||
foreach ($vevent->children() as $child) {
|
||||
/** @var $child Sabre\VObject\Property */
|
||||
if ($child->name == 'DTSTART') {
|
||||
// DTSTART has to be one of two valid values
|
||||
$this->assertContains($child->getValue(), ['20120214T171500Z', '20120216T171500Z'], 'DTSTART is not a valid value: ' . $child->getValue());
|
||||
} elseif ($child->name == 'DTEND') {
|
||||
// DTEND has to be one of two valid values
|
||||
$this->assertContains($child->getValue(), ['20120214T181500Z', '20120216T181500Z'], 'DTEND is not a valid value: ' . $child->getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,103 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\HTTP;
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* This unittests is created to find out why certain events show up twice.
|
||||
*
|
||||
* Hopefully, by the time I'm done with this, I've both found the problem, and
|
||||
* fixed it :)
|
||||
*
|
||||
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
class ExpandEventsDoubleEventsTest extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
|
||||
protected $caldavCalendars = [
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => 'Calendar',
|
||||
'principaluri' => 'principals/user1',
|
||||
'uri' => 'calendar1',
|
||||
]
|
||||
];
|
||||
|
||||
protected $caldavCalendarObjects = [
|
||||
1 => [
|
||||
'event.ics' => [
|
||||
'calendardata' => 'BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foobar
|
||||
DTEND;TZID=Europe/Berlin:20120207T191500
|
||||
RRULE:FREQ=DAILY;INTERVAL=1;COUNT=3
|
||||
SUMMARY:RecurringEvents 3 times
|
||||
DTSTART;TZID=Europe/Berlin:20120207T181500
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
CREATED:20120207T111900Z
|
||||
UID:foobar
|
||||
DTEND;TZID=Europe/Berlin:20120208T191500
|
||||
SUMMARY:RecurringEvents 3 times OVERWRITTEN
|
||||
DTSTART;TZID=Europe/Berlin:20120208T181500
|
||||
RECURRENCE-ID;TZID=Europe/Berlin:20120208T181500
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
function testExpand() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'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="20120205T230000Z" end="20120212T225959Z"/>
|
||||
</C:calendar-data>
|
||||
<D:getetag/>
|
||||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT">
|
||||
<C:time-range start="20120205T230000Z" end="20120212T225959Z"/>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
</C:calendar-query>');
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
// Everts super awesome xml parser.
|
||||
$body = substr(
|
||||
$response->body,
|
||||
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
|
||||
strpos($response->body, 'END:VCALENDAR') - $start + 13
|
||||
);
|
||||
$body = str_replace(' ', '', $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);
|
||||
|
||||
// TZID should be gone
|
||||
$this->assertFalse(isset($vObject->VEVENT->DTSTART['TZID']));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,207 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\HTTP;
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* This unittest is created to check if expand() works correctly with
|
||||
* floating times (using calendar-timezone information).
|
||||
*/
|
||||
class ExpandEventsFloatingTimeTest extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
|
||||
protected $setupCalDAVICSExport = true;
|
||||
|
||||
protected $caldavCalendars = [
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => 'Calendar',
|
||||
'principaluri' => 'principals/user1',
|
||||
'uri' => 'calendar1',
|
||||
'{urn:ietf:params:xml:ns:caldav}calendar-timezone' => 'BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
CALSCALE:GREGORIAN
|
||||
BEGIN:VTIMEZONE
|
||||
TZID:Europe/Berlin
|
||||
BEGIN:DAYLIGHT
|
||||
TZOFFSETFROM:+0100
|
||||
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
|
||||
DTSTART:19810329T020000
|
||||
TZNAME:GMT+2
|
||||
TZOFFSETTO:+0200
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
TZOFFSETFROM:+0200
|
||||
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
|
||||
DTSTART:19961027T030000
|
||||
TZNAME:GMT+1
|
||||
TZOFFSETTO:+0100
|
||||
END:STANDARD
|
||||
END:VTIMEZONE
|
||||
END:VCALENDAR',
|
||||
]
|
||||
];
|
||||
|
||||
protected $caldavCalendarObjects = [
|
||||
1 => [
|
||||
'event.ics' => [
|
||||
'calendardata' => 'BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
CALSCALE:GREGORIAN
|
||||
BEGIN:VEVENT
|
||||
CREATED:20140701T143658Z
|
||||
UID:dba46fe8-1631-4d98-a575-97963c364dfe
|
||||
DTEND:20141108T073000
|
||||
TRANSP:OPAQUE
|
||||
SUMMARY:Floating Time event, starting 05:30am Europe/Berlin
|
||||
DTSTART:20141108T053000
|
||||
DTSTAMP:20140701T143706Z
|
||||
SEQUENCE:1
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
function testExpandCalendarQuery() {
|
||||
|
||||
$request = new HTTP\Request('REPORT', '/calendars/user1/calendar1', [
|
||||
'Depth' => 1,
|
||||
'Content-Type' => 'application/xml',
|
||||
]);
|
||||
|
||||
$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="20141107T230000Z" end="20141108T225959Z"/>
|
||||
</C:calendar-data>
|
||||
<D:getetag/>
|
||||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT">
|
||||
<C:time-range start="20141107T230000Z" end="20141108T225959Z"/>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
</C:calendar-query>');
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
// Everts super awesome xml parser.
|
||||
$body = substr(
|
||||
$response->body,
|
||||
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
|
||||
strpos($response->body, 'END:VCALENDAR') - $start + 13
|
||||
);
|
||||
$body = str_replace(' ', '', $body);
|
||||
|
||||
$vObject = VObject\Reader::read($body);
|
||||
|
||||
// check if DTSTARTs and DTENDs are correct
|
||||
foreach ($vObject->VEVENT as $vevent) {
|
||||
/** @var $vevent Sabre\VObject\Component\VEvent */
|
||||
foreach ($vevent->children() as $child) {
|
||||
/** @var $child Sabre\VObject\Property */
|
||||
if ($child->name == 'DTSTART') {
|
||||
// DTSTART should be the UTC equivalent of given floating time
|
||||
$this->assertEquals('20141108T043000Z', $child->getValue());
|
||||
} elseif ($child->name == 'DTEND') {
|
||||
// DTEND should be the UTC equivalent of given floating time
|
||||
$this->assertEquals('20141108T063000Z', $child->getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testExpandMultiGet() {
|
||||
|
||||
$request = new HTTP\Request('REPORT', '/calendars/user1/calendar1', [
|
||||
'Depth' => 1,
|
||||
'Content-Type' => 'application/xml',
|
||||
]);
|
||||
|
||||
$request->setBody('<?xml version="1.0" encoding="utf-8" ?>
|
||||
<C:calendar-multiget xmlns:D="DAV:" xmlns:C="urn:ietf:params:xml:ns:caldav">
|
||||
<D:prop>
|
||||
<C:calendar-data>
|
||||
<C:expand start="20141107T230000Z" end="20141108T225959Z"/>
|
||||
</C:calendar-data>
|
||||
<D:getetag/>
|
||||
</D:prop>
|
||||
<D:href>/calendars/user1/calendar1/event.ics</D:href>
|
||||
</C:calendar-multiget>');
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(207, $response->getStatus());
|
||||
|
||||
// Everts super awesome xml parser.
|
||||
$body = substr(
|
||||
$response->body,
|
||||
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
|
||||
strpos($response->body, 'END:VCALENDAR') - $start + 13
|
||||
);
|
||||
$body = str_replace(' ', '', $body);
|
||||
|
||||
$vObject = VObject\Reader::read($body);
|
||||
|
||||
// check if DTSTARTs and DTENDs are correct
|
||||
foreach ($vObject->VEVENT as $vevent) {
|
||||
/** @var $vevent Sabre\VObject\Component\VEvent */
|
||||
foreach ($vevent->children() as $child) {
|
||||
/** @var $child Sabre\VObject\Property */
|
||||
if ($child->name == 'DTSTART') {
|
||||
// DTSTART should be the UTC equivalent of given floating time
|
||||
$this->assertEquals($child->getValue(), '20141108T043000Z');
|
||||
} elseif ($child->name == 'DTEND') {
|
||||
// DTEND should be the UTC equivalent of given floating time
|
||||
$this->assertEquals($child->getValue(), '20141108T063000Z');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function testExpandExport() {
|
||||
|
||||
$request = new HTTP\Request('GET', '/calendars/user1/calendar1?export&start=1&end=2000000000&expand=1', [
|
||||
'Depth' => 1,
|
||||
'Content-Type' => 'application/xml',
|
||||
]);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(200, $response->getStatus());
|
||||
|
||||
// Everts super awesome xml parser.
|
||||
$body = substr(
|
||||
$response->body,
|
||||
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
|
||||
strpos($response->body, 'END:VCALENDAR') - $start + 13
|
||||
);
|
||||
$body = str_replace(' ', '', $body);
|
||||
|
||||
$vObject = VObject\Reader::read($body);
|
||||
|
||||
// check if DTSTARTs and DTENDs are correct
|
||||
foreach ($vObject->VEVENT as $vevent) {
|
||||
/** @var $vevent Sabre\VObject\Component\VEvent */
|
||||
foreach ($vevent->children() as $child) {
|
||||
/** @var $child Sabre\VObject\Property */
|
||||
if ($child->name == 'DTSTART') {
|
||||
// DTSTART should be the UTC equivalent of given floating time
|
||||
$this->assertEquals('20141108T043000Z', $child->getValue());
|
||||
} elseif ($child->name == 'DTEND') {
|
||||
// DTEND should be the UTC equivalent of given floating time
|
||||
$this->assertEquals('20141108T063000Z', $child->getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,174 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\DAV;
|
||||
use Sabre\HTTP;
|
||||
|
||||
require_once 'Sabre/CalDAV/Backend/Mock.php';
|
||||
require_once 'Sabre/HTTP/ResponseMock.php';
|
||||
|
||||
class FreeBusyReportTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Plugin
|
||||
*/
|
||||
protected $plugin;
|
||||
/**
|
||||
* @var DAV\Server
|
||||
*/
|
||||
protected $server;
|
||||
|
||||
function setUp() {
|
||||
|
||||
$obj1 = <<<ics
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20111005T120000Z
|
||||
DURATION:PT1H
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ics;
|
||||
|
||||
$obj2 = fopen('php://memory', 'r+');
|
||||
fwrite($obj2, <<<ics
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20121005T120000Z
|
||||
DURATION:PT1H
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ics
|
||||
);
|
||||
rewind($obj2);
|
||||
|
||||
$obj3 = <<<ics
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20111006T120000
|
||||
DURATION:PT1H
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ics;
|
||||
|
||||
$calendarData = [
|
||||
1 => [
|
||||
'obj1' => [
|
||||
'calendarid' => 1,
|
||||
'uri' => 'event1.ics',
|
||||
'calendardata' => $obj1,
|
||||
],
|
||||
'obj2' => [
|
||||
'calendarid' => 1,
|
||||
'uri' => 'event2.ics',
|
||||
'calendardata' => $obj2
|
||||
],
|
||||
'obj3' => [
|
||||
'calendarid' => 1,
|
||||
'uri' => 'event3.ics',
|
||||
'calendardata' => $obj3
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
$caldavBackend = new Backend\Mock([], $calendarData);
|
||||
|
||||
$calendar = new Calendar($caldavBackend, [
|
||||
'id' => 1,
|
||||
'uri' => 'calendar',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{' . Plugin::NS_CALDAV . '}calendar-timezone' => "BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nEND:VTIMEZONE\r\nEND:VCALENDAR",
|
||||
]);
|
||||
|
||||
$this->server = new DAV\Server([$calendar]);
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_URI' => '/calendar',
|
||||
]);
|
||||
$this->server->httpRequest = $request;
|
||||
$this->server->httpResponse = new HTTP\ResponseMock();
|
||||
|
||||
$this->plugin = new Plugin();
|
||||
$this->server->addPlugin($this->plugin);
|
||||
|
||||
}
|
||||
|
||||
function testFreeBusyReport() {
|
||||
|
||||
$reportXML = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:free-busy-query xmlns:c="urn:ietf:params:xml:ns:caldav">
|
||||
<c:time-range start="20111001T000000Z" end="20111101T000000Z" />
|
||||
</c:free-busy-query>
|
||||
XML;
|
||||
|
||||
$report = $this->server->xml->parse($reportXML, null, $rootElem);
|
||||
$this->plugin->report($rootElem, $report, null);
|
||||
|
||||
$this->assertEquals(200, $this->server->httpResponse->status);
|
||||
$this->assertEquals('text/calendar', $this->server->httpResponse->getHeader('Content-Type'));
|
||||
$this->assertTrue(strpos($this->server->httpResponse->body, 'BEGIN:VFREEBUSY') !== false);
|
||||
$this->assertTrue(strpos($this->server->httpResponse->body, '20111005T120000Z/20111005T130000Z') !== false);
|
||||
$this->assertTrue(strpos($this->server->httpResponse->body, '20111006T100000Z/20111006T110000Z') !== false);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testFreeBusyReportNoTimeRange() {
|
||||
|
||||
$reportXML = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:free-busy-query xmlns:c="urn:ietf:params:xml:ns:caldav">
|
||||
</c:free-busy-query>
|
||||
XML;
|
||||
|
||||
$report = $this->server->xml->parse($reportXML, null, $rootElem);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\NotImplemented
|
||||
*/
|
||||
function testFreeBusyReportWrongNode() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_URI' => '/',
|
||||
]);
|
||||
$this->server->httpRequest = $request;
|
||||
|
||||
$reportXML = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:free-busy-query xmlns:c="urn:ietf:params:xml:ns:caldav">
|
||||
<c:time-range start="20111001T000000Z" end="20111101T000000Z" />
|
||||
</c:free-busy-query>
|
||||
XML;
|
||||
|
||||
$report = $this->server->xml->parse($reportXML, null, $rootElem);
|
||||
$this->plugin->report($rootElem, $report, null);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception
|
||||
*/
|
||||
function testFreeBusyReportNoACLPlugin() {
|
||||
|
||||
$this->server = new DAV\Server();
|
||||
$this->plugin = new Plugin();
|
||||
$this->server->addPlugin($this->plugin);
|
||||
|
||||
$reportXML = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:free-busy-query xmlns:c="urn:ietf:params:xml:ns:caldav">
|
||||
<c:time-range start="20111001T000000Z" end="20111101T000000Z" />
|
||||
</c:free-busy-query>
|
||||
XML;
|
||||
|
||||
$report = $this->server->xml->parse($reportXML, null, $rootElem);
|
||||
$this->plugin->report($rootElem, $report, null);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,82 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\HTTP;
|
||||
|
||||
/**
|
||||
* This unittest is created to check if queries for time-range include the start timestamp or not
|
||||
*
|
||||
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
class GetEventsByTimerangeTest extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
|
||||
protected $caldavCalendars = [
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => 'Calendar',
|
||||
'principaluri' => 'principals/user1',
|
||||
'uri' => 'calendar1',
|
||||
]
|
||||
];
|
||||
|
||||
protected $caldavCalendarObjects = [
|
||||
1 => [
|
||||
'event.ics' => [
|
||||
'calendardata' => 'BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
CREATED:20120313T142342Z
|
||||
UID:171EBEFC-C951-499D-B234-7BA7D677B45D
|
||||
DTEND;TZID=Europe/Berlin:20120227T010000
|
||||
TRANSP:OPAQUE
|
||||
SUMMARY:Monday 0h
|
||||
DTSTART;TZID=Europe/Berlin:20120227T000000
|
||||
DTSTAMP:20120313T142416Z
|
||||
SEQUENCE:4
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
function testQueryTimerange() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'REPORT',
|
||||
'/calendars/user1/calendar1',
|
||||
[
|
||||
'Content-Type' => 'application/xml',
|
||||
'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="20120226T220000Z" end="20120228T225959Z"/>
|
||||
</C:calendar-data>
|
||||
<D:getetag/>
|
||||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT">
|
||||
<C:time-range start="20120226T220000Z" end="20120228T225959Z"/>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
</C:calendar-query>');
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertTrue(strpos($response->body, 'BEGIN:VCALENDAR') !== false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,386 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\DAV;
|
||||
use Sabre\DAVACL;
|
||||
use Sabre\HTTP;
|
||||
use Sabre\VObject;
|
||||
|
||||
class ICSExportPluginTest extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
|
||||
protected $icsExportPlugin;
|
||||
|
||||
function setUp() {
|
||||
|
||||
parent::setUp();
|
||||
$this->icsExportPlugin = new ICSExportPlugin();
|
||||
$this->server->addPlugin(
|
||||
$this->icsExportPlugin
|
||||
);
|
||||
|
||||
$id = $this->caldavBackend->createCalendar(
|
||||
'principals/admin',
|
||||
'UUID-123467',
|
||||
[
|
||||
'{DAV:}displayname' => 'Hello!',
|
||||
'{http://apple.com/ns/ical/}calendar-color' => '#AA0000FF',
|
||||
]
|
||||
);
|
||||
|
||||
$this->caldavBackend->createCalendarObject(
|
||||
$id,
|
||||
'event-1',
|
||||
<<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VTIMEZONE
|
||||
TZID:Europe/Amsterdam
|
||||
END:VTIMEZONE
|
||||
BEGIN:VEVENT
|
||||
UID:event-1
|
||||
DTSTART;TZID=Europe/Amsterdam:20151020T000000
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS
|
||||
);
|
||||
$this->caldavBackend->createCalendarObject(
|
||||
$id,
|
||||
'todo-1',
|
||||
<<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VTODO
|
||||
UID:todo-1
|
||||
END:VTODO
|
||||
END:VCALENDAR
|
||||
ICS
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function testInit() {
|
||||
|
||||
$this->assertEquals(
|
||||
$this->icsExportPlugin,
|
||||
$this->server->getPlugin('ics-export')
|
||||
);
|
||||
$this->assertEquals($this->icsExportPlugin, $this->server->getPlugin('ics-export'));
|
||||
$this->assertEquals('ics-export', $this->icsExportPlugin->getPluginInfo()['name']);
|
||||
|
||||
}
|
||||
|
||||
function testBeforeMethod() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export'
|
||||
);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(200, $response->getStatus());
|
||||
$this->assertEquals('text/calendar', $response->getHeader('Content-Type'));
|
||||
|
||||
$obj = VObject\Reader::read($response->body);
|
||||
|
||||
$this->assertEquals(8, count($obj->children()));
|
||||
$this->assertEquals(1, count($obj->VERSION));
|
||||
$this->assertEquals(1, count($obj->CALSCALE));
|
||||
$this->assertEquals(1, count($obj->PRODID));
|
||||
$this->assertTrue(strpos((string)$obj->PRODID, DAV\Version::VERSION) !== false);
|
||||
$this->assertEquals(1, count($obj->VTIMEZONE));
|
||||
$this->assertEquals(1, count($obj->VEVENT));
|
||||
$this->assertEquals("Hello!", $obj->{"X-WR-CALNAME"});
|
||||
$this->assertEquals("#AA0000FF", $obj->{"X-APPLE-CALENDAR-COLOR"});
|
||||
|
||||
}
|
||||
function testBeforeMethodNoVersion() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export'
|
||||
);
|
||||
DAV\Server::$exposeVersion = false;
|
||||
$response = $this->request($request);
|
||||
DAV\Server::$exposeVersion = true;
|
||||
|
||||
$this->assertEquals(200, $response->getStatus());
|
||||
$this->assertEquals('text/calendar', $response->getHeader('Content-Type'));
|
||||
|
||||
$obj = VObject\Reader::read($response->body);
|
||||
|
||||
$this->assertEquals(8, count($obj->children()));
|
||||
$this->assertEquals(1, count($obj->VERSION));
|
||||
$this->assertEquals(1, count($obj->CALSCALE));
|
||||
$this->assertEquals(1, count($obj->PRODID));
|
||||
$this->assertFalse(strpos((string)$obj->PRODID, DAV\Version::VERSION) !== false);
|
||||
$this->assertEquals(1, count($obj->VTIMEZONE));
|
||||
$this->assertEquals(1, count($obj->VEVENT));
|
||||
|
||||
}
|
||||
|
||||
function testBeforeMethodNoExport() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467'
|
||||
);
|
||||
$response = new HTTP\Response();
|
||||
$this->assertNull($this->icsExportPlugin->httpGet($request, $response));
|
||||
|
||||
}
|
||||
|
||||
function testACLIntegrationBlocked() {
|
||||
|
||||
$aclPlugin = new DAVACL\Plugin();
|
||||
$aclPlugin->allowUnauthenticatedAccess = false;
|
||||
$this->server->addPlugin(
|
||||
$aclPlugin
|
||||
);
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export'
|
||||
);
|
||||
|
||||
$this->request($request, 403);
|
||||
|
||||
}
|
||||
|
||||
function testACLIntegrationNotBlocked() {
|
||||
|
||||
$aclPlugin = new DAVACL\Plugin();
|
||||
$aclPlugin->allowUnauthenticatedAccess = false;
|
||||
$this->server->addPlugin(
|
||||
$aclPlugin
|
||||
);
|
||||
$this->server->addPlugin(
|
||||
new Plugin()
|
||||
);
|
||||
|
||||
$this->autoLogin('admin');
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export'
|
||||
);
|
||||
|
||||
$response = $this->request($request, 200);
|
||||
$this->assertEquals('text/calendar', $response->getHeader('Content-Type'));
|
||||
|
||||
$obj = VObject\Reader::read($response->body);
|
||||
|
||||
$this->assertEquals(8, count($obj->children()));
|
||||
$this->assertEquals(1, count($obj->VERSION));
|
||||
$this->assertEquals(1, count($obj->CALSCALE));
|
||||
$this->assertEquals(1, count($obj->PRODID));
|
||||
$this->assertTrue(strpos((string)$obj->PRODID, DAV\Version::VERSION) !== false);
|
||||
$this->assertEquals(1, count($obj->VTIMEZONE));
|
||||
$this->assertEquals(1, count($obj->VEVENT));
|
||||
|
||||
}
|
||||
|
||||
function testBadStartParam() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export&start=foo'
|
||||
);
|
||||
$this->request($request, 400);
|
||||
|
||||
}
|
||||
|
||||
function testBadEndParam() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export&end=foo'
|
||||
);
|
||||
$this->request($request, 400);
|
||||
|
||||
}
|
||||
|
||||
function testFilterStartEnd() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export&start=1&end=2'
|
||||
);
|
||||
$response = $this->request($request, 200);
|
||||
|
||||
$obj = VObject\Reader::read($response->getBody());
|
||||
|
||||
$this->assertEquals(0, count($obj->VTIMEZONE));
|
||||
$this->assertEquals(0, count($obj->VEVENT));
|
||||
|
||||
}
|
||||
|
||||
function testExpandNoStart() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export&expand=1&end=2'
|
||||
);
|
||||
$this->request($request, 400);
|
||||
|
||||
}
|
||||
|
||||
function testExpand() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export&start=1&end=2000000000&expand=1'
|
||||
);
|
||||
$response = $this->request($request, 200);
|
||||
|
||||
$obj = VObject\Reader::read($response->getBody());
|
||||
|
||||
$this->assertEquals(0, count($obj->VTIMEZONE));
|
||||
$this->assertEquals(1, count($obj->VEVENT));
|
||||
|
||||
}
|
||||
|
||||
function testJCal() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export',
|
||||
['Accept' => 'application/calendar+json']
|
||||
);
|
||||
|
||||
$response = $this->request($request, 200);
|
||||
$this->assertEquals('application/calendar+json', $response->getHeader('Content-Type'));
|
||||
|
||||
}
|
||||
|
||||
function testJCalInUrl() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export&accept=jcal'
|
||||
);
|
||||
|
||||
$response = $this->request($request, 200);
|
||||
$this->assertEquals('application/calendar+json', $response->getHeader('Content-Type'));
|
||||
|
||||
}
|
||||
|
||||
function testNegotiateDefault() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export',
|
||||
['Accept' => 'text/plain']
|
||||
);
|
||||
|
||||
$response = $this->request($request, 200);
|
||||
$this->assertEquals('text/calendar', $response->getHeader('Content-Type'));
|
||||
|
||||
}
|
||||
|
||||
function testFilterComponentVEVENT() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export&componentType=VEVENT'
|
||||
);
|
||||
|
||||
$response = $this->request($request, 200);
|
||||
|
||||
$obj = VObject\Reader::read($response->body);
|
||||
$this->assertEquals(1, count($obj->VTIMEZONE));
|
||||
$this->assertEquals(1, count($obj->VEVENT));
|
||||
$this->assertEquals(0, count($obj->VTODO));
|
||||
|
||||
}
|
||||
|
||||
function testFilterComponentVTODO() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export&componentType=VTODO'
|
||||
);
|
||||
|
||||
$response = $this->request($request, 200);
|
||||
|
||||
$obj = VObject\Reader::read($response->body);
|
||||
|
||||
$this->assertEquals(0, count($obj->VTIMEZONE));
|
||||
$this->assertEquals(0, count($obj->VEVENT));
|
||||
$this->assertEquals(1, count($obj->VTODO));
|
||||
|
||||
}
|
||||
|
||||
function testFilterComponentBadComponent() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export&componentType=VVOODOO'
|
||||
);
|
||||
|
||||
$response = $this->request($request, 400);
|
||||
|
||||
}
|
||||
|
||||
function testContentDisposition() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export'
|
||||
);
|
||||
|
||||
$response = $this->request($request, 200);
|
||||
$this->assertEquals('text/calendar', $response->getHeader('Content-Type'));
|
||||
$this->assertEquals(
|
||||
'attachment; filename="UUID-123467-' . date('Y-m-d') . '.ics"',
|
||||
$response->getHeader('Content-Disposition')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testContentDispositionJson() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-123467?export',
|
||||
['Accept' => 'application/calendar+json']
|
||||
);
|
||||
|
||||
$response = $this->request($request, 200);
|
||||
$this->assertEquals('application/calendar+json', $response->getHeader('Content-Type'));
|
||||
$this->assertEquals(
|
||||
'attachment; filename="UUID-123467-' . date('Y-m-d') . '.json"',
|
||||
$response->getHeader('Content-Disposition')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testContentDispositionBadChars() {
|
||||
|
||||
$this->caldavBackend->createCalendar(
|
||||
'principals/admin',
|
||||
'UUID-b_ad"(ch)ars',
|
||||
[
|
||||
'{DAV:}displayname' => 'Test bad characters',
|
||||
'{http://apple.com/ns/ical/}calendar-color' => '#AA0000FF',
|
||||
]
|
||||
);
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/calendars/admin/UUID-b_ad"(ch)ars?export',
|
||||
['Accept' => 'application/calendar+json']
|
||||
);
|
||||
|
||||
$response = $this->request($request, 200);
|
||||
$this->assertEquals('application/calendar+json', $response->getHeader('Content-Type'));
|
||||
$this->assertEquals(
|
||||
'attachment; filename="UUID-b_adchars-' . date('Y-m-d') . '.json"',
|
||||
$response->getHeader('Content-Disposition')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
class Issue166Test extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function testFlaw() {
|
||||
|
||||
$input = <<<HI
|
||||
BEGIN:VCALENDAR
|
||||
PRODID:-//Mozilla.org/NONSGML Mozilla Calendar V1.1//EN
|
||||
VERSION:2.0
|
||||
BEGIN:VTIMEZONE
|
||||
TZID:Asia/Pyongyang
|
||||
X-LIC-LOCATION:Asia/Pyongyang
|
||||
BEGIN:STANDARD
|
||||
TZOFFSETFROM:+0900
|
||||
TZOFFSETTO:+0900
|
||||
TZNAME:KST
|
||||
DTSTART:19700101T000000
|
||||
END:STANDARD
|
||||
END:VTIMEZONE
|
||||
BEGIN:VEVENT
|
||||
CREATED:20111118T010857Z
|
||||
LAST-MODIFIED:20111118T010937Z
|
||||
DTSTAMP:20111118T010937Z
|
||||
UID:a03245b3-9947-9a48-a088-863c74e0fdd8
|
||||
SUMMARY:New Event
|
||||
RRULE:FREQ=YEARLY
|
||||
DTSTART;TZID=Asia/Pyongyang:19960102T111500
|
||||
DTEND;TZID=Asia/Pyongyang:19960102T121500
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
HI;
|
||||
|
||||
$validator = new CalendarQueryValidator();
|
||||
|
||||
$filters = [
|
||||
'name' => 'VCALENDAR',
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VEVENT',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2011-12-01'),
|
||||
'end' => new \DateTime('2012-02-01'),
|
||||
],
|
||||
],
|
||||
],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => null,
|
||||
];
|
||||
$input = VObject\Reader::read($input);
|
||||
$this->assertTrue($validator->validate($input, $filters));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,135 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\VObject;
|
||||
|
||||
class Issue172Test extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
// DateTimeZone() native name: America/Los_Angeles (GMT-8 in January)
|
||||
function testBuiltInTimezoneName() {
|
||||
$input = <<<HI
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
DTSTART;TZID=America/Los_Angeles:20120118T204500
|
||||
DTEND;TZID=America/Los_Angeles:20120118T214500
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
HI;
|
||||
$validator = new CalendarQueryValidator();
|
||||
$filters = [
|
||||
'name' => 'VCALENDAR',
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VEVENT',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2012-01-18 21:00:00 GMT-08:00'),
|
||||
'end' => new \DateTime('2012-01-18 21:00:00 GMT-08:00'),
|
||||
],
|
||||
],
|
||||
],
|
||||
'prop-filters' => [],
|
||||
];
|
||||
$input = VObject\Reader::read($input);
|
||||
$this->assertTrue($validator->validate($input, $filters));
|
||||
}
|
||||
|
||||
// Pacific Standard Time, translates to America/Los_Angeles (GMT-8 in January)
|
||||
function testOutlookTimezoneName() {
|
||||
$input = <<<HI
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VTIMEZONE
|
||||
TZID:Pacific Standard Time
|
||||
BEGIN:STANDARD
|
||||
DTSTART:16010101T030000
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0100
|
||||
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
|
||||
END:STANDARD
|
||||
BEGIN:DAYLIGHT
|
||||
DTSTART:16010101T020000
|
||||
TZOFFSETFROM:+0100
|
||||
TZOFFSETTO:+0200
|
||||
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
|
||||
END:DAYLIGHT
|
||||
END:VTIMEZONE
|
||||
BEGIN:VEVENT
|
||||
DTSTART;TZID=Pacific Standard Time:20120113T100000
|
||||
DTEND;TZID=Pacific Standard Time:20120113T110000
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
HI;
|
||||
$validator = new CalendarQueryValidator();
|
||||
$filters = [
|
||||
'name' => 'VCALENDAR',
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VEVENT',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2012-01-13 10:30:00 GMT-08:00'),
|
||||
'end' => new \DateTime('2012-01-13 10:30:00 GMT-08:00'),
|
||||
],
|
||||
],
|
||||
],
|
||||
'prop-filters' => [],
|
||||
];
|
||||
$input = VObject\Reader::read($input);
|
||||
$this->assertTrue($validator->validate($input, $filters));
|
||||
}
|
||||
|
||||
// X-LIC-LOCATION, translates to America/Los_Angeles (GMT-8 in January)
|
||||
function testLibICalLocationName() {
|
||||
$input = <<<HI
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VTIMEZONE
|
||||
TZID:My own timezone name
|
||||
X-LIC-LOCATION:America/Los_Angeles
|
||||
BEGIN:STANDARD
|
||||
DTSTART:16010101T030000
|
||||
TZOFFSETFROM:+0200
|
||||
TZOFFSETTO:+0100
|
||||
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
|
||||
END:STANDARD
|
||||
BEGIN:DAYLIGHT
|
||||
DTSTART:16010101T020000
|
||||
TZOFFSETFROM:+0100
|
||||
TZOFFSETTO:+0200
|
||||
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
|
||||
END:DAYLIGHT
|
||||
END:VTIMEZONE
|
||||
BEGIN:VEVENT
|
||||
DTSTART;TZID=My own timezone name:20120113T100000
|
||||
DTEND;TZID=My own timezone name:20120113T110000
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
HI;
|
||||
$validator = new CalendarQueryValidator();
|
||||
$filters = [
|
||||
'name' => 'VCALENDAR',
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VEVENT',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false,
|
||||
'time-range' => [
|
||||
'start' => new \DateTime('2012-01-13 10:30:00 GMT-08:00'),
|
||||
'end' => new \DateTime('2012-01-13 10:30:00 GMT-08:00'),
|
||||
],
|
||||
],
|
||||
],
|
||||
'prop-filters' => [],
|
||||
];
|
||||
$input = VObject\Reader::read($input);
|
||||
$this->assertTrue($validator->validate($input, $filters));
|
||||
}
|
||||
}
|
||||
@ -1,137 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\HTTP;
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* This unittest is created to find out why an overwritten DAILY event has wrong DTSTART, DTEND, SUMMARY and RECURRENCEID
|
||||
*
|
||||
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
class Issue203Test extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
|
||||
protected $caldavCalendars = [
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => 'Calendar',
|
||||
'principaluri' => 'principals/user1',
|
||||
'uri' => 'calendar1',
|
||||
]
|
||||
];
|
||||
|
||||
protected $caldavCalendarObjects = [
|
||||
1 => [
|
||||
'event.ics' => [
|
||||
'calendardata' => 'BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:20120330T155305CEST-6585fBUVgV
|
||||
DTSTAMP:20120330T135305Z
|
||||
DTSTART;TZID=Europe/Berlin:20120326T155200
|
||||
DTEND;TZID=Europe/Berlin:20120326T165200
|
||||
RRULE:FREQ=DAILY;COUNT=2;INTERVAL=1
|
||||
SUMMARY:original summary
|
||||
TRANSP:OPAQUE
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
UID:20120330T155305CEST-6585fBUVgV
|
||||
DTSTAMP:20120330T135352Z
|
||||
DESCRIPTION:
|
||||
DTSTART;TZID=Europe/Berlin:20120328T155200
|
||||
DTEND;TZID=Europe/Berlin:20120328T165200
|
||||
RECURRENCE-ID;TZID=Europe/Berlin:20120327T155200
|
||||
SEQUENCE:1
|
||||
SUMMARY:overwritten summary
|
||||
TRANSP:OPAQUE
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
function testIssue203() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'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="20120325T220000Z" end="20120401T215959Z"/>
|
||||
</C:calendar-data>
|
||||
<D:getetag/>
|
||||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT">
|
||||
<C:time-range start="20120325T220000Z" end="20120401T215959Z"/>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
</C:calendar-query>');
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
// Everts super awesome xml parser.
|
||||
$body = substr(
|
||||
$response->body,
|
||||
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
|
||||
strpos($response->body, 'END:VCALENDAR') - $start + 13
|
||||
);
|
||||
$body = str_replace(' ', '', $body);
|
||||
|
||||
$vObject = VObject\Reader::read($body);
|
||||
|
||||
$this->assertEquals(2, count($vObject->VEVENT));
|
||||
|
||||
|
||||
$expectedEvents = [
|
||||
[
|
||||
'DTSTART' => '20120326T135200Z',
|
||||
'DTEND' => '20120326T145200Z',
|
||||
'SUMMARY' => 'original summary',
|
||||
],
|
||||
[
|
||||
'DTSTART' => '20120328T135200Z',
|
||||
'DTEND' => '20120328T145200Z',
|
||||
'SUMMARY' => 'overwritten summary',
|
||||
'RECURRENCE-ID' => '20120327T135200Z',
|
||||
]
|
||||
];
|
||||
|
||||
// try to match agains $expectedEvents array
|
||||
foreach ($expectedEvents as $expectedEvent) {
|
||||
|
||||
$matching = false;
|
||||
|
||||
foreach ($vObject->VEVENT as $vevent) {
|
||||
/** @var $vevent Sabre\VObject\Component\VEvent */
|
||||
foreach ($vevent->children() as $child) {
|
||||
/** @var $child Sabre\VObject\Property */
|
||||
if (isset($expectedEvent[$child->name])) {
|
||||
if ($expectedEvent[$child->name] != $child->getValue()) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$matching = true;
|
||||
break;
|
||||
}
|
||||
|
||||
$this->assertTrue($matching, 'Did not find the following event in the response: ' . var_export($expectedEvent, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,98 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\HTTP;
|
||||
use Sabre\VObject;
|
||||
|
||||
/**
|
||||
* This unittest is created to check if a VALARM TRIGGER of PT0S is supported
|
||||
*
|
||||
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
class Issue205Test extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
|
||||
protected $caldavCalendars = [
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => 'Calendar',
|
||||
'principaluri' => 'principals/user1',
|
||||
'uri' => 'calendar1',
|
||||
]
|
||||
];
|
||||
|
||||
protected $caldavCalendarObjects = [
|
||||
1 => [
|
||||
'event.ics' => [
|
||||
'calendardata' => 'BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:20120330T155305CEST-6585fBUVgV
|
||||
DTSTAMP:20120330T135305Z
|
||||
DTSTART;TZID=Europe/Berlin:20120326T155200
|
||||
DTEND;TZID=Europe/Berlin:20120326T165200
|
||||
SUMMARY:original summary
|
||||
TRANSP:OPAQUE
|
||||
BEGIN:VALARM
|
||||
ACTION:AUDIO
|
||||
ATTACH;VALUE=URI:Basso
|
||||
TRIGGER:PT0S
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
function testIssue205() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'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="20120325T220000Z" end="20120401T215959Z"/>
|
||||
</C:calendar-data>
|
||||
<D:getetag/>
|
||||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT">
|
||||
<C:comp-filter name="VALARM">
|
||||
<C:time-range start="20120325T220000Z" end="20120401T215959Z"/>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
</C:calendar-query>');
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertFalse(strpos($response->body, '<s:exception>Exception</s:exception>'), 'Exception occurred: ' . $response->body);
|
||||
$this->assertFalse(strpos($response->body, 'Unknown or bad format'), 'DateTime unknown format Exception: ' . $response->body);
|
||||
|
||||
// Everts super awesome xml parser.
|
||||
$body = substr(
|
||||
$response->body,
|
||||
$start = strpos($response->body, 'BEGIN:VCALENDAR'),
|
||||
strpos($response->body, 'END:VCALENDAR') - $start + 13
|
||||
);
|
||||
$body = str_replace(' ', '', $body);
|
||||
|
||||
$vObject = VObject\Reader::read($body);
|
||||
|
||||
$this->assertEquals(1, count($vObject->VEVENT));
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,89 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\HTTP;
|
||||
|
||||
/**
|
||||
* This unittest is created to check for an endless loop in Sabre\CalDAV\CalendarQueryValidator
|
||||
*
|
||||
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
class Issue211Test extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
|
||||
protected $caldavCalendars = [
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => 'Calendar',
|
||||
'principaluri' => 'principals/user1',
|
||||
'uri' => 'calendar1',
|
||||
]
|
||||
];
|
||||
|
||||
protected $caldavCalendarObjects = [
|
||||
1 => [
|
||||
'event.ics' => [
|
||||
'calendardata' => 'BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:20120418T172519CEST-3510gh1hVw
|
||||
DTSTAMP:20120418T152519Z
|
||||
DTSTART;VALUE=DATE:20120330
|
||||
DTEND;VALUE=DATE:20120531
|
||||
EXDATE;TZID=Europe/Berlin:20120330T000000
|
||||
RRULE:FREQ=YEARLY;INTERVAL=1
|
||||
SEQUENCE:1
|
||||
SUMMARY:Birthday
|
||||
TRANSP:TRANSPARENT
|
||||
BEGIN:VALARM
|
||||
ACTION:EMAIL
|
||||
ATTENDEE:MAILTO:xxx@domain.de
|
||||
DESCRIPTION:Dies ist eine Kalender Erinnerung
|
||||
SUMMARY:Kalender Alarm Erinnerung
|
||||
TRIGGER;VALUE=DATE-TIME:20120329T060000Z
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
function testIssue211() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'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/>
|
||||
<D:getetag/>
|
||||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT">
|
||||
<C:comp-filter name="VALARM">
|
||||
<C:time-range start="20120426T220000Z" end="20120427T215959Z"/>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
</C:calendar-query>');
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
// if this assert is reached, the endless loop is gone
|
||||
// There should be no matching events
|
||||
$this->assertFalse(strpos('BEGIN:VEVENT', $response->body));
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,99 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\HTTP;
|
||||
|
||||
/**
|
||||
* This unittest is created to check for an endless loop in CalendarQueryValidator
|
||||
*
|
||||
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
class Issue220Test extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
|
||||
protected $caldavCalendars = [
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => 'Calendar',
|
||||
'principaluri' => 'principals/user1',
|
||||
'uri' => 'calendar1',
|
||||
]
|
||||
];
|
||||
|
||||
protected $caldavCalendarObjects = [
|
||||
1 => [
|
||||
'event.ics' => [
|
||||
'calendardata' => 'BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
DTSTART;TZID=Europe/Berlin:20120601T180000
|
||||
SUMMARY:Brot backen
|
||||
RRULE:FREQ=DAILY;INTERVAL=1;WKST=MO
|
||||
TRANSP:OPAQUE
|
||||
DURATION:PT20M
|
||||
LAST-MODIFIED:20120601T064634Z
|
||||
CREATED:20120601T064634Z
|
||||
DTSTAMP:20120601T064634Z
|
||||
UID:b64f14c5-dccc-4eda-947f-bdb1f763fbcd
|
||||
BEGIN:VALARM
|
||||
TRIGGER;VALUE=DURATION:-PT5M
|
||||
ACTION:DISPLAY
|
||||
DESCRIPTION:Default Event Notification
|
||||
X-WR-ALARMUID:cd952c1b-b3d6-41fb-b0a6-ec3a1a5bdd58
|
||||
END:VALARM
|
||||
END:VEVENT
|
||||
BEGIN:VEVENT
|
||||
DTSTART;TZID=Europe/Berlin:20120606T180000
|
||||
SUMMARY:Brot backen
|
||||
TRANSP:OPAQUE
|
||||
STATUS:CANCELLED
|
||||
DTEND;TZID=Europe/Berlin:20120606T182000
|
||||
LAST-MODIFIED:20120605T094310Z
|
||||
SEQUENCE:1
|
||||
RECURRENCE-ID:20120606T160000Z
|
||||
UID:b64f14c5-dccc-4eda-947f-bdb1f763fbcd
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
function testIssue220() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'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/>
|
||||
<D:getetag/>
|
||||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VEVENT">
|
||||
<C:comp-filter name="VALARM">
|
||||
<C:time-range start="20120607T161646Z" end="20120612T161646Z"/>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
</C:filter>
|
||||
</C:calendar-query>');
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertFalse(strpos($response->body, '<s:exception>PHPUnit_Framework_Error_Warning</s:exception>'), 'Error Warning occurred: ' . $response->body);
|
||||
$this->assertFalse(strpos($response->body, 'Invalid argument supplied for foreach()'), 'Invalid argument supplied for foreach(): ' . $response->body);
|
||||
|
||||
$this->assertEquals(207, $response->status);
|
||||
}
|
||||
}
|
||||
@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\HTTP;
|
||||
|
||||
/**
|
||||
* This unittest is created to check if the time-range filter is working correctly with all-day-events
|
||||
*
|
||||
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
class Issue228Test extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
|
||||
protected $caldavCalendars = [
|
||||
[
|
||||
'id' => 1,
|
||||
'name' => 'Calendar',
|
||||
'principaluri' => 'principals/user1',
|
||||
'uri' => 'calendar1',
|
||||
]
|
||||
];
|
||||
|
||||
protected $caldavCalendarObjects = [
|
||||
1 => [
|
||||
'event.ics' => [
|
||||
'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 = HTTP\Sapi::createFromServerArray([
|
||||
'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'));
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,262 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\HTTP\Request;
|
||||
use Sabre\VObject;
|
||||
|
||||
class JCalTransformTest extends \Sabre\DAVServerTest {
|
||||
|
||||
use VObject\PHPUnitAssertions;
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
protected $caldavCalendars = [
|
||||
[
|
||||
'id' => 1,
|
||||
'principaluri' => 'principals/user1',
|
||||
'uri' => 'foo',
|
||||
]
|
||||
];
|
||||
protected $caldavCalendarObjects = [
|
||||
1 => [
|
||||
'bar.ics' => [
|
||||
'uri' => 'bar.ics',
|
||||
'calendarid' => 1,
|
||||
'calendardata' => "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n",
|
||||
'lastmodified' => null
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
function testGet() {
|
||||
|
||||
$headers = [
|
||||
'Accept' => 'application/calendar+json',
|
||||
];
|
||||
$request = new Request('GET', '/calendars/user1/foo/bar.ics', $headers);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$body = $response->getBodyAsString();
|
||||
$this->assertEquals(200, $response->getStatus(), "Incorrect status code: " . $body);
|
||||
|
||||
$response = json_decode($body, true);
|
||||
if (json_last_error() !== JSON_ERROR_NONE) {
|
||||
$this->fail('Json decoding error: ' . json_last_error_msg());
|
||||
}
|
||||
$this->assertEquals(
|
||||
[
|
||||
'vcalendar',
|
||||
[],
|
||||
[
|
||||
[
|
||||
'vevent',
|
||||
[],
|
||||
[],
|
||||
],
|
||||
],
|
||||
],
|
||||
$response
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testMultiGet() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:calendar-multiget xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
|
||||
<d:prop>
|
||||
<c:calendar-data content-type="application/calendar+json" />
|
||||
</d:prop>
|
||||
<d:href>/calendars/user1/foo/bar.ics</d:href>
|
||||
</c:calendar-multiget>
|
||||
XML;
|
||||
|
||||
$headers = [];
|
||||
$request = new Request('REPORT', '/calendars/user1/foo', $headers, $xml);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(207, $response->getStatus(), 'Full rsponse: ' . $response->getBodyAsString());
|
||||
|
||||
$multiStatus = $this->server->xml->parse(
|
||||
$response->getBodyAsString()
|
||||
);
|
||||
|
||||
$responses = $multiStatus->getResponses();
|
||||
$this->assertEquals(1, count($responses));
|
||||
|
||||
$response = $responses[0]->getResponseProperties()[200]["{urn:ietf:params:xml:ns:caldav}calendar-data"];
|
||||
|
||||
$jresponse = json_decode($response, true);
|
||||
if (json_last_error()) {
|
||||
$this->fail('Json decoding error: ' . json_last_error_msg() . '. Full response: ' . $response);
|
||||
}
|
||||
$this->assertEquals(
|
||||
[
|
||||
'vcalendar',
|
||||
[],
|
||||
[
|
||||
[
|
||||
'vevent',
|
||||
[],
|
||||
[],
|
||||
],
|
||||
],
|
||||
],
|
||||
$jresponse
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testCalendarQueryDepth1() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
|
||||
<d:prop>
|
||||
<c:calendar-data content-type="application/calendar+json" />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:comp-filter name="VCALENDAR" />
|
||||
</c:filter>
|
||||
</c:calendar-query>
|
||||
XML;
|
||||
|
||||
$headers = [
|
||||
'Depth' => '1',
|
||||
];
|
||||
$request = new Request('REPORT', '/calendars/user1/foo', $headers, $xml);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(207, $response->getStatus(), "Invalid response code. Full body: " . $response->getBodyAsString());
|
||||
|
||||
$multiStatus = $this->server->xml->parse(
|
||||
$response->getBodyAsString()
|
||||
);
|
||||
|
||||
$responses = $multiStatus->getResponses();
|
||||
|
||||
$this->assertEquals(1, count($responses));
|
||||
|
||||
$response = $responses[0]->getResponseProperties()[200]["{urn:ietf:params:xml:ns:caldav}calendar-data"];
|
||||
$response = json_decode($response, true);
|
||||
if (json_last_error()) {
|
||||
$this->fail('Json decoding error: ' . json_last_error_msg());
|
||||
}
|
||||
$this->assertEquals(
|
||||
[
|
||||
'vcalendar',
|
||||
[],
|
||||
[
|
||||
[
|
||||
'vevent',
|
||||
[],
|
||||
[],
|
||||
],
|
||||
],
|
||||
],
|
||||
$response
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testCalendarQueryDepth0() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:calendar-query xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
|
||||
<d:prop>
|
||||
<c:calendar-data content-type="application/calendar+json" />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:comp-filter name="VCALENDAR" />
|
||||
</c:filter>
|
||||
</c:calendar-query>
|
||||
XML;
|
||||
|
||||
$headers = [
|
||||
'Depth' => '0',
|
||||
];
|
||||
$request = new Request('REPORT', '/calendars/user1/foo/bar.ics', $headers, $xml);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(207, $response->getStatus(), "Invalid response code. Full body: " . $response->getBodyAsString());
|
||||
|
||||
$multiStatus = $this->server->xml->parse(
|
||||
$response->getBodyAsString()
|
||||
);
|
||||
|
||||
$responses = $multiStatus->getResponses();
|
||||
|
||||
$this->assertEquals(1, count($responses));
|
||||
|
||||
$response = $responses[0]->getResponseProperties()[200]["{urn:ietf:params:xml:ns:caldav}calendar-data"];
|
||||
$response = json_decode($response, true);
|
||||
if (json_last_error()) {
|
||||
$this->fail('Json decoding error: ' . json_last_error_msg());
|
||||
}
|
||||
$this->assertEquals(
|
||||
[
|
||||
'vcalendar',
|
||||
[],
|
||||
[
|
||||
[
|
||||
'vevent',
|
||||
[],
|
||||
[],
|
||||
],
|
||||
],
|
||||
],
|
||||
$response
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testValidateICalendar() {
|
||||
|
||||
$input = [
|
||||
'vcalendar',
|
||||
[],
|
||||
[
|
||||
[
|
||||
'vevent',
|
||||
[
|
||||
['uid', (object)[], 'text', 'foo'],
|
||||
['dtstart', (object)[], 'date', '2016-04-06'],
|
||||
],
|
||||
[],
|
||||
],
|
||||
],
|
||||
];
|
||||
$input = json_encode($input);
|
||||
$this->caldavPlugin->beforeWriteContent(
|
||||
'calendars/user1/foo/bar.ics',
|
||||
$this->server->tree->getNodeForPath('calendars/user1/foo/bar.ics'),
|
||||
$input,
|
||||
$modified
|
||||
);
|
||||
|
||||
|
||||
$expected = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART;VALUE=DATE:20160406
|
||||
DTSTAMP:**ANY**
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->assertVObjectEqualsVObject(
|
||||
$expected,
|
||||
$input
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,85 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Notifications;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
|
||||
class CollectionTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
protected $caldavBackend;
|
||||
protected $principalUri;
|
||||
protected $notification;
|
||||
|
||||
function getInstance() {
|
||||
|
||||
$this->principalUri = 'principals/user1';
|
||||
|
||||
$this->notification = new CalDAV\Xml\Notification\SystemStatus(1, '"1"');
|
||||
|
||||
$this->caldavBackend = new CalDAV\Backend\MockSharing([], [], [
|
||||
'principals/user1' => [
|
||||
$this->notification
|
||||
]
|
||||
]);
|
||||
|
||||
return new Collection($this->caldavBackend, $this->principalUri);
|
||||
|
||||
}
|
||||
|
||||
function testGetChildren() {
|
||||
|
||||
$col = $this->getInstance();
|
||||
$this->assertEquals('notifications', $col->getName());
|
||||
|
||||
$this->assertEquals([
|
||||
new Node($this->caldavBackend, $this->principalUri, $this->notification)
|
||||
], $col->getChildren());
|
||||
|
||||
}
|
||||
|
||||
function testGetOwner() {
|
||||
|
||||
$col = $this->getInstance();
|
||||
$this->assertEquals('principals/user1', $col->getOwner());
|
||||
|
||||
}
|
||||
|
||||
function testGetGroup() {
|
||||
|
||||
$col = $this->getInstance();
|
||||
$this->assertNull($col->getGroup());
|
||||
|
||||
}
|
||||
|
||||
function testGetACL() {
|
||||
|
||||
$col = $this->getInstance();
|
||||
$expected = [
|
||||
[
|
||||
'privilege' => '{DAV:}all',
|
||||
'principal' => '{DAV:}owner',
|
||||
'protected' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $col->getACL());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testSetACL() {
|
||||
|
||||
$col = $this->getInstance();
|
||||
$col->setACL([]);
|
||||
|
||||
}
|
||||
|
||||
function testGetSupportedPrivilegeSet() {
|
||||
|
||||
$col = $this->getInstance();
|
||||
$this->assertNull($col->getSupportedPrivilegeSet());
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,96 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Notifications;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
|
||||
class NodeTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
protected $systemStatus;
|
||||
protected $caldavBackend;
|
||||
|
||||
function getInstance() {
|
||||
|
||||
$principalUri = 'principals/user1';
|
||||
|
||||
$this->systemStatus = new CalDAV\Xml\Notification\SystemStatus(1, '"1"');
|
||||
|
||||
$this->caldavBackend = new CalDAV\Backend\MockSharing([], [], [
|
||||
'principals/user1' => [
|
||||
$this->systemStatus
|
||||
]
|
||||
]);
|
||||
|
||||
$node = new Node($this->caldavBackend, 'principals/user1', $this->systemStatus);
|
||||
return $node;
|
||||
|
||||
}
|
||||
|
||||
function testGetId() {
|
||||
|
||||
$node = $this->getInstance();
|
||||
$this->assertEquals($this->systemStatus->getId() . '.xml', $node->getName());
|
||||
|
||||
}
|
||||
|
||||
function testGetEtag() {
|
||||
|
||||
$node = $this->getInstance();
|
||||
$this->assertEquals('"1"', $node->getETag());
|
||||
|
||||
}
|
||||
|
||||
function testGetNotificationType() {
|
||||
|
||||
$node = $this->getInstance();
|
||||
$this->assertEquals($this->systemStatus, $node->getNotificationType());
|
||||
|
||||
}
|
||||
|
||||
function testDelete() {
|
||||
|
||||
$node = $this->getInstance();
|
||||
$node->delete();
|
||||
$this->assertEquals([], $this->caldavBackend->getNotificationsForPrincipal('principals/user1'));
|
||||
|
||||
}
|
||||
|
||||
function testGetGroup() {
|
||||
|
||||
$node = $this->getInstance();
|
||||
$this->assertNull($node->getGroup());
|
||||
|
||||
}
|
||||
|
||||
function testGetACL() {
|
||||
|
||||
$node = $this->getInstance();
|
||||
$expected = [
|
||||
[
|
||||
'privilege' => '{DAV:}all',
|
||||
'principal' => '{DAV:}owner',
|
||||
'protected' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $node->getACL());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testSetACL() {
|
||||
|
||||
$node = $this->getInstance();
|
||||
$node->setACL([]);
|
||||
|
||||
}
|
||||
|
||||
function testGetSupportedPrivilegeSet() {
|
||||
|
||||
$node = $this->getInstance();
|
||||
$this->assertNull($node->getSupportedPrivilegeSet());
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,168 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Notifications;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\CalDAV\Xml\Notification\SystemStatus;
|
||||
use Sabre\DAV;
|
||||
use Sabre\DAVACL;
|
||||
use Sabre\HTTP;
|
||||
use Sabre\HTTP\Request;
|
||||
|
||||
class PluginTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Sabre\DAV\Server
|
||||
*/
|
||||
protected $server;
|
||||
/**
|
||||
* @var Sabre\CalDAV\Plugin
|
||||
*/
|
||||
protected $plugin;
|
||||
protected $response;
|
||||
/**
|
||||
* @var Sabre\CalDAV\Backend\PDO
|
||||
*/
|
||||
protected $caldavBackend;
|
||||
|
||||
function setup() {
|
||||
|
||||
$this->caldavBackend = new CalDAV\Backend\MockSharing();
|
||||
$principalBackend = new DAVACL\PrincipalBackend\Mock();
|
||||
$calendars = new CalDAV\CalendarRoot($principalBackend, $this->caldavBackend);
|
||||
$principals = new CalDAV\Principal\Collection($principalBackend);
|
||||
|
||||
$root = new DAV\SimpleCollection('root');
|
||||
$root->addChild($calendars);
|
||||
$root->addChild($principals);
|
||||
|
||||
$this->server = new DAV\Server($root);
|
||||
$this->server->sapi = new HTTP\SapiMock();
|
||||
$this->server->debugExceptions = true;
|
||||
$this->server->setBaseUri('/');
|
||||
$this->plugin = new Plugin();
|
||||
$this->server->addPlugin($this->plugin);
|
||||
|
||||
|
||||
// Adding ACL plugin
|
||||
$aclPlugin = new DAVACL\Plugin();
|
||||
$aclPlugin->allowUnauthenticatedAccess = false;
|
||||
$this->server->addPlugin($aclPlugin);
|
||||
|
||||
// CalDAV is also required.
|
||||
$this->server->addPlugin(new CalDAV\Plugin());
|
||||
// Adding Auth plugin, and ensuring that we are logged in.
|
||||
$authBackend = new DAV\Auth\Backend\Mock();
|
||||
$authPlugin = new DAV\Auth\Plugin($authBackend);
|
||||
$this->server->addPlugin($authPlugin);
|
||||
|
||||
// This forces a login
|
||||
$authPlugin->beforeMethod(new HTTP\Request(), new HTTP\Response());
|
||||
|
||||
$this->response = new HTTP\ResponseMock();
|
||||
$this->server->httpResponse = $this->response;
|
||||
|
||||
}
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$this->assertEquals([], $this->plugin->getFeatures());
|
||||
$this->assertEquals('notifications', $this->plugin->getPluginName());
|
||||
$this->assertEquals(
|
||||
'notifications',
|
||||
$this->plugin->getPluginInfo()['name']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testPrincipalProperties() {
|
||||
|
||||
$httpRequest = new Request('GET', '/', ['Host' => 'sabredav.org']);
|
||||
$this->server->httpRequest = $httpRequest;
|
||||
|
||||
$props = $this->server->getPropertiesForPath('principals/admin', [
|
||||
'{' . Plugin::NS_CALENDARSERVER . '}notification-URL',
|
||||
]);
|
||||
|
||||
$this->assertArrayHasKey(0, $props);
|
||||
$this->assertArrayHasKey(200, $props[0]);
|
||||
|
||||
$this->assertArrayHasKey('{' . Plugin::NS_CALENDARSERVER . '}notification-URL', $props[0][200]);
|
||||
$prop = $props[0][200]['{' . Plugin::NS_CALENDARSERVER . '}notification-URL'];
|
||||
$this->assertTrue($prop instanceof DAV\Xml\Property\Href);
|
||||
$this->assertEquals('calendars/admin/notifications/', $prop->getHref());
|
||||
|
||||
}
|
||||
|
||||
function testNotificationProperties() {
|
||||
|
||||
$notification = new Node(
|
||||
$this->caldavBackend,
|
||||
'principals/user1',
|
||||
new SystemStatus('foo', '"1"')
|
||||
);
|
||||
$propFind = new DAV\PropFind('calendars/user1/notifications', [
|
||||
'{' . Plugin::NS_CALENDARSERVER . '}notificationtype',
|
||||
]);
|
||||
|
||||
$this->plugin->propFind($propFind, $notification);
|
||||
|
||||
$this->assertEquals(
|
||||
$notification->getNotificationType(),
|
||||
$propFind->get('{' . Plugin::NS_CALENDARSERVER . '}notificationtype')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testNotificationGet() {
|
||||
|
||||
$notification = new Node(
|
||||
$this->caldavBackend,
|
||||
'principals/user1',
|
||||
new SystemStatus('foo', '"1"')
|
||||
);
|
||||
|
||||
$server = new DAV\Server([$notification]);
|
||||
$caldav = new Plugin();
|
||||
|
||||
$server->httpRequest = new Request('GET', '/foo.xml');
|
||||
$httpResponse = new HTTP\ResponseMock();
|
||||
$server->httpResponse = $httpResponse;
|
||||
|
||||
$server->addPlugin($caldav);
|
||||
|
||||
$caldav->httpGet($server->httpRequest, $server->httpResponse);
|
||||
|
||||
$this->assertEquals(200, $httpResponse->status);
|
||||
$this->assertEquals([
|
||||
'Content-Type' => ['application/xml'],
|
||||
'ETag' => ['"1"'],
|
||||
], $httpResponse->getHeaders());
|
||||
|
||||
$expected =
|
||||
'<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cs:notification xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns" xmlns:cs="http://calendarserver.org/ns/">
|
||||
<cs:systemstatus type="high"/>
|
||||
</cs:notification>
|
||||
';
|
||||
|
||||
$this->assertXmlStringEqualsXmlString($expected, $httpResponse->getBodyAsString());
|
||||
|
||||
}
|
||||
|
||||
function testGETPassthrough() {
|
||||
|
||||
$server = new DAV\Server();
|
||||
$caldav = new Plugin();
|
||||
|
||||
$httpResponse = new HTTP\ResponseMock();
|
||||
$server->httpResponse = $httpResponse;
|
||||
|
||||
$server->addPlugin($caldav);
|
||||
|
||||
$this->assertNull($caldav->httpGet(new HTTP\Request('GET', '/foozz'), $server->httpResponse));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Principal;
|
||||
|
||||
use Sabre\DAVACL;
|
||||
|
||||
class CollectionTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function testGetChildForPrincipal() {
|
||||
|
||||
$back = new DAVACL\PrincipalBackend\Mock();
|
||||
$col = new Collection($back);
|
||||
$r = $col->getChildForPrincipal([
|
||||
'uri' => 'principals/admin',
|
||||
]);
|
||||
$this->assertInstanceOf('Sabre\\CalDAV\\Principal\\User', $r);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Principal;
|
||||
|
||||
use Sabre\DAVACL;
|
||||
|
||||
class ProxyReadTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
protected $backend;
|
||||
|
||||
function getInstance() {
|
||||
|
||||
$backend = new DAVACL\PrincipalBackend\Mock();
|
||||
$principal = new ProxyRead($backend, [
|
||||
'uri' => 'principal/user',
|
||||
]);
|
||||
$this->backend = $backend;
|
||||
return $principal;
|
||||
|
||||
}
|
||||
|
||||
function testGetName() {
|
||||
|
||||
$i = $this->getInstance();
|
||||
$this->assertEquals('calendar-proxy-read', $i->getName());
|
||||
|
||||
}
|
||||
function testGetDisplayName() {
|
||||
|
||||
$i = $this->getInstance();
|
||||
$this->assertEquals('calendar-proxy-read', $i->getDisplayName());
|
||||
|
||||
}
|
||||
|
||||
function testGetLastModified() {
|
||||
|
||||
$i = $this->getInstance();
|
||||
$this->assertNull($i->getLastModified());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testDelete() {
|
||||
|
||||
$i = $this->getInstance();
|
||||
$i->delete();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testSetName() {
|
||||
|
||||
$i = $this->getInstance();
|
||||
$i->setName('foo');
|
||||
|
||||
}
|
||||
|
||||
function testGetAlternateUriSet() {
|
||||
|
||||
$i = $this->getInstance();
|
||||
$this->assertEquals([], $i->getAlternateUriSet());
|
||||
|
||||
}
|
||||
|
||||
function testGetPrincipalUri() {
|
||||
|
||||
$i = $this->getInstance();
|
||||
$this->assertEquals('principal/user/calendar-proxy-read', $i->getPrincipalUrl());
|
||||
|
||||
}
|
||||
|
||||
function testGetGroupMemberSet() {
|
||||
|
||||
$i = $this->getInstance();
|
||||
$this->assertEquals([], $i->getGroupMemberSet());
|
||||
|
||||
}
|
||||
|
||||
function testGetGroupMembership() {
|
||||
|
||||
$i = $this->getInstance();
|
||||
$this->assertEquals([], $i->getGroupMembership());
|
||||
|
||||
}
|
||||
|
||||
function testSetGroupMemberSet() {
|
||||
|
||||
$i = $this->getInstance();
|
||||
$i->setGroupMemberSet(['principals/foo']);
|
||||
|
||||
$expected = [
|
||||
$i->getPrincipalUrl() => ['principals/foo']
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $this->backend->groupMembers);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Principal;
|
||||
|
||||
use Sabre\DAVACL;
|
||||
|
||||
class ProxyWriteTest extends ProxyReadTest {
|
||||
|
||||
function getInstance() {
|
||||
|
||||
$backend = new DAVACL\PrincipalBackend\Mock();
|
||||
$principal = new ProxyWrite($backend, [
|
||||
'uri' => 'principal/user',
|
||||
]);
|
||||
$this->backend = $backend;
|
||||
return $principal;
|
||||
|
||||
}
|
||||
|
||||
function testGetName() {
|
||||
|
||||
$i = $this->getInstance();
|
||||
$this->assertEquals('calendar-proxy-write', $i->getName());
|
||||
|
||||
}
|
||||
function testGetDisplayName() {
|
||||
|
||||
$i = $this->getInstance();
|
||||
$this->assertEquals('calendar-proxy-write', $i->getDisplayName());
|
||||
|
||||
}
|
||||
|
||||
function testGetPrincipalUri() {
|
||||
|
||||
$i = $this->getInstance();
|
||||
$this->assertEquals('principal/user/calendar-proxy-write', $i->getPrincipalUrl());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,127 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Principal;
|
||||
|
||||
use Sabre\DAVACL;
|
||||
|
||||
class UserTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function getInstance() {
|
||||
|
||||
$backend = new DAVACL\PrincipalBackend\Mock();
|
||||
$backend->addPrincipal([
|
||||
'uri' => 'principals/user/calendar-proxy-read',
|
||||
]);
|
||||
$backend->addPrincipal([
|
||||
'uri' => 'principals/user/calendar-proxy-write',
|
||||
]);
|
||||
$backend->addPrincipal([
|
||||
'uri' => 'principals/user/random',
|
||||
]);
|
||||
return new User($backend, [
|
||||
'uri' => 'principals/user',
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testCreateFile() {
|
||||
|
||||
$u = $this->getInstance();
|
||||
$u->createFile('test');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testCreateDirectory() {
|
||||
|
||||
$u = $this->getInstance();
|
||||
$u->createDirectory('test');
|
||||
|
||||
}
|
||||
|
||||
function testGetChildProxyRead() {
|
||||
|
||||
$u = $this->getInstance();
|
||||
$child = $u->getChild('calendar-proxy-read');
|
||||
$this->assertInstanceOf('Sabre\\CalDAV\\Principal\\ProxyRead', $child);
|
||||
|
||||
}
|
||||
|
||||
function testGetChildProxyWrite() {
|
||||
|
||||
$u = $this->getInstance();
|
||||
$child = $u->getChild('calendar-proxy-write');
|
||||
$this->assertInstanceOf('Sabre\\CalDAV\\Principal\\ProxyWrite', $child);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\NotFound
|
||||
*/
|
||||
function testGetChildNotFound() {
|
||||
|
||||
$u = $this->getInstance();
|
||||
$child = $u->getChild('foo');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\NotFound
|
||||
*/
|
||||
function testGetChildNotFound2() {
|
||||
|
||||
$u = $this->getInstance();
|
||||
$child = $u->getChild('random');
|
||||
|
||||
}
|
||||
|
||||
function testGetChildren() {
|
||||
|
||||
$u = $this->getInstance();
|
||||
$children = $u->getChildren();
|
||||
$this->assertEquals(2, count($children));
|
||||
$this->assertInstanceOf('Sabre\\CalDAV\\Principal\\ProxyRead', $children[0]);
|
||||
$this->assertInstanceOf('Sabre\\CalDAV\\Principal\\ProxyWrite', $children[1]);
|
||||
|
||||
}
|
||||
|
||||
function testChildExist() {
|
||||
|
||||
$u = $this->getInstance();
|
||||
$this->assertTrue($u->childExists('calendar-proxy-read'));
|
||||
$this->assertTrue($u->childExists('calendar-proxy-write'));
|
||||
$this->assertFalse($u->childExists('foo'));
|
||||
|
||||
}
|
||||
|
||||
function testGetACL() {
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'privilege' => '{DAV:}all',
|
||||
'principal' => '{DAV:}owner',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user/calendar-proxy-read',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$u = $this->getInstance();
|
||||
$this->assertEquals($expected, $u->getACL());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,92 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Schedule;
|
||||
|
||||
use Sabre\HTTP\Request;
|
||||
use Sabre\VObject;
|
||||
|
||||
class DeliverNewEventTest extends \Sabre\DAVServerTest {
|
||||
|
||||
public $setupCalDAV = true;
|
||||
public $setupCalDAVScheduling = true;
|
||||
public $setupACL = true;
|
||||
public $autoLogin = 'user1';
|
||||
|
||||
function setUp() {
|
||||
|
||||
parent::setUp();
|
||||
$this->caldavBackend->createCalendar(
|
||||
'principals/user1',
|
||||
'default',
|
||||
[
|
||||
|
||||
]
|
||||
);
|
||||
$this->caldavBackend->createCalendar(
|
||||
'principals/user2',
|
||||
'default',
|
||||
[
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testDelivery() {
|
||||
|
||||
$request = new Request('PUT', '/calendars/user1/default/foo.ics');
|
||||
$request->setBody(<<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//Apple Inc.//Mac OS X 10.9.1//EN
|
||||
CALSCALE:GREGORIAN
|
||||
BEGIN:VEVENT
|
||||
CREATED:20140109T204404Z
|
||||
UID:AADC6438-18CF-4B52-8DD2-EF9AD75ADE83
|
||||
DTEND;TZID=America/Toronto:20140107T110000
|
||||
TRANSP:OPAQUE
|
||||
ATTENDEE;CN="Administrator";CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE;CN="Roxy Kesh";CUTYPE=INDIVIDUAL;EMAIL="user2.sabredav@sabrdav.org";
|
||||
PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT;RSVP=TRUE:mailto:user2.sabredav@sabredav.org
|
||||
SUMMARY:Just testing!
|
||||
DTSTART;TZID=America/Toronto:20140107T100000
|
||||
DTSTAMP:20140109T204422Z
|
||||
ORGANIZER;CN="Administrator":mailto:user1.sabredav@sabredav.org
|
||||
SEQUENCE:4
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS
|
||||
);
|
||||
|
||||
$messages = [];
|
||||
$this->server->on('schedule', function($message) use (&$messages) {
|
||||
$messages[] = $message;
|
||||
});
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(201, $response->getStatus(), 'Incorrect status code received. Response body:' . $response->getBodyAsString());
|
||||
|
||||
$result = $this->request(new Request('GET', '/calendars/user1/default/foo.ics'))->getBody();
|
||||
$resultVObj = VObject\Reader::read($result);
|
||||
|
||||
$this->assertEquals(
|
||||
'1.2',
|
||||
$resultVObj->VEVENT->ATTENDEE[1]['SCHEDULE-STATUS']->getValue()
|
||||
);
|
||||
|
||||
$this->assertEquals(1, count($messages));
|
||||
$message = $messages[0];
|
||||
|
||||
$this->assertInstanceOf('\Sabre\VObject\ITip\Message', $message);
|
||||
$this->assertEquals('mailto:user2.sabredav@sabredav.org', $message->recipient);
|
||||
$this->assertEquals('Roxy Kesh', $message->recipientName);
|
||||
$this->assertEquals('mailto:user1.sabredav@sabredav.org', $message->sender);
|
||||
$this->assertEquals('Administrator', $message->senderName);
|
||||
$this->assertEquals('REQUEST', $message->method);
|
||||
|
||||
$this->assertEquals('REQUEST', $message->message->METHOD->getValue());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,611 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Schedule;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\CalDAV\Xml\Property\ScheduleCalendarTransp;
|
||||
use Sabre\DAV;
|
||||
use Sabre\DAVACL;
|
||||
use Sabre\HTTP;
|
||||
|
||||
class FreeBusyRequestTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
protected $plugin;
|
||||
protected $server;
|
||||
protected $aclPlugin;
|
||||
protected $request;
|
||||
protected $authPlugin;
|
||||
protected $caldavBackend;
|
||||
|
||||
function setUp() {
|
||||
|
||||
$caldavNS = '{' . CalDAV\Plugin::NS_CALDAV . '}';
|
||||
$calendars = [
|
||||
[
|
||||
'principaluri' => 'principals/user2',
|
||||
'id' => 1,
|
||||
'uri' => 'calendar1',
|
||||
$caldavNS . 'calendar-timezone' => "BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nTZID:Europe/Berlin\r\nEND:VTIMEZONE\r\nEND:VCALENDAR",
|
||||
],
|
||||
[
|
||||
'principaluri' => 'principals/user2',
|
||||
'id' => 2,
|
||||
'uri' => 'calendar2',
|
||||
$caldavNS . 'schedule-calendar-transp' => new ScheduleCalendarTransp(ScheduleCalendarTransp::TRANSPARENT),
|
||||
],
|
||||
];
|
||||
$calendarobjects = [
|
||||
1 => ['1.ics' => [
|
||||
'uri' => '1.ics',
|
||||
'calendardata' => 'BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20110101T130000
|
||||
DURATION:PT1H
|
||||
END:VEVENT
|
||||
END:VCALENDAR',
|
||||
'calendarid' => 1,
|
||||
]],
|
||||
2 => ['2.ics' => [
|
||||
'uri' => '2.ics',
|
||||
'calendardata' => 'BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
DTSTART:20110101T080000
|
||||
DURATION:PT1H
|
||||
END:VEVENT
|
||||
END:VCALENDAR',
|
||||
'calendarid' => 2,
|
||||
]]
|
||||
|
||||
];
|
||||
|
||||
$principalBackend = new DAVACL\PrincipalBackend\Mock();
|
||||
$this->caldavBackend = new CalDAV\Backend\MockScheduling($calendars, $calendarobjects);
|
||||
|
||||
$tree = [
|
||||
new DAVACL\PrincipalCollection($principalBackend),
|
||||
new CalDAV\CalendarRoot($principalBackend, $this->caldavBackend),
|
||||
];
|
||||
|
||||
$this->request = HTTP\Sapi::createFromServerArray([
|
||||
'CONTENT_TYPE' => 'text/calendar',
|
||||
]);
|
||||
$this->response = new HTTP\ResponseMock();
|
||||
|
||||
$this->server = new DAV\Server($tree);
|
||||
$this->server->httpRequest = $this->request;
|
||||
$this->server->httpResponse = $this->response;
|
||||
|
||||
$this->aclPlugin = new DAVACL\Plugin();
|
||||
$this->aclPlugin->allowUnauthenticatedAccess = false;
|
||||
$this->server->addPlugin($this->aclPlugin);
|
||||
|
||||
$authBackend = new DAV\Auth\Backend\Mock();
|
||||
$authBackend->setPrincipal('principals/user1');
|
||||
$this->authPlugin = new DAV\Auth\Plugin($authBackend);
|
||||
// Forcing authentication to work.
|
||||
$this->authPlugin->beforeMethod($this->request, $this->response);
|
||||
$this->server->addPlugin($this->authPlugin);
|
||||
|
||||
// CalDAV plugin
|
||||
$this->plugin = new CalDAV\Plugin();
|
||||
$this->server->addPlugin($this->plugin);
|
||||
|
||||
// Scheduling plugin
|
||||
$this->plugin = new Plugin();
|
||||
$this->server->addPlugin($this->plugin);
|
||||
|
||||
}
|
||||
|
||||
function testWrongContentType() {
|
||||
|
||||
$this->server->httpRequest = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/outbox',
|
||||
['Content-Type' => 'text/plain']
|
||||
);
|
||||
|
||||
$this->assertNull(
|
||||
$this->plugin->httpPost($this->server->httpRequest, $this->server->httpResponse)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testNotFound() {
|
||||
|
||||
$this->server->httpRequest = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/blabla',
|
||||
['Content-Type' => 'text/calendar']
|
||||
);
|
||||
|
||||
$this->assertNull(
|
||||
$this->plugin->httpPost($this->server->httpRequest, $this->server->httpResponse)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testNotOutbox() {
|
||||
|
||||
$this->server->httpRequest = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/inbox',
|
||||
['Content-Type' => 'text/calendar']
|
||||
);
|
||||
|
||||
$this->assertNull(
|
||||
$this->plugin->httpPost($this->server->httpRequest, $this->server->httpResponse)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testNoItipMethod() {
|
||||
|
||||
$this->server->httpRequest = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/outbox',
|
||||
['Content-Type' => 'text/calendar']
|
||||
);
|
||||
|
||||
$body = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VFREEBUSY
|
||||
END:VFREEBUSY
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->httpRequest->setBody($body);
|
||||
$this->plugin->httpPost($this->server->httpRequest, $this->server->httpResponse);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\NotImplemented
|
||||
*/
|
||||
function testNoVFreeBusy() {
|
||||
|
||||
$this->server->httpRequest = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/outbox',
|
||||
['Content-Type' => 'text/calendar']
|
||||
);
|
||||
|
||||
$body = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
METHOD:REQUEST
|
||||
BEGIN:VEVENT
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->httpRequest->setBody($body);
|
||||
$this->plugin->httpPost($this->server->httpRequest, $this->server->httpResponse);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testIncorrectOrganizer() {
|
||||
|
||||
$this->server->httpRequest = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/outbox',
|
||||
['Content-Type' => 'text/calendar']
|
||||
);
|
||||
|
||||
|
||||
$body = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
METHOD:REQUEST
|
||||
BEGIN:VFREEBUSY
|
||||
ORGANIZER:mailto:john@wayne.org
|
||||
END:VFREEBUSY
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->httpRequest->setBody($body);
|
||||
$this->plugin->httpPost($this->server->httpRequest, $this->server->httpResponse);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testNoAttendees() {
|
||||
|
||||
$this->server->httpRequest = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/outbox',
|
||||
['Content-Type' => 'text/calendar']
|
||||
);
|
||||
|
||||
$body = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
METHOD:REQUEST
|
||||
BEGIN:VFREEBUSY
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
END:VFREEBUSY
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->httpRequest->setBody($body);
|
||||
$this->plugin->httpPost($this->server->httpRequest, $this->server->httpResponse);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testNoDTStart() {
|
||||
|
||||
$this->server->httpRequest = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/outbox',
|
||||
['Content-Type' => 'text/calendar']
|
||||
);
|
||||
|
||||
$body = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
METHOD:REQUEST
|
||||
BEGIN:VFREEBUSY
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VFREEBUSY
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->httpRequest->setBody($body);
|
||||
$this->plugin->httpPost($this->server->httpRequest, $this->server->httpResponse);
|
||||
|
||||
}
|
||||
|
||||
function testSucceed() {
|
||||
|
||||
$this->server->httpRequest = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/outbox',
|
||||
['Content-Type' => 'text/calendar']
|
||||
);
|
||||
|
||||
$body = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
METHOD:REQUEST
|
||||
BEGIN:VFREEBUSY
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user3.sabredav@sabredav.org
|
||||
DTSTART:20110101T080000Z
|
||||
DTEND:20110101T180000Z
|
||||
END:VFREEBUSY
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->httpRequest->setBody($body);
|
||||
|
||||
// Lazily making the current principal an admin.
|
||||
$this->aclPlugin->adminPrincipals[] = 'principals/user1';
|
||||
|
||||
$this->assertFalse(
|
||||
$this->plugin->httpPost($this->server->httpRequest, $this->response)
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $this->response->status);
|
||||
$this->assertEquals([
|
||||
'Content-Type' => ['application/xml'],
|
||||
], $this->response->getHeaders());
|
||||
|
||||
$strings = [
|
||||
'<d:href>mailto:user2.sabredav@sabredav.org</d:href>',
|
||||
'<d:href>mailto:user3.sabredav@sabredav.org</d:href>',
|
||||
'<cal:request-status>2.0;Success</cal:request-status>',
|
||||
'<cal:request-status>3.7;Could not find principal</cal:request-status>',
|
||||
'FREEBUSY:20110101T120000Z/20110101T130000Z',
|
||||
];
|
||||
|
||||
foreach ($strings as $string) {
|
||||
$this->assertTrue(
|
||||
strpos($this->response->body, $string) !== false,
|
||||
'The response body did not contain: ' . $string . 'Full response: ' . $this->response->body
|
||||
);
|
||||
}
|
||||
|
||||
$this->assertTrue(
|
||||
strpos($this->response->body, 'FREEBUSY;FBTYPE=BUSY:20110101T080000Z/20110101T090000Z') == false,
|
||||
'The response body did contain free busy info from a transparent calendar.'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing if the freebusy request still works, even if there are no
|
||||
* calendars in the target users' account.
|
||||
*/
|
||||
function testSucceedNoCalendars() {
|
||||
|
||||
// Deleting calendars
|
||||
$this->caldavBackend->deleteCalendar(1);
|
||||
$this->caldavBackend->deleteCalendar(2);
|
||||
|
||||
$this->server->httpRequest = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/outbox',
|
||||
['Content-Type' => 'text/calendar']
|
||||
);
|
||||
|
||||
$body = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
METHOD:REQUEST
|
||||
BEGIN:VFREEBUSY
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
DTSTART:20110101T080000Z
|
||||
DTEND:20110101T180000Z
|
||||
END:VFREEBUSY
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->httpRequest->setBody($body);
|
||||
|
||||
// Lazily making the current principal an admin.
|
||||
$this->aclPlugin->adminPrincipals[] = 'principals/user1';
|
||||
|
||||
$this->assertFalse(
|
||||
$this->plugin->httpPost($this->server->httpRequest, $this->response)
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $this->response->status);
|
||||
$this->assertEquals([
|
||||
'Content-Type' => ['application/xml'],
|
||||
], $this->response->getHeaders());
|
||||
|
||||
$strings = [
|
||||
'<d:href>mailto:user2.sabredav@sabredav.org</d:href>',
|
||||
'<cal:request-status>2.0;Success</cal:request-status>',
|
||||
];
|
||||
|
||||
foreach ($strings as $string) {
|
||||
$this->assertTrue(
|
||||
strpos($this->response->body, $string) !== false,
|
||||
'The response body did not contain: ' . $string . 'Full response: ' . $this->response->body
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function testNoCalendarHomeFound() {
|
||||
|
||||
$this->server->httpRequest = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/outbox',
|
||||
['Content-Type' => 'text/calendar']
|
||||
);
|
||||
|
||||
$body = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
METHOD:REQUEST
|
||||
BEGIN:VFREEBUSY
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
DTSTART:20110101T080000Z
|
||||
DTEND:20110101T180000Z
|
||||
END:VFREEBUSY
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->httpRequest->setBody($body);
|
||||
|
||||
// Lazily making the current principal an admin.
|
||||
$this->aclPlugin->adminPrincipals[] = 'principals/user1';
|
||||
|
||||
// Removing the calendar home
|
||||
$this->server->on('propFind', function(DAV\PropFind $propFind) {
|
||||
|
||||
$propFind->set('{' . Plugin::NS_CALDAV . '}calendar-home-set', null, 403);
|
||||
|
||||
});
|
||||
|
||||
$this->assertFalse(
|
||||
$this->plugin->httpPost($this->server->httpRequest, $this->response)
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $this->response->status);
|
||||
$this->assertEquals([
|
||||
'Content-Type' => ['application/xml'],
|
||||
], $this->response->getHeaders());
|
||||
|
||||
$strings = [
|
||||
'<d:href>mailto:user2.sabredav@sabredav.org</d:href>',
|
||||
'<cal:request-status>3.7;No calendar-home-set property found</cal:request-status>',
|
||||
];
|
||||
|
||||
foreach ($strings as $string) {
|
||||
$this->assertTrue(
|
||||
strpos($this->response->body, $string) !== false,
|
||||
'The response body did not contain: ' . $string . 'Full response: ' . $this->response->body
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function testNoInboxFound() {
|
||||
|
||||
$this->server->httpRequest = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/outbox',
|
||||
['Content-Type' => 'text/calendar']
|
||||
);
|
||||
|
||||
$body = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
METHOD:REQUEST
|
||||
BEGIN:VFREEBUSY
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
DTSTART:20110101T080000Z
|
||||
DTEND:20110101T180000Z
|
||||
END:VFREEBUSY
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->httpRequest->setBody($body);
|
||||
|
||||
// Lazily making the current principal an admin.
|
||||
$this->aclPlugin->adminPrincipals[] = 'principals/user1';
|
||||
|
||||
// Removing the inbox
|
||||
$this->server->on('propFind', function(DAV\PropFind $propFind) {
|
||||
|
||||
$propFind->set('{' . Plugin::NS_CALDAV . '}schedule-inbox-URL', null, 403);
|
||||
|
||||
});
|
||||
|
||||
$this->assertFalse(
|
||||
$this->plugin->httpPost($this->server->httpRequest, $this->response)
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $this->response->status);
|
||||
$this->assertEquals([
|
||||
'Content-Type' => ['application/xml'],
|
||||
], $this->response->getHeaders());
|
||||
|
||||
$strings = [
|
||||
'<d:href>mailto:user2.sabredav@sabredav.org</d:href>',
|
||||
'<cal:request-status>3.7;No schedule-inbox-URL property found</cal:request-status>',
|
||||
];
|
||||
|
||||
foreach ($strings as $string) {
|
||||
$this->assertTrue(
|
||||
strpos($this->response->body, $string) !== false,
|
||||
'The response body did not contain: ' . $string . 'Full response: ' . $this->response->body
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function testSucceedUseVAVAILABILITY() {
|
||||
|
||||
$this->server->httpRequest = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/outbox',
|
||||
['Content-Type' => 'text/calendar']
|
||||
);
|
||||
|
||||
$body = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
METHOD:REQUEST
|
||||
BEGIN:VFREEBUSY
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
DTSTART:20110101T080000Z
|
||||
DTEND:20110101T180000Z
|
||||
END:VFREEBUSY
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->httpRequest->setBody($body);
|
||||
|
||||
// Lazily making the current principal an admin.
|
||||
$this->aclPlugin->adminPrincipals[] = 'principals/user1';
|
||||
|
||||
// Adding VAVAILABILITY manually
|
||||
$this->server->on('propFind', function(DAV\PropFind $propFind) {
|
||||
|
||||
$propFind->handle('{' . Plugin::NS_CALDAV . '}calendar-availability', function() {
|
||||
|
||||
$avail = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VAVAILABILITY
|
||||
DTSTART:20110101T000000Z
|
||||
DTEND:20110102T000000Z
|
||||
BEGIN:AVAILABLE
|
||||
DTSTART:20110101T090000Z
|
||||
DTEND:20110101T170000Z
|
||||
END:AVAILABLE
|
||||
END:VAVAILABILITY
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
return $avail;
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$this->assertFalse(
|
||||
$this->plugin->httpPost($this->server->httpRequest, $this->response)
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $this->response->status);
|
||||
$this->assertEquals([
|
||||
'Content-Type' => ['application/xml'],
|
||||
], $this->response->getHeaders());
|
||||
|
||||
$strings = [
|
||||
'<d:href>mailto:user2.sabredav@sabredav.org</d:href>',
|
||||
'<cal:request-status>2.0;Success</cal:request-status>',
|
||||
'FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:20110101T080000Z/20110101T090000Z',
|
||||
'FREEBUSY:20110101T120000Z/20110101T130000Z',
|
||||
'FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:20110101T170000Z/20110101T180000Z',
|
||||
];
|
||||
|
||||
foreach ($strings as $string) {
|
||||
$this->assertTrue(
|
||||
strpos($this->response->body, $string) !== false,
|
||||
'The response body did not contain: ' . $string . 'Full response: ' . $this->response->body
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
function testNoPrivilege() {
|
||||
|
||||
$this->markTestIncomplete('Currently there\'s no "no privilege" situation');
|
||||
|
||||
$this->server->httpRequest = HTTP\Sapi::createFromServerArray(array(
|
||||
'CONTENT_TYPE' => 'text/calendar',
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'REQUEST_URI' => '/calendars/user1/outbox',
|
||||
));
|
||||
|
||||
$body = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
METHOD:REQUEST
|
||||
BEGIN:VFREEBUSY
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
DTSTART:20110101T080000Z
|
||||
DTEND:20110101T180000Z
|
||||
END:VFREEBUSY
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->httpRequest->setBody($body);
|
||||
|
||||
$this->assertFalse(
|
||||
$this->plugin->httpPost($this->server->httpRequest, $this->response)
|
||||
);
|
||||
|
||||
$this->assertEquals(200, $this->response->status);
|
||||
$this->assertEquals([
|
||||
'Content-Type' => 'application/xml',
|
||||
], $this->response->getHeaders());
|
||||
|
||||
$strings = [
|
||||
'<d:href>mailto:user2.sabredav@sabredav.org</d:href>',
|
||||
'<cal:request-status>3.7;No calendar-home-set property found</cal:request-status>',
|
||||
];
|
||||
|
||||
foreach($strings as $string) {
|
||||
$this->assertTrue(
|
||||
strpos($this->response->body, $string)!==false,
|
||||
'The response body did not contain: ' . $string .'Full response: ' . $this->response->body
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Schedule\IMip;
|
||||
|
||||
/**
|
||||
* iMIP handler.
|
||||
*
|
||||
* This class is responsible for sending out iMIP messages. iMIP is the
|
||||
* email-based transport for iTIP. iTIP deals with scheduling operations for
|
||||
* iCalendar objects.
|
||||
*
|
||||
* If you want to customize the email that gets sent out, you can do so by
|
||||
* extending this class and overriding the sendMessage method.
|
||||
*
|
||||
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
|
||||
* @author Evert Pot (http://evertpot.com/)
|
||||
* @license http://sabre.io/license/ Modified BSD License
|
||||
*/
|
||||
class MockPlugin extends \Sabre\CalDAV\Schedule\IMipPlugin {
|
||||
|
||||
protected $emails = [];
|
||||
|
||||
/**
|
||||
* This function is responsible for sending the actual email.
|
||||
*
|
||||
* @param string $to Recipient email address
|
||||
* @param string $subject Subject of the email
|
||||
* @param string $body iCalendar body
|
||||
* @param array $headers List of headers
|
||||
* @return void
|
||||
*/
|
||||
protected function mail($to, $subject, $body, array $headers) {
|
||||
|
||||
$this->emails[] = [
|
||||
'to' => $to,
|
||||
'subject' => $subject,
|
||||
'body' => $body,
|
||||
'headers' => $headers,
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
function getSentEmails() {
|
||||
|
||||
return $this->emails;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,221 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Schedule;
|
||||
|
||||
use Sabre\DAV\Server;
|
||||
use Sabre\VObject\ITip\Message;
|
||||
use Sabre\VObject\Reader;
|
||||
|
||||
class IMipPluginTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function testGetPluginInfo() {
|
||||
|
||||
$plugin = new IMipPlugin('system@example.com');
|
||||
$this->assertEquals(
|
||||
'imip',
|
||||
$plugin->getPluginInfo()['name']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testDeliverReply() {
|
||||
|
||||
$message = new Message();
|
||||
$message->sender = 'mailto:sender@example.org';
|
||||
$message->senderName = 'Sender';
|
||||
$message->recipient = 'mailto:recipient@example.org';
|
||||
$message->recipientName = 'Recipient';
|
||||
$message->method = 'REPLY';
|
||||
|
||||
$ics = <<<ICS
|
||||
BEGIN:VCALENDAR\r
|
||||
METHOD:REPLY\r
|
||||
BEGIN:VEVENT\r
|
||||
SUMMARY:Birthday party\r
|
||||
END:VEVENT\r
|
||||
END:VCALENDAR\r
|
||||
|
||||
ICS;
|
||||
|
||||
|
||||
$message->message = Reader::read($ics);
|
||||
|
||||
$result = $this->schedule($message);
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'to' => 'Recipient <recipient@example.org>',
|
||||
'subject' => 'Re: Birthday party',
|
||||
'body' => $ics,
|
||||
'headers' => [
|
||||
'Reply-To: Sender <sender@example.org>',
|
||||
'From: system@example.org',
|
||||
'Content-Type: text/calendar; charset=UTF-8; method=REPLY',
|
||||
'X-Sabre-Version: ' . \Sabre\DAV\Version::VERSION,
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
function testDeliverReplyNoMailto() {
|
||||
|
||||
$message = new Message();
|
||||
$message->sender = 'mailto:sender@example.org';
|
||||
$message->senderName = 'Sender';
|
||||
$message->recipient = 'http://example.org/recipient';
|
||||
$message->recipientName = 'Recipient';
|
||||
$message->method = 'REPLY';
|
||||
|
||||
$ics = <<<ICS
|
||||
BEGIN:VCALENDAR\r
|
||||
METHOD:REPLY\r
|
||||
BEGIN:VEVENT\r
|
||||
SUMMARY:Birthday party\r
|
||||
END:VEVENT\r
|
||||
END:VCALENDAR\r
|
||||
|
||||
ICS;
|
||||
|
||||
|
||||
$message->message = Reader::read($ics);
|
||||
|
||||
$result = $this->schedule($message);
|
||||
|
||||
$expected = [];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
function testDeliverRequest() {
|
||||
|
||||
$message = new Message();
|
||||
$message->sender = 'mailto:sender@example.org';
|
||||
$message->senderName = 'Sender';
|
||||
$message->recipient = 'mailto:recipient@example.org';
|
||||
$message->recipientName = 'Recipient';
|
||||
$message->method = 'REQUEST';
|
||||
|
||||
$ics = <<<ICS
|
||||
BEGIN:VCALENDAR\r
|
||||
METHOD:REQUEST\r
|
||||
BEGIN:VEVENT\r
|
||||
SUMMARY:Birthday party\r
|
||||
END:VEVENT\r
|
||||
END:VCALENDAR\r
|
||||
|
||||
ICS;
|
||||
|
||||
|
||||
$message->message = Reader::read($ics);
|
||||
|
||||
$result = $this->schedule($message);
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'to' => 'Recipient <recipient@example.org>',
|
||||
'subject' => 'Birthday party',
|
||||
'body' => $ics,
|
||||
'headers' => [
|
||||
'Reply-To: Sender <sender@example.org>',
|
||||
'From: system@example.org',
|
||||
'Content-Type: text/calendar; charset=UTF-8; method=REQUEST',
|
||||
'X-Sabre-Version: ' . \Sabre\DAV\Version::VERSION,
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
function testDeliverCancel() {
|
||||
|
||||
$message = new Message();
|
||||
$message->sender = 'mailto:sender@example.org';
|
||||
$message->senderName = 'Sender';
|
||||
$message->recipient = 'mailto:recipient@example.org';
|
||||
$message->recipientName = 'Recipient';
|
||||
$message->method = 'CANCEL';
|
||||
|
||||
$ics = <<<ICS
|
||||
BEGIN:VCALENDAR\r
|
||||
METHOD:CANCEL\r
|
||||
BEGIN:VEVENT\r
|
||||
SUMMARY:Birthday party\r
|
||||
END:VEVENT\r
|
||||
END:VCALENDAR\r
|
||||
|
||||
ICS;
|
||||
|
||||
|
||||
$message->message = Reader::read($ics);
|
||||
|
||||
$result = $this->schedule($message);
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'to' => 'Recipient <recipient@example.org>',
|
||||
'subject' => 'Cancelled: Birthday party',
|
||||
'body' => $ics,
|
||||
'headers' => [
|
||||
'Reply-To: Sender <sender@example.org>',
|
||||
'From: system@example.org',
|
||||
'Content-Type: text/calendar; charset=UTF-8; method=CANCEL',
|
||||
'X-Sabre-Version: ' . \Sabre\DAV\Version::VERSION,
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals('1.1', substr($message->scheduleStatus, 0, 3));
|
||||
|
||||
}
|
||||
|
||||
function schedule(Message $message) {
|
||||
|
||||
$plugin = new IMip\MockPlugin('system@example.org');
|
||||
|
||||
$server = new Server();
|
||||
$server->addPlugin($plugin);
|
||||
$server->emit('schedule', [$message]);
|
||||
|
||||
return $plugin->getSentEmails();
|
||||
|
||||
}
|
||||
|
||||
function testDeliverInsignificantRequest() {
|
||||
|
||||
$message = new Message();
|
||||
$message->sender = 'mailto:sender@example.org';
|
||||
$message->senderName = 'Sender';
|
||||
$message->recipient = 'mailto:recipient@example.org';
|
||||
$message->recipientName = 'Recipient';
|
||||
$message->method = 'REQUEST';
|
||||
$message->significantChange = false;
|
||||
|
||||
$ics = <<<ICS
|
||||
BEGIN:VCALENDAR\r
|
||||
METHOD:REQUEST\r
|
||||
BEGIN:VEVENT\r
|
||||
SUMMARY:Birthday party\r
|
||||
END:VEVENT\r
|
||||
END:VCALENDAR\r
|
||||
|
||||
ICS;
|
||||
|
||||
|
||||
$message->message = Reader::read($ics);
|
||||
|
||||
$result = $this->schedule($message);
|
||||
|
||||
$expected = [];
|
||||
$this->assertEquals($expected, $result);
|
||||
$this->assertEquals('1.0', $message->getScheduleStatus()[0]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,136 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Schedule;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\DAV;
|
||||
|
||||
class InboxTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function testSetup() {
|
||||
|
||||
$inbox = new Inbox(
|
||||
new CalDAV\Backend\MockScheduling(),
|
||||
'principals/user1'
|
||||
);
|
||||
$this->assertEquals('inbox', $inbox->getName());
|
||||
$this->assertEquals([], $inbox->getChildren());
|
||||
$this->assertEquals('principals/user1', $inbox->getOwner());
|
||||
$this->assertEquals(null, $inbox->getGroup());
|
||||
|
||||
$this->assertEquals([
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => '{DAV:}authenticated',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}write-properties',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}unbind',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}unbind',
|
||||
'principal' => 'principals/user1/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{urn:ietf:params:xml:ns:caldav}schedule-deliver',
|
||||
'principal' => '{DAV:}authenticated',
|
||||
'protected' => true,
|
||||
],
|
||||
], $inbox->getACL());
|
||||
|
||||
$ok = false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSetup
|
||||
*/
|
||||
function testGetChildren() {
|
||||
|
||||
$backend = new CalDAV\Backend\MockScheduling();
|
||||
$inbox = new Inbox(
|
||||
$backend,
|
||||
'principals/user1'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
0,
|
||||
count($inbox->getChildren())
|
||||
);
|
||||
$backend->createSchedulingObject('principals/user1', 'schedule1.ics', "BEGIN:VCALENDAR\r\nEND:VCALENDAR");
|
||||
$this->assertEquals(
|
||||
1,
|
||||
count($inbox->getChildren())
|
||||
);
|
||||
$this->assertInstanceOf('Sabre\CalDAV\Schedule\SchedulingObject', $inbox->getChildren()[0]);
|
||||
$this->assertEquals(
|
||||
'schedule1.ics',
|
||||
$inbox->getChildren()[0]->getName()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetChildren
|
||||
*/
|
||||
function testCreateFile() {
|
||||
|
||||
$backend = new CalDAV\Backend\MockScheduling();
|
||||
$inbox = new Inbox(
|
||||
$backend,
|
||||
'principals/user1'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
0,
|
||||
count($inbox->getChildren())
|
||||
);
|
||||
$inbox->createFile('schedule1.ics', "BEGIN:VCALENDAR\r\nEND:VCALENDAR");
|
||||
$this->assertEquals(
|
||||
1,
|
||||
count($inbox->getChildren())
|
||||
);
|
||||
$this->assertInstanceOf('Sabre\CalDAV\Schedule\SchedulingObject', $inbox->getChildren()[0]);
|
||||
$this->assertEquals(
|
||||
'schedule1.ics',
|
||||
$inbox->getChildren()[0]->getName()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSetup
|
||||
*/
|
||||
function testCalendarQuery() {
|
||||
|
||||
$backend = new CalDAV\Backend\MockScheduling();
|
||||
$inbox = new Inbox(
|
||||
$backend,
|
||||
'principals/user1'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
0,
|
||||
count($inbox->getChildren())
|
||||
);
|
||||
$backend->createSchedulingObject('principals/user1', 'schedule1.ics', "BEGIN:VCALENDAR\r\nEND:VCALENDAR");
|
||||
$this->assertEquals(
|
||||
['schedule1.ics'],
|
||||
$inbox->calendarQuery([
|
||||
'name' => 'VCALENDAR',
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'is-not-defined' => false
|
||||
])
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,134 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Schedule;
|
||||
|
||||
use Sabre\HTTP;
|
||||
|
||||
class OutboxPostTest extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
protected $setupACL = true;
|
||||
protected $autoLogin = 'user1';
|
||||
protected $setupCalDAVScheduling = true;
|
||||
|
||||
function testPostPassThruNotFound() {
|
||||
|
||||
$req = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'REQUEST_URI' => '/notfound',
|
||||
'HTTP_CONTENT_TYPE' => 'text/calendar',
|
||||
]);
|
||||
|
||||
$this->assertHTTPStatus(501, $req);
|
||||
|
||||
}
|
||||
|
||||
function testPostPassThruNotTextCalendar() {
|
||||
|
||||
$req = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'REQUEST_URI' => '/calendars/user1/outbox',
|
||||
]);
|
||||
|
||||
$this->assertHTTPStatus(501, $req);
|
||||
|
||||
}
|
||||
|
||||
function testPostPassThruNoOutBox() {
|
||||
|
||||
$req = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'REQUEST_URI' => '/calendars',
|
||||
'HTTP_CONTENT_TYPE' => 'text/calendar',
|
||||
]);
|
||||
|
||||
$this->assertHTTPStatus(501, $req);
|
||||
|
||||
}
|
||||
|
||||
function testInvalidIcalBody() {
|
||||
|
||||
$req = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'REQUEST_URI' => '/calendars/user1/outbox',
|
||||
'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
|
||||
'HTTP_RECIPIENT' => 'mailto:user2@example.org',
|
||||
'HTTP_CONTENT_TYPE' => 'text/calendar',
|
||||
]);
|
||||
$req->setBody('foo');
|
||||
|
||||
$this->assertHTTPStatus(400, $req);
|
||||
|
||||
}
|
||||
|
||||
function testNoVEVENT() {
|
||||
|
||||
$req = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'REQUEST_URI' => '/calendars/user1/outbox',
|
||||
'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
|
||||
'HTTP_RECIPIENT' => 'mailto:user2@example.org',
|
||||
'HTTP_CONTENT_TYPE' => 'text/calendar',
|
||||
]);
|
||||
|
||||
$body = [
|
||||
'BEGIN:VCALENDAR',
|
||||
'BEGIN:VTIMEZONE',
|
||||
'END:VTIMEZONE',
|
||||
'END:VCALENDAR',
|
||||
];
|
||||
|
||||
$req->setBody(implode("\r\n", $body));
|
||||
|
||||
$this->assertHTTPStatus(400, $req);
|
||||
|
||||
}
|
||||
|
||||
function testNoMETHOD() {
|
||||
|
||||
$req = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'REQUEST_URI' => '/calendars/user1/outbox',
|
||||
'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
|
||||
'HTTP_RECIPIENT' => 'mailto:user2@example.org',
|
||||
'HTTP_CONTENT_TYPE' => 'text/calendar',
|
||||
]);
|
||||
|
||||
$body = [
|
||||
'BEGIN:VCALENDAR',
|
||||
'BEGIN:VEVENT',
|
||||
'END:VEVENT',
|
||||
'END:VCALENDAR',
|
||||
];
|
||||
|
||||
$req->setBody(implode("\r\n", $body));
|
||||
|
||||
$this->assertHTTPStatus(400, $req);
|
||||
|
||||
}
|
||||
|
||||
function testUnsupportedMethod() {
|
||||
|
||||
$req = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'REQUEST_URI' => '/calendars/user1/outbox',
|
||||
'HTTP_ORIGINATOR' => 'mailto:user1.sabredav@sabredav.org',
|
||||
'HTTP_RECIPIENT' => 'mailto:user2@example.org',
|
||||
'HTTP_CONTENT_TYPE' => 'text/calendar',
|
||||
]);
|
||||
|
||||
$body = [
|
||||
'BEGIN:VCALENDAR',
|
||||
'METHOD:PUBLISH',
|
||||
'BEGIN:VEVENT',
|
||||
'END:VEVENT',
|
||||
'END:VCALENDAR',
|
||||
];
|
||||
|
||||
$req->setBody(implode("\r\n", $body));
|
||||
|
||||
$this->assertHTTPStatus(501, $req);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Schedule;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\DAV;
|
||||
|
||||
class OutboxTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function testSetup() {
|
||||
|
||||
$outbox = new Outbox('principals/user1');
|
||||
$this->assertEquals('outbox', $outbox->getName());
|
||||
$this->assertEquals([], $outbox->getChildren());
|
||||
$this->assertEquals('principals/user1', $outbox->getOwner());
|
||||
$this->assertEquals(null, $outbox->getGroup());
|
||||
|
||||
$this->assertEquals([
|
||||
[
|
||||
'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-send',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-send',
|
||||
'principal' => 'principals/user1/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1/calendar-proxy-read',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
], $outbox->getACL());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Schedule;
|
||||
|
||||
class PluginBasicTest extends \Sabre\DAVServerTest {
|
||||
|
||||
public $setupCalDAV = true;
|
||||
public $setupCalDAVScheduling = true;
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$plugin = new Plugin();
|
||||
$this->assertEquals(
|
||||
'caldav-schedule',
|
||||
$plugin->getPluginInfo()['name']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testOptions() {
|
||||
|
||||
$plugin = new Plugin();
|
||||
$expected = [
|
||||
'calendar-auto-schedule',
|
||||
'calendar-availability',
|
||||
];
|
||||
$this->assertEquals($expected, $plugin->getFeatures());
|
||||
|
||||
}
|
||||
|
||||
function testGetHTTPMethods() {
|
||||
|
||||
$this->assertEquals([], $this->caldavSchedulePlugin->getHTTPMethods('notfound'));
|
||||
$this->assertEquals([], $this->caldavSchedulePlugin->getHTTPMethods('calendars/user1'));
|
||||
$this->assertEquals(['POST'], $this->caldavSchedulePlugin->getHTTPMethods('calendars/user1/outbox'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,146 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Schedule;
|
||||
|
||||
use Sabre\DAV;
|
||||
|
||||
class PluginPropertiesTest extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
protected $setupCalDAVScheduling = true;
|
||||
protected $setupPropertyStorage = true;
|
||||
|
||||
function setUp() {
|
||||
|
||||
parent::setUp();
|
||||
$this->caldavBackend->createCalendar(
|
||||
'principals/user1',
|
||||
'default',
|
||||
[
|
||||
|
||||
]
|
||||
);
|
||||
$this->principalBackend->addPrincipal([
|
||||
'uri' => 'principals/user1/calendar-proxy-read'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
function testPrincipalProperties() {
|
||||
|
||||
$props = $this->server->getPropertiesForPath('/principals/user1', [
|
||||
'{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL',
|
||||
'{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',
|
||||
'{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',
|
||||
'{urn:ietf:params:xml:ns:caldav}calendar-user-type',
|
||||
'{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL',
|
||||
]);
|
||||
|
||||
$this->assertArrayHasKey(0, $props);
|
||||
$this->assertArrayHasKey(200, $props[0]);
|
||||
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL', $props[0][200]);
|
||||
$prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL'];
|
||||
$this->assertTrue($prop instanceof DAV\Xml\Property\Href);
|
||||
$this->assertEquals('calendars/user1/outbox/', $prop->getHref());
|
||||
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL', $props[0][200]);
|
||||
$prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL'];
|
||||
$this->assertTrue($prop instanceof DAV\Xml\Property\Href);
|
||||
$this->assertEquals('calendars/user1/inbox/', $prop->getHref());
|
||||
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-address-set', $props[0][200]);
|
||||
$prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'];
|
||||
$this->assertTrue($prop instanceof DAV\Xml\Property\Href);
|
||||
$this->assertEquals(['mailto:user1.sabredav@sabredav.org', '/principals/user1/'], $prop->getHrefs());
|
||||
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-type', $props[0][200]);
|
||||
$prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-type'];
|
||||
$this->assertEquals('INDIVIDUAL', $prop);
|
||||
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL', $props[0][200]);
|
||||
$prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL'];
|
||||
$this->assertEquals('calendars/user1/default/', $prop->getHref());
|
||||
|
||||
}
|
||||
function testPrincipalPropertiesBadPrincipal() {
|
||||
|
||||
$props = $this->server->getPropertiesForPath('principals/user1/calendar-proxy-read', [
|
||||
'{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL',
|
||||
'{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',
|
||||
'{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',
|
||||
'{urn:ietf:params:xml:ns:caldav}calendar-user-type',
|
||||
'{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL',
|
||||
]);
|
||||
|
||||
$this->assertArrayHasKey(0, $props);
|
||||
$this->assertArrayHasKey(200, $props[0]);
|
||||
$this->assertArrayHasKey(404, $props[0]);
|
||||
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL', $props[0][404]);
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL', $props[0][404]);
|
||||
|
||||
$prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'];
|
||||
$this->assertTrue($prop instanceof DAV\Xml\Property\Href);
|
||||
$this->assertEquals(['/principals/user1/calendar-proxy-read/'], $prop->getHrefs());
|
||||
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-type', $props[0][200]);
|
||||
$prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-type'];
|
||||
$this->assertEquals('INDIVIDUAL', $prop);
|
||||
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL', $props[0][404]);
|
||||
|
||||
}
|
||||
function testNoDefaultCalendar() {
|
||||
|
||||
foreach ($this->caldavBackend->getCalendarsForUser('principals/user1') as $calendar) {
|
||||
$this->caldavBackend->deleteCalendar($calendar['id']);
|
||||
}
|
||||
$props = $this->server->getPropertiesForPath('/principals/user1', [
|
||||
'{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL',
|
||||
]);
|
||||
|
||||
$this->assertArrayHasKey(0, $props);
|
||||
$this->assertArrayHasKey(404, $props[0]);
|
||||
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL', $props[0][404]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* There are two properties for availability. The server should
|
||||
* automatically map the old property to the standard property.
|
||||
*/
|
||||
function testAvailabilityMapping() {
|
||||
|
||||
$path = 'calendars/user1/inbox';
|
||||
$oldProp = '{http://calendarserver.org/ns/}calendar-availability';
|
||||
$newProp = '{urn:ietf:params:xml:ns:caldav}calendar-availability';
|
||||
$value1 = 'first value';
|
||||
$value2 = 'second value';
|
||||
|
||||
// Storing with the old name
|
||||
$this->server->updateProperties($path, [
|
||||
$oldProp => $value1
|
||||
]);
|
||||
|
||||
// Retrieving with the new name
|
||||
$this->assertEquals(
|
||||
[$newProp => $value1],
|
||||
$this->server->getProperties($path, [$newProp])
|
||||
);
|
||||
|
||||
// Storing with the new name
|
||||
$this->server->updateProperties($path, [
|
||||
$newProp => $value2
|
||||
]);
|
||||
|
||||
// Retrieving with the old name
|
||||
$this->assertEquals(
|
||||
[$oldProp => $value2],
|
||||
$this->server->getProperties($path, [$oldProp])
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,71 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Schedule;
|
||||
|
||||
use Sabre\DAV;
|
||||
|
||||
class PluginPropertiesWithSharedCalendarTest extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
protected $setupCalDAVScheduling = true;
|
||||
protected $setupCalDAVSharing = true;
|
||||
|
||||
function setUp() {
|
||||
|
||||
parent::setUp();
|
||||
$this->caldavBackend->createCalendar(
|
||||
'principals/user1',
|
||||
'shared',
|
||||
[
|
||||
'share-access' => DAV\Sharing\Plugin::ACCESS_READWRITE
|
||||
]
|
||||
);
|
||||
$this->caldavBackend->createCalendar(
|
||||
'principals/user1',
|
||||
'default',
|
||||
[
|
||||
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testPrincipalProperties() {
|
||||
|
||||
$props = $this->server->getPropertiesForPath('/principals/user1', [
|
||||
'{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL',
|
||||
'{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL',
|
||||
'{urn:ietf:params:xml:ns:caldav}calendar-user-address-set',
|
||||
'{urn:ietf:params:xml:ns:caldav}calendar-user-type',
|
||||
'{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL',
|
||||
]);
|
||||
|
||||
$this->assertArrayHasKey(0, $props);
|
||||
$this->assertArrayHasKey(200, $props[0]);
|
||||
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL', $props[0][200]);
|
||||
$prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-outbox-URL'];
|
||||
$this->assertTrue($prop instanceof DAV\Xml\Property\Href);
|
||||
$this->assertEquals('calendars/user1/outbox/', $prop->getHref());
|
||||
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL', $props[0][200]);
|
||||
$prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-inbox-URL'];
|
||||
$this->assertTrue($prop instanceof DAV\Xml\Property\Href);
|
||||
$this->assertEquals('calendars/user1/inbox/', $prop->getHref());
|
||||
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-address-set', $props[0][200]);
|
||||
$prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-address-set'];
|
||||
$this->assertTrue($prop instanceof DAV\Xml\Property\Href);
|
||||
$this->assertEquals(['mailto:user1.sabredav@sabredav.org', '/principals/user1/'], $prop->getHrefs());
|
||||
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}calendar-user-type', $props[0][200]);
|
||||
$prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}calendar-user-type'];
|
||||
$this->assertEquals('INDIVIDUAL', $prop);
|
||||
|
||||
$this->assertArrayHasKey('{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL', $props[0][200]);
|
||||
$prop = $props[0][200]['{urn:ietf:params:xml:ns:caldav}schedule-default-calendar-URL'];
|
||||
$this->assertEquals('calendars/user1/default/', $prop->getHref());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,666 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Schedule;
|
||||
|
||||
use Sabre\HTTP\Request;
|
||||
use Sabre\VObject;
|
||||
|
||||
class ScheduleDeliverTest extends \Sabre\DAVServerTest {
|
||||
|
||||
use VObject\PHPUnitAssertions;
|
||||
|
||||
public $setupCalDAV = true;
|
||||
public $setupCalDAVScheduling = true;
|
||||
public $setupACL = true;
|
||||
public $autoLogin = 'user1';
|
||||
|
||||
public $caldavCalendars = [
|
||||
[
|
||||
'principaluri' => 'principals/user1',
|
||||
'uri' => 'cal',
|
||||
],
|
||||
[
|
||||
'principaluri' => 'principals/user2',
|
||||
'uri' => 'cal',
|
||||
],
|
||||
];
|
||||
|
||||
function setUp() {
|
||||
|
||||
$this->calendarObjectUri = '/calendars/user1/cal/object.ics';
|
||||
|
||||
parent::setUp();
|
||||
|
||||
}
|
||||
|
||||
function testNewInvite() {
|
||||
|
||||
$newObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->deliver(null, $newObject);
|
||||
$this->assertItemsInInbox('user2', 1);
|
||||
|
||||
$expected = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE;SCHEDULE-STATUS=1.2:mailto:user2.sabredav@sabredav.org
|
||||
DTSTAMP:**ANY**
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->assertVObjectEqualsVObject(
|
||||
$expected,
|
||||
$newObject
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testNewOnWrongCollection() {
|
||||
|
||||
$newObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->calendarObjectUri = '/calendars/user1/object.ics';
|
||||
$this->deliver(null, $newObject);
|
||||
$this->assertItemsInInbox('user2', 0);
|
||||
|
||||
|
||||
}
|
||||
function testNewInviteSchedulingDisabled() {
|
||||
|
||||
$newObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->deliver(null, $newObject, true);
|
||||
$this->assertItemsInInbox('user2', 0);
|
||||
|
||||
}
|
||||
function testUpdatedInvite() {
|
||||
|
||||
$newObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
$oldObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->deliver($oldObject, $newObject);
|
||||
$this->assertItemsInInbox('user2', 1);
|
||||
|
||||
$expected = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE;SCHEDULE-STATUS=1.2:mailto:user2.sabredav@sabredav.org
|
||||
DTSTAMP:**ANY**
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->assertVObjectEqualsVObject(
|
||||
$expected,
|
||||
$newObject
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
function testUpdatedInviteSchedulingDisabled() {
|
||||
|
||||
$newObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
$oldObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->deliver($oldObject, $newObject, true);
|
||||
$this->assertItemsInInbox('user2', 0);
|
||||
|
||||
}
|
||||
|
||||
function testUpdatedInviteWrongPath() {
|
||||
|
||||
$newObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
$oldObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->calendarObjectUri = '/calendars/user1/inbox/foo.ics';
|
||||
$this->deliver($oldObject, $newObject);
|
||||
$this->assertItemsInInbox('user2', 0);
|
||||
|
||||
}
|
||||
|
||||
function testDeletedInvite() {
|
||||
|
||||
$newObject = null;
|
||||
|
||||
$oldObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->deliver($oldObject, $newObject);
|
||||
$this->assertItemsInInbox('user2', 1);
|
||||
|
||||
}
|
||||
|
||||
function testDeletedInviteSchedulingDisabled() {
|
||||
|
||||
$newObject = null;
|
||||
|
||||
$oldObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->deliver($oldObject, $newObject, true);
|
||||
$this->assertItemsInInbox('user2', 0);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A MOVE request will trigger an unbind on a scheduling resource.
|
||||
*
|
||||
* However, we must not treat it as a cancellation, it just got moved to a
|
||||
* different calendar.
|
||||
*/
|
||||
function testUnbindIgnoredOnMove() {
|
||||
|
||||
$newObject = null;
|
||||
|
||||
$oldObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
|
||||
$this->server->httpRequest->setMethod('MOVE');
|
||||
$this->deliver($oldObject, $newObject);
|
||||
$this->assertItemsInInbox('user2', 0);
|
||||
|
||||
}
|
||||
|
||||
function testDeletedInviteWrongUrl() {
|
||||
|
||||
$newObject = null;
|
||||
|
||||
$oldObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->calendarObjectUri = '/calendars/user1/inbox/foo.ics';
|
||||
$this->deliver($oldObject, $newObject);
|
||||
$this->assertItemsInInbox('user2', 0);
|
||||
|
||||
}
|
||||
|
||||
function testReply() {
|
||||
|
||||
$oldObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user2.sabredav@sabredav.org
|
||||
ATTENDEE;PARTSTAT=ACCEPTED:mailto:user2.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user3.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$newObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user2.sabredav@sabredav.org
|
||||
ATTENDEE;PARTSTAT=ACCEPTED:mailto:user2.sabredav@sabredav.org
|
||||
ATTENDEE;PARTSTAT=ACCEPTED:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user3.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->putPath('calendars/user2/cal/foo.ics', $oldObject);
|
||||
|
||||
$this->deliver($oldObject, $newObject);
|
||||
$this->assertItemsInInbox('user2', 1);
|
||||
$this->assertItemsInInbox('user1', 0);
|
||||
|
||||
$expected = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER;SCHEDULE-STATUS=1.2:mailto:user2.sabredav@sabredav.org
|
||||
ATTENDEE;PARTSTAT=ACCEPTED:mailto:user2.sabredav@sabredav.org
|
||||
ATTENDEE;PARTSTAT=ACCEPTED:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user3.sabredav@sabredav.org
|
||||
DTSTAMP:**ANY**
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->assertVObjectEqualsVObject(
|
||||
$expected,
|
||||
$newObject
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function testInviteUnknownUser() {
|
||||
|
||||
$newObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user3.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->deliver(null, $newObject);
|
||||
|
||||
$expected = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE;SCHEDULE-STATUS=3.7:mailto:user3.sabredav@sabredav.org
|
||||
DTSTAMP:**ANY**
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->assertVObjectEqualsVObject(
|
||||
$expected,
|
||||
$newObject
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testInviteNoInboxUrl() {
|
||||
|
||||
$newObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->on('propFind', function($propFind) {
|
||||
$propFind->set('{' . Plugin::NS_CALDAV . '}schedule-inbox-URL', null, 403);
|
||||
});
|
||||
$this->deliver(null, $newObject);
|
||||
|
||||
$expected = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
|
||||
DTSTAMP:**ANY**
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->assertVObjectEqualsVObject(
|
||||
$expected,
|
||||
$newObject
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testInviteNoCalendarHomeSet() {
|
||||
|
||||
$newObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->on('propFind', function($propFind) {
|
||||
$propFind->set('{' . Plugin::NS_CALDAV . '}calendar-home-set', null, 403);
|
||||
});
|
||||
$this->deliver(null, $newObject);
|
||||
|
||||
$expected = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
|
||||
DTSTAMP:**ANY**
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->assertVObjectEqualsVObject(
|
||||
$expected,
|
||||
$newObject
|
||||
);
|
||||
|
||||
}
|
||||
function testInviteNoDefaultCalendar() {
|
||||
|
||||
$newObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->on('propFind', function($propFind) {
|
||||
$propFind->set('{' . Plugin::NS_CALDAV . '}schedule-default-calendar-URL', null, 403);
|
||||
});
|
||||
$this->deliver(null, $newObject);
|
||||
|
||||
$expected = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
|
||||
DTSTAMP:**ANY**
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->assertVObjectEqualsVObject(
|
||||
$expected,
|
||||
$newObject
|
||||
);
|
||||
|
||||
}
|
||||
function testInviteNoScheduler() {
|
||||
|
||||
$newObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->server->removeAllListeners('schedule');
|
||||
$this->deliver(null, $newObject);
|
||||
|
||||
$expected = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
|
||||
DTSTAMP:**ANY**
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->assertVObjectEqualsVObject(
|
||||
$expected,
|
||||
$newObject
|
||||
);
|
||||
|
||||
}
|
||||
function testInviteNoACLPlugin() {
|
||||
|
||||
$this->setupACL = false;
|
||||
parent::setUp();
|
||||
|
||||
$newObject = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE:mailto:user2.sabredav@sabredav.org
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->deliver(null, $newObject);
|
||||
|
||||
$expected = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTART:20140811T230000Z
|
||||
ORGANIZER:mailto:user1.sabredav@sabredav.org
|
||||
ATTENDEE;SCHEDULE-STATUS=5.2:mailto:user2.sabredav@sabredav.org
|
||||
DTSTAMP:**ANY**
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->assertVObjectEqualsVObject(
|
||||
$expected,
|
||||
$newObject
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
protected $calendarObjectUri;
|
||||
|
||||
function deliver($oldObject, &$newObject, $disableScheduling = false) {
|
||||
|
||||
$this->server->httpRequest->setUrl($this->calendarObjectUri);
|
||||
if ($disableScheduling) {
|
||||
$this->server->httpRequest->setHeader('Schedule-Reply', 'F');
|
||||
}
|
||||
|
||||
if ($oldObject && $newObject) {
|
||||
// update
|
||||
$this->putPath($this->calendarObjectUri, $oldObject);
|
||||
|
||||
$stream = fopen('php://memory', 'r+');
|
||||
fwrite($stream, $newObject);
|
||||
rewind($stream);
|
||||
$modified = false;
|
||||
|
||||
$this->server->emit('beforeWriteContent', [
|
||||
$this->calendarObjectUri,
|
||||
$this->server->tree->getNodeForPath($this->calendarObjectUri),
|
||||
&$stream,
|
||||
&$modified
|
||||
]);
|
||||
if ($modified) {
|
||||
$newObject = $stream;
|
||||
}
|
||||
|
||||
} elseif ($oldObject && !$newObject) {
|
||||
// delete
|
||||
$this->putPath($this->calendarObjectUri, $oldObject);
|
||||
|
||||
$this->caldavSchedulePlugin->beforeUnbind(
|
||||
$this->calendarObjectUri
|
||||
);
|
||||
} else {
|
||||
|
||||
// create
|
||||
$stream = fopen('php://memory', 'r+');
|
||||
fwrite($stream, $newObject);
|
||||
rewind($stream);
|
||||
$modified = false;
|
||||
$this->server->emit('beforeCreateFile', [
|
||||
$this->calendarObjectUri,
|
||||
&$stream,
|
||||
$this->server->tree->getNodeForPath(dirname($this->calendarObjectUri)),
|
||||
&$modified
|
||||
]);
|
||||
|
||||
if ($modified) {
|
||||
$newObject = $stream;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates or updates a node at the specified path.
|
||||
*
|
||||
* This circumvents sabredav's internal server apis, so all events and
|
||||
* access control is skipped.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $data
|
||||
* @return void
|
||||
*/
|
||||
function putPath($path, $data) {
|
||||
|
||||
list($parent, $base) = \Sabre\HTTP\UrlUtil::splitPath($path);
|
||||
$parentNode = $this->server->tree->getNodeForPath($parent);
|
||||
|
||||
/*
|
||||
if ($parentNode->childExists($base)) {
|
||||
$childNode = $parentNode->getChild($base);
|
||||
$childNode->put($data);
|
||||
} else {*/
|
||||
$parentNode->createFile($base, $data);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
function assertItemsInInbox($user, $count) {
|
||||
|
||||
$inboxNode = $this->server->tree->getNodeForPath('calendars/' . $user . '/inbox');
|
||||
$this->assertEquals($count, count($inboxNode->getChildren()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,378 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Schedule;
|
||||
|
||||
use Sabre\CalDAV\Backend;
|
||||
|
||||
class SchedulingObjectTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Sabre\CalDAV\Backend_PDO
|
||||
*/
|
||||
protected $backend;
|
||||
/**
|
||||
* @var Sabre\CalDAV\Calendar
|
||||
*/
|
||||
protected $calendar;
|
||||
protected $principalBackend;
|
||||
|
||||
protected $data;
|
||||
protected $data2;
|
||||
|
||||
function setup() {
|
||||
|
||||
if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
|
||||
$this->backend = new Backend\MockScheduling();
|
||||
|
||||
$this->data = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
METHOD:REQUEST
|
||||
BEGIN:VEVENT
|
||||
SEQUENCE:1
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
$this->data = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
METHOD:REQUEST
|
||||
BEGIN:VEVENT
|
||||
SEQUENCE:2
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$this->inbox = new Inbox($this->backend, 'principals/user1');
|
||||
$this->inbox->createFile('item1.ics', $this->data);
|
||||
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
|
||||
unset($this->inbox);
|
||||
unset($this->backend);
|
||||
|
||||
}
|
||||
|
||||
function testSetup() {
|
||||
|
||||
$children = $this->inbox->getChildren();
|
||||
$this->assertTrue($children[0] instanceof SchedulingObject);
|
||||
|
||||
$this->assertInternalType('string', $children[0]->getName());
|
||||
$this->assertInternalType('string', $children[0]->get());
|
||||
$this->assertInternalType('string', $children[0]->getETag());
|
||||
$this->assertEquals('text/calendar; charset=utf-8', $children[0]->getContentType());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
function testInvalidArg1() {
|
||||
|
||||
$obj = new SchedulingObject(
|
||||
new Backend\MockScheduling([], []),
|
||||
[],
|
||||
[]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
function testInvalidArg2() {
|
||||
|
||||
$obj = new SchedulingObject(
|
||||
new Backend\MockScheduling([], []),
|
||||
[],
|
||||
['calendarid' => '1']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSetup
|
||||
* @expectedException \Sabre\DAV\Exception\MethodNotAllowed
|
||||
*/
|
||||
function testPut() {
|
||||
|
||||
$children = $this->inbox->getChildren();
|
||||
$this->assertTrue($children[0] instanceof SchedulingObject);
|
||||
|
||||
$children[0]->put('');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSetup
|
||||
*/
|
||||
function testDelete() {
|
||||
|
||||
$children = $this->inbox->getChildren();
|
||||
$this->assertTrue($children[0] instanceof SchedulingObject);
|
||||
|
||||
$obj = $children[0];
|
||||
$obj->delete();
|
||||
|
||||
$children2 = $this->inbox->getChildren();
|
||||
$this->assertEquals(count($children) - 1, count($children2));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSetup
|
||||
*/
|
||||
function testGetLastModified() {
|
||||
|
||||
$children = $this->inbox->getChildren();
|
||||
$this->assertTrue($children[0] instanceof SchedulingObject);
|
||||
|
||||
$obj = $children[0];
|
||||
|
||||
$lastMod = $obj->getLastModified();
|
||||
$this->assertTrue(is_int($lastMod) || ctype_digit($lastMod) || is_null($lastMod));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSetup
|
||||
*/
|
||||
function testGetSize() {
|
||||
|
||||
$children = $this->inbox->getChildren();
|
||||
$this->assertTrue($children[0] instanceof SchedulingObject);
|
||||
|
||||
$obj = $children[0];
|
||||
|
||||
$size = $obj->getSize();
|
||||
$this->assertInternalType('int', $size);
|
||||
|
||||
}
|
||||
|
||||
function testGetOwner() {
|
||||
|
||||
$children = $this->inbox->getChildren();
|
||||
$this->assertTrue($children[0] instanceof SchedulingObject);
|
||||
|
||||
$obj = $children[0];
|
||||
$this->assertEquals('principals/user1', $obj->getOwner());
|
||||
|
||||
}
|
||||
|
||||
function testGetGroup() {
|
||||
|
||||
$children = $this->inbox->getChildren();
|
||||
$this->assertTrue($children[0] instanceof SchedulingObject);
|
||||
|
||||
$obj = $children[0];
|
||||
$this->assertNull($obj->getGroup());
|
||||
|
||||
}
|
||||
|
||||
function testGetACL() {
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'privilege' => '{DAV:}all',
|
||||
'principal' => '{DAV:}owner',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}all',
|
||||
'principal' => 'principals/user1/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1/calendar-proxy-read',
|
||||
'protected' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$children = $this->inbox->getChildren();
|
||||
$this->assertTrue($children[0] instanceof SchedulingObject);
|
||||
|
||||
$obj = $children[0];
|
||||
$this->assertEquals($expected, $obj->getACL());
|
||||
|
||||
}
|
||||
|
||||
function testDefaultACL() {
|
||||
|
||||
$backend = new Backend\MockScheduling([], []);
|
||||
$calendarObject = new SchedulingObject($backend, ['calendarid' => 1, 'uri' => 'foo', 'principaluri' => 'principals/user1']);
|
||||
$expected = [
|
||||
[
|
||||
'privilege' => '{DAV:}all',
|
||||
'principal' => '{DAV:}owner',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}all',
|
||||
'principal' => 'principals/user1/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1/calendar-proxy-read',
|
||||
'protected' => true,
|
||||
],
|
||||
];
|
||||
$this->assertEquals($expected, $calendarObject->getACL());
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testSetACL() {
|
||||
|
||||
$children = $this->inbox->getChildren();
|
||||
$this->assertTrue($children[0] instanceof SchedulingObject);
|
||||
|
||||
$obj = $children[0];
|
||||
$obj->setACL([]);
|
||||
|
||||
}
|
||||
|
||||
function testGet() {
|
||||
|
||||
$children = $this->inbox->getChildren();
|
||||
$this->assertTrue($children[0] instanceof SchedulingObject);
|
||||
|
||||
$obj = $children[0];
|
||||
|
||||
$this->assertEquals($this->data, $obj->get());
|
||||
|
||||
}
|
||||
|
||||
function testGetRefetch() {
|
||||
|
||||
$backend = new Backend\MockScheduling();
|
||||
$backend->createSchedulingObject('principals/user1', 'foo', 'foo');
|
||||
|
||||
$obj = new SchedulingObject($backend, [
|
||||
'calendarid' => 1,
|
||||
'uri' => 'foo',
|
||||
'principaluri' => 'principals/user1',
|
||||
]);
|
||||
|
||||
$this->assertEquals('foo', $obj->get());
|
||||
|
||||
}
|
||||
|
||||
function testGetEtag1() {
|
||||
|
||||
$objectInfo = [
|
||||
'calendardata' => 'foo',
|
||||
'uri' => 'foo',
|
||||
'etag' => 'bar',
|
||||
'calendarid' => 1
|
||||
];
|
||||
|
||||
$backend = new Backend\MockScheduling([], []);
|
||||
$obj = new SchedulingObject($backend, $objectInfo);
|
||||
|
||||
$this->assertEquals('bar', $obj->getETag());
|
||||
|
||||
}
|
||||
|
||||
function testGetEtag2() {
|
||||
|
||||
$objectInfo = [
|
||||
'calendardata' => 'foo',
|
||||
'uri' => 'foo',
|
||||
'calendarid' => 1
|
||||
];
|
||||
|
||||
$backend = new Backend\MockScheduling([], []);
|
||||
$obj = new SchedulingObject($backend, $objectInfo);
|
||||
|
||||
$this->assertEquals('"' . md5('foo') . '"', $obj->getETag());
|
||||
|
||||
}
|
||||
|
||||
function testGetSupportedPrivilegesSet() {
|
||||
|
||||
$objectInfo = [
|
||||
'calendardata' => 'foo',
|
||||
'uri' => 'foo',
|
||||
'calendarid' => 1
|
||||
];
|
||||
|
||||
$backend = new Backend\MockScheduling([], []);
|
||||
$obj = new SchedulingObject($backend, $objectInfo);
|
||||
$this->assertNull($obj->getSupportedPrivilegeSet());
|
||||
|
||||
}
|
||||
|
||||
function testGetSize1() {
|
||||
|
||||
$objectInfo = [
|
||||
'calendardata' => 'foo',
|
||||
'uri' => 'foo',
|
||||
'calendarid' => 1
|
||||
];
|
||||
|
||||
$backend = new Backend\MockScheduling([], []);
|
||||
$obj = new SchedulingObject($backend, $objectInfo);
|
||||
$this->assertEquals(3, $obj->getSize());
|
||||
|
||||
}
|
||||
|
||||
function testGetSize2() {
|
||||
|
||||
$objectInfo = [
|
||||
'uri' => 'foo',
|
||||
'calendarid' => 1,
|
||||
'size' => 4,
|
||||
];
|
||||
|
||||
$backend = new Backend\MockScheduling([], []);
|
||||
$obj = new SchedulingObject($backend, $objectInfo);
|
||||
$this->assertEquals(4, $obj->getSize());
|
||||
|
||||
}
|
||||
|
||||
function testGetContentType() {
|
||||
|
||||
$objectInfo = [
|
||||
'uri' => 'foo',
|
||||
'calendarid' => 1,
|
||||
];
|
||||
|
||||
$backend = new Backend\MockScheduling([], []);
|
||||
$obj = new SchedulingObject($backend, $objectInfo);
|
||||
$this->assertEquals('text/calendar; charset=utf-8', $obj->getContentType());
|
||||
|
||||
}
|
||||
|
||||
function testGetContentType2() {
|
||||
|
||||
$objectInfo = [
|
||||
'uri' => 'foo',
|
||||
'calendarid' => 1,
|
||||
'component' => 'VEVENT',
|
||||
];
|
||||
|
||||
$backend = new Backend\MockScheduling([], []);
|
||||
$obj = new SchedulingObject($backend, $objectInfo);
|
||||
$this->assertEquals('text/calendar; charset=utf-8; component=VEVENT', $obj->getContentType());
|
||||
|
||||
}
|
||||
function testGetACL2() {
|
||||
|
||||
$objectInfo = [
|
||||
'uri' => 'foo',
|
||||
'calendarid' => 1,
|
||||
'acl' => [],
|
||||
];
|
||||
|
||||
$backend = new Backend\MockScheduling([], []);
|
||||
$obj = new SchedulingObject($backend, $objectInfo);
|
||||
$this->assertEquals([], $obj->getACL());
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,176 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\DAV\Sharing;
|
||||
use Sabre\DAV\Xml\Element\Sharee;
|
||||
|
||||
class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
protected $backend;
|
||||
|
||||
function getInstance(array $props = null) {
|
||||
|
||||
if (is_null($props)) {
|
||||
$props = [
|
||||
'id' => 1,
|
||||
'{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original',
|
||||
'{http://sabredav.org/ns}owner-principal' => 'principals/owner',
|
||||
'{http://sabredav.org/ns}read-only' => false,
|
||||
'share-access' => Sharing\Plugin::ACCESS_READWRITE,
|
||||
'principaluri' => 'principals/sharee',
|
||||
];
|
||||
}
|
||||
|
||||
$this->backend = new Backend\MockSharing(
|
||||
[$props],
|
||||
[],
|
||||
[]
|
||||
);
|
||||
|
||||
$sharee = new Sharee();
|
||||
$sharee->href = 'mailto:removeme@example.org';
|
||||
$sharee->properties['{DAV:}displayname'] = 'To be removed';
|
||||
$sharee->access = Sharing\Plugin::ACCESS_READ;
|
||||
$this->backend->updateInvites(1, [$sharee]);
|
||||
|
||||
return new SharedCalendar($this->backend, $props);
|
||||
|
||||
}
|
||||
|
||||
function testGetInvites() {
|
||||
|
||||
$sharee = new Sharee();
|
||||
$sharee->href = 'mailto:removeme@example.org';
|
||||
$sharee->properties['{DAV:}displayname'] = 'To be removed';
|
||||
$sharee->access = Sharing\Plugin::ACCESS_READ;
|
||||
$sharee->inviteStatus = Sharing\Plugin::INVITE_NORESPONSE;
|
||||
|
||||
$this->assertEquals(
|
||||
[$sharee],
|
||||
$this->getInstance()->getInvites()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testGetOwner() {
|
||||
$this->assertEquals('principals/sharee', $this->getInstance()->getOwner());
|
||||
}
|
||||
|
||||
function testGetACL() {
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'privilege' => '{DAV:}write',
|
||||
'principal' => 'principals/sharee',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}write',
|
||||
'principal' => 'principals/sharee/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}write-properties',
|
||||
'principal' => 'principals/sharee',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}write-properties',
|
||||
'principal' => 'principals/sharee/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/sharee',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/sharee/calendar-proxy-read',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/sharee/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
|
||||
'principal' => '{DAV:}authenticated',
|
||||
'protected' => true,
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $this->getInstance()->getACL());
|
||||
|
||||
}
|
||||
|
||||
function testGetChildACL() {
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'privilege' => '{DAV:}write',
|
||||
'principal' => 'principals/sharee',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}write',
|
||||
'principal' => 'principals/sharee/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/sharee',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/sharee/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/sharee/calendar-proxy-read',
|
||||
'protected' => true,
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $this->getInstance()->getChildACL());
|
||||
|
||||
}
|
||||
|
||||
function testUpdateInvites() {
|
||||
|
||||
$instance = $this->getInstance();
|
||||
$newSharees = [
|
||||
new Sharee(),
|
||||
new Sharee()
|
||||
];
|
||||
$newSharees[0]->href = 'mailto:test@example.org';
|
||||
$newSharees[0]->properties['{DAV:}displayname'] = 'Foo Bar';
|
||||
$newSharees[0]->comment = 'Booh';
|
||||
$newSharees[0]->access = Sharing\Plugin::ACCESS_READWRITE;
|
||||
|
||||
$newSharees[1]->href = 'mailto:removeme@example.org';
|
||||
$newSharees[1]->access = Sharing\Plugin::ACCESS_NOACCESS;
|
||||
|
||||
$instance->updateInvites($newSharees);
|
||||
|
||||
$expected = [
|
||||
clone $newSharees[0]
|
||||
];
|
||||
$expected[0]->inviteStatus = Sharing\Plugin::INVITE_NORESPONSE;
|
||||
$this->assertEquals($expected, $instance->getInvites());
|
||||
|
||||
}
|
||||
|
||||
function testPublish() {
|
||||
|
||||
$instance = $this->getInstance();
|
||||
$this->assertNull($instance->setPublishStatus(true));
|
||||
$this->assertNull($instance->setPublishStatus(false));
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,396 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\DAV;
|
||||
use Sabre\DAV\Xml\Element\Sharee;
|
||||
use Sabre\HTTP;
|
||||
|
||||
class SharingPluginTest extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
protected $setupCalDAVSharing = true;
|
||||
protected $setupACL = true;
|
||||
protected $autoLogin = 'user1';
|
||||
|
||||
function setUp() {
|
||||
|
||||
$this->caldavCalendars = [
|
||||
[
|
||||
'principaluri' => 'principals/user1',
|
||||
'id' => 1,
|
||||
'uri' => 'cal1',
|
||||
],
|
||||
[
|
||||
'principaluri' => 'principals/user1',
|
||||
'id' => 2,
|
||||
'uri' => 'cal2',
|
||||
'share-access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE,
|
||||
],
|
||||
[
|
||||
'principaluri' => 'principals/user1',
|
||||
'id' => 3,
|
||||
'uri' => 'cal3',
|
||||
],
|
||||
];
|
||||
|
||||
parent::setUp();
|
||||
|
||||
// Making the logged in user an admin, for full access:
|
||||
$this->aclPlugin->adminPrincipals[] = 'principals/user2';
|
||||
|
||||
}
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$this->assertInstanceOf('Sabre\\CalDAV\\SharingPlugin', $this->server->getPlugin('caldav-sharing'));
|
||||
$this->assertEquals(
|
||||
'caldav-sharing',
|
||||
$this->caldavSharingPlugin->getPluginInfo()['name']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
function testSetupWithoutCoreSharingPlugin() {
|
||||
|
||||
$server = new DAV\Server();
|
||||
$server->addPlugin(
|
||||
new SharingPlugin()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testGetFeatures() {
|
||||
|
||||
$this->assertEquals(['calendarserver-sharing'], $this->caldavSharingPlugin->getFeatures());
|
||||
|
||||
}
|
||||
|
||||
function testBeforeGetShareableCalendar() {
|
||||
|
||||
// Forcing the server to authenticate:
|
||||
$this->authPlugin->beforeMethod(new HTTP\Request(), new HTTP\Response());
|
||||
$props = $this->server->getProperties('calendars/user1/cal1', [
|
||||
'{' . Plugin::NS_CALENDARSERVER . '}invite',
|
||||
'{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\Invite', $props['{' . Plugin::NS_CALENDARSERVER . '}invite']);
|
||||
$this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\AllowedSharingModes', $props['{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes']);
|
||||
|
||||
}
|
||||
|
||||
function testBeforeGetSharedCalendar() {
|
||||
|
||||
$props = $this->server->getProperties('calendars/user1/cal2', [
|
||||
'{' . Plugin::NS_CALENDARSERVER . '}shared-url',
|
||||
'{' . Plugin::NS_CALENDARSERVER . '}invite',
|
||||
]);
|
||||
|
||||
$this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\Invite', $props['{' . Plugin::NS_CALENDARSERVER . '}invite']);
|
||||
//$this->assertInstanceOf('Sabre\\DAV\\Xml\\Property\\Href', $props['{' . Plugin::NS_CALENDARSERVER . '}shared-url']);
|
||||
|
||||
}
|
||||
|
||||
function testUpdateResourceType() {
|
||||
|
||||
$this->caldavBackend->updateInvites(1,
|
||||
[
|
||||
new Sharee([
|
||||
'href' => 'mailto:joe@example.org',
|
||||
])
|
||||
]
|
||||
);
|
||||
$result = $this->server->updateProperties('calendars/user1/cal1', [
|
||||
'{DAV:}resourcetype' => new DAV\Xml\Property\ResourceType(['{DAV:}collection'])
|
||||
]);
|
||||
|
||||
$this->assertEquals([
|
||||
'{DAV:}resourcetype' => 200
|
||||
], $result);
|
||||
|
||||
$this->assertEquals(0, count($this->caldavBackend->getInvites(1)));
|
||||
|
||||
}
|
||||
|
||||
function testUpdatePropertiesPassThru() {
|
||||
|
||||
$result = $this->server->updateProperties('calendars/user1/cal3', [
|
||||
'{DAV:}foo' => 'bar',
|
||||
]);
|
||||
|
||||
$this->assertEquals([
|
||||
'{DAV:}foo' => 200,
|
||||
], $result);
|
||||
|
||||
}
|
||||
|
||||
function testUnknownMethodNoPOST() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'PATCH',
|
||||
'REQUEST_URI' => '/',
|
||||
]);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(501, $response->status, $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testUnknownMethodNoXML() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'REQUEST_URI' => '/',
|
||||
'CONTENT_TYPE' => 'text/plain',
|
||||
]);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(501, $response->status, $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testUnknownMethodNoNode() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'REQUEST_URI' => '/foo',
|
||||
'CONTENT_TYPE' => 'text/xml',
|
||||
]);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(501, $response->status, $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testShareRequest() {
|
||||
|
||||
$request = new HTTP\Request('POST', '/calendars/user1/cal1', ['Content-Type' => 'text/xml']);
|
||||
|
||||
$xml = <<<RRR
|
||||
<?xml version="1.0"?>
|
||||
<cs:share xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:">
|
||||
<cs:set>
|
||||
<d:href>mailto:joe@example.org</d:href>
|
||||
<cs:common-name>Joe Shmoe</cs:common-name>
|
||||
<cs:read-write />
|
||||
</cs:set>
|
||||
<cs:remove>
|
||||
<d:href>mailto:nancy@example.org</d:href>
|
||||
</cs:remove>
|
||||
</cs:share>
|
||||
RRR;
|
||||
|
||||
$request->setBody($xml);
|
||||
|
||||
$response = $this->request($request, 200);
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
new Sharee([
|
||||
'href' => 'mailto:joe@example.org',
|
||||
'properties' => [
|
||||
'{DAV:}displayname' => 'Joe Shmoe',
|
||||
],
|
||||
'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE,
|
||||
'inviteStatus' => \Sabre\DAV\Sharing\Plugin::INVITE_NORESPONSE,
|
||||
'comment' => '',
|
||||
]),
|
||||
],
|
||||
$this->caldavBackend->getInvites(1)
|
||||
);
|
||||
|
||||
// Wiping out tree cache
|
||||
$this->server->tree->markDirty('');
|
||||
|
||||
// Verifying that the calendar is now marked shared.
|
||||
$props = $this->server->getProperties('calendars/user1/cal1', ['{DAV:}resourcetype']);
|
||||
$this->assertTrue(
|
||||
$props['{DAV:}resourcetype']->is('{http://calendarserver.org/ns/}shared-owner')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testShareRequestNoShareableCalendar() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/cal2',
|
||||
['Content-Type' => 'text/xml']
|
||||
);
|
||||
|
||||
$xml = '<?xml version="1.0"?>
|
||||
<cs:share xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:">
|
||||
<cs:set>
|
||||
<d:href>mailto:joe@example.org</d:href>
|
||||
<cs:common-name>Joe Shmoe</cs:common-name>
|
||||
<cs:read-write />
|
||||
</cs:set>
|
||||
<cs:remove>
|
||||
<d:href>mailto:nancy@example.org</d:href>
|
||||
</cs:remove>
|
||||
</cs:share>
|
||||
';
|
||||
|
||||
$request->setBody($xml);
|
||||
|
||||
$response = $this->request($request, 403);
|
||||
|
||||
}
|
||||
|
||||
function testInviteReply() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'REQUEST_URI' => '/calendars/user1',
|
||||
'CONTENT_TYPE' => 'text/xml',
|
||||
]);
|
||||
|
||||
$xml = '<?xml version="1.0"?>
|
||||
<cs:invite-reply xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:">
|
||||
<cs:hosturl><d:href>/principals/owner</d:href></cs:hosturl>
|
||||
<cs:invite-accepted />
|
||||
</cs:invite-reply>
|
||||
';
|
||||
|
||||
$request->setBody($xml);
|
||||
$response = $this->request($request);
|
||||
$this->assertEquals(200, $response->status, $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testInviteBadXML() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'REQUEST_URI' => '/calendars/user1',
|
||||
'CONTENT_TYPE' => 'text/xml',
|
||||
]);
|
||||
|
||||
$xml = '<?xml version="1.0"?>
|
||||
<cs:invite-reply xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:">
|
||||
</cs:invite-reply>
|
||||
';
|
||||
$request->setBody($xml);
|
||||
$response = $this->request($request);
|
||||
$this->assertEquals(400, $response->status, $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testInviteWrongUrl() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'POST',
|
||||
'REQUEST_URI' => '/calendars/user1/cal1',
|
||||
'CONTENT_TYPE' => 'text/xml',
|
||||
]);
|
||||
|
||||
$xml = '<?xml version="1.0"?>
|
||||
<cs:invite-reply xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:">
|
||||
<cs:hosturl><d:href>/principals/owner</d:href></cs:hosturl>
|
||||
</cs:invite-reply>
|
||||
';
|
||||
$request->setBody($xml);
|
||||
$response = $this->request($request);
|
||||
$this->assertEquals(501, $response->status, $response->body);
|
||||
|
||||
// If the plugin did not handle this request, it must ensure that the
|
||||
// body is still accessible by other plugins.
|
||||
$this->assertEquals($xml, $request->getBody(true));
|
||||
|
||||
}
|
||||
|
||||
function testPublish() {
|
||||
|
||||
$request = new HTTP\Request('POST', '/calendars/user1/cal1', ['Content-Type' => 'text/xml']);
|
||||
|
||||
$xml = '<?xml version="1.0"?>
|
||||
<cs:publish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
|
||||
';
|
||||
|
||||
$request->setBody($xml);
|
||||
|
||||
$response = $this->request($request);
|
||||
$this->assertEquals(202, $response->status, $response->body);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testUnpublish() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/cal1',
|
||||
['Content-Type' => 'text/xml']
|
||||
);
|
||||
|
||||
$xml = '<?xml version="1.0"?>
|
||||
<cs:unpublish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
|
||||
';
|
||||
|
||||
$request->setBody($xml);
|
||||
|
||||
$response = $this->request($request);
|
||||
$this->assertEquals(200, $response->status, $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testPublishWrongUrl() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1',
|
||||
['Content-Type' => 'text/xml']
|
||||
);
|
||||
|
||||
$xml = '<?xml version="1.0"?>
|
||||
<cs:publish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
|
||||
';
|
||||
|
||||
$request->setBody($xml);
|
||||
$this->request($request, 501);
|
||||
|
||||
}
|
||||
|
||||
function testUnpublishWrongUrl() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1',
|
||||
['Content-Type' => 'text/xml']
|
||||
);
|
||||
$xml = '<?xml version="1.0"?>
|
||||
<cs:unpublish-calendar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />
|
||||
';
|
||||
|
||||
$request->setBody($xml);
|
||||
|
||||
$this->request($request, 501);
|
||||
|
||||
}
|
||||
|
||||
function testUnknownXmlDoc() {
|
||||
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'POST',
|
||||
'/calendars/user1/cal2',
|
||||
['Content-Type' => 'text/xml']
|
||||
);
|
||||
|
||||
$xml = '<?xml version="1.0"?>
|
||||
<cs:foo-bar xmlns:cs="' . Plugin::NS_CALENDARSERVER . '" xmlns:d="DAV:" />';
|
||||
|
||||
$request->setBody($xml);
|
||||
|
||||
$response = $this->request($request);
|
||||
$this->assertEquals(501, $response->status, $response->body);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,123 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Subscriptions;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\HTTP\Request;
|
||||
|
||||
class CreateSubscriptionTest extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCalDAV = true;
|
||||
protected $setupCalDAVSubscriptions = true;
|
||||
|
||||
/**
|
||||
* OS X 10.7 - 10.9.1
|
||||
*/
|
||||
function testMKCOL() {
|
||||
|
||||
$body = <<<XML
|
||||
<A:mkcol xmlns:A="DAV:">
|
||||
<A:set>
|
||||
<A:prop>
|
||||
<B:subscribed-strip-attachments xmlns:B="http://calendarserver.org/ns/" />
|
||||
<B:subscribed-strip-todos xmlns:B="http://calendarserver.org/ns/" />
|
||||
<A:resourcetype>
|
||||
<A:collection />
|
||||
<B:subscribed xmlns:B="http://calendarserver.org/ns/" />
|
||||
</A:resourcetype>
|
||||
<E:calendar-color xmlns:E="http://apple.com/ns/ical/">#1C4587FF</E:calendar-color>
|
||||
<A:displayname>Jewish holidays</A:displayname>
|
||||
<C:calendar-description xmlns:C="urn:ietf:params:xml:ns:caldav">Foo</C:calendar-description>
|
||||
<E:calendar-order xmlns:E="http://apple.com/ns/ical/">19</E:calendar-order>
|
||||
<B:source xmlns:B="http://calendarserver.org/ns/">
|
||||
<A:href>webcal://www.example.org/</A:href>
|
||||
</B:source>
|
||||
<E:refreshrate xmlns:E="http://apple.com/ns/ical/">P1W</E:refreshrate>
|
||||
<B:subscribed-strip-alarms xmlns:B="http://calendarserver.org/ns/" />
|
||||
</A:prop>
|
||||
</A:set>
|
||||
</A:mkcol>
|
||||
XML;
|
||||
|
||||
$headers = [
|
||||
'Content-Type' => 'application/xml',
|
||||
];
|
||||
$request = new Request('MKCOL', '/calendars/user1/subscription1', $headers, $body);
|
||||
|
||||
$response = $this->request($request);
|
||||
$this->assertEquals(201, $response->getStatus());
|
||||
$subscriptions = $this->caldavBackend->getSubscriptionsForUser('principals/user1');
|
||||
$this->assertSubscription($subscriptions[0]);
|
||||
|
||||
|
||||
}
|
||||
/**
|
||||
* OS X 10.9.2 and up
|
||||
*/
|
||||
function testMKCALENDAR() {
|
||||
|
||||
$body = <<<XML
|
||||
<B:mkcalendar xmlns:B="urn:ietf:params:xml:ns:caldav">
|
||||
<A:set xmlns:A="DAV:">
|
||||
<A:prop>
|
||||
<B:supported-calendar-component-set>
|
||||
<B:comp name="VEVENT" />
|
||||
</B:supported-calendar-component-set>
|
||||
<C:subscribed-strip-alarms xmlns:C="http://calendarserver.org/ns/" />
|
||||
<C:subscribed-strip-attachments xmlns:C="http://calendarserver.org/ns/" />
|
||||
<A:resourcetype>
|
||||
<A:collection />
|
||||
<C:subscribed xmlns:C="http://calendarserver.org/ns/" />
|
||||
</A:resourcetype>
|
||||
<D:refreshrate xmlns:D="http://apple.com/ns/ical/">P1W</D:refreshrate>
|
||||
<C:source xmlns:C="http://calendarserver.org/ns/">
|
||||
<A:href>webcal://www.example.org/</A:href>
|
||||
</C:source>
|
||||
<D:calendar-color xmlns:D="http://apple.com/ns/ical/">#1C4587FF</D:calendar-color>
|
||||
<D:calendar-order xmlns:D="http://apple.com/ns/ical/">19</D:calendar-order>
|
||||
<B:calendar-description>Foo</B:calendar-description>
|
||||
<C:subscribed-strip-todos xmlns:C="http://calendarserver.org/ns/" />
|
||||
<A:displayname>Jewish holidays</A:displayname>
|
||||
</A:prop>
|
||||
</A:set>
|
||||
</B:mkcalendar>
|
||||
XML;
|
||||
|
||||
$headers = [
|
||||
'Content-Type' => 'application/xml',
|
||||
];
|
||||
$request = new Request('MKCALENDAR', '/calendars/user1/subscription1', $headers, $body);
|
||||
|
||||
$response = $this->request($request);
|
||||
$this->assertEquals(201, $response->getStatus());
|
||||
$subscriptions = $this->caldavBackend->getSubscriptionsForUser('principals/user1');
|
||||
$this->assertSubscription($subscriptions[0]);
|
||||
|
||||
// Also seeing if it works when calling this as a PROPFIND.
|
||||
$this->assertEquals([
|
||||
'{http://calendarserver.org/ns/}subscribed-strip-alarms' => '',
|
||||
],
|
||||
$this->server->getProperties('calendars/user1/subscription1', ['{http://calendarserver.org/ns/}subscribed-strip-alarms'])
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function assertSubscription($subscription) {
|
||||
|
||||
$this->assertEquals('', $subscription['{http://calendarserver.org/ns/}subscribed-strip-attachments']);
|
||||
$this->assertEquals('', $subscription['{http://calendarserver.org/ns/}subscribed-strip-todos']);
|
||||
$this->assertEquals('#1C4587FF', $subscription['{http://apple.com/ns/ical/}calendar-color']);
|
||||
$this->assertEquals('Jewish holidays', $subscription['{DAV:}displayname']);
|
||||
$this->assertEquals('Foo', $subscription['{urn:ietf:params:xml:ns:caldav}calendar-description']);
|
||||
$this->assertEquals('19', $subscription['{http://apple.com/ns/ical/}calendar-order']);
|
||||
$this->assertEquals('webcal://www.example.org/', $subscription['{http://calendarserver.org/ns/}source']->getHref());
|
||||
$this->assertEquals('P1W', $subscription['{http://apple.com/ns/ical/}refreshrate']);
|
||||
$this->assertEquals('subscription1', $subscription['uri']);
|
||||
$this->assertEquals('principals/user1', $subscription['principaluri']);
|
||||
$this->assertEquals('webcal://www.example.org/', $subscription['source']);
|
||||
$this->assertEquals(['principals/user1', 1], $subscription['id']);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Subscriptions;
|
||||
|
||||
use Sabre\DAV\PropFind;
|
||||
|
||||
class PluginTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function testInit() {
|
||||
|
||||
$server = new \Sabre\DAV\Server();
|
||||
$plugin = new Plugin();
|
||||
|
||||
$server->addPlugin($plugin);
|
||||
|
||||
$this->assertEquals(
|
||||
'{http://calendarserver.org/ns/}subscribed',
|
||||
$server->resourceTypeMapping['Sabre\\CalDAV\\Subscriptions\\ISubscription']
|
||||
);
|
||||
$this->assertEquals(
|
||||
'Sabre\\DAV\\Xml\\Property\\Href',
|
||||
$server->xml->elementMap['{http://calendarserver.org/ns/}source']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
['calendarserver-subscribed'],
|
||||
$plugin->getFeatures()
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
'subscriptions',
|
||||
$plugin->getPluginInfo()['name']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testPropFind() {
|
||||
|
||||
$propName = '{http://calendarserver.org/ns/}subscribed-strip-alarms';
|
||||
$propFind = new PropFind('foo', [$propName]);
|
||||
$propFind->set($propName, null, 200);
|
||||
|
||||
$plugin = new Plugin();
|
||||
$plugin->propFind($propFind, new \Sabre\DAV\SimpleCollection('hi'));
|
||||
|
||||
$this->assertFalse(is_null($propFind->get($propName)));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,131 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Subscriptions;
|
||||
|
||||
use Sabre\DAV\PropPatch;
|
||||
use Sabre\DAV\Xml\Property\Href;
|
||||
|
||||
class SubscriptionTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
protected $backend;
|
||||
|
||||
function getSub($override = []) {
|
||||
|
||||
$caldavBackend = new \Sabre\CalDAV\Backend\MockSubscriptionSupport([], []);
|
||||
|
||||
$info = [
|
||||
'{http://calendarserver.org/ns/}source' => new Href('http://example.org/src', false),
|
||||
'lastmodified' => date('2013-04-06 11:40:00'), // tomorrow is my birthday!
|
||||
'{DAV:}displayname' => 'displayname',
|
||||
];
|
||||
|
||||
|
||||
$id = $caldavBackend->createSubscription('principals/user1', 'uri', array_merge($info, $override));
|
||||
$subInfo = $caldavBackend->getSubscriptionsForUser('principals/user1');
|
||||
|
||||
$this->assertEquals(1, count($subInfo));
|
||||
$subscription = new Subscription($caldavBackend, $subInfo[0]);
|
||||
|
||||
$this->backend = $caldavBackend;
|
||||
return $subscription;
|
||||
|
||||
}
|
||||
|
||||
function testValues() {
|
||||
|
||||
$sub = $this->getSub();
|
||||
|
||||
$this->assertEquals('uri', $sub->getName());
|
||||
$this->assertEquals(date('2013-04-06 11:40:00'), $sub->getLastModified());
|
||||
$this->assertEquals([], $sub->getChildren());
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
'{DAV:}displayname' => 'displayname',
|
||||
'{http://calendarserver.org/ns/}source' => new Href('http://example.org/src', false),
|
||||
],
|
||||
$sub->getProperties(['{DAV:}displayname', '{http://calendarserver.org/ns/}source'])
|
||||
);
|
||||
|
||||
$this->assertEquals('principals/user1', $sub->getOwner());
|
||||
$this->assertNull($sub->getGroup());
|
||||
|
||||
$acl = [
|
||||
[
|
||||
'privilege' => '{DAV:}all',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}all',
|
||||
'principal' => 'principals/user1/calendar-proxy-write',
|
||||
'protected' => true,
|
||||
],
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1/calendar-proxy-read',
|
||||
'protected' => true,
|
||||
]
|
||||
];
|
||||
$this->assertEquals($acl, $sub->getACL());
|
||||
|
||||
$this->assertNull($sub->getSupportedPrivilegeSet());
|
||||
|
||||
}
|
||||
|
||||
function testValues2() {
|
||||
|
||||
$sub = $this->getSub([
|
||||
'lastmodified' => null,
|
||||
]);
|
||||
|
||||
$this->assertEquals(null, $sub->getLastModified());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testSetACL() {
|
||||
|
||||
$sub = $this->getSub();
|
||||
$sub->setACL([]);
|
||||
|
||||
}
|
||||
|
||||
function testDelete() {
|
||||
|
||||
$sub = $this->getSub();
|
||||
$sub->delete();
|
||||
|
||||
$this->assertEquals([], $this->backend->getSubscriptionsForUser('principals1/user1'));
|
||||
|
||||
}
|
||||
|
||||
function testUpdateProperties() {
|
||||
|
||||
$sub = $this->getSub();
|
||||
$propPatch = new PropPatch([
|
||||
'{DAV:}displayname' => 'foo',
|
||||
]);
|
||||
$sub->propPatch($propPatch);
|
||||
$this->assertTrue($propPatch->commit());
|
||||
|
||||
$this->assertEquals(
|
||||
'foo',
|
||||
$this->backend->getSubscriptionsForUser('principals/user1')[0]['{DAV:}displayname']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
function testBadConstruct() {
|
||||
|
||||
$caldavBackend = new \Sabre\CalDAV\Backend\MockSubscriptionSupport([], []);
|
||||
new Subscription($caldavBackend, []);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,189 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
class TestUtil {
|
||||
|
||||
static function getBackend() {
|
||||
|
||||
$backend = new Backend\Mock();
|
||||
$calendarId = $backend->createCalendar(
|
||||
'principals/user1',
|
||||
'UUID-123467',
|
||||
[
|
||||
'{DAV:}displayname' => 'user1 calendar',
|
||||
'{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar description',
|
||||
'{http://apple.com/ns/ical/}calendar-order' => '1',
|
||||
'{http://apple.com/ns/ical/}calendar-color' => '#FF0000',
|
||||
]
|
||||
);
|
||||
$backend->createCalendar(
|
||||
'principals/user1',
|
||||
'UUID-123468',
|
||||
[
|
||||
'{DAV:}displayname' => 'user1 calendar2',
|
||||
'{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Calendar description',
|
||||
'{http://apple.com/ns/ical/}calendar-order' => '1',
|
||||
'{http://apple.com/ns/ical/}calendar-color' => '#FF0000',
|
||||
]
|
||||
);
|
||||
$backend->createCalendarObject($calendarId, 'UUID-2345', self::getTestCalendarData());
|
||||
return $backend;
|
||||
|
||||
}
|
||||
|
||||
static function getTestCalendarData($type = 1) {
|
||||
|
||||
$calendarData = 'BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//Apple Inc.//iCal 4.0.1//EN
|
||||
CALSCALE:GREGORIAN
|
||||
BEGIN:VTIMEZONE
|
||||
TZID:Asia/Seoul
|
||||
BEGIN:DAYLIGHT
|
||||
TZOFFSETFROM:+0900
|
||||
RRULE:FREQ=YEARLY;UNTIL=19880507T150000Z;BYMONTH=5;BYDAY=2SU
|
||||
DTSTART:19870510T000000
|
||||
TZNAME:GMT+09:00
|
||||
TZOFFSETTO:+1000
|
||||
END:DAYLIGHT
|
||||
BEGIN:STANDARD
|
||||
TZOFFSETFROM:+1000
|
||||
DTSTART:19881009T000000
|
||||
TZNAME:GMT+09:00
|
||||
TZOFFSETTO:+0900
|
||||
END:STANDARD
|
||||
END:VTIMEZONE
|
||||
BEGIN:VEVENT
|
||||
CREATED:20100225T154229Z
|
||||
UID:39A6B5ED-DD51-4AFE-A683-C35EE3749627
|
||||
TRANSP:TRANSPARENT
|
||||
SUMMARY:Something here
|
||||
DTSTAMP:20100228T130202Z';
|
||||
|
||||
switch ($type) {
|
||||
case 1 :
|
||||
$calendarData .= "\nDTSTART;TZID=Asia/Seoul:20100223T060000\nDTEND;TZID=Asia/Seoul:20100223T070000\n";
|
||||
break;
|
||||
case 2 :
|
||||
$calendarData .= "\nDTSTART:20100223T060000\nDTEND:20100223T070000\n";
|
||||
break;
|
||||
case 3 :
|
||||
$calendarData .= "\nDTSTART;VALUE=DATE:20100223\nDTEND;VALUE=DATE:20100223\n";
|
||||
break;
|
||||
case 4 :
|
||||
$calendarData .= "\nDTSTART;TZID=Asia/Seoul:20100223T060000\nDURATION:PT1H\n";
|
||||
break;
|
||||
case 5 :
|
||||
$calendarData .= "\nDTSTART;TZID=Asia/Seoul:20100223T060000\nDURATION:-P5D\n";
|
||||
break;
|
||||
case 6 :
|
||||
$calendarData .= "\nDTSTART;VALUE=DATE:20100223\n";
|
||||
break;
|
||||
case 7 :
|
||||
$calendarData .= "\nDTSTART;VALUE=DATETIME:20100223T060000\n";
|
||||
break;
|
||||
|
||||
// No DTSTART, so intentionally broken
|
||||
case 'X' :
|
||||
$calendarData .= "\n";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
$calendarData .= 'ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa@example.com
|
||||
SEQUENCE:2
|
||||
END:VEVENT
|
||||
END:VCALENDAR';
|
||||
|
||||
return $calendarData;
|
||||
|
||||
}
|
||||
|
||||
static function getTestTODO($type = 'due') {
|
||||
|
||||
switch ($type) {
|
||||
|
||||
case 'due' :
|
||||
$extra = "DUE:20100104T000000Z";
|
||||
break;
|
||||
case 'due2' :
|
||||
$extra = "DUE:20060104T000000Z";
|
||||
break;
|
||||
case 'due_date' :
|
||||
$extra = "DUE;VALUE=DATE:20060104";
|
||||
break;
|
||||
case 'due_tz' :
|
||||
$extra = "DUE;TZID=Asia/Seoul:20060104T000000Z";
|
||||
break;
|
||||
case 'due_dtstart' :
|
||||
$extra = "DTSTART:20050223T060000Z\nDUE:20060104T000000Z";
|
||||
break;
|
||||
case 'due_dtstart2' :
|
||||
$extra = "DTSTART:20090223T060000Z\nDUE:20100104T000000Z";
|
||||
break;
|
||||
case 'dtstart' :
|
||||
$extra = 'DTSTART:20100223T060000Z';
|
||||
break;
|
||||
case 'dtstart2' :
|
||||
$extra = 'DTSTART:20060223T060000Z';
|
||||
break;
|
||||
case 'dtstart_date' :
|
||||
$extra = 'DTSTART;VALUE=DATE:20100223';
|
||||
break;
|
||||
case 'dtstart_tz' :
|
||||
$extra = 'DTSTART;TZID=Asia/Seoul:20100223T060000Z';
|
||||
break;
|
||||
case 'dtstart_duration' :
|
||||
$extra = "DTSTART:20061023T060000Z\nDURATION:PT1H";
|
||||
break;
|
||||
case 'dtstart_duration2' :
|
||||
$extra = "DTSTART:20101023T060000Z\nDURATION:PT1H";
|
||||
break;
|
||||
case 'completed' :
|
||||
$extra = 'COMPLETED:20060601T000000Z';
|
||||
break;
|
||||
case 'completed2' :
|
||||
$extra = 'COMPLETED:20090601T000000Z';
|
||||
break;
|
||||
case 'created' :
|
||||
$extra = 'CREATED:20060601T000000Z';
|
||||
break;
|
||||
case 'created2' :
|
||||
$extra = 'CREATED:20090601T000000Z';
|
||||
break;
|
||||
case 'completedcreated' :
|
||||
$extra = "CREATED:20060601T000000Z\nCOMPLETED:20070101T000000Z";
|
||||
break;
|
||||
case 'completedcreated2' :
|
||||
$extra = "CREATED:20090601T000000Z\nCOMPLETED:20100101T000000Z";
|
||||
break;
|
||||
case 'notime' :
|
||||
$extra = 'X-FILLER:oh hello';
|
||||
break;
|
||||
default :
|
||||
throw new Exception('Unknown type: ' . $type);
|
||||
|
||||
}
|
||||
|
||||
$todo = 'BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//Example Corp.//CalDAV Client//EN
|
||||
BEGIN:VTODO
|
||||
DTSTAMP:20060205T235335Z
|
||||
' . $extra . '
|
||||
STATUS:NEEDS-ACTION
|
||||
SUMMARY:Task #1
|
||||
UID:DDDEEB7915FA61233B861457@example.com
|
||||
BEGIN:VALARM
|
||||
ACTION:AUDIO
|
||||
TRIGGER;RELATED=START:-PT10M
|
||||
END:VALARM
|
||||
END:VTODO
|
||||
END:VCALENDAR';
|
||||
|
||||
return $todo;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,406 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV;
|
||||
|
||||
use Sabre\DAV;
|
||||
use Sabre\DAVACL;
|
||||
use Sabre\HTTP;
|
||||
|
||||
require_once 'Sabre/HTTP/ResponseMock.php';
|
||||
|
||||
class ValidateICalTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Sabre\DAV\Server
|
||||
*/
|
||||
protected $server;
|
||||
/**
|
||||
* @var Sabre\CalDAV\Backend\Mock
|
||||
*/
|
||||
protected $calBackend;
|
||||
|
||||
function setUp() {
|
||||
|
||||
$calendars = [
|
||||
[
|
||||
'id' => 'calendar1',
|
||||
'principaluri' => 'principals/admin',
|
||||
'uri' => 'calendar1',
|
||||
'{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Xml\Property\SupportedCalendarComponentSet(['VEVENT', 'VTODO', 'VJOURNAL']),
|
||||
],
|
||||
[
|
||||
'id' => 'calendar2',
|
||||
'principaluri' => 'principals/admin',
|
||||
'uri' => 'calendar2',
|
||||
'{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new Xml\Property\SupportedCalendarComponentSet(['VTODO', 'VJOURNAL']),
|
||||
]
|
||||
];
|
||||
|
||||
$this->calBackend = new Backend\Mock($calendars, []);
|
||||
$principalBackend = new DAVACL\PrincipalBackend\Mock();
|
||||
|
||||
$tree = [
|
||||
new CalendarRoot($principalBackend, $this->calBackend),
|
||||
];
|
||||
|
||||
$this->server = new DAV\Server($tree);
|
||||
$this->server->sapi = new HTTP\SapiMock();
|
||||
$this->server->debugExceptions = true;
|
||||
|
||||
$plugin = new Plugin();
|
||||
$this->server->addPlugin($plugin);
|
||||
|
||||
$response = new HTTP\ResponseMock();
|
||||
$this->server->httpResponse = $response;
|
||||
|
||||
}
|
||||
|
||||
function request(HTTP\Request $request) {
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->server->exec();
|
||||
|
||||
return $this->server->httpResponse;
|
||||
|
||||
}
|
||||
|
||||
function testCreateFile() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'PUT',
|
||||
'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
|
||||
]);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(415, $response->status);
|
||||
|
||||
}
|
||||
|
||||
function testCreateFileValid() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'PUT',
|
||||
'/calendars/admin/calendar1/blabla.ics',
|
||||
['Prefer' => 'handling=strict']
|
||||
);
|
||||
|
||||
$ics = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:foo
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTAMP:20160406T052348Z
|
||||
DTSTART:20160706T140000Z
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$request->setBody($ics);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
|
||||
$this->assertEquals([
|
||||
'X-Sabre-Version' => [DAV\Version::VERSION],
|
||||
'Content-Length' => ['0'],
|
||||
'ETag' => ['"' . md5($ics) . '"'],
|
||||
], $response->getHeaders());
|
||||
|
||||
$expected = [
|
||||
'uri' => 'blabla.ics',
|
||||
'calendardata' => $ics,
|
||||
'calendarid' => 'calendar1',
|
||||
'lastmodified' => null,
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1', 'blabla.ics'));
|
||||
|
||||
}
|
||||
|
||||
function testCreateFileNoVersion() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'PUT',
|
||||
'/calendars/admin/calendar1/blabla.ics',
|
||||
['Prefer' => 'handling=strict']
|
||||
);
|
||||
|
||||
$ics = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
PRODID:foo
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTAMP:20160406T052348Z
|
||||
DTSTART:20160706T140000Z
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$request->setBody($ics);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testCreateFileNoVersionFixed() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'PUT',
|
||||
'/calendars/admin/calendar1/blabla.ics',
|
||||
['Prefer' => 'handling=lenient']
|
||||
);
|
||||
|
||||
$ics = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
PRODID:foo
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTAMP:20160406T052348Z
|
||||
DTSTART:20160706T140000Z
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$request->setBody($ics);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
|
||||
$this->assertEquals([
|
||||
'X-Sabre-Version' => [DAV\Version::VERSION],
|
||||
'Content-Length' => ['0'],
|
||||
'X-Sabre-Ew-Gross' => ['iCalendar validation warning: VERSION MUST appear exactly once in a VCALENDAR component'],
|
||||
], $response->getHeaders());
|
||||
|
||||
$ics = <<<ICS
|
||||
BEGIN:VCALENDAR\r
|
||||
VERSION:2.0\r
|
||||
PRODID:foo\r
|
||||
BEGIN:VEVENT\r
|
||||
UID:foo\r
|
||||
DTSTAMP:20160406T052348Z\r
|
||||
DTSTART:20160706T140000Z\r
|
||||
END:VEVENT\r
|
||||
END:VCALENDAR\r
|
||||
|
||||
ICS;
|
||||
|
||||
$expected = [
|
||||
'uri' => 'blabla.ics',
|
||||
'calendardata' => $ics,
|
||||
'calendarid' => 'calendar1',
|
||||
'lastmodified' => null,
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1', 'blabla.ics'));
|
||||
|
||||
}
|
||||
|
||||
function testCreateFileNoComponents() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'PUT',
|
||||
'/calendars/admin/calendar1/blabla.ics',
|
||||
['Prefer' => 'handling=strict']
|
||||
);
|
||||
$ics = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:foo
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$request->setBody($ics);
|
||||
|
||||
$response = $this->request($request);
|
||||
$this->assertEquals(403, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testCreateFileNoUID() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'PUT',
|
||||
'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
|
||||
]);
|
||||
$request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testCreateFileVCard() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'PUT',
|
||||
'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
|
||||
]);
|
||||
$request->setBody("BEGIN:VCARD\r\nEND:VCARD\r\n");
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testCreateFile2Components() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'PUT',
|
||||
'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
|
||||
]);
|
||||
$request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nBEGIN:VJOURNAL\r\nUID:foo\r\nEND:VJOURNAL\r\nEND:VCALENDAR\r\n");
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testCreateFile2UIDS() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'PUT',
|
||||
'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
|
||||
]);
|
||||
$request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nBEGIN:VEVENT\r\nUID:bar\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testCreateFileWrongComponent() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'PUT',
|
||||
'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
|
||||
]);
|
||||
$request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VFREEBUSY\r\nUID:foo\r\nEND:VFREEBUSY\r\nEND:VCALENDAR\r\n");
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(403, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testUpdateFile() {
|
||||
|
||||
$this->calBackend->createCalendarObject('calendar1', 'blabla.ics', 'foo');
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'PUT',
|
||||
'REQUEST_URI' => '/calendars/admin/calendar1/blabla.ics',
|
||||
]);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(415, $response->status);
|
||||
|
||||
}
|
||||
|
||||
function testUpdateFileParsableBody() {
|
||||
|
||||
$this->calBackend->createCalendarObject('calendar1', 'blabla.ics', 'foo');
|
||||
$request = new HTTP\Request(
|
||||
'PUT',
|
||||
'/calendars/admin/calendar1/blabla.ics'
|
||||
);
|
||||
$ics = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:foo
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
DTSTAMP:20160406T052348Z
|
||||
DTSTART:20160706T140000Z
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$request->setBody($ics);
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(204, $response->status);
|
||||
|
||||
$expected = [
|
||||
'uri' => 'blabla.ics',
|
||||
'calendardata' => $ics,
|
||||
'calendarid' => 'calendar1',
|
||||
'lastmodified' => null,
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $this->calBackend->getCalendarObject('calendar1', 'blabla.ics'));
|
||||
|
||||
}
|
||||
|
||||
function testCreateFileInvalidComponent() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'PUT',
|
||||
'REQUEST_URI' => '/calendars/admin/calendar2/blabla.ics',
|
||||
]);
|
||||
$request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(403, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testUpdateFileInvalidComponent() {
|
||||
|
||||
$this->calBackend->createCalendarObject('calendar2', 'blabla.ics', 'foo');
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'PUT',
|
||||
'REQUEST_URI' => '/calendars/admin/calendar2/blabla.ics',
|
||||
]);
|
||||
$request->setBody("BEGIN:VCALENDAR\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nUID:foo\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n");
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(403, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* What we are testing here, is if we send in a latin1 character, the
|
||||
* server should automatically transform this into UTF-8.
|
||||
*
|
||||
* More importantly. If any transformation happens, the etag must no longer
|
||||
* be returned by the server.
|
||||
*/
|
||||
function testCreateFileModified() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'PUT',
|
||||
'/calendars/admin/calendar1/blabla.ics'
|
||||
);
|
||||
$ics = <<<ICS
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:foo
|
||||
BEGIN:VEVENT
|
||||
UID:foo
|
||||
SUMMARY:Meeting in M\xfcnster
|
||||
DTSTAMP:20160406T052348Z
|
||||
DTSTART:20160706T140000Z
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
||||
ICS;
|
||||
|
||||
$request->setBody($ics);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
|
||||
$this->assertNull($response->getHeader('ETag'));
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,146 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Xml\Notification;
|
||||
|
||||
use Sabre\DAV;
|
||||
use Sabre\Xml\Writer;
|
||||
|
||||
class InviteReplyTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @param array $notification
|
||||
* @param string $expected
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
function testSerializers($notification, $expected) {
|
||||
|
||||
$notification = new InviteReply($notification);
|
||||
|
||||
$this->assertEquals('foo', $notification->getId());
|
||||
$this->assertEquals('"1"', $notification->getETag());
|
||||
|
||||
$simpleExpected = '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<cs:root xmlns:cs="http://calendarserver.org/ns/"><cs:invite-reply/></cs:root>';
|
||||
|
||||
$writer = new Writer();
|
||||
$writer->namespaceMap = [
|
||||
'http://calendarserver.org/ns/' => 'cs',
|
||||
];
|
||||
$writer->openMemory();
|
||||
$writer->startDocument('1.0', 'UTF-8');
|
||||
$writer->startElement('{http://calendarserver.org/ns/}root');
|
||||
$writer->write($notification);
|
||||
$writer->endElement();
|
||||
|
||||
$this->assertEquals($simpleExpected, $writer->outputMemory());
|
||||
|
||||
$writer = new Writer();
|
||||
$writer->contextUri = '/';
|
||||
$writer->namespaceMap = [
|
||||
'http://calendarserver.org/ns/' => 'cs',
|
||||
'DAV:' => 'd',
|
||||
];
|
||||
$writer->openMemory();
|
||||
$writer->startDocument('1.0', 'UTF-8');
|
||||
$writer->startElement('{http://calendarserver.org/ns/}root');
|
||||
$notification->xmlSerializeFull($writer);
|
||||
$writer->endElement();
|
||||
|
||||
$this->assertXmlStringEqualsXmlString($expected, $writer->outputMemory());
|
||||
|
||||
|
||||
}
|
||||
|
||||
function dataProvider() {
|
||||
|
||||
$dtStamp = new \DateTime('2012-01-01 00:00:00 GMT');
|
||||
return [
|
||||
[
|
||||
[
|
||||
'id' => 'foo',
|
||||
'dtStamp' => $dtStamp,
|
||||
'etag' => '"1"',
|
||||
'inReplyTo' => 'bar',
|
||||
'href' => 'mailto:foo@example.org',
|
||||
'type' => DAV\Sharing\Plugin::INVITE_ACCEPTED,
|
||||
'hostUrl' => 'calendar'
|
||||
],
|
||||
<<<FOO
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:">
|
||||
<cs:dtstamp>20120101T000000Z</cs:dtstamp>
|
||||
<cs:invite-reply>
|
||||
<cs:uid>foo</cs:uid>
|
||||
<cs:in-reply-to>bar</cs:in-reply-to>
|
||||
<d:href>mailto:foo@example.org</d:href>
|
||||
<cs:invite-accepted/>
|
||||
<cs:hosturl>
|
||||
<d:href>/calendar</d:href>
|
||||
</cs:hosturl>
|
||||
</cs:invite-reply>
|
||||
</cs:root>
|
||||
|
||||
FOO
|
||||
],
|
||||
[
|
||||
[
|
||||
'id' => 'foo',
|
||||
'dtStamp' => $dtStamp,
|
||||
'etag' => '"1"',
|
||||
'inReplyTo' => 'bar',
|
||||
'href' => 'mailto:foo@example.org',
|
||||
'type' => DAV\Sharing\Plugin::INVITE_DECLINED,
|
||||
'hostUrl' => 'calendar',
|
||||
'summary' => 'Summary!'
|
||||
],
|
||||
<<<FOO
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:">
|
||||
<cs:dtstamp>20120101T000000Z</cs:dtstamp>
|
||||
<cs:invite-reply>
|
||||
<cs:uid>foo</cs:uid>
|
||||
<cs:in-reply-to>bar</cs:in-reply-to>
|
||||
<d:href>mailto:foo@example.org</d:href>
|
||||
<cs:invite-declined/>
|
||||
<cs:hosturl>
|
||||
<d:href>/calendar</d:href>
|
||||
</cs:hosturl>
|
||||
<cs:summary>Summary!</cs:summary>
|
||||
</cs:invite-reply>
|
||||
</cs:root>
|
||||
|
||||
FOO
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
function testMissingArg() {
|
||||
|
||||
new InviteReply([]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
function testUnknownArg() {
|
||||
|
||||
new InviteReply([
|
||||
'foo-i-will-break' => true,
|
||||
|
||||
'id' => 1,
|
||||
'etag' => '"bla"',
|
||||
'href' => 'abc',
|
||||
'dtStamp' => 'def',
|
||||
'inReplyTo' => 'qrs',
|
||||
'type' => 'ghi',
|
||||
'hostUrl' => 'jkl',
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,165 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Xml\Notification;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\DAV;
|
||||
use Sabre\Xml\Writer;
|
||||
|
||||
class InviteTest extends DAV\Xml\XmlTest {
|
||||
|
||||
/**
|
||||
* @param array $notification
|
||||
* @param string $expected
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
function testSerializers($notification, $expected) {
|
||||
|
||||
$notification = new Invite($notification);
|
||||
|
||||
$this->assertEquals('foo', $notification->getId());
|
||||
$this->assertEquals('"1"', $notification->getETag());
|
||||
|
||||
$simpleExpected = '<cs:invite-notification xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/" />' . "\n";
|
||||
$this->namespaceMap['http://calendarserver.org/ns/'] = 'cs';
|
||||
|
||||
$xml = $this->write($notification);
|
||||
|
||||
$this->assertXmlStringEqualsXmlString($simpleExpected, $xml);
|
||||
|
||||
$this->namespaceMap['urn:ietf:params:xml:ns:caldav'] = 'cal';
|
||||
$xml = $this->writeFull($notification);
|
||||
|
||||
$this->assertXmlStringEqualsXmlString($expected, $xml);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function dataProvider() {
|
||||
|
||||
$dtStamp = new \DateTime('2012-01-01 00:00:00', new \DateTimeZone('GMT'));
|
||||
return [
|
||||
[
|
||||
[
|
||||
'id' => 'foo',
|
||||
'dtStamp' => $dtStamp,
|
||||
'etag' => '"1"',
|
||||
'href' => 'mailto:foo@example.org',
|
||||
'type' => DAV\Sharing\Plugin::INVITE_ACCEPTED,
|
||||
'readOnly' => true,
|
||||
'hostUrl' => 'calendar',
|
||||
'organizer' => 'principal/user1',
|
||||
'commonName' => 'John Doe',
|
||||
'summary' => 'Awesome stuff!'
|
||||
],
|
||||
<<<FOO
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:cal="urn:ietf:params:xml:ns:caldav">
|
||||
<cs:dtstamp>20120101T000000Z</cs:dtstamp>
|
||||
<cs:invite-notification>
|
||||
<cs:uid>foo</cs:uid>
|
||||
<d:href>mailto:foo@example.org</d:href>
|
||||
<cs:invite-accepted/>
|
||||
<cs:hosturl>
|
||||
<d:href>/calendar</d:href>
|
||||
</cs:hosturl>
|
||||
<cs:summary>Awesome stuff!</cs:summary>
|
||||
<cs:access>
|
||||
<cs:read/>
|
||||
</cs:access>
|
||||
<cs:organizer>
|
||||
<d:href>/principal/user1</d:href>
|
||||
<cs:common-name>John Doe</cs:common-name>
|
||||
</cs:organizer>
|
||||
<cs:organizer-cn>John Doe</cs:organizer-cn>
|
||||
</cs:invite-notification>
|
||||
</cs:root>
|
||||
|
||||
FOO
|
||||
],
|
||||
[
|
||||
[
|
||||
'id' => 'foo',
|
||||
'dtStamp' => $dtStamp,
|
||||
'etag' => '"1"',
|
||||
'href' => 'mailto:foo@example.org',
|
||||
'type' => DAV\Sharing\Plugin::INVITE_NORESPONSE,
|
||||
'readOnly' => true,
|
||||
'hostUrl' => 'calendar',
|
||||
'organizer' => 'principal/user1',
|
||||
'firstName' => 'Foo',
|
||||
'lastName' => 'Bar',
|
||||
],
|
||||
<<<FOO
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:" xmlns:cal="urn:ietf:params:xml:ns:caldav">
|
||||
<cs:dtstamp>20120101T000000Z</cs:dtstamp>
|
||||
<cs:invite-notification>
|
||||
<cs:uid>foo</cs:uid>
|
||||
<d:href>mailto:foo@example.org</d:href>
|
||||
<cs:invite-noresponse/>
|
||||
<cs:hosturl>
|
||||
<d:href>/calendar</d:href>
|
||||
</cs:hosturl>
|
||||
<cs:access>
|
||||
<cs:read/>
|
||||
</cs:access>
|
||||
<cs:organizer>
|
||||
<d:href>/principal/user1</d:href>
|
||||
<cs:first-name>Foo</cs:first-name>
|
||||
<cs:last-name>Bar</cs:last-name>
|
||||
</cs:organizer>
|
||||
<cs:organizer-first>Foo</cs:organizer-first>
|
||||
<cs:organizer-last>Bar</cs:organizer-last>
|
||||
</cs:invite-notification>
|
||||
</cs:root>
|
||||
|
||||
FOO
|
||||
],
|
||||
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
function testMissingArg() {
|
||||
|
||||
new Invite([]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
function testUnknownArg() {
|
||||
|
||||
new Invite([
|
||||
'foo-i-will-break' => true,
|
||||
|
||||
'id' => 1,
|
||||
'etag' => '"bla"',
|
||||
'href' => 'abc',
|
||||
'dtStamp' => 'def',
|
||||
'type' => 'ghi',
|
||||
'readOnly' => true,
|
||||
'hostUrl' => 'jkl',
|
||||
'organizer' => 'mno',
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
function writeFull($input) {
|
||||
|
||||
$writer = new Writer();
|
||||
$writer->contextUri = '/';
|
||||
$writer->namespaceMap = $this->namespaceMap;
|
||||
$writer->openMemory();
|
||||
$writer->startElement('{http://calendarserver.org/ns/}root');
|
||||
$input->xmlSerializeFull($writer);
|
||||
$writer->endElement();
|
||||
return $writer->outputMemory();
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Xml\Notification;
|
||||
|
||||
use Sabre\DAV;
|
||||
use Sabre\Xml\Writer;
|
||||
|
||||
class SystemStatusTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @param array $notification
|
||||
* @param string $expected1
|
||||
* @param string $expected2
|
||||
* @dataProvider dataProvider
|
||||
*/
|
||||
function testSerializers($notification, $expected1, $expected2) {
|
||||
|
||||
$this->assertEquals('foo', $notification->getId());
|
||||
$this->assertEquals('"1"', $notification->getETag());
|
||||
|
||||
$writer = new Writer();
|
||||
$writer->namespaceMap = [
|
||||
'http://calendarserver.org/ns/' => 'cs',
|
||||
];
|
||||
$writer->openMemory();
|
||||
$writer->startDocument('1.0', 'UTF-8');
|
||||
$writer->startElement('{http://calendarserver.org/ns/}root');
|
||||
$writer->write($notification);
|
||||
$writer->endElement();
|
||||
$this->assertXmlStringEqualsXmlString($expected1, $writer->outputMemory());
|
||||
|
||||
$writer = new Writer();
|
||||
$writer->namespaceMap = [
|
||||
'http://calendarserver.org/ns/' => 'cs',
|
||||
'DAV:' => 'd',
|
||||
];
|
||||
$writer->openMemory();
|
||||
$writer->startDocument('1.0', 'UTF-8');
|
||||
$writer->startElement('{http://calendarserver.org/ns/}root');
|
||||
$notification->xmlSerializeFull($writer);
|
||||
$writer->endElement();
|
||||
$this->assertXmlStringEqualsXmlString($expected2, $writer->outputMemory());
|
||||
|
||||
}
|
||||
|
||||
function dataProvider() {
|
||||
|
||||
return [
|
||||
|
||||
[
|
||||
new SystemStatus('foo', '"1"'),
|
||||
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<cs:root xmlns:cs="http://calendarserver.org/ns/"><cs:systemstatus type="high"/></cs:root>' . "\n",
|
||||
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:"><cs:systemstatus type="high"/></cs:root>' . "\n",
|
||||
],
|
||||
[
|
||||
new SystemStatus('foo', '"1"', SystemStatus::TYPE_MEDIUM, 'bar'),
|
||||
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<cs:root xmlns:cs="http://calendarserver.org/ns/"><cs:systemstatus type="medium"/></cs:root>' . "\n",
|
||||
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:"><cs:systemstatus type="medium"><cs:description>bar</cs:description></cs:systemstatus></cs:root>' . "\n",
|
||||
],
|
||||
[
|
||||
new SystemStatus('foo', '"1"', SystemStatus::TYPE_LOW, null, 'http://example.org/'),
|
||||
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<cs:root xmlns:cs="http://calendarserver.org/ns/"><cs:systemstatus type="low"/></cs:root>' . "\n",
|
||||
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<cs:root xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:"><cs:systemstatus type="low"><d:href>http://example.org/</d:href></cs:systemstatus></cs:root>' . "\n",
|
||||
]
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Xml\Property;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\DAV;
|
||||
|
||||
class AllowedSharingModesTest extends DAV\Xml\XmlTest {
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$sccs = new AllowedSharingModes(true, true);
|
||||
$this->assertInstanceOf('Sabre\CalDAV\Xml\Property\AllowedSharingModes', $sccs);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testSerialize() {
|
||||
|
||||
$property = new AllowedSharingModes(true, true);
|
||||
|
||||
$this->namespaceMap[CalDAV\Plugin::NS_CALDAV] = 'cal';
|
||||
$this->namespaceMap[CalDAV\Plugin::NS_CALENDARSERVER] = 'cs';
|
||||
$xml = $this->write(['{DAV:}root' => $property]);
|
||||
|
||||
$this->assertXmlStringEqualsXmlString(
|
||||
'<?xml version="1.0"?>
|
||||
<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '" xmlns:cs="' . CalDAV\Plugin::NS_CALENDARSERVER . '">
|
||||
<cs:can-be-shared/>
|
||||
<cs:can-be-published/>
|
||||
</d:root>
|
||||
', $xml);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Xml\Property;
|
||||
|
||||
use Sabre\DAV\Xml\XmlTest;
|
||||
|
||||
class EmailAddressSetTest extends XmlTest {
|
||||
|
||||
protected $namespaceMap = [
|
||||
\Sabre\CalDAV\Plugin::NS_CALENDARSERVER => 'cs',
|
||||
'DAV:' => 'd',
|
||||
];
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$eas = new EmailAddressSet(['foo@example.org']);
|
||||
$this->assertEquals(['foo@example.org'], $eas->getValue());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testSerialize() {
|
||||
|
||||
$property = new EmailAddressSet(['foo@example.org']);
|
||||
|
||||
$xml = $this->write([
|
||||
'{DAV:}root' => $property
|
||||
]);
|
||||
|
||||
$this->assertXmlStringEqualsXmlString(
|
||||
'<?xml version="1.0"?>
|
||||
<d:root xmlns:d="DAV:" xmlns:cs="' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '">
|
||||
<cs:email-address>foo@example.org</cs:email-address>
|
||||
</d:root>', $xml);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,112 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Xml\Property;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\DAV;
|
||||
use Sabre\DAV\Sharing\Plugin as SP;
|
||||
use Sabre\DAV\Xml\Element\Sharee;
|
||||
|
||||
class InviteTest extends DAV\Xml\XmlTest {
|
||||
|
||||
function setUp() {
|
||||
|
||||
$this->namespaceMap[CalDAV\Plugin::NS_CALDAV] = 'cal';
|
||||
$this->namespaceMap[CalDAV\Plugin::NS_CALENDARSERVER] = 'cs';
|
||||
|
||||
|
||||
}
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$invite = new Invite([]);
|
||||
$this->assertInstanceOf('Sabre\CalDAV\Xml\Property\Invite', $invite);
|
||||
$this->assertEquals([], $invite->getValue());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testSerialize() {
|
||||
|
||||
$property = new Invite([
|
||||
new Sharee([
|
||||
'href' => 'mailto:thedoctor@example.org',
|
||||
'properties' => ['{DAV:}displayname' => 'The Doctor'],
|
||||
'inviteStatus' => SP::INVITE_ACCEPTED,
|
||||
'access' => SP::ACCESS_SHAREDOWNER,
|
||||
]),
|
||||
new Sharee([
|
||||
'href' => 'mailto:user1@example.org',
|
||||
'inviteStatus' => SP::INVITE_ACCEPTED,
|
||||
'access' => SP::ACCESS_READWRITE,
|
||||
]),
|
||||
new Sharee([
|
||||
'href' => 'mailto:user2@example.org',
|
||||
'properties' => ['{DAV:}displayname' => 'John Doe'],
|
||||
'inviteStatus' => SP::INVITE_DECLINED,
|
||||
'access' => SP::ACCESS_READ,
|
||||
]),
|
||||
new Sharee([
|
||||
'href' => 'mailto:user3@example.org',
|
||||
'properties' => ['{DAV:}displayname' => 'Joe Shmoe'],
|
||||
'inviteStatus' => SP::INVITE_NORESPONSE,
|
||||
'access' => SP::ACCESS_READ,
|
||||
'comment' => 'Something, something',
|
||||
]),
|
||||
new Sharee([
|
||||
'href' => 'mailto:user4@example.org',
|
||||
'properties' => ['{DAV:}displayname' => 'Hoe Boe'],
|
||||
'inviteStatus' => SP::INVITE_INVALID,
|
||||
'access' => SP::ACCESS_READ,
|
||||
]),
|
||||
]);
|
||||
|
||||
$xml = $this->write(['{DAV:}root' => $property]);
|
||||
|
||||
$this->assertXmlStringEqualsXmlString(
|
||||
'<?xml version="1.0"?>
|
||||
<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '" xmlns:cs="' . CalDAV\Plugin::NS_CALENDARSERVER . '">
|
||||
<cs:organizer>
|
||||
<d:href>mailto:thedoctor@example.org</d:href>
|
||||
<cs:common-name>The Doctor</cs:common-name>
|
||||
</cs:organizer>
|
||||
<cs:user>
|
||||
<cs:invite-accepted/>
|
||||
<cs:access>
|
||||
<cs:read-write/>
|
||||
</cs:access>
|
||||
<d:href>mailto:user1@example.org</d:href>
|
||||
</cs:user>
|
||||
<cs:user>
|
||||
<cs:invite-declined/>
|
||||
<cs:access>
|
||||
<cs:read/>
|
||||
</cs:access>
|
||||
<d:href>mailto:user2@example.org</d:href>
|
||||
<cs:common-name>John Doe</cs:common-name>
|
||||
</cs:user>
|
||||
<cs:user>
|
||||
<cs:invite-noresponse/>
|
||||
<cs:access>
|
||||
<cs:read/>
|
||||
</cs:access>
|
||||
<d:href>mailto:user3@example.org</d:href>
|
||||
<cs:common-name>Joe Shmoe</cs:common-name>
|
||||
<cs:summary>Something, something</cs:summary>
|
||||
</cs:user>
|
||||
<cs:user>
|
||||
<cs:invite-invalid/>
|
||||
<cs:access>
|
||||
<cs:read/>
|
||||
</cs:access>
|
||||
<d:href>mailto:user4@example.org</d:href>
|
||||
<cs:common-name>Hoe Boe</cs:common-name>
|
||||
</cs:user>
|
||||
</d:root>
|
||||
', $xml);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,118 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Xml\Property;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\DAV;
|
||||
|
||||
class ScheduleCalendarTranspTest extends DAV\Xml\XmlTest {
|
||||
|
||||
function setUp() {
|
||||
|
||||
$this->namespaceMap[CalDAV\Plugin::NS_CALDAV] = 'cal';
|
||||
$this->namespaceMap[CalDAV\Plugin::NS_CALENDARSERVER] = 'cs';
|
||||
|
||||
|
||||
}
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$prop = new ScheduleCalendarTransp(ScheduleCalendarTransp::OPAQUE);
|
||||
$this->assertEquals(
|
||||
ScheduleCalendarTransp::OPAQUE,
|
||||
$prop->getValue()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
function testBadValue() {
|
||||
|
||||
new ScheduleCalendarTransp('ahhh');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testSerializeOpaque() {
|
||||
|
||||
$property = new ScheduleCalendarTransp(ScheduleCalendarTransp::OPAQUE);
|
||||
$xml = $this->write(['{DAV:}root' => $property]);
|
||||
|
||||
$this->assertXmlStringEqualsXmlString(
|
||||
'<?xml version="1.0"?>
|
||||
<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '" xmlns:cs="' . CalDAV\Plugin::NS_CALENDARSERVER . '">
|
||||
<cal:opaque />
|
||||
</d:root>
|
||||
', $xml);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testSerializeTransparent() {
|
||||
|
||||
$property = new ScheduleCalendarTransp(ScheduleCalendarTransp::TRANSPARENT);
|
||||
$xml = $this->write(['{DAV:}root' => $property]);
|
||||
|
||||
$this->assertXmlStringEqualsXmlString(
|
||||
'<?xml version="1.0"?>
|
||||
<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '" xmlns:cs="' . CalDAV\Plugin::NS_CALENDARSERVER . '">
|
||||
<cal:transparent />
|
||||
</d:root>
|
||||
', $xml);
|
||||
|
||||
}
|
||||
|
||||
function testUnserializeTransparent() {
|
||||
|
||||
$cal = CalDAV\Plugin::NS_CALDAV;
|
||||
$cs = CalDAV\Plugin::NS_CALENDARSERVER;
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<d:root xmlns:d="DAV:" xmlns:cal="$cal" xmlns:cs="$cs">
|
||||
<cal:transparent />
|
||||
</d:root>
|
||||
XML;
|
||||
|
||||
$result = $this->parse(
|
||||
$xml,
|
||||
['{DAV:}root' => 'Sabre\\CalDAV\\Xml\\Property\\ScheduleCalendarTransp']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
new ScheduleCalendarTransp(ScheduleCalendarTransp::TRANSPARENT),
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testUnserializeOpaque() {
|
||||
|
||||
$cal = CalDAV\Plugin::NS_CALDAV;
|
||||
$cs = CalDAV\Plugin::NS_CALENDARSERVER;
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<d:root xmlns:d="DAV:" xmlns:cal="$cal" xmlns:cs="$cs">
|
||||
<cal:opaque />
|
||||
</d:root>
|
||||
XML;
|
||||
|
||||
$result = $this->parse(
|
||||
$xml,
|
||||
['{DAV:}root' => 'Sabre\\CalDAV\\Xml\\Property\\ScheduleCalendarTransp']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
new ScheduleCalendarTransp(ScheduleCalendarTransp::OPAQUE),
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Xml\Property;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\DAV;
|
||||
|
||||
class SupportedCalendarComponentSetTest extends DAV\Xml\XmlTest {
|
||||
|
||||
function setUp() {
|
||||
|
||||
$this->namespaceMap[CalDAV\Plugin::NS_CALDAV] = 'cal';
|
||||
$this->namespaceMap[CalDAV\Plugin::NS_CALENDARSERVER] = 'cs';
|
||||
|
||||
}
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$prop = new SupportedCalendarComponentSet(['VEVENT']);
|
||||
$this->assertEquals(
|
||||
['VEVENT'],
|
||||
$prop->getValue()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testMultiple() {
|
||||
|
||||
$prop = new SupportedCalendarComponentSet(['VEVENT', 'VTODO']);
|
||||
$this->assertEquals(
|
||||
['VEVENT', 'VTODO'],
|
||||
$prop->getValue()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
* @depends testMultiple
|
||||
*/
|
||||
function testSerialize() {
|
||||
|
||||
$property = new SupportedCalendarComponentSet(['VEVENT', 'VTODO']);
|
||||
$xml = $this->write(['{DAV:}root' => $property]);
|
||||
|
||||
$this->assertXmlStringEqualsXmlString(
|
||||
'<?xml version="1.0"?>
|
||||
<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '" xmlns:cs="' . CalDAV\Plugin::NS_CALENDARSERVER . '">
|
||||
<cal:comp name="VEVENT"/>
|
||||
<cal:comp name="VTODO"/>
|
||||
</d:root>
|
||||
', $xml);
|
||||
|
||||
}
|
||||
|
||||
function testUnserialize() {
|
||||
|
||||
$cal = CalDAV\Plugin::NS_CALDAV;
|
||||
$cs = CalDAV\Plugin::NS_CALENDARSERVER;
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<d:root xmlns:cal="$cal" xmlns:cs="$cs" xmlns:d="DAV:">
|
||||
<cal:comp name="VEVENT"/>
|
||||
<cal:comp name="VTODO"/>
|
||||
</d:root>
|
||||
XML;
|
||||
|
||||
$result = $this->parse(
|
||||
$xml,
|
||||
['{DAV:}root' => 'Sabre\\CalDAV\\Xml\\Property\\SupportedCalendarComponentSet']
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
new SupportedCalendarComponentSet(['VEVENT', 'VTODO']),
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\Xml\ParseException
|
||||
*/
|
||||
function testUnserializeEmpty() {
|
||||
|
||||
$cal = CalDAV\Plugin::NS_CALDAV;
|
||||
$cs = CalDAV\Plugin::NS_CALENDARSERVER;
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<d:root xmlns:cal="$cal" xmlns:cs="$cs" xmlns:d="DAV:">
|
||||
</d:root>
|
||||
XML;
|
||||
|
||||
$result = $this->parse(
|
||||
$xml,
|
||||
['{DAV:}root' => 'Sabre\\CalDAV\\Xml\\Property\\SupportedCalendarComponentSet']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Xml\Property;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\DAV;
|
||||
|
||||
class SupportedCalendarDataTest extends DAV\Xml\XmlTest {
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$sccs = new SupportedCalendarData();
|
||||
$this->assertInstanceOf('Sabre\CalDAV\Xml\Property\SupportedCalendarData', $sccs);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testSerialize() {
|
||||
|
||||
$this->namespaceMap[CalDAV\Plugin::NS_CALDAV] = 'cal';
|
||||
$property = new SupportedCalendarData();
|
||||
|
||||
$xml = $this->write(['{DAV:}root' => $property]);
|
||||
|
||||
$this->assertXmlStringEqualsXmlString(
|
||||
'<?xml version="1.0"?>
|
||||
<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '">
|
||||
<cal:calendar-data content-type="text/calendar" version="2.0"/>
|
||||
<cal:calendar-data content-type="application/calendar+json"/>
|
||||
</d:root>', $xml);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Xml\Property;
|
||||
|
||||
use Sabre\CalDAV;
|
||||
use Sabre\DAV;
|
||||
|
||||
class SupportedCollationSetTest extends DAV\Xml\XmlTest {
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$scs = new SupportedCollationSet();
|
||||
$this->assertInstanceOf('Sabre\CalDAV\Xml\Property\SupportedCollationSet', $scs);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testSerialize() {
|
||||
|
||||
$property = new SupportedCollationSet();
|
||||
|
||||
$this->namespaceMap[CalDAV\Plugin::NS_CALDAV] = 'cal';
|
||||
$xml = $this->write(['{DAV:}root' => $property]);
|
||||
|
||||
$this->assertXmlStringEqualsXmlString(
|
||||
'<?xml version="1.0"?>
|
||||
<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '">
|
||||
<cal:supported-collation>i;ascii-casemap</cal:supported-collation>
|
||||
<cal:supported-collation>i;octet</cal:supported-collation>
|
||||
<cal:supported-collation>i;unicode-casemap</cal:supported-collation>
|
||||
</d:root>', $xml);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,369 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Xml\Request;
|
||||
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use Sabre\DAV\Xml\XmlTest;
|
||||
|
||||
class CalendarQueryReportTest extends XmlTest {
|
||||
|
||||
protected $elementMap = [
|
||||
'{urn:ietf:params:xml:ns:caldav}calendar-query' => 'Sabre\\CalDAV\\Xml\\Request\CalendarQueryReport',
|
||||
];
|
||||
|
||||
function testDeserialize() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:comp-filter name="VCALENDAR" />
|
||||
</c:filter>
|
||||
</c:calendar-query>
|
||||
XML;
|
||||
|
||||
$result = $this->parse($xml);
|
||||
$calendarQueryReport = new CalendarQueryReport();
|
||||
$calendarQueryReport->properties = [
|
||||
'{DAV:}getetag',
|
||||
];
|
||||
$calendarQueryReport->filters = [
|
||||
'name' => 'VCALENDAR',
|
||||
'is-not-defined' => false,
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'time-range' => false,
|
||||
];
|
||||
|
||||
$this->assertEquals(
|
||||
$calendarQueryReport,
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testDeserializeNoFilter() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
</c:calendar-query>
|
||||
XML;
|
||||
|
||||
$this->parse($xml);
|
||||
|
||||
}
|
||||
|
||||
function testDeserializeComplex() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
<c:calendar-data content-type="application/json+calendar" version="2.0">
|
||||
<c:expand start="20150101T000000Z" end="20160101T000000Z" />
|
||||
</c:calendar-data>
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:comp-filter name="VCALENDAR">
|
||||
<c:comp-filter name="VEVENT">
|
||||
<c:time-range start="20150101T000000Z" end="20160101T000000Z" />
|
||||
<c:prop-filter name="UID" />
|
||||
<c:comp-filter name="VALARM">
|
||||
<c:is-not-defined />
|
||||
</c:comp-filter>
|
||||
<c:prop-filter name="X-PROP">
|
||||
<c:param-filter name="X-PARAM" />
|
||||
<c:param-filter name="X-PARAM2">
|
||||
<c:is-not-defined />
|
||||
</c:param-filter>
|
||||
<c:param-filter name="X-PARAM3">
|
||||
<c:text-match negate-condition="yes">hi</c:text-match>
|
||||
</c:param-filter>
|
||||
</c:prop-filter>
|
||||
<c:prop-filter name="X-PROP2">
|
||||
<c:is-not-defined />
|
||||
</c:prop-filter>
|
||||
<c:prop-filter name="X-PROP3">
|
||||
<c:time-range start="20150101T000000Z" end="20160101T000000Z" />
|
||||
</c:prop-filter>
|
||||
<c:prop-filter name="X-PROP4">
|
||||
<c:text-match>Hello</c:text-match>
|
||||
</c:prop-filter>
|
||||
</c:comp-filter>
|
||||
</c:comp-filter>
|
||||
</c:filter>
|
||||
</c:calendar-query>
|
||||
XML;
|
||||
|
||||
$result = $this->parse($xml);
|
||||
$calendarQueryReport = new CalendarQueryReport();
|
||||
$calendarQueryReport->version = '2.0';
|
||||
$calendarQueryReport->contentType = 'application/json+calendar';
|
||||
$calendarQueryReport->properties = [
|
||||
'{DAV:}getetag',
|
||||
'{urn:ietf:params:xml:ns:caldav}calendar-data',
|
||||
];
|
||||
$calendarQueryReport->expand = [
|
||||
'start' => new DateTimeImmutable('2015-01-01 00:00:00', new DateTimeZone('UTC')),
|
||||
'end' => new DateTimeImmutable('2016-01-01 00:00:00', new DateTimeZone('UTC')),
|
||||
];
|
||||
$calendarQueryReport->filters = [
|
||||
'name' => 'VCALENDAR',
|
||||
'is-not-defined' => false,
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VEVENT',
|
||||
'is-not-defined' => false,
|
||||
'comp-filters' => [
|
||||
[
|
||||
'name' => 'VALARM',
|
||||
'is-not-defined' => true,
|
||||
'comp-filters' => [],
|
||||
'prop-filters' => [],
|
||||
'time-range' => false,
|
||||
],
|
||||
],
|
||||
'prop-filters' => [
|
||||
[
|
||||
'name' => 'UID',
|
||||
'is-not-defined' => false,
|
||||
'time-range' => false,
|
||||
'text-match' => null,
|
||||
'param-filters' => [],
|
||||
],
|
||||
[
|
||||
'name' => 'X-PROP',
|
||||
'is-not-defined' => false,
|
||||
'time-range' => false,
|
||||
'text-match' => null,
|
||||
'param-filters' => [
|
||||
[
|
||||
'name' => 'X-PARAM',
|
||||
'is-not-defined' => false,
|
||||
'text-match' => null,
|
||||
],
|
||||
[
|
||||
'name' => 'X-PARAM2',
|
||||
'is-not-defined' => true,
|
||||
'text-match' => null,
|
||||
],
|
||||
[
|
||||
'name' => 'X-PARAM3',
|
||||
'is-not-defined' => false,
|
||||
'text-match' => [
|
||||
'negate-condition' => true,
|
||||
'collation' => 'i;ascii-casemap',
|
||||
'value' => 'hi',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'X-PROP2',
|
||||
'is-not-defined' => true,
|
||||
'time-range' => false,
|
||||
'text-match' => null,
|
||||
'param-filters' => [],
|
||||
],
|
||||
[
|
||||
'name' => 'X-PROP3',
|
||||
'is-not-defined' => false,
|
||||
'time-range' => [
|
||||
'start' => new DateTimeImmutable('2015-01-01 00:00:00', new DateTimeZone('UTC')),
|
||||
'end' => new DateTimeImmutable('2016-01-01 00:00:00', new DateTimeZone('UTC')),
|
||||
],
|
||||
'text-match' => null,
|
||||
'param-filters' => [],
|
||||
],
|
||||
[
|
||||
'name' => 'X-PROP4',
|
||||
'is-not-defined' => false,
|
||||
'time-range' => false,
|
||||
'text-match' => [
|
||||
'negate-condition' => false,
|
||||
'collation' => 'i;ascii-casemap',
|
||||
'value' => 'Hello',
|
||||
],
|
||||
'param-filters' => [],
|
||||
],
|
||||
],
|
||||
'time-range' => [
|
||||
'start' => new DateTimeImmutable('2015-01-01 00:00:00', new DateTimeZone('UTC')),
|
||||
'end' => new DateTimeImmutable('2016-01-01 00:00:00', new DateTimeZone('UTC')),
|
||||
]
|
||||
],
|
||||
],
|
||||
'prop-filters' => [],
|
||||
'time-range' => false,
|
||||
];
|
||||
|
||||
$this->assertEquals(
|
||||
$calendarQueryReport,
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testDeserializeDoubleTopCompFilter() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
<c:calendar-data content-type="application/json+calendar" version="2.0">
|
||||
<c:expand start="20150101T000000Z" end="20160101T000000Z" />
|
||||
</c:calendar-data>
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:comp-filter name="VCALENDAR" />
|
||||
<c:comp-filter name="VCALENDAR" />
|
||||
</c:filter>
|
||||
</c:calendar-query>
|
||||
XML;
|
||||
|
||||
$this->parse($xml);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testDeserializeMissingExpandEnd() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
<c:calendar-data content-type="application/json+calendar" version="2.0">
|
||||
<c:expand start="20150101T000000Z" />
|
||||
</c:calendar-data>
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:comp-filter name="VCALENDAR" />
|
||||
</c:filter>
|
||||
</c:calendar-query>
|
||||
XML;
|
||||
|
||||
$this->parse($xml);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testDeserializeExpandEndBeforeStart() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
<c:calendar-data content-type="application/json+calendar" version="2.0">
|
||||
<c:expand start="20150101T000000Z" end="20140101T000000Z" />
|
||||
</c:calendar-data>
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:comp-filter name="VCALENDAR" />
|
||||
</c:filter>
|
||||
</c:calendar-query>
|
||||
XML;
|
||||
|
||||
$this->parse($xml);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testDeserializeTimeRangeOnVCALENDAR() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
<c:calendar-data />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:comp-filter name="VCALENDAR">
|
||||
<c:time-range start="20150101T000000Z" end="20160101T000000Z" />
|
||||
</c:comp-filter>
|
||||
</c:filter>
|
||||
</c:calendar-query>
|
||||
XML;
|
||||
|
||||
$this->parse($xml);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testDeserializeTimeRangeEndBeforeStart() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
<c:calendar-data />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:comp-filter name="VCALENDAR">
|
||||
<c:comp-filter name="VEVENT">
|
||||
<c:time-range start="20150101T000000Z" end="20140101T000000Z" />
|
||||
</c:comp-filter>
|
||||
</c:comp-filter>
|
||||
</c:filter>
|
||||
</c:calendar-query>
|
||||
XML;
|
||||
|
||||
$this->parse($xml);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testDeserializeTimeRangePropEndBeforeStart() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
<c:calendar-data />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:comp-filter name="VCALENDAR">
|
||||
<c:comp-filter name="VEVENT">
|
||||
<c:prop-filter name="DTSTART">
|
||||
<c:time-range start="20150101T000000Z" end="20140101T000000Z" />
|
||||
</c:prop-filter>
|
||||
</c:comp-filter>
|
||||
</c:comp-filter>
|
||||
</c:filter>
|
||||
</c:calendar-query>
|
||||
XML;
|
||||
|
||||
$this->parse($xml);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Xml\Request;
|
||||
|
||||
use Sabre\DAV;
|
||||
use Sabre\DAV\Xml\XmlTest;
|
||||
|
||||
class InviteReplyTest extends XmlTest {
|
||||
|
||||
protected $elementMap = [
|
||||
'{http://calendarserver.org/ns/}invite-reply' => 'Sabre\\CalDAV\\Xml\\Request\\InviteReply',
|
||||
];
|
||||
|
||||
function testDeserialize() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<cs:invite-reply xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:">
|
||||
<d:href>/principal/1</d:href>
|
||||
<cs:hosturl><d:href>/calendar/1</d:href></cs:hosturl>
|
||||
<cs:invite-accepted />
|
||||
<cs:in-reply-to>blabla</cs:in-reply-to>
|
||||
<cs:summary>Summary</cs:summary>
|
||||
</cs:invite-reply>
|
||||
XML;
|
||||
|
||||
$result = $this->parse($xml);
|
||||
$inviteReply = new InviteReply('/principal/1', '/calendar/1', 'blabla', 'Summary', DAV\Sharing\Plugin::INVITE_ACCEPTED);
|
||||
|
||||
$this->assertEquals(
|
||||
$inviteReply,
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testDeserializeDeclined() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<cs:invite-reply xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:">
|
||||
<d:href>/principal/1</d:href>
|
||||
<cs:hosturl><d:href>/calendar/1</d:href></cs:hosturl>
|
||||
<cs:invite-declined />
|
||||
<cs:in-reply-to>blabla</cs:in-reply-to>
|
||||
<cs:summary>Summary</cs:summary>
|
||||
</cs:invite-reply>
|
||||
XML;
|
||||
|
||||
$result = $this->parse($xml);
|
||||
$inviteReply = new InviteReply('/principal/1', '/calendar/1', 'blabla', 'Summary', DAV\Sharing\Plugin::INVITE_DECLINED);
|
||||
|
||||
$this->assertEquals(
|
||||
$inviteReply,
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testDeserializeNoHostUrl() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<cs:invite-reply xmlns:cs="http://calendarserver.org/ns/" xmlns:d="DAV:">
|
||||
<d:href>/principal/1</d:href>
|
||||
<cs:invite-declined />
|
||||
<cs:in-reply-to>blabla</cs:in-reply-to>
|
||||
<cs:summary>Summary</cs:summary>
|
||||
</cs:invite-reply>
|
||||
XML;
|
||||
|
||||
$this->parse($xml);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,83 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CalDAV\Xml\Request;
|
||||
|
||||
use Sabre\DAV\Xml\Element\Sharee;
|
||||
use Sabre\DAV\Xml\XmlTest;
|
||||
|
||||
class ShareTest extends XmlTest {
|
||||
|
||||
protected $elementMap = [
|
||||
'{http://calendarserver.org/ns/}share' => 'Sabre\\CalDAV\\Xml\\Request\\Share',
|
||||
];
|
||||
|
||||
function testDeserialize() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<CS:share xmlns:D="DAV:"
|
||||
xmlns:CS="http://calendarserver.org/ns/">
|
||||
<CS:set>
|
||||
<D:href>mailto:eric@example.com</D:href>
|
||||
<CS:common-name>Eric York</CS:common-name>
|
||||
<CS:summary>Shared workspace</CS:summary>
|
||||
<CS:read-write />
|
||||
</CS:set>
|
||||
<CS:remove>
|
||||
<D:href>mailto:foo@bar</D:href>
|
||||
</CS:remove>
|
||||
</CS:share>
|
||||
XML;
|
||||
|
||||
$result = $this->parse($xml);
|
||||
$share = new Share([
|
||||
new Sharee([
|
||||
'href' => 'mailto:eric@example.com',
|
||||
'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE,
|
||||
'properties' => [
|
||||
'{DAV:}displayname' => 'Eric York',
|
||||
],
|
||||
'comment' => 'Shared workspace',
|
||||
]),
|
||||
new Sharee([
|
||||
'href' => 'mailto:foo@bar',
|
||||
'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_NOACCESS,
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->assertEquals(
|
||||
$share,
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testDeserializeMinimal() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<CS:share xmlns:D="DAV:"
|
||||
xmlns:CS="http://calendarserver.org/ns/">
|
||||
<CS:set>
|
||||
<D:href>mailto:eric@example.com</D:href>
|
||||
<CS:read />
|
||||
</CS:set>
|
||||
</CS:share>
|
||||
XML;
|
||||
|
||||
$result = $this->parse($xml);
|
||||
$share = new Share([
|
||||
new Sharee([
|
||||
'href' => 'mailto:eric@example.com',
|
||||
'access' => \Sabre\DAV\Sharing\Plugin::ACCESS_READ,
|
||||
]),
|
||||
]);
|
||||
|
||||
$this->assertEquals(
|
||||
$share,
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV;
|
||||
|
||||
use Sabre\DAV;
|
||||
use Sabre\DAVACL;
|
||||
use Sabre\HTTP;
|
||||
|
||||
abstract class AbstractPluginTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Sabre\CardDAV\Plugin
|
||||
*/
|
||||
protected $plugin;
|
||||
/**
|
||||
* @var Sabre\DAV\Server
|
||||
*/
|
||||
protected $server;
|
||||
/**
|
||||
* @var Sabre\CardDAV\Backend\Mock;
|
||||
*/
|
||||
protected $backend;
|
||||
|
||||
function setUp() {
|
||||
|
||||
$this->backend = new Backend\Mock();
|
||||
$principalBackend = new DAVACL\PrincipalBackend\Mock();
|
||||
|
||||
$tree = [
|
||||
new AddressBookRoot($principalBackend, $this->backend),
|
||||
new DAVACL\PrincipalCollection($principalBackend)
|
||||
];
|
||||
|
||||
$this->plugin = new Plugin();
|
||||
$this->plugin->directories = ['directory'];
|
||||
$this->server = new DAV\Server($tree);
|
||||
$this->server->sapi = new HTTP\SapiMock();
|
||||
$this->server->addPlugin($this->plugin);
|
||||
$this->server->debugExceptions = true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,159 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV;
|
||||
|
||||
use Sabre\DAV\MkCol;
|
||||
|
||||
class AddressBookHomeTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Sabre\CardDAV\AddressBookHome
|
||||
*/
|
||||
protected $s;
|
||||
protected $backend;
|
||||
|
||||
function setUp() {
|
||||
|
||||
$this->backend = new Backend\Mock();
|
||||
$this->s = new AddressBookHome(
|
||||
$this->backend,
|
||||
'principals/user1'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testGetName() {
|
||||
|
||||
$this->assertEquals('user1', $this->s->getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
|
||||
*/
|
||||
function testSetName() {
|
||||
|
||||
$this->s->setName('user2');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
|
||||
*/
|
||||
function testDelete() {
|
||||
|
||||
$this->s->delete();
|
||||
|
||||
}
|
||||
|
||||
function testGetLastModified() {
|
||||
|
||||
$this->assertNull($this->s->getLastModified());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
|
||||
*/
|
||||
function testCreateFile() {
|
||||
|
||||
$this->s->createFile('bla');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
|
||||
*/
|
||||
function testCreateDirectory() {
|
||||
|
||||
$this->s->createDirectory('bla');
|
||||
|
||||
}
|
||||
|
||||
function testGetChild() {
|
||||
|
||||
$child = $this->s->getChild('book1');
|
||||
$this->assertInstanceOf('Sabre\\CardDAV\\AddressBook', $child);
|
||||
$this->assertEquals('book1', $child->getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\NotFound
|
||||
*/
|
||||
function testGetChild404() {
|
||||
|
||||
$this->s->getChild('book2');
|
||||
|
||||
}
|
||||
|
||||
function testGetChildren() {
|
||||
|
||||
$children = $this->s->getChildren();
|
||||
$this->assertEquals(2, count($children));
|
||||
$this->assertInstanceOf('Sabre\\CardDAV\\AddressBook', $children[0]);
|
||||
$this->assertEquals('book1', $children[0]->getName());
|
||||
|
||||
}
|
||||
|
||||
function testCreateExtendedCollection() {
|
||||
|
||||
$resourceType = [
|
||||
'{' . Plugin::NS_CARDDAV . '}addressbook',
|
||||
'{DAV:}collection',
|
||||
];
|
||||
$this->s->createExtendedCollection('book2', new MkCol($resourceType, ['{DAV:}displayname' => 'a-book 2']));
|
||||
|
||||
$this->assertEquals([
|
||||
'id' => 'book2',
|
||||
'uri' => 'book2',
|
||||
'{DAV:}displayname' => 'a-book 2',
|
||||
'principaluri' => 'principals/user1',
|
||||
], $this->backend->addressBooks[2]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\InvalidResourceType
|
||||
*/
|
||||
function testCreateExtendedCollectionInvalid() {
|
||||
|
||||
$resourceType = [
|
||||
'{DAV:}collection',
|
||||
];
|
||||
$this->s->createExtendedCollection('book2', new MkCol($resourceType, ['{DAV:}displayname' => 'a-book 2']));
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testACLMethods() {
|
||||
|
||||
$this->assertEquals('principals/user1', $this->s->getOwner());
|
||||
$this->assertNull($this->s->getGroup());
|
||||
$this->assertEquals([
|
||||
[
|
||||
'privilege' => '{DAV:}all',
|
||||
'principal' => '{DAV:}owner',
|
||||
'protected' => true,
|
||||
],
|
||||
], $this->s->getACL());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testSetACL() {
|
||||
|
||||
$this->s->setACL([]);
|
||||
|
||||
}
|
||||
|
||||
function testGetSupportedPrivilegeSet() {
|
||||
|
||||
$this->assertNull(
|
||||
$this->s->getSupportedPrivilegeSet()
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,355 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV;
|
||||
|
||||
use Sabre\DAV;
|
||||
use Sabre\HTTP;
|
||||
|
||||
require_once 'Sabre/CardDAV/AbstractPluginTest.php';
|
||||
require_once 'Sabre/HTTP/ResponseMock.php';
|
||||
|
||||
class AddressBookQueryTest extends AbstractPluginTest {
|
||||
|
||||
function testQuery() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'REPORT',
|
||||
'/addressbooks/user1/book1',
|
||||
['Depth' => '1']
|
||||
);
|
||||
|
||||
$request->setBody(
|
||||
'<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:prop-filter name="uid" />
|
||||
</c:filter>
|
||||
</c:addressbook-query>'
|
||||
);
|
||||
|
||||
$response = new HTTP\ResponseMock();
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->server->httpResponse = $response;
|
||||
|
||||
$this->server->exec();
|
||||
|
||||
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
||||
|
||||
// using the client for parsing
|
||||
$client = new DAV\Client(['baseUri' => '/']);
|
||||
|
||||
$result = $client->parseMultiStatus($response->body);
|
||||
|
||||
$this->assertEquals([
|
||||
'/addressbooks/user1/book1/card1' => [
|
||||
200 => [
|
||||
'{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
|
||||
],
|
||||
],
|
||||
'/addressbooks/user1/book1/card2' => [
|
||||
404 => [
|
||||
'{DAV:}getetag' => null,
|
||||
],
|
||||
]
|
||||
], $result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function testQueryDepth0() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'REPORT',
|
||||
'/addressbooks/user1/book1/card1',
|
||||
['Depth' => '0']
|
||||
);
|
||||
|
||||
$request->setBody(
|
||||
'<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:prop-filter name="uid" />
|
||||
</c:filter>
|
||||
</c:addressbook-query>'
|
||||
);
|
||||
|
||||
$response = new HTTP\ResponseMock();
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->server->httpResponse = $response;
|
||||
|
||||
$this->server->exec();
|
||||
|
||||
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
||||
|
||||
// using the client for parsing
|
||||
$client = new DAV\Client(['baseUri' => '/']);
|
||||
|
||||
$result = $client->parseMultiStatus($response->body);
|
||||
|
||||
$this->assertEquals([
|
||||
'/addressbooks/user1/book1/card1' => [
|
||||
200 => [
|
||||
'{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
|
||||
],
|
||||
],
|
||||
], $result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function testQueryNoMatch() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'REPORT',
|
||||
'/addressbooks/user1/book1',
|
||||
['Depth' => '1']
|
||||
);
|
||||
|
||||
$request->setBody(
|
||||
'<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:prop-filter name="email" />
|
||||
</c:filter>
|
||||
</c:addressbook-query>'
|
||||
);
|
||||
|
||||
$response = new HTTP\ResponseMock();
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->server->httpResponse = $response;
|
||||
|
||||
$this->server->exec();
|
||||
|
||||
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
||||
|
||||
// using the client for parsing
|
||||
$client = new DAV\Client(['baseUri' => '/']);
|
||||
|
||||
$result = $client->parseMultiStatus($response->body);
|
||||
|
||||
$this->assertEquals([], $result);
|
||||
|
||||
}
|
||||
|
||||
function testQueryLimit() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'REPORT',
|
||||
'REQUEST_URI' => '/addressbooks/user1/book1',
|
||||
'HTTP_DEPTH' => '1',
|
||||
]);
|
||||
|
||||
$request->setBody(
|
||||
'<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:prop-filter name="uid" />
|
||||
</c:filter>
|
||||
<c:limit><c:nresults>1</c:nresults></c:limit>
|
||||
</c:addressbook-query>'
|
||||
);
|
||||
|
||||
$response = new HTTP\ResponseMock();
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->server->httpResponse = $response;
|
||||
|
||||
$this->server->exec();
|
||||
|
||||
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
||||
|
||||
// using the client for parsing
|
||||
$client = new DAV\Client(['baseUri' => '/']);
|
||||
|
||||
$result = $client->parseMultiStatus($response->body);
|
||||
|
||||
$this->assertEquals([
|
||||
'/addressbooks/user1/book1/card1' => [
|
||||
200 => [
|
||||
'{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
|
||||
],
|
||||
],
|
||||
], $result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function testJson() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'REPORT',
|
||||
'/addressbooks/user1/book1/card1',
|
||||
['Depth' => '0']
|
||||
);
|
||||
|
||||
$request->setBody(
|
||||
'<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<c:address-data content-type="application/vcard+json" />
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
</c:addressbook-query>'
|
||||
);
|
||||
|
||||
$response = new HTTP\ResponseMock();
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->server->httpResponse = $response;
|
||||
|
||||
$this->server->exec();
|
||||
|
||||
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
||||
|
||||
// using the client for parsing
|
||||
$client = new DAV\Client(['baseUri' => '/']);
|
||||
|
||||
$result = $client->parseMultiStatus($response->body);
|
||||
|
||||
$vobjVersion = \Sabre\VObject\Version::VERSION;
|
||||
|
||||
$this->assertEquals([
|
||||
'/addressbooks/user1/book1/card1' => [
|
||||
200 => [
|
||||
'{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
|
||||
'{urn:ietf:params:xml:ns:carddav}address-data' => '["vcard",[["version",{},"text","4.0"],["prodid",{},"text","-\/\/Sabre\/\/Sabre VObject ' . $vobjVersion . '\/\/EN"],["uid",{},"text","12345"]]]',
|
||||
],
|
||||
],
|
||||
], $result);
|
||||
|
||||
}
|
||||
|
||||
function testVCard4() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'REPORT',
|
||||
'/addressbooks/user1/book1/card1',
|
||||
['Depth' => '0']
|
||||
);
|
||||
|
||||
$request->setBody(
|
||||
'<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<c:address-data content-type="text/vcard" version="4.0" />
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
</c:addressbook-query>'
|
||||
);
|
||||
|
||||
$response = new HTTP\ResponseMock();
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->server->httpResponse = $response;
|
||||
|
||||
$this->server->exec();
|
||||
|
||||
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
||||
|
||||
// using the client for parsing
|
||||
$client = new DAV\Client(['baseUri' => '/']);
|
||||
|
||||
$result = $client->parseMultiStatus($response->body);
|
||||
|
||||
$vobjVersion = \Sabre\VObject\Version::VERSION;
|
||||
|
||||
$this->assertEquals([
|
||||
'/addressbooks/user1/book1/card1' => [
|
||||
200 => [
|
||||
'{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
|
||||
'{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:4.0\r\nPRODID:-//Sabre//Sabre VObject $vobjVersion//EN\r\nUID:12345\r\nEND:VCARD\r\n",
|
||||
],
|
||||
],
|
||||
], $result);
|
||||
|
||||
}
|
||||
|
||||
function testAddressBookDepth0() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'REPORT',
|
||||
'/addressbooks/user1/book1',
|
||||
['Depth' => '0']
|
||||
);
|
||||
|
||||
$request->setBody(
|
||||
'<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<c:address-data content-type="application/vcard+json" />
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
</c:addressbook-query>'
|
||||
);
|
||||
|
||||
$response = new HTTP\ResponseMock();
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->server->httpResponse = $response;
|
||||
|
||||
$this->server->exec();
|
||||
|
||||
$this->assertEquals(415, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
||||
}
|
||||
|
||||
function testAddressBookProperties() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'REPORT',
|
||||
'/addressbooks/user1/book3',
|
||||
['Depth' => '1']
|
||||
);
|
||||
|
||||
$request->setBody(
|
||||
'<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<c:address-data>
|
||||
<c:prop name="FN"/>
|
||||
<c:prop name="BDAY"/>
|
||||
</c:address-data>
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
</c:addressbook-query>'
|
||||
);
|
||||
|
||||
$response = new HTTP\ResponseMock();
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->server->httpResponse = $response;
|
||||
|
||||
$this->server->exec();
|
||||
|
||||
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
||||
|
||||
// using the client for parsing
|
||||
$client = new DAV\Client(['baseUri' => '/']);
|
||||
|
||||
$result = $client->parseMultiStatus($response->body);
|
||||
|
||||
$this->assertEquals([
|
||||
'/addressbooks/user1/book3/card3' => [
|
||||
200 => [
|
||||
'{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nFN:Test-Card\nEMAIL;TYPE=home:bar@example.org\nEND:VCARD") . '"',
|
||||
'{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:3.0\r\nUID:12345\r\nFN:Test-Card\r\nEND:VCARD\r\n",
|
||||
],
|
||||
],
|
||||
], $result);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV;
|
||||
|
||||
use Sabre\DAVACL;
|
||||
|
||||
class AddressBookRootTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function testGetName() {
|
||||
|
||||
$pBackend = new DAVACL\PrincipalBackend\Mock();
|
||||
$cBackend = new Backend\Mock();
|
||||
$root = new AddressBookRoot($pBackend, $cBackend);
|
||||
$this->assertEquals('addressbooks', $root->getName());
|
||||
|
||||
}
|
||||
|
||||
function testGetChildForPrincipal() {
|
||||
|
||||
$pBackend = new DAVACL\PrincipalBackend\Mock();
|
||||
$cBackend = new Backend\Mock();
|
||||
$root = new AddressBookRoot($pBackend, $cBackend);
|
||||
|
||||
$children = $root->getChildren();
|
||||
$this->assertEquals(3, count($children));
|
||||
|
||||
$this->assertInstanceOf('Sabre\\CardDAV\\AddressBookHome', $children[0]);
|
||||
$this->assertEquals('user1', $children[0]->getName());
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,194 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV;
|
||||
|
||||
use Sabre\DAV\PropPatch;
|
||||
|
||||
class AddressBookTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
use \Sabre\DAV\DbTestHelperTrait;
|
||||
|
||||
/**
|
||||
* @var Sabre\CardDAV\AddressBook
|
||||
*/
|
||||
protected $ab;
|
||||
protected $backend;
|
||||
|
||||
function setUp() {
|
||||
|
||||
$this->backend = new Backend\Mock();
|
||||
$this->ab = new AddressBook(
|
||||
$this->backend,
|
||||
[
|
||||
'uri' => 'book1',
|
||||
'id' => 'foo',
|
||||
'{DAV:}displayname' => 'd-name',
|
||||
'principaluri' => 'principals/user1',
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testGetName() {
|
||||
|
||||
$this->assertEquals('book1', $this->ab->getName());
|
||||
|
||||
}
|
||||
|
||||
function testGetChild() {
|
||||
|
||||
$card = $this->ab->getChild('card1');
|
||||
$this->assertInstanceOf('Sabre\\CardDAV\\Card', $card);
|
||||
$this->assertEquals('card1', $card->getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\NotFound
|
||||
*/
|
||||
function testGetChildNotFound() {
|
||||
|
||||
$card = $this->ab->getChild('card3');
|
||||
|
||||
}
|
||||
|
||||
function testGetChildren() {
|
||||
|
||||
$cards = $this->ab->getChildren();
|
||||
$this->assertEquals(2, count($cards));
|
||||
|
||||
$this->assertEquals('card1', $cards[0]->getName());
|
||||
$this->assertEquals('card2', $cards[1]->getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
|
||||
*/
|
||||
function testCreateDirectory() {
|
||||
|
||||
$this->ab->createDirectory('name');
|
||||
|
||||
}
|
||||
|
||||
function testCreateFile() {
|
||||
|
||||
$file = fopen('php://memory', 'r+');
|
||||
fwrite($file, 'foo');
|
||||
rewind($file);
|
||||
$this->ab->createFile('card2', $file);
|
||||
|
||||
$this->assertEquals('foo', $this->backend->cards['foo']['card2']);
|
||||
|
||||
}
|
||||
|
||||
function testDelete() {
|
||||
|
||||
$this->ab->delete();
|
||||
$this->assertEquals(1, count($this->backend->addressBooks));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
|
||||
*/
|
||||
function testSetName() {
|
||||
|
||||
$this->ab->setName('foo');
|
||||
|
||||
}
|
||||
|
||||
function testGetLastModified() {
|
||||
|
||||
$this->assertNull($this->ab->getLastModified());
|
||||
|
||||
}
|
||||
|
||||
function testUpdateProperties() {
|
||||
|
||||
$propPatch = new PropPatch([
|
||||
'{DAV:}displayname' => 'barrr',
|
||||
]);
|
||||
$this->ab->propPatch($propPatch);
|
||||
$this->assertTrue($propPatch->commit());
|
||||
|
||||
$this->assertEquals('barrr', $this->backend->addressBooks[0]['{DAV:}displayname']);
|
||||
|
||||
}
|
||||
|
||||
function testGetProperties() {
|
||||
|
||||
$props = $this->ab->getProperties(['{DAV:}displayname']);
|
||||
$this->assertEquals([
|
||||
'{DAV:}displayname' => 'd-name',
|
||||
], $props);
|
||||
|
||||
}
|
||||
|
||||
function testACLMethods() {
|
||||
|
||||
$this->assertEquals('principals/user1', $this->ab->getOwner());
|
||||
$this->assertNull($this->ab->getGroup());
|
||||
$this->assertEquals([
|
||||
[
|
||||
'privilege' => '{DAV:}all',
|
||||
'principal' => '{DAV:}owner',
|
||||
'protected' => true,
|
||||
],
|
||||
], $this->ab->getACL());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testSetACL() {
|
||||
|
||||
$this->ab->setACL([]);
|
||||
|
||||
}
|
||||
|
||||
function testGetSupportedPrivilegeSet() {
|
||||
|
||||
$this->assertNull(
|
||||
$this->ab->getSupportedPrivilegeSet()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testGetSyncTokenNoSyncSupport() {
|
||||
|
||||
$this->assertNull($this->ab->getSyncToken());
|
||||
|
||||
}
|
||||
function testGetChangesNoSyncSupport() {
|
||||
|
||||
$this->assertNull($this->ab->getChanges(1, null));
|
||||
|
||||
}
|
||||
|
||||
function testGetSyncToken() {
|
||||
|
||||
$this->driver = 'sqlite';
|
||||
$this->dropTables(['addressbooks', 'cards', 'addressbookchanges']);
|
||||
$this->createSchema('addressbooks');
|
||||
$backend = new Backend\PDO(
|
||||
$this->getPDO()
|
||||
);
|
||||
$ab = new AddressBook($backend, ['id' => 1, '{DAV:}sync-token' => 2]);
|
||||
$this->assertEquals(2, $ab->getSyncToken());
|
||||
}
|
||||
|
||||
function testGetSyncToken2() {
|
||||
|
||||
$this->driver = 'sqlite';
|
||||
$this->dropTables(['addressbooks', 'cards', 'addressbookchanges']);
|
||||
$this->createSchema('addressbooks');
|
||||
$backend = new Backend\PDO(
|
||||
$this->getPDO()
|
||||
);
|
||||
$ab = new AddressBook($backend, ['id' => 1, '{http://sabredav.org/ns}sync-token' => 2]);
|
||||
$this->assertEquals(2, $ab->getSyncToken());
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,373 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV\Backend;
|
||||
|
||||
use Sabre\CardDAV;
|
||||
use Sabre\DAV\PropPatch;
|
||||
|
||||
abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
use \Sabre\DAV\DbTestHelperTrait;
|
||||
|
||||
/**
|
||||
* @var CardDAV\Backend\PDO
|
||||
*/
|
||||
protected $backend;
|
||||
|
||||
function setUp() {
|
||||
|
||||
$this->dropTables([
|
||||
'addressbooks',
|
||||
'cards',
|
||||
'addressbookchanges',
|
||||
]);
|
||||
$this->createSchema('addressbooks');
|
||||
$pdo = $this->getPDO();
|
||||
|
||||
$this->backend = new PDO($pdo);
|
||||
$pdo->exec("INSERT INTO addressbooks (principaluri, displayname, uri, description, synctoken) VALUES ('principals/user1', 'book1', 'book1', 'addressbook 1', 1)");
|
||||
$pdo->exec("INSERT INTO cards (addressbookid, carddata, uri, lastmodified, etag, size) VALUES (1, 'card1', 'card1', 0, '" . md5('card1') . "', 5)");
|
||||
|
||||
}
|
||||
|
||||
function testGetAddressBooksForUser() {
|
||||
|
||||
$result = $this->backend->getAddressBooksForUser('principals/user1');
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'id' => 1,
|
||||
'uri' => 'book1',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'book1',
|
||||
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
|
||||
'{http://calendarserver.org/ns/}getctag' => 1,
|
||||
'{http://sabredav.org/ns}sync-token' => 1
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
function testUpdateAddressBookInvalidProp() {
|
||||
|
||||
$propPatch = new PropPatch([
|
||||
'{DAV:}displayname' => 'updated',
|
||||
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
|
||||
'{DAV:}foo' => 'bar',
|
||||
]);
|
||||
|
||||
$this->backend->updateAddressBook(1, $propPatch);
|
||||
$result = $propPatch->commit();
|
||||
|
||||
$this->assertFalse($result);
|
||||
|
||||
$result = $this->backend->getAddressBooksForUser('principals/user1');
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'id' => 1,
|
||||
'uri' => 'book1',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'book1',
|
||||
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
|
||||
'{http://calendarserver.org/ns/}getctag' => 1,
|
||||
'{http://sabredav.org/ns}sync-token' => 1
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
function testUpdateAddressBookNoProps() {
|
||||
|
||||
$propPatch = new PropPatch([
|
||||
]);
|
||||
|
||||
$this->backend->updateAddressBook(1, $propPatch);
|
||||
$result = $propPatch->commit();
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->backend->getAddressBooksForUser('principals/user1');
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'id' => 1,
|
||||
'uri' => 'book1',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'book1',
|
||||
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
|
||||
'{http://calendarserver.org/ns/}getctag' => 1,
|
||||
'{http://sabredav.org/ns}sync-token' => 1
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function testUpdateAddressBookSuccess() {
|
||||
|
||||
$propPatch = new PropPatch([
|
||||
'{DAV:}displayname' => 'updated',
|
||||
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
|
||||
]);
|
||||
|
||||
$this->backend->updateAddressBook(1, $propPatch);
|
||||
$result = $propPatch->commit();
|
||||
|
||||
$this->assertTrue($result);
|
||||
|
||||
$result = $this->backend->getAddressBooksForUser('principals/user1');
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'id' => 1,
|
||||
'uri' => 'book1',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'updated',
|
||||
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
|
||||
'{http://calendarserver.org/ns/}getctag' => 2,
|
||||
'{http://sabredav.org/ns}sync-token' => 2
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function testDeleteAddressBook() {
|
||||
|
||||
$this->backend->deleteAddressBook(1);
|
||||
|
||||
$this->assertEquals([], $this->backend->getAddressBooksForUser('principals/user1'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testCreateAddressBookUnsupportedProp() {
|
||||
|
||||
$this->backend->createAddressBook('principals/user1', 'book2', [
|
||||
'{DAV:}foo' => 'bar',
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
function testCreateAddressBookSuccess() {
|
||||
|
||||
$this->backend->createAddressBook('principals/user1', 'book2', [
|
||||
'{DAV:}displayname' => 'book2',
|
||||
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 2',
|
||||
]);
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'id' => 1,
|
||||
'uri' => 'book1',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'book1',
|
||||
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
|
||||
'{http://calendarserver.org/ns/}getctag' => 1,
|
||||
'{http://sabredav.org/ns}sync-token' => 1,
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'uri' => 'book2',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'book2',
|
||||
'{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 2',
|
||||
'{http://calendarserver.org/ns/}getctag' => 1,
|
||||
'{http://sabredav.org/ns}sync-token' => 1,
|
||||
]
|
||||
];
|
||||
$result = $this->backend->getAddressBooksForUser('principals/user1');
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
function testGetCards() {
|
||||
|
||||
$result = $this->backend->getCards(1);
|
||||
|
||||
$expected = [
|
||||
[
|
||||
'id' => 1,
|
||||
'uri' => 'card1',
|
||||
'lastmodified' => 0,
|
||||
'etag' => '"' . md5('card1') . '"',
|
||||
'size' => 5
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
function testGetCard() {
|
||||
|
||||
$result = $this->backend->getCard(1, 'card1');
|
||||
|
||||
$expected = [
|
||||
'id' => 1,
|
||||
'uri' => 'card1',
|
||||
'carddata' => 'card1',
|
||||
'lastmodified' => 0,
|
||||
'etag' => '"' . md5('card1') . '"',
|
||||
'size' => 5
|
||||
];
|
||||
|
||||
if (is_resource($result['carddata'])) {
|
||||
$result['carddata'] = stream_get_contents($result['carddata']);
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetCard
|
||||
*/
|
||||
function testCreateCard() {
|
||||
|
||||
$result = $this->backend->createCard(1, 'card2', 'data2');
|
||||
$this->assertEquals('"' . md5('data2') . '"', $result);
|
||||
$result = $this->backend->getCard(1, 'card2');
|
||||
$this->assertEquals(2, $result['id']);
|
||||
$this->assertEquals('card2', $result['uri']);
|
||||
if (is_resource($result['carddata'])) {
|
||||
$result['carddata'] = stream_get_contents($result['carddata']);
|
||||
}
|
||||
$this->assertEquals('data2', $result['carddata']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCreateCard
|
||||
*/
|
||||
function testGetMultiple() {
|
||||
|
||||
$result = $this->backend->createCard(1, 'card2', 'data2');
|
||||
$result = $this->backend->createCard(1, 'card3', 'data3');
|
||||
$check = [
|
||||
[
|
||||
'id' => 1,
|
||||
'uri' => 'card1',
|
||||
'carddata' => 'card1',
|
||||
'lastmodified' => 0,
|
||||
],
|
||||
[
|
||||
'id' => 2,
|
||||
'uri' => 'card2',
|
||||
'carddata' => 'data2',
|
||||
'lastmodified' => time(),
|
||||
],
|
||||
[
|
||||
'id' => 3,
|
||||
'uri' => 'card3',
|
||||
'carddata' => 'data3',
|
||||
'lastmodified' => time(),
|
||||
],
|
||||
];
|
||||
|
||||
$result = $this->backend->getMultipleCards(1, ['card1', 'card2', 'card3']);
|
||||
|
||||
foreach ($check as $index => $node) {
|
||||
|
||||
foreach ($node as $k => $v) {
|
||||
|
||||
$expected = $v;
|
||||
$actual = $result[$index][$k];
|
||||
|
||||
switch ($k) {
|
||||
case 'lastmodified' :
|
||||
$this->assertInternalType('int', $actual);
|
||||
break;
|
||||
case 'carddata' :
|
||||
if (is_resource($actual)) {
|
||||
$actual = stream_get_contents($actual);
|
||||
}
|
||||
// No break intended.
|
||||
default :
|
||||
$this->assertEquals($expected, $actual);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetCard
|
||||
*/
|
||||
function testUpdateCard() {
|
||||
|
||||
$result = $this->backend->updateCard(1, 'card1', 'newdata');
|
||||
$this->assertEquals('"' . md5('newdata') . '"', $result);
|
||||
|
||||
$result = $this->backend->getCard(1, 'card1');
|
||||
$this->assertEquals(1, $result['id']);
|
||||
if (is_resource($result['carddata'])) {
|
||||
$result['carddata'] = stream_get_contents($result['carddata']);
|
||||
}
|
||||
$this->assertEquals('newdata', $result['carddata']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testGetCard
|
||||
*/
|
||||
function testDeleteCard() {
|
||||
|
||||
$this->backend->deleteCard(1, 'card1');
|
||||
$result = $this->backend->getCard(1, 'card1');
|
||||
$this->assertFalse($result);
|
||||
|
||||
}
|
||||
|
||||
function testGetChanges() {
|
||||
|
||||
$backend = $this->backend;
|
||||
$id = $backend->createAddressBook(
|
||||
'principals/user1',
|
||||
'bla',
|
||||
[]
|
||||
);
|
||||
$result = $backend->getChangesForAddressBook($id, null, 1);
|
||||
|
||||
$this->assertEquals([
|
||||
'syncToken' => 1,
|
||||
"added" => [],
|
||||
'modified' => [],
|
||||
'deleted' => [],
|
||||
], $result);
|
||||
|
||||
$currentToken = $result['syncToken'];
|
||||
|
||||
$dummyCard = "BEGIN:VCARD\r\nEND:VCARD\r\n";
|
||||
|
||||
$backend->createCard($id, "card1.ics", $dummyCard);
|
||||
$backend->createCard($id, "card2.ics", $dummyCard);
|
||||
$backend->createCard($id, "card3.ics", $dummyCard);
|
||||
$backend->updateCard($id, "card1.ics", $dummyCard);
|
||||
$backend->deleteCard($id, "card2.ics");
|
||||
|
||||
$result = $backend->getChangesForAddressBook($id, $currentToken, 1);
|
||||
|
||||
$this->assertEquals([
|
||||
'syncToken' => 6,
|
||||
'modified' => ["card1.ics"],
|
||||
'deleted' => ["card2.ics"],
|
||||
"added" => ["card3.ics"],
|
||||
], $result);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,258 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV\Backend;
|
||||
|
||||
class Mock extends AbstractBackend {
|
||||
|
||||
public $addressBooks;
|
||||
public $cards;
|
||||
|
||||
function __construct($addressBooks = null, $cards = null) {
|
||||
|
||||
$this->addressBooks = $addressBooks;
|
||||
$this->cards = $cards;
|
||||
|
||||
if (is_null($this->addressBooks)) {
|
||||
$this->addressBooks = [
|
||||
[
|
||||
'id' => 'foo',
|
||||
'uri' => 'book1',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'd-name',
|
||||
],
|
||||
[
|
||||
'id' => 'bar',
|
||||
'uri' => 'book3',
|
||||
'principaluri' => 'principals/user1',
|
||||
'{DAV:}displayname' => 'd-name',
|
||||
],
|
||||
];
|
||||
|
||||
$card2 = fopen('php://memory', 'r+');
|
||||
fwrite($card2, "BEGIN:VCARD\nVERSION:3.0\nUID:45678\nEND:VCARD");
|
||||
rewind($card2);
|
||||
$this->cards = [
|
||||
'foo' => [
|
||||
'card1' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD",
|
||||
'card2' => $card2,
|
||||
],
|
||||
'bar' => [
|
||||
'card3' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nFN:Test-Card\nEMAIL;TYPE=home:bar@example.org\nEND:VCARD",
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function getAddressBooksForUser($principalUri) {
|
||||
|
||||
$books = [];
|
||||
foreach ($this->addressBooks as $book) {
|
||||
if ($book['principaluri'] === $principalUri) {
|
||||
$books[] = $book;
|
||||
}
|
||||
}
|
||||
return $books;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates properties for an address book.
|
||||
*
|
||||
* The list of mutations is stored in a Sabre\DAV\PropPatch object.
|
||||
* To do the actual updates, you must tell this object which properties
|
||||
* you're going to process with the handle() method.
|
||||
*
|
||||
* Calling the handle method is like telling the PropPatch object "I
|
||||
* promise I can handle updating this property".
|
||||
*
|
||||
* Read the PropPatch documentation for more info and examples.
|
||||
*
|
||||
* @param string $addressBookId
|
||||
* @param \Sabre\DAV\PropPatch $propPatch
|
||||
* @return void
|
||||
*/
|
||||
function updateAddressBook($addressBookId, \Sabre\DAV\PropPatch $propPatch) {
|
||||
|
||||
foreach ($this->addressBooks as &$book) {
|
||||
if ($book['id'] !== $addressBookId)
|
||||
continue;
|
||||
|
||||
$propPatch->handleRemaining(function($mutations) use (&$book) {
|
||||
foreach ($mutations as $key => $value) {
|
||||
$book[$key] = $value;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function createAddressBook($principalUri, $url, array $properties) {
|
||||
|
||||
$this->addressBooks[] = array_merge($properties, [
|
||||
'id' => $url,
|
||||
'uri' => $url,
|
||||
'principaluri' => $principalUri,
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
function deleteAddressBook($addressBookId) {
|
||||
|
||||
foreach ($this->addressBooks as $key => $value) {
|
||||
if ($value['id'] === $addressBookId)
|
||||
unset($this->addressBooks[$key]);
|
||||
}
|
||||
unset($this->cards[$addressBookId]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all cards for a specific addressbook id.
|
||||
*
|
||||
* This method should return the following properties for each card:
|
||||
* * carddata - raw vcard data
|
||||
* * uri - Some unique url
|
||||
* * lastmodified - A unix timestamp
|
||||
*
|
||||
* It's recommended to also return the following properties:
|
||||
* * etag - A unique etag. This must change every time the card changes.
|
||||
* * size - The size of the card in bytes.
|
||||
*
|
||||
* If these last two properties are provided, less time will be spent
|
||||
* calculating them. If they are specified, you can also ommit carddata.
|
||||
* This may speed up certain requests, especially with large cards.
|
||||
*
|
||||
* @param mixed $addressBookId
|
||||
* @return array
|
||||
*/
|
||||
function getCards($addressBookId) {
|
||||
|
||||
$cards = [];
|
||||
foreach ($this->cards[$addressBookId] as $uri => $data) {
|
||||
if (is_resource($data)) {
|
||||
$cards[] = [
|
||||
'uri' => $uri,
|
||||
'carddata' => $data,
|
||||
];
|
||||
} else {
|
||||
$cards[] = [
|
||||
'uri' => $uri,
|
||||
'carddata' => $data,
|
||||
'etag' => '"' . md5($data) . '"',
|
||||
'size' => strlen($data)
|
||||
];
|
||||
}
|
||||
}
|
||||
return $cards;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a specfic card.
|
||||
*
|
||||
* The same set of properties must be returned as with getCards. The only
|
||||
* exception is that 'carddata' is absolutely required.
|
||||
*
|
||||
* If the card does not exist, you must return false.
|
||||
*
|
||||
* @param mixed $addressBookId
|
||||
* @param string $cardUri
|
||||
* @return array
|
||||
*/
|
||||
function getCard($addressBookId, $cardUri) {
|
||||
|
||||
if (!isset($this->cards[$addressBookId][$cardUri])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = $this->cards[$addressBookId][$cardUri];
|
||||
return [
|
||||
'uri' => $cardUri,
|
||||
'carddata' => $data,
|
||||
'etag' => '"' . md5($data) . '"',
|
||||
'size' => strlen($data)
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new card.
|
||||
*
|
||||
* The addressbook id will be passed as the first argument. This is the
|
||||
* same id as it is returned from the getAddressBooksForUser method.
|
||||
*
|
||||
* The cardUri is a base uri, and doesn't include the full path. The
|
||||
* cardData argument is the vcard body, and is passed as a string.
|
||||
*
|
||||
* It is possible to return an ETag from this method. This ETag is for the
|
||||
* newly created resource, and must be enclosed with double quotes (that
|
||||
* is, the string itself must contain the double quotes).
|
||||
*
|
||||
* You should only return the ETag if you store the carddata as-is. If a
|
||||
* subsequent GET request on the same card does not have the same body,
|
||||
* byte-by-byte and you did return an ETag here, clients tend to get
|
||||
* confused.
|
||||
*
|
||||
* If you don't return an ETag, you can just return null.
|
||||
*
|
||||
* @param mixed $addressBookId
|
||||
* @param string $cardUri
|
||||
* @param string $cardData
|
||||
* @return string|null
|
||||
*/
|
||||
function createCard($addressBookId, $cardUri, $cardData) {
|
||||
|
||||
if (is_resource($cardData)) {
|
||||
$cardData = stream_get_contents($cardData);
|
||||
}
|
||||
$this->cards[$addressBookId][$cardUri] = $cardData;
|
||||
return '"' . md5($cardData) . '"';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates a card.
|
||||
*
|
||||
* The addressbook id will be passed as the first argument. This is the
|
||||
* same id as it is returned from the getAddressBooksForUser method.
|
||||
*
|
||||
* The cardUri is a base uri, and doesn't include the full path. The
|
||||
* cardData argument is the vcard body, and is passed as a string.
|
||||
*
|
||||
* It is possible to return an ETag from this method. This ETag should
|
||||
* match that of the updated resource, and must be enclosed with double
|
||||
* quotes (that is: the string itself must contain the actual quotes).
|
||||
*
|
||||
* You should only return the ETag if you store the carddata as-is. If a
|
||||
* subsequent GET request on the same card does not have the same body,
|
||||
* byte-by-byte and you did return an ETag here, clients tend to get
|
||||
* confused.
|
||||
*
|
||||
* If you don't return an ETag, you can just return null.
|
||||
*
|
||||
* @param mixed $addressBookId
|
||||
* @param string $cardUri
|
||||
* @param string $cardData
|
||||
* @return string|null
|
||||
*/
|
||||
function updateCard($addressBookId, $cardUri, $cardData) {
|
||||
|
||||
if (is_resource($cardData)) {
|
||||
$cardData = stream_get_contents($cardData);
|
||||
}
|
||||
$this->cards[$addressBookId][$cardUri] = $cardData;
|
||||
return '"' . md5($cardData) . '"';
|
||||
|
||||
}
|
||||
|
||||
function deleteCard($addressBookId, $cardUri) {
|
||||
|
||||
unset($this->cards[$addressBookId][$cardUri]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV\Backend;
|
||||
|
||||
class PDOMySQLTest extends AbstractPDOTest {
|
||||
|
||||
public $driver = 'mysql';
|
||||
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV\Backend;
|
||||
|
||||
class PDOPgSqlTest extends AbstractPDOTest {
|
||||
|
||||
public $driver = 'pgsql';
|
||||
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV\Backend;
|
||||
|
||||
class PDOSqliteTest extends AbstractPDOTest {
|
||||
|
||||
public $driver = 'sqlite';
|
||||
|
||||
}
|
||||
@ -1,210 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV;
|
||||
|
||||
class CardTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Sabre\CardDAV\Card
|
||||
*/
|
||||
protected $card;
|
||||
/**
|
||||
* @var Sabre\CardDAV\MockBackend
|
||||
*/
|
||||
protected $backend;
|
||||
|
||||
function setUp() {
|
||||
|
||||
$this->backend = new Backend\Mock();
|
||||
$this->card = new Card(
|
||||
$this->backend,
|
||||
[
|
||||
'uri' => 'book1',
|
||||
'id' => 'foo',
|
||||
'principaluri' => 'principals/user1',
|
||||
],
|
||||
[
|
||||
'uri' => 'card1',
|
||||
'addressbookid' => 'foo',
|
||||
'carddata' => 'card',
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testGet() {
|
||||
|
||||
$result = $this->card->get();
|
||||
$this->assertEquals('card', $result);
|
||||
|
||||
}
|
||||
function testGet2() {
|
||||
|
||||
$this->card = new Card(
|
||||
$this->backend,
|
||||
[
|
||||
'uri' => 'book1',
|
||||
'id' => 'foo',
|
||||
'principaluri' => 'principals/user1',
|
||||
],
|
||||
[
|
||||
'uri' => 'card1',
|
||||
'addressbookid' => 'foo',
|
||||
]
|
||||
);
|
||||
$result = $this->card->get();
|
||||
$this->assertEquals("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD", $result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @depends testGet
|
||||
*/
|
||||
function testPut() {
|
||||
|
||||
$file = fopen('php://memory', 'r+');
|
||||
fwrite($file, 'newdata');
|
||||
rewind($file);
|
||||
$this->card->put($file);
|
||||
$result = $this->card->get();
|
||||
$this->assertEquals('newdata', $result);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function testDelete() {
|
||||
|
||||
$this->card->delete();
|
||||
$this->assertEquals(1, count($this->backend->cards['foo']));
|
||||
|
||||
}
|
||||
|
||||
function testGetContentType() {
|
||||
|
||||
$this->assertEquals('text/vcard; charset=utf-8', $this->card->getContentType());
|
||||
|
||||
}
|
||||
|
||||
function testGetETag() {
|
||||
|
||||
$this->assertEquals('"' . md5('card') . '"', $this->card->getETag());
|
||||
|
||||
}
|
||||
|
||||
function testGetETag2() {
|
||||
|
||||
$card = new Card(
|
||||
$this->backend,
|
||||
[
|
||||
'uri' => 'book1',
|
||||
'id' => 'foo',
|
||||
'principaluri' => 'principals/user1',
|
||||
],
|
||||
[
|
||||
'uri' => 'card1',
|
||||
'addressbookid' => 'foo',
|
||||
'carddata' => 'card',
|
||||
'etag' => '"blabla"',
|
||||
]
|
||||
);
|
||||
$this->assertEquals('"blabla"', $card->getETag());
|
||||
|
||||
}
|
||||
|
||||
function testGetLastModified() {
|
||||
|
||||
$this->assertEquals(null, $this->card->getLastModified());
|
||||
|
||||
}
|
||||
|
||||
function testGetSize() {
|
||||
|
||||
$this->assertEquals(4, $this->card->getSize());
|
||||
$this->assertEquals(4, $this->card->getSize());
|
||||
|
||||
}
|
||||
|
||||
function testGetSize2() {
|
||||
|
||||
$card = new Card(
|
||||
$this->backend,
|
||||
[
|
||||
'uri' => 'book1',
|
||||
'id' => 'foo',
|
||||
'principaluri' => 'principals/user1',
|
||||
],
|
||||
[
|
||||
'uri' => 'card1',
|
||||
'addressbookid' => 'foo',
|
||||
'etag' => '"blabla"',
|
||||
'size' => 4,
|
||||
]
|
||||
);
|
||||
$this->assertEquals(4, $card->getSize());
|
||||
|
||||
}
|
||||
|
||||
function testACLMethods() {
|
||||
|
||||
$this->assertEquals('principals/user1', $this->card->getOwner());
|
||||
$this->assertNull($this->card->getGroup());
|
||||
$this->assertEquals([
|
||||
[
|
||||
'privilege' => '{DAV:}all',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
], $this->card->getACL());
|
||||
|
||||
}
|
||||
function testOverrideACL() {
|
||||
|
||||
$card = new Card(
|
||||
$this->backend,
|
||||
[
|
||||
'uri' => 'book1',
|
||||
'id' => 'foo',
|
||||
'principaluri' => 'principals/user1',
|
||||
],
|
||||
[
|
||||
'uri' => 'card1',
|
||||
'addressbookid' => 'foo',
|
||||
'carddata' => 'card',
|
||||
'acl' => [
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
$this->assertEquals([
|
||||
[
|
||||
'privilege' => '{DAV:}read',
|
||||
'principal' => 'principals/user1',
|
||||
'protected' => true,
|
||||
],
|
||||
], $card->getACL());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception\Forbidden
|
||||
*/
|
||||
function testSetACL() {
|
||||
|
||||
$this->card->setACL([]);
|
||||
|
||||
}
|
||||
|
||||
function testGetSupportedPrivilegeSet() {
|
||||
|
||||
$this->assertNull(
|
||||
$this->card->getSupportedPrivilegeSet()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV;
|
||||
|
||||
use Sabre\DAV;
|
||||
|
||||
class IDirectoryTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function testResourceType() {
|
||||
|
||||
$tree = [
|
||||
new DirectoryMock('directory')
|
||||
];
|
||||
|
||||
$server = new DAV\Server($tree);
|
||||
$plugin = new Plugin();
|
||||
$server->addPlugin($plugin);
|
||||
|
||||
$props = $server->getProperties('directory', ['{DAV:}resourcetype']);
|
||||
$this->assertTrue($props['{DAV:}resourcetype']->is('{' . Plugin::NS_CARDDAV . '}directory'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DirectoryMock extends DAV\SimpleCollection implements IDirectory {
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -1,99 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV;
|
||||
|
||||
use Sabre\DAV;
|
||||
use Sabre\HTTP;
|
||||
|
||||
require_once 'Sabre/HTTP/ResponseMock.php';
|
||||
|
||||
class MultiGetTest extends AbstractPluginTest {
|
||||
|
||||
function testMultiGet() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'REPORT',
|
||||
'REQUEST_URI' => '/addressbooks/user1/book1',
|
||||
]);
|
||||
|
||||
$request->setBody(
|
||||
'<?xml version="1.0"?>
|
||||
<c:addressbook-multiget xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
<c:address-data />
|
||||
</d:prop>
|
||||
<d:href>/addressbooks/user1/book1/card1</d:href>
|
||||
</c:addressbook-multiget>'
|
||||
);
|
||||
|
||||
$response = new HTTP\ResponseMock();
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->server->httpResponse = $response;
|
||||
|
||||
$this->server->exec();
|
||||
|
||||
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
||||
|
||||
// using the client for parsing
|
||||
$client = new DAV\Client(['baseUri' => '/']);
|
||||
|
||||
$result = $client->parseMultiStatus($response->body);
|
||||
|
||||
$this->assertEquals([
|
||||
'/addressbooks/user1/book1/card1' => [
|
||||
200 => [
|
||||
'{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
|
||||
'{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD",
|
||||
]
|
||||
]
|
||||
], $result);
|
||||
|
||||
}
|
||||
|
||||
function testMultiGetVCard4() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'REPORT',
|
||||
'REQUEST_URI' => '/addressbooks/user1/book1',
|
||||
]);
|
||||
|
||||
$request->setBody(
|
||||
'<?xml version="1.0"?>
|
||||
<c:addressbook-multiget xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
<c:address-data content-type="text/vcard" version="4.0" />
|
||||
</d:prop>
|
||||
<d:href>/addressbooks/user1/book1/card1</d:href>
|
||||
</c:addressbook-multiget>'
|
||||
);
|
||||
|
||||
$response = new HTTP\ResponseMock();
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->server->httpResponse = $response;
|
||||
|
||||
$this->server->exec();
|
||||
|
||||
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
||||
|
||||
// using the client for parsing
|
||||
$client = new DAV\Client(['baseUri' => '/']);
|
||||
|
||||
$result = $client->parseMultiStatus($response->body);
|
||||
|
||||
$prodId = "PRODID:-//Sabre//Sabre VObject " . \Sabre\VObject\Version::VERSION . "//EN";
|
||||
|
||||
$this->assertEquals([
|
||||
'/addressbooks/user1/book1/card1' => [
|
||||
200 => [
|
||||
'{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
|
||||
'{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:4.0\r\n$prodId\r\nUID:12345\r\nEND:VCARD\r\n",
|
||||
]
|
||||
]
|
||||
], $result);
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV;
|
||||
|
||||
use Sabre\DAV;
|
||||
|
||||
class PluginTest extends AbstractPluginTest {
|
||||
|
||||
function testConstruct() {
|
||||
|
||||
$this->assertEquals('{' . Plugin::NS_CARDDAV . '}addressbook', $this->server->resourceTypeMapping['Sabre\\CardDAV\\IAddressBook']);
|
||||
|
||||
$this->assertTrue(in_array('addressbook', $this->plugin->getFeatures()));
|
||||
$this->assertEquals('carddav', $this->plugin->getPluginInfo()['name']);
|
||||
|
||||
}
|
||||
|
||||
function testSupportedReportSet() {
|
||||
|
||||
$this->assertEquals([
|
||||
'{' . Plugin::NS_CARDDAV . '}addressbook-multiget',
|
||||
'{' . Plugin::NS_CARDDAV . '}addressbook-query',
|
||||
], $this->plugin->getSupportedReportSet('addressbooks/user1/book1'));
|
||||
|
||||
}
|
||||
|
||||
function testSupportedReportSetEmpty() {
|
||||
|
||||
$this->assertEquals([
|
||||
], $this->plugin->getSupportedReportSet(''));
|
||||
|
||||
}
|
||||
|
||||
function testAddressBookHomeSet() {
|
||||
|
||||
$result = $this->server->getProperties('principals/user1', ['{' . Plugin::NS_CARDDAV . '}addressbook-home-set']);
|
||||
|
||||
$this->assertEquals(1, count($result));
|
||||
$this->assertTrue(isset($result['{' . Plugin::NS_CARDDAV . '}addressbook-home-set']));
|
||||
$this->assertEquals('addressbooks/user1/', $result['{' . Plugin::NS_CARDDAV . '}addressbook-home-set']->getHref());
|
||||
|
||||
}
|
||||
|
||||
function testDirectoryGateway() {
|
||||
|
||||
$result = $this->server->getProperties('principals/user1', ['{' . Plugin::NS_CARDDAV . '}directory-gateway']);
|
||||
|
||||
$this->assertEquals(1, count($result));
|
||||
$this->assertTrue(isset($result['{' . Plugin::NS_CARDDAV . '}directory-gateway']));
|
||||
$this->assertEquals(['directory'], $result['{' . Plugin::NS_CARDDAV . '}directory-gateway']->getHrefs());
|
||||
|
||||
}
|
||||
|
||||
function testReportPassThrough() {
|
||||
|
||||
$this->assertNull($this->plugin->report('{DAV:}foo', new \DomDocument(), ''));
|
||||
|
||||
}
|
||||
|
||||
function testHTMLActionsPanel() {
|
||||
|
||||
$output = '';
|
||||
$r = $this->server->emit('onHTMLActionsPanel', [$this->server->tree->getNodeForPath('addressbooks/user1'), &$output]);
|
||||
$this->assertFalse($r);
|
||||
|
||||
$this->assertTrue(!!strpos($output, 'Display name'));
|
||||
|
||||
}
|
||||
|
||||
function testAddressbookPluginProperties() {
|
||||
|
||||
$ns = '{' . Plugin::NS_CARDDAV . '}';
|
||||
$propFind = new DAV\PropFind('addressbooks/user1/book1', [
|
||||
$ns . 'supported-address-data',
|
||||
$ns . 'supported-collation-set',
|
||||
]);
|
||||
$node = $this->server->tree->getNodeForPath('addressbooks/user1/book1');
|
||||
$this->plugin->propFindEarly($propFind, $node);
|
||||
|
||||
$this->assertInstanceOf(
|
||||
'Sabre\\CardDAV\\Xml\\Property\\SupportedAddressData',
|
||||
$propFind->get($ns . 'supported-address-data')
|
||||
);
|
||||
$this->assertInstanceOf(
|
||||
'Sabre\\CardDAV\\Xml\\Property\\SupportedCollationSet',
|
||||
$propFind->get($ns . 'supported-collation-set')
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function testGetTransform() {
|
||||
|
||||
$request = new \Sabre\HTTP\Request('GET', '/addressbooks/user1/book1/card1', ['Accept: application/vcard+json']);
|
||||
$response = new \Sabre\HTTP\ResponseMock();
|
||||
$this->server->invokeMethod($request, $response);
|
||||
|
||||
$this->assertEquals(200, $response->getStatus());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,56 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV;
|
||||
|
||||
use Sabre\DAV\PropFind;
|
||||
use Sabre\HTTP;
|
||||
|
||||
class SogoStripContentTypeTest extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCardDAV = true;
|
||||
protected $carddavAddressBooks = [
|
||||
[
|
||||
'id' => 1,
|
||||
'uri' => 'book1',
|
||||
'principaluri' => 'principals/user1',
|
||||
],
|
||||
];
|
||||
protected $carddavCards = [
|
||||
1 => [
|
||||
'card1.vcf' => "BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD",
|
||||
],
|
||||
];
|
||||
|
||||
function testDontStrip() {
|
||||
|
||||
$result = $this->server->getProperties('addressbooks/user1/book1/card1.vcf', ['{DAV:}getcontenttype']);
|
||||
$this->assertEquals([
|
||||
'{DAV:}getcontenttype' => 'text/vcard; charset=utf-8'
|
||||
], $result);
|
||||
|
||||
}
|
||||
function testStrip() {
|
||||
|
||||
$this->server->httpRequest = HTTP\Sapi::createFromServerArray([
|
||||
'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 Lightning/1.2.1',
|
||||
]);
|
||||
$result = $this->server->getProperties('addressbooks/user1/book1/card1.vcf', ['{DAV:}getcontenttype']);
|
||||
$this->assertEquals([
|
||||
'{DAV:}getcontenttype' => 'text/x-vcard'
|
||||
], $result);
|
||||
|
||||
}
|
||||
function testDontTouchOtherMimeTypes() {
|
||||
|
||||
$this->server->httpRequest = new HTTP\Request('GET', '/addressbooks/user1/book1/card1.vcf', [
|
||||
'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 Lightning/1.2.1',
|
||||
]);
|
||||
|
||||
$propFind = new PropFind('hello', ['{DAV:}getcontenttype']);
|
||||
$propFind->set('{DAV:}getcontenttype', 'text/plain');
|
||||
$this->carddavPlugin->propFindLate($propFind, new \Sabre\DAV\SimpleCollection('foo'));
|
||||
$this->assertEquals('text/plain', $propFind->get('{DAV:}getcontenttype'));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV;
|
||||
|
||||
class TestUtil {
|
||||
|
||||
static function getBackend() {
|
||||
|
||||
$backend = new Backend\PDO(self::getSQLiteDB());
|
||||
return $backend;
|
||||
|
||||
}
|
||||
|
||||
static function getSQLiteDB() {
|
||||
|
||||
$pdo = Backend\PDOSqliteTest::getSQLite();
|
||||
|
||||
// Inserting events through a backend class.
|
||||
$backend = new Backend\PDO($pdo);
|
||||
$addressbookId = $backend->createAddressBook(
|
||||
'principals/user1',
|
||||
'UUID-123467',
|
||||
[
|
||||
'{DAV:}displayname' => 'user1 addressbook',
|
||||
'{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'AddressBook description',
|
||||
]
|
||||
);
|
||||
$backend->createAddressBook(
|
||||
'principals/user1',
|
||||
'UUID-123468',
|
||||
[
|
||||
'{DAV:}displayname' => 'user1 addressbook2',
|
||||
'{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'AddressBook description',
|
||||
]
|
||||
);
|
||||
$backend->createCard($addressbookId, 'UUID-2345', self::getTestCardData());
|
||||
return $pdo;
|
||||
|
||||
}
|
||||
|
||||
static function deleteSQLiteDB() {
|
||||
$sqliteTest = new Backend\PDOSqliteTest();
|
||||
$pdo = $sqliteTest->tearDown();
|
||||
}
|
||||
|
||||
static function getTestCardData() {
|
||||
|
||||
$addressbookData = 'BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
PRODID:-//Acme Inc.//RoadRunner 1.0//EN
|
||||
FN:Wile E. Coyote
|
||||
N:Coyote;Wile;Erroll;;
|
||||
ORG:Acme Inc.
|
||||
UID:39A6B5ED-DD51-4AFE-A683-C35EE3749627
|
||||
REV:2012-06-20T07:00:39+00:00
|
||||
END:VCARD';
|
||||
|
||||
return $addressbookData;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,135 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV;
|
||||
|
||||
use Sabre\HTTP;
|
||||
|
||||
class VCFExportTest extends \Sabre\DAVServerTest {
|
||||
|
||||
protected $setupCardDAV = true;
|
||||
protected $autoLogin = 'user1';
|
||||
protected $setupACL = true;
|
||||
|
||||
protected $carddavAddressBooks = [
|
||||
[
|
||||
'id' => 'book1',
|
||||
'uri' => 'book1',
|
||||
'principaluri' => 'principals/user1',
|
||||
]
|
||||
];
|
||||
protected $carddavCards = [
|
||||
'book1' => [
|
||||
"card1" => "BEGIN:VCARD\r\nFN:Person1\r\nEND:VCARD\r\n",
|
||||
"card2" => "BEGIN:VCARD\r\nFN:Person2\r\nEND:VCARD",
|
||||
"card3" => "BEGIN:VCARD\r\nFN:Person3\r\nEND:VCARD\r\n",
|
||||
"card4" => "BEGIN:VCARD\nFN:Person4\nEND:VCARD\n",
|
||||
]
|
||||
];
|
||||
|
||||
function setUp() {
|
||||
|
||||
parent::setUp();
|
||||
$plugin = new VCFExportPlugin();
|
||||
$this->server->addPlugin(
|
||||
$plugin
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$plugin = $this->server->getPlugin('vcf-export');
|
||||
$this->assertInstanceOf('Sabre\\CardDAV\\VCFExportPlugin', $plugin);
|
||||
|
||||
$this->assertEquals(
|
||||
'vcf-export',
|
||||
$plugin->getPluginInfo()['name']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testExport() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_URI' => '/addressbooks/user1/book1?export',
|
||||
'QUERY_STRING' => 'export',
|
||||
'REQUEST_METHOD' => 'GET',
|
||||
]);
|
||||
|
||||
$response = $this->request($request);
|
||||
$this->assertEquals(200, $response->status, $response->body);
|
||||
|
||||
$expected = "BEGIN:VCARD
|
||||
FN:Person1
|
||||
END:VCARD
|
||||
BEGIN:VCARD
|
||||
FN:Person2
|
||||
END:VCARD
|
||||
BEGIN:VCARD
|
||||
FN:Person3
|
||||
END:VCARD
|
||||
BEGIN:VCARD
|
||||
FN:Person4
|
||||
END:VCARD
|
||||
";
|
||||
// We actually expected windows line endings
|
||||
$expected = str_replace("\n", "\r\n", $expected);
|
||||
|
||||
$this->assertEquals($expected, $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testBrowserIntegration() {
|
||||
|
||||
$plugin = $this->server->getPlugin('vcf-export');
|
||||
$actions = '';
|
||||
$addressbook = new AddressBook($this->carddavBackend, []);
|
||||
$this->server->emit('browserButtonActions', ['/foo', $addressbook, &$actions]);
|
||||
$this->assertContains('/foo?export', $actions);
|
||||
|
||||
}
|
||||
|
||||
function testContentDisposition() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/addressbooks/user1/book1?export'
|
||||
);
|
||||
|
||||
$response = $this->request($request, 200);
|
||||
$this->assertEquals('text/directory', $response->getHeader('Content-Type'));
|
||||
$this->assertEquals(
|
||||
'attachment; filename="book1-' . date('Y-m-d') . '.vcf"',
|
||||
$response->getHeader('Content-Disposition')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testContentDispositionBadChars() {
|
||||
|
||||
$this->carddavBackend->createAddressBook(
|
||||
'principals/user1',
|
||||
'book-b_ad"(ch)ars',
|
||||
[]
|
||||
);
|
||||
$this->carddavBackend->createCard(
|
||||
'book-b_ad"(ch)ars',
|
||||
'card1',
|
||||
"BEGIN:VCARD\r\nFN:Person1\r\nEND:VCARD\r\n"
|
||||
);
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'GET',
|
||||
'/addressbooks/user1/book-b_ad"(ch)ars?export'
|
||||
);
|
||||
|
||||
$response = $this->request($request, 200);
|
||||
$this->assertEquals('text/directory', $response->getHeader('Content-Type'));
|
||||
$this->assertEquals(
|
||||
'attachment; filename="book-b_adchars-' . date('Y-m-d') . '.vcf"',
|
||||
$response->getHeader('Content-Disposition')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,209 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV;
|
||||
|
||||
require_once 'Sabre/CardDAV/AbstractPluginTest.php';
|
||||
|
||||
class ValidateFilterTest extends AbstractPluginTest {
|
||||
|
||||
/**
|
||||
* @param string $input
|
||||
* @param array $filters
|
||||
* @param string $test
|
||||
* @param bool $result
|
||||
* @param string|null $message
|
||||
* @dataProvider data
|
||||
*/
|
||||
function testFilter($input, $filters, $test, $result, $message = null) {
|
||||
|
||||
if ($result) {
|
||||
$this->assertTrue($this->plugin->validateFilters($input, $filters, $test), $message);
|
||||
} else {
|
||||
$this->assertFalse($this->plugin->validateFilters($input, $filters, $test), $message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function data() {
|
||||
|
||||
$body1 = <<<HELLO
|
||||
BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
ORG:Company;
|
||||
TITLE:Title
|
||||
TEL;TYPE=IPHONE;TYPE=pref:(222) 22 22 22
|
||||
TEL;TYPE=HOME:(33) 333 66 66
|
||||
TEL;TYPE=WORK:(444) 44 44 44
|
||||
TEL;TYPE=MAIN:(55) 555 55 55
|
||||
ITEM4.TEL:(111) 11 11 11
|
||||
ITEM5.TEL:(6) 66 66 66 66
|
||||
ITEM6.TEL:(77) 777 77 77
|
||||
UID:3151DE6A-BC35-4612-B340-B53A034A2B27
|
||||
ITEM1.EMAIL:1111@111.com
|
||||
ITEM2.EMAIL:bbbbb@bbbb.com
|
||||
ITEM3.EMAIL:ccccc@ccccc.com
|
||||
FN:First Last
|
||||
N:Last;First;Middle;Dr
|
||||
BDAY:1985-07-20
|
||||
ADR;TYPE=HOME:;;Street;City;;3556;Montenegro
|
||||
ADR;TYPE=WORK:;;Street\\nStreet2;Harkema;;35444;Australia
|
||||
URL:http://google.com
|
||||
END:VCARD
|
||||
HELLO;
|
||||
|
||||
// Check if TITLE is defined
|
||||
$filter1 =
|
||||
['name' => 'title', 'is-not-defined' => false, 'param-filters' => [], 'text-matches' => []];
|
||||
|
||||
// Check if FOO is defined
|
||||
$filter2 =
|
||||
['name' => 'foo', 'is-not-defined' => false, 'param-filters' => [], 'text-matches' => []];
|
||||
|
||||
// Check if TITLE is not defined
|
||||
$filter3 =
|
||||
['name' => 'title', 'is-not-defined' => true, 'param-filters' => [], 'text-matches' => []];
|
||||
|
||||
// Check if FOO is not defined
|
||||
$filter4 =
|
||||
['name' => 'foo', 'is-not-defined' => true, 'param-filters' => [], 'text-matches' => []];
|
||||
|
||||
// Check if TEL[TYPE] is defined
|
||||
$filter5 =
|
||||
[
|
||||
'name' => 'tel',
|
||||
'is-not-defined' => false,
|
||||
'test' => 'anyof',
|
||||
'param-filters' => [
|
||||
[
|
||||
'name' => 'type',
|
||||
'is-not-defined' => false,
|
||||
'text-match' => null
|
||||
],
|
||||
],
|
||||
'text-matches' => [],
|
||||
];
|
||||
|
||||
// Check if TEL[FOO] is defined
|
||||
$filter6 = $filter5;
|
||||
$filter6['param-filters'][0]['name'] = 'FOO';
|
||||
|
||||
// Check if TEL[TYPE] is not defined
|
||||
$filter7 = $filter5;
|
||||
$filter7['param-filters'][0]['is-not-defined'] = true;
|
||||
|
||||
// Check if TEL[FOO] is not defined
|
||||
$filter8 = $filter5;
|
||||
$filter8['param-filters'][0]['name'] = 'FOO';
|
||||
$filter8['param-filters'][0]['is-not-defined'] = true;
|
||||
|
||||
// Combining property filters
|
||||
$filter9 = $filter5;
|
||||
$filter9['param-filters'][] = $filter6['param-filters'][0];
|
||||
|
||||
$filter10 = $filter5;
|
||||
$filter10['param-filters'][] = $filter6['param-filters'][0];
|
||||
$filter10['test'] = 'allof';
|
||||
|
||||
// Check if URL contains 'google'
|
||||
$filter11 =
|
||||
[
|
||||
'name' => 'url',
|
||||
'is-not-defined' => false,
|
||||
'test' => 'anyof',
|
||||
'param-filters' => [],
|
||||
'text-matches' => [
|
||||
[
|
||||
'match-type' => 'contains',
|
||||
'value' => 'google',
|
||||
'negate-condition' => false,
|
||||
'collation' => 'i;octet',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
// Check if URL contains 'bing'
|
||||
$filter12 = $filter11;
|
||||
$filter12['text-matches'][0]['value'] = 'bing';
|
||||
|
||||
// Check if URL does not contain 'google'
|
||||
$filter13 = $filter11;
|
||||
$filter13['text-matches'][0]['negate-condition'] = true;
|
||||
|
||||
// Check if URL does not contain 'bing'
|
||||
$filter14 = $filter11;
|
||||
$filter14['text-matches'][0]['value'] = 'bing';
|
||||
$filter14['text-matches'][0]['negate-condition'] = true;
|
||||
|
||||
// Param filter with text
|
||||
$filter15 = $filter5;
|
||||
$filter15['param-filters'][0]['text-match'] = [
|
||||
'match-type' => 'contains',
|
||||
'value' => 'WORK',
|
||||
'collation' => 'i;octet',
|
||||
'negate-condition' => false,
|
||||
];
|
||||
$filter16 = $filter15;
|
||||
$filter16['param-filters'][0]['text-match']['negate-condition'] = true;
|
||||
|
||||
|
||||
// Param filter + text filter
|
||||
$filter17 = $filter5;
|
||||
$filter17['test'] = 'anyof';
|
||||
$filter17['text-matches'][] = [
|
||||
'match-type' => 'contains',
|
||||
'value' => '444',
|
||||
'collation' => 'i;octet',
|
||||
'negate-condition' => false,
|
||||
];
|
||||
|
||||
$filter18 = $filter17;
|
||||
$filter18['text-matches'][0]['negate-condition'] = true;
|
||||
|
||||
$filter18['test'] = 'allof';
|
||||
|
||||
return [
|
||||
|
||||
// Basic filters
|
||||
[$body1, [$filter1], 'anyof',true],
|
||||
[$body1, [$filter2], 'anyof',false],
|
||||
[$body1, [$filter3], 'anyof',false],
|
||||
[$body1, [$filter4], 'anyof',true],
|
||||
|
||||
// Combinations
|
||||
[$body1, [$filter1, $filter2], 'anyof',true],
|
||||
[$body1, [$filter1, $filter2], 'allof',false],
|
||||
[$body1, [$filter1, $filter4], 'anyof',true],
|
||||
[$body1, [$filter1, $filter4], 'allof',true],
|
||||
[$body1, [$filter2, $filter3], 'anyof',false],
|
||||
[$body1, [$filter2, $filter3], 'allof',false],
|
||||
|
||||
// Basic parameters
|
||||
[$body1, [$filter5], 'anyof', true, 'TEL;TYPE is defined, so this should return true'],
|
||||
[$body1, [$filter6], 'anyof', false, 'TEL;FOO is not defined, so this should return false'],
|
||||
|
||||
[$body1, [$filter7], 'anyof', false, 'TEL;TYPE is defined, so this should return false'],
|
||||
[$body1, [$filter8], 'anyof', true, 'TEL;TYPE is not defined, so this should return true'],
|
||||
|
||||
// Combined parameters
|
||||
[$body1, [$filter9], 'anyof', true],
|
||||
[$body1, [$filter10], 'anyof', false],
|
||||
|
||||
// Text-filters
|
||||
[$body1, [$filter11], 'anyof', true],
|
||||
[$body1, [$filter12], 'anyof', false],
|
||||
[$body1, [$filter13], 'anyof', false],
|
||||
[$body1, [$filter14], 'anyof', true],
|
||||
|
||||
// Param filter with text-match
|
||||
[$body1, [$filter15], 'anyof', true],
|
||||
[$body1, [$filter16], 'anyof', false],
|
||||
|
||||
// Param filter + text filter
|
||||
[$body1, [$filter17], 'anyof', true],
|
||||
[$body1, [$filter18], 'anyof', false],
|
||||
[$body1, [$filter18], 'anyof', false],
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,305 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV;
|
||||
|
||||
use Sabre\DAV;
|
||||
use Sabre\DAVACL;
|
||||
use Sabre\HTTP;
|
||||
|
||||
require_once 'Sabre/HTTP/ResponseMock.php';
|
||||
|
||||
class ValidateVCardTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
protected $server;
|
||||
protected $cardBackend;
|
||||
|
||||
function setUp() {
|
||||
|
||||
$addressbooks = [
|
||||
[
|
||||
'id' => 'addressbook1',
|
||||
'principaluri' => 'principals/admin',
|
||||
'uri' => 'addressbook1',
|
||||
]
|
||||
];
|
||||
|
||||
$this->cardBackend = new Backend\Mock($addressbooks, []);
|
||||
$principalBackend = new DAVACL\PrincipalBackend\Mock();
|
||||
|
||||
$tree = [
|
||||
new AddressBookRoot($principalBackend, $this->cardBackend),
|
||||
];
|
||||
|
||||
$this->server = new DAV\Server($tree);
|
||||
$this->server->sapi = new HTTP\SapiMock();
|
||||
$this->server->debugExceptions = true;
|
||||
|
||||
$plugin = new Plugin();
|
||||
$this->server->addPlugin($plugin);
|
||||
|
||||
$response = new HTTP\ResponseMock();
|
||||
$this->server->httpResponse = $response;
|
||||
|
||||
}
|
||||
|
||||
function request(HTTP\Request $request, $expectedStatus = null) {
|
||||
|
||||
$this->server->httpRequest = $request;
|
||||
$this->server->exec();
|
||||
|
||||
if ($expectedStatus) {
|
||||
|
||||
$realStatus = $this->server->httpResponse->getStatus();
|
||||
|
||||
$msg = '';
|
||||
if ($realStatus !== $expectedStatus) {
|
||||
$msg = 'Response body: ' . $this->server->httpResponse->getBodyAsString();
|
||||
}
|
||||
$this->assertEquals(
|
||||
$expectedStatus,
|
||||
$realStatus,
|
||||
$msg
|
||||
);
|
||||
}
|
||||
|
||||
return $this->server->httpResponse;
|
||||
|
||||
}
|
||||
|
||||
function testCreateFile() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'PUT',
|
||||
'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf',
|
||||
]);
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(415, $response->status);
|
||||
|
||||
}
|
||||
|
||||
function testCreateFileValid() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'PUT',
|
||||
'/addressbooks/admin/addressbook1/blabla.vcf'
|
||||
);
|
||||
|
||||
$vcard = <<<VCF
|
||||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
UID:foo
|
||||
FN:Firstname LastName
|
||||
N:LastName;FirstName;;;
|
||||
END:VCARD
|
||||
VCF;
|
||||
$request->setBody($vcard);
|
||||
|
||||
$response = $this->request($request, 201);
|
||||
|
||||
// The custom Ew header should not be set
|
||||
$this->assertNull(
|
||||
$response->getHeader('X-Sabre-Ew-Gross')
|
||||
);
|
||||
// Valid, non-auto-fixed responses should contain an ETag.
|
||||
$this->assertTrue(
|
||||
$response->getHeader('ETag') !== null,
|
||||
'We did not receive an etag'
|
||||
);
|
||||
|
||||
|
||||
$expected = [
|
||||
'uri' => 'blabla.vcf',
|
||||
'carddata' => $vcard,
|
||||
'size' => strlen($vcard),
|
||||
'etag' => '"' . md5($vcard) . '"',
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $this->cardBackend->getCard('addressbook1', 'blabla.vcf'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This test creates an intentionally broken vCard that vobject is able
|
||||
* to automatically repair.
|
||||
*
|
||||
* @depends testCreateFileValid
|
||||
*/
|
||||
function testCreateVCardAutoFix() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'PUT',
|
||||
'/addressbooks/admin/addressbook1/blabla.vcf'
|
||||
);
|
||||
|
||||
// The error in this vcard is that there's not enough semi-colons in N
|
||||
$vcard = <<<VCF
|
||||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
UID:foo
|
||||
FN:Firstname LastName
|
||||
N:LastName;FirstName;;
|
||||
END:VCARD
|
||||
VCF;
|
||||
|
||||
$request->setBody($vcard);
|
||||
|
||||
$response = $this->request($request, 201);
|
||||
|
||||
// Auto-fixed vcards should NOT return an etag
|
||||
$this->assertNull(
|
||||
$response->getHeader('ETag')
|
||||
);
|
||||
|
||||
// We should have gotten an Ew header
|
||||
$this->assertNotNull(
|
||||
$response->getHeader('X-Sabre-Ew-Gross')
|
||||
);
|
||||
|
||||
$expectedVCard = <<<VCF
|
||||
BEGIN:VCARD\r
|
||||
VERSION:4.0\r
|
||||
UID:foo\r
|
||||
FN:Firstname LastName\r
|
||||
N:LastName;FirstName;;;\r
|
||||
END:VCARD\r
|
||||
|
||||
VCF;
|
||||
|
||||
$expected = [
|
||||
'uri' => 'blabla.vcf',
|
||||
'carddata' => $expectedVCard,
|
||||
'size' => strlen($expectedVCard),
|
||||
'etag' => '"' . md5($expectedVCard) . '"',
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $this->cardBackend->getCard('addressbook1', 'blabla.vcf'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This test creates an intentionally broken vCard that vobject is able
|
||||
* to automatically repair.
|
||||
*
|
||||
* However, we're supplying a heading asking the server to treat the
|
||||
* request as strict, so the server should still let the request fail.
|
||||
*
|
||||
* @depends testCreateFileValid
|
||||
*/
|
||||
function testCreateVCardStrictFail() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'PUT',
|
||||
'/addressbooks/admin/addressbook1/blabla.vcf',
|
||||
[
|
||||
'Prefer' => 'handling=strict',
|
||||
]
|
||||
);
|
||||
|
||||
// The error in this vcard is that there's not enough semi-colons in N
|
||||
$vcard = <<<VCF
|
||||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
UID:foo
|
||||
FN:Firstname LastName
|
||||
N:LastName;FirstName;;
|
||||
END:VCARD
|
||||
VCF;
|
||||
|
||||
$request->setBody($vcard);
|
||||
$this->request($request, 415);
|
||||
|
||||
}
|
||||
|
||||
function testCreateFileNoUID() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'PUT',
|
||||
'/addressbooks/admin/addressbook1/blabla.vcf'
|
||||
);
|
||||
$vcard = <<<VCF
|
||||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
FN:Firstname LastName
|
||||
N:LastName;FirstName;;;
|
||||
END:VCARD
|
||||
VCF;
|
||||
$request->setBody($vcard);
|
||||
|
||||
$response = $this->request($request, 201);
|
||||
|
||||
$foo = $this->cardBackend->getCard('addressbook1', 'blabla.vcf');
|
||||
$this->assertTrue(
|
||||
strpos($foo['carddata'], 'UID') !== false,
|
||||
print_r($foo, true)
|
||||
);
|
||||
}
|
||||
|
||||
function testCreateFileJson() {
|
||||
|
||||
$request = new HTTP\Request(
|
||||
'PUT',
|
||||
'/addressbooks/admin/addressbook1/blabla.vcf'
|
||||
);
|
||||
$request->setBody('[ "vcard" , [ [ "VERSION", {}, "text", "4.0"], [ "UID" , {}, "text", "foo" ], [ "FN", {}, "text", "FirstName LastName"] ] ]');
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(201, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
|
||||
|
||||
$foo = $this->cardBackend->getCard('addressbook1', 'blabla.vcf');
|
||||
$this->assertEquals("BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nFN:FirstName LastName\r\nEND:VCARD\r\n", $foo['carddata']);
|
||||
|
||||
}
|
||||
|
||||
function testCreateFileVCalendar() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'PUT',
|
||||
'REQUEST_URI' => '/addressbooks/admin/addressbook1/blabla.vcf',
|
||||
]);
|
||||
$request->setBody("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n");
|
||||
|
||||
$response = $this->request($request);
|
||||
|
||||
$this->assertEquals(415, $response->status, 'Incorrect status returned! Full response body: ' . $response->body);
|
||||
|
||||
}
|
||||
|
||||
function testUpdateFile() {
|
||||
|
||||
$this->cardBackend->createCard('addressbook1', 'blabla.vcf', 'foo');
|
||||
$request = new HTTP\Request(
|
||||
'PUT',
|
||||
'/addressbooks/admin/addressbook1/blabla.vcf'
|
||||
);
|
||||
|
||||
$response = $this->request($request, 415);
|
||||
|
||||
}
|
||||
|
||||
function testUpdateFileParsableBody() {
|
||||
|
||||
$this->cardBackend->createCard('addressbook1', 'blabla.vcf', 'foo');
|
||||
$request = new HTTP\Request(
|
||||
'PUT',
|
||||
'/addressbooks/admin/addressbook1/blabla.vcf'
|
||||
);
|
||||
|
||||
$body = "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nFN:FirstName LastName\r\nEND:VCARD\r\n";
|
||||
$request->setBody($body);
|
||||
|
||||
$response = $this->request($request, 204);
|
||||
|
||||
$expected = [
|
||||
'uri' => 'blabla.vcf',
|
||||
'carddata' => $body,
|
||||
'size' => strlen($body),
|
||||
'etag' => '"' . md5($body) . '"',
|
||||
];
|
||||
|
||||
$this->assertEquals($expected, $this->cardBackend->getCard('addressbook1', 'blabla.vcf'));
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV\Xml\Property;
|
||||
|
||||
use Sabre\CardDAV;
|
||||
use Sabre\DAV;
|
||||
|
||||
class SupportedAddressDataTest extends DAV\Xml\XmlTest {
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$property = new SupportedAddressData();
|
||||
$this->assertInstanceOf('Sabre\CardDAV\Xml\Property\SupportedAddressData', $property);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testSerialize() {
|
||||
|
||||
$property = new SupportedAddressData();
|
||||
|
||||
$this->namespaceMap[CardDAV\Plugin::NS_CARDDAV] = 'card';
|
||||
$xml = $this->write(['{DAV:}root' => $property]);
|
||||
|
||||
$this->assertXmlStringEqualsXmlString(
|
||||
'<?xml version="1.0"?>
|
||||
<d:root xmlns:card="' . CardDAV\Plugin::NS_CARDDAV . '" xmlns:d="DAV:">' .
|
||||
'<card:address-data-type content-type="text/vcard" version="3.0"/>' .
|
||||
'<card:address-data-type content-type="text/vcard" version="4.0"/>' .
|
||||
'<card:address-data-type content-type="application/vcard+json" version="4.0"/>' .
|
||||
'</d:root>
|
||||
', $xml);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV\Xml\Property;
|
||||
|
||||
use Sabre\CardDAV;
|
||||
use Sabre\DAV;
|
||||
|
||||
class SupportedCollationSetTest extends DAV\Xml\XmlTest {
|
||||
|
||||
function testSimple() {
|
||||
|
||||
$property = new SupportedCollationSet();
|
||||
$this->assertInstanceOf('Sabre\CardDAV\Xml\Property\SupportedCollationSet', $property);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testSimple
|
||||
*/
|
||||
function testSerialize() {
|
||||
|
||||
$property = new SupportedCollationSet();
|
||||
|
||||
$this->namespaceMap[CardDAV\Plugin::NS_CARDDAV] = 'card';
|
||||
$xml = $this->write(['{DAV:}root' => $property]);
|
||||
|
||||
$this->assertXmlStringEqualsXmlString(
|
||||
'<?xml version="1.0"?>
|
||||
<d:root xmlns:card="' . CardDAV\Plugin::NS_CARDDAV . '" xmlns:d="DAV:">' .
|
||||
'<card:supported-collation>i;ascii-casemap</card:supported-collation>' .
|
||||
'<card:supported-collation>i;octet</card:supported-collation>' .
|
||||
'<card:supported-collation>i;unicode-casemap</card:supported-collation>' .
|
||||
'</d:root>
|
||||
', $xml);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV\Xml\Request;
|
||||
|
||||
use Sabre\DAV\Xml\XmlTest;
|
||||
|
||||
class AddressBookMultiGetTest extends XmlTest {
|
||||
|
||||
protected $elementMap = [
|
||||
'{urn:ietf:params:xml:ns:carddav}addressbook-multiget' => 'Sabre\\CardDAV\\Xml\\Request\AddressBookMultiGetReport',
|
||||
];
|
||||
|
||||
function testDeserialize() {
|
||||
|
||||
/* lines look a bit odd but this triggers an XML parsing bug */
|
||||
$xml = <<<XML
|
||||
<?xml version='1.0' encoding='UTF-8' ?>
|
||||
<CARD:addressbook-multiget xmlns="DAV:" xmlns:CARD="urn:ietf:params:xml:ns:carddav">
|
||||
<prop>
|
||||
<getcontenttype />
|
||||
<getetag />
|
||||
<CARD:address-data content-type="text/vcard" version="4.0" /></prop><href>/foo.vcf</href>
|
||||
</CARD:addressbook-multiget>
|
||||
XML;
|
||||
|
||||
$result = $this->parse($xml);
|
||||
$addressBookMultiGetReport = new AddressBookMultiGetReport();
|
||||
$addressBookMultiGetReport->properties = [
|
||||
'{DAV:}getcontenttype',
|
||||
'{DAV:}getetag',
|
||||
'{urn:ietf:params:xml:ns:carddav}address-data',
|
||||
];
|
||||
$addressBookMultiGetReport->hrefs = ['/foo.vcf'];
|
||||
$addressBookMultiGetReport->contentType = 'text/vcard';
|
||||
$addressBookMultiGetReport->version = '4.0';
|
||||
$addressBookMultiGetReport->addressDataProperties = [];
|
||||
|
||||
|
||||
$this->assertEquals(
|
||||
$addressBookMultiGetReport,
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,350 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\CardDAV\Xml\Request;
|
||||
|
||||
use Sabre\DAV\Xml\XmlTest;
|
||||
|
||||
class AddressBookQueryReportTest extends XmlTest {
|
||||
|
||||
protected $elementMap = [
|
||||
'{urn:ietf:params:xml:ns:carddav}addressbook-query' => 'Sabre\\CardDAV\\Xml\\Request\AddressBookQueryReport',
|
||||
];
|
||||
|
||||
function testDeserialize() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:prop-filter name="uid" />
|
||||
</c:filter>
|
||||
</c:addressbook-query>
|
||||
XML;
|
||||
|
||||
$result = $this->parse($xml);
|
||||
$addressBookQueryReport = new AddressBookQueryReport();
|
||||
$addressBookQueryReport->properties = [
|
||||
'{DAV:}getetag',
|
||||
];
|
||||
$addressBookQueryReport->test = 'anyof';
|
||||
$addressBookQueryReport->filters = [
|
||||
[
|
||||
'name' => 'uid',
|
||||
'test' => 'anyof',
|
||||
'is-not-defined' => false,
|
||||
'param-filters' => [],
|
||||
'text-matches' => [],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals(
|
||||
$addressBookQueryReport,
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testDeserializeAllOf() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
<c:filter test="allof">
|
||||
<c:prop-filter name="uid" />
|
||||
</c:filter>
|
||||
</c:addressbook-query>
|
||||
XML;
|
||||
|
||||
$result = $this->parse($xml);
|
||||
$addressBookQueryReport = new AddressBookQueryReport();
|
||||
$addressBookQueryReport->properties = [
|
||||
'{DAV:}getetag',
|
||||
];
|
||||
$addressBookQueryReport->test = 'allof';
|
||||
$addressBookQueryReport->filters = [
|
||||
[
|
||||
'name' => 'uid',
|
||||
'test' => 'anyof',
|
||||
'is-not-defined' => false,
|
||||
'param-filters' => [],
|
||||
'text-matches' => [],
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals(
|
||||
$addressBookQueryReport,
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testDeserializeBadTest() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
<c:filter test="bad">
|
||||
<c:prop-filter name="uid" />
|
||||
</c:filter>
|
||||
</c:addressbook-query>
|
||||
XML;
|
||||
|
||||
$this->parse($xml);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* We should error on this, but KDE does this, so we chose to support it.
|
||||
*/
|
||||
function testDeserializeNoFilter() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
</c:addressbook-query>
|
||||
XML;
|
||||
|
||||
$result = $this->parse($xml);
|
||||
$addressBookQueryReport = new AddressBookQueryReport();
|
||||
$addressBookQueryReport->properties = [
|
||||
'{DAV:}getetag',
|
||||
];
|
||||
$addressBookQueryReport->test = 'anyof';
|
||||
$addressBookQueryReport->filters = [];
|
||||
|
||||
$this->assertEquals(
|
||||
$addressBookQueryReport,
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testDeserializeComplex() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
<c:address-data content-type="application/vcard+json" version="4.0" />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:prop-filter name="uid">
|
||||
<c:is-not-defined />
|
||||
</c:prop-filter>
|
||||
<c:prop-filter name="x-foo" test="allof">
|
||||
<c:param-filter name="x-param1" />
|
||||
<c:param-filter name="x-param2">
|
||||
<c:is-not-defined />
|
||||
</c:param-filter>
|
||||
<c:param-filter name="x-param3">
|
||||
<c:text-match match-type="contains">Hello!</c:text-match>
|
||||
</c:param-filter>
|
||||
</c:prop-filter>
|
||||
<c:prop-filter name="x-prop2">
|
||||
<c:text-match match-type="starts-with" negate-condition="yes">No</c:text-match>
|
||||
</c:prop-filter>
|
||||
</c:filter>
|
||||
<c:limit><c:nresults>10</c:nresults></c:limit>
|
||||
</c:addressbook-query>
|
||||
XML;
|
||||
|
||||
$result = $this->parse($xml);
|
||||
$addressBookQueryReport = new AddressBookQueryReport();
|
||||
$addressBookQueryReport->properties = [
|
||||
'{DAV:}getetag',
|
||||
'{urn:ietf:params:xml:ns:carddav}address-data',
|
||||
];
|
||||
$addressBookQueryReport->test = 'anyof';
|
||||
$addressBookQueryReport->filters = [
|
||||
[
|
||||
'name' => 'uid',
|
||||
'test' => 'anyof',
|
||||
'is-not-defined' => true,
|
||||
'param-filters' => [],
|
||||
'text-matches' => [],
|
||||
],
|
||||
[
|
||||
'name' => 'x-foo',
|
||||
'test' => 'allof',
|
||||
'is-not-defined' => false,
|
||||
'param-filters' => [
|
||||
[
|
||||
'name' => 'x-param1',
|
||||
'is-not-defined' => false,
|
||||
'text-match' => null,
|
||||
],
|
||||
[
|
||||
'name' => 'x-param2',
|
||||
'is-not-defined' => true,
|
||||
'text-match' => null,
|
||||
],
|
||||
[
|
||||
'name' => 'x-param3',
|
||||
'is-not-defined' => false,
|
||||
'text-match' => [
|
||||
'negate-condition' => false,
|
||||
'value' => 'Hello!',
|
||||
'match-type' => 'contains',
|
||||
'collation' => 'i;unicode-casemap',
|
||||
],
|
||||
],
|
||||
],
|
||||
'text-matches' => [],
|
||||
],
|
||||
[
|
||||
'name' => 'x-prop2',
|
||||
'test' => 'anyof',
|
||||
'is-not-defined' => false,
|
||||
'param-filters' => [],
|
||||
'text-matches' => [
|
||||
[
|
||||
'negate-condition' => true,
|
||||
'value' => 'No',
|
||||
'match-type' => 'starts-with',
|
||||
'collation' => 'i;unicode-casemap',
|
||||
],
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
$addressBookQueryReport->version = '4.0';
|
||||
$addressBookQueryReport->contentType = 'application/vcard+json';
|
||||
$addressBookQueryReport->limit = 10;
|
||||
|
||||
$this->assertEquals(
|
||||
$addressBookQueryReport,
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testDeserializeBadMatchType() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:prop-filter name="x-foo" test="allof">
|
||||
<c:param-filter name="x-param3">
|
||||
<c:text-match match-type="bad">Hello!</c:text-match>
|
||||
</c:param-filter>
|
||||
</c:prop-filter>
|
||||
</c:filter>
|
||||
</c:addressbook-query>
|
||||
XML;
|
||||
$this->parse($xml);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testDeserializeBadMatchType2() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
<c:prop-filter name="x-prop2">
|
||||
<c:text-match match-type="bad" negate-condition="yes">No</c:text-match>
|
||||
</c:prop-filter>
|
||||
</c:filter>
|
||||
</c:addressbook-query>
|
||||
XML;
|
||||
$this->parse($xml);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Sabre\DAV\Exception\BadRequest
|
||||
*/
|
||||
function testDeserializeDoubleFilter() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
</d:prop>
|
||||
<c:filter>
|
||||
</c:filter>
|
||||
<c:filter>
|
||||
</c:filter>
|
||||
</c:addressbook-query>
|
||||
XML;
|
||||
$this->parse($xml);
|
||||
|
||||
}
|
||||
|
||||
function testDeserializeAddressbookElements() {
|
||||
|
||||
$xml = <<<XML
|
||||
<?xml version="1.0"?>
|
||||
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
||||
<d:prop>
|
||||
<d:getetag />
|
||||
<c:address-data>
|
||||
<c:prop name="VERSION"/>
|
||||
<c:prop name="UID"/>
|
||||
<c:prop name="NICKNAME"/>
|
||||
<c:prop name="EMAIL"/>
|
||||
<c:prop name="FN"/>
|
||||
<c:prop name="TEL"/>
|
||||
</c:address-data>
|
||||
</d:prop>
|
||||
</c:addressbook-query>
|
||||
XML;
|
||||
|
||||
$result = $this->parse($xml);
|
||||
$addressBookQueryReport = new AddressBookQueryReport();
|
||||
$addressBookQueryReport->properties = [
|
||||
'{DAV:}getetag',
|
||||
'{urn:ietf:params:xml:ns:carddav}address-data'
|
||||
];
|
||||
$addressBookQueryReport->filters = [];
|
||||
$addressBookQueryReport->test = 'anyof';
|
||||
$addressBookQueryReport->contentType = 'text/vcard';
|
||||
$addressBookQueryReport->version = '3.0';
|
||||
$addressBookQueryReport->addressDataProperties = [
|
||||
'VERSION',
|
||||
'UID',
|
||||
'NICKNAME',
|
||||
'EMAIL',
|
||||
'FN',
|
||||
'TEL',
|
||||
];
|
||||
|
||||
$this->assertEquals(
|
||||
$addressBookQueryReport,
|
||||
$result['value']
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\DAV;
|
||||
|
||||
use Sabre\HTTP;
|
||||
|
||||
abstract class AbstractServer extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Sabre\HTTP\ResponseMock
|
||||
*/
|
||||
protected $response;
|
||||
protected $request;
|
||||
/**
|
||||
* @var Sabre\DAV\Server
|
||||
*/
|
||||
protected $server;
|
||||
protected $tempDir = SABRE_TEMPDIR;
|
||||
|
||||
function setUp() {
|
||||
|
||||
$this->response = new HTTP\ResponseMock();
|
||||
$this->server = new Server($this->getRootNode());
|
||||
$this->server->sapi = new HTTP\SapiMock();
|
||||
$this->server->httpResponse = $this->response;
|
||||
$this->server->debugExceptions = true;
|
||||
$this->deleteTree(SABRE_TEMPDIR, false);
|
||||
file_put_contents(SABRE_TEMPDIR . '/test.txt', 'Test contents');
|
||||
mkdir(SABRE_TEMPDIR . '/dir');
|
||||
file_put_contents(SABRE_TEMPDIR . '/dir/child.txt', 'Child contents');
|
||||
|
||||
|
||||
}
|
||||
|
||||
function tearDown() {
|
||||
|
||||
$this->deleteTree(SABRE_TEMPDIR, false);
|
||||
|
||||
}
|
||||
|
||||
protected function getRootNode() {
|
||||
|
||||
return new FS\Directory(SABRE_TEMPDIR);
|
||||
|
||||
}
|
||||
|
||||
private function deleteTree($path, $deleteRoot = true) {
|
||||
|
||||
foreach (scandir($path) as $node) {
|
||||
|
||||
if ($node == '.' || $node == '.svn' || $node == '..') continue;
|
||||
$myPath = $path . '/' . $node;
|
||||
if (is_file($myPath)) {
|
||||
unlink($myPath);
|
||||
} else {
|
||||
$this->deleteTree($myPath);
|
||||
}
|
||||
|
||||
}
|
||||
if ($deleteRoot) rmdir($path);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,91 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\DAV\Auth\Backend;
|
||||
|
||||
use Sabre\HTTP;
|
||||
|
||||
class AbstractBasicTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function testCheckNoHeaders() {
|
||||
|
||||
$request = new HTTP\Request();
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractBasicMock();
|
||||
|
||||
$this->assertFalse(
|
||||
$backend->check($request, $response)[0]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testCheckUnknownUser() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'PHP_AUTH_USER' => 'username',
|
||||
'PHP_AUTH_PW' => 'wrongpassword',
|
||||
]);
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractBasicMock();
|
||||
|
||||
$this->assertFalse(
|
||||
$backend->check($request, $response)[0]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testCheckSuccess() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'PHP_AUTH_USER' => 'username',
|
||||
'PHP_AUTH_PW' => 'password',
|
||||
]);
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractBasicMock();
|
||||
$this->assertEquals(
|
||||
[true, 'principals/username'],
|
||||
$backend->check($request, $response)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testRequireAuth() {
|
||||
|
||||
$request = new HTTP\Request();
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractBasicMock();
|
||||
$backend->setRealm('writing unittests on a saturday night');
|
||||
$backend->challenge($request, $response);
|
||||
|
||||
$this->assertEquals(
|
||||
'Basic realm="writing unittests on a saturday night"',
|
||||
$response->getHeader('WWW-Authenticate')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class AbstractBasicMock extends AbstractBasic {
|
||||
|
||||
/**
|
||||
* Validates a username and password
|
||||
*
|
||||
* This method should return true or false depending on if login
|
||||
* succeeded.
|
||||
*
|
||||
* @param string $username
|
||||
* @param string $password
|
||||
* @return bool
|
||||
*/
|
||||
function validateUserPass($username, $password) {
|
||||
|
||||
return ($username == 'username' && $password == 'password');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,90 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\DAV\Auth\Backend;
|
||||
|
||||
use Sabre\HTTP;
|
||||
|
||||
require_once 'Sabre/HTTP/ResponseMock.php';
|
||||
|
||||
class AbstractBearerTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function testCheckNoHeaders() {
|
||||
|
||||
$request = new HTTP\Request();
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractBearerMock();
|
||||
|
||||
$this->assertFalse(
|
||||
$backend->check($request, $response)[0]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testCheckInvalidToken() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'HTTP_AUTHORIZATION' => 'Bearer foo',
|
||||
]);
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractBearerMock();
|
||||
|
||||
$this->assertFalse(
|
||||
$backend->check($request, $response)[0]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testCheckSuccess() {
|
||||
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'HTTP_AUTHORIZATION' => 'Bearer valid',
|
||||
]);
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractBearerMock();
|
||||
$this->assertEquals(
|
||||
[true, 'principals/username'],
|
||||
$backend->check($request, $response)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testRequireAuth() {
|
||||
|
||||
$request = new HTTP\Request();
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractBearerMock();
|
||||
$backend->setRealm('writing unittests on a saturday night');
|
||||
$backend->challenge($request, $response);
|
||||
|
||||
$this->assertEquals(
|
||||
'Bearer realm="writing unittests on a saturday night"',
|
||||
$response->getHeader('WWW-Authenticate')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class AbstractBearerMock extends AbstractBearer {
|
||||
|
||||
/**
|
||||
* Validates a bearer token
|
||||
*
|
||||
* This method should return true or false depending on if login
|
||||
* succeeded.
|
||||
*
|
||||
* @param string $bearerToken
|
||||
* @return bool
|
||||
*/
|
||||
function validateBearerToken($bearerToken) {
|
||||
|
||||
return 'valid' === $bearerToken ? 'principals/username' : false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,138 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Sabre\DAV\Auth\Backend;
|
||||
|
||||
use Sabre\HTTP;
|
||||
|
||||
class AbstractDigestTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
function testCheckNoHeaders() {
|
||||
|
||||
$request = new HTTP\Request();
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractDigestMock();
|
||||
$this->assertFalse(
|
||||
$backend->check($request, $response)[0]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testCheckBadGetUserInfoResponse() {
|
||||
|
||||
$header = 'username=null, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1';
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'PHP_AUTH_DIGEST' => $header,
|
||||
]);
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractDigestMock();
|
||||
$this->assertFalse(
|
||||
$backend->check($request, $response)[0]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Sabre\DAV\Exception
|
||||
*/
|
||||
function testCheckBadGetUserInfoResponse2() {
|
||||
|
||||
$header = 'username=array, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1';
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'PHP_AUTH_DIGEST' => $header,
|
||||
]);
|
||||
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractDigestMock();
|
||||
$backend->check($request, $response);
|
||||
|
||||
}
|
||||
|
||||
function testCheckUnknownUser() {
|
||||
|
||||
$header = 'username=false, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1';
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'PHP_AUTH_DIGEST' => $header,
|
||||
]);
|
||||
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractDigestMock();
|
||||
$this->assertFalse(
|
||||
$backend->check($request, $response)[0]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testCheckBadPassword() {
|
||||
|
||||
$header = 'username=user, realm=myRealm, nonce=12345, uri=/, response=HASH, opaque=1, qop=auth, nc=1, cnonce=1';
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'PHP_AUTH_DIGEST' => $header,
|
||||
'REQUEST_METHOD' => 'PUT',
|
||||
]);
|
||||
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractDigestMock();
|
||||
$this->assertFalse(
|
||||
$backend->check($request, $response)[0]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testCheck() {
|
||||
|
||||
$digestHash = md5('HELLO:12345:1:1:auth:' . md5('GET:/'));
|
||||
$header = 'username=user, realm=myRealm, nonce=12345, uri=/, response=' . $digestHash . ', opaque=1, qop=auth, nc=1, cnonce=1';
|
||||
$request = HTTP\Sapi::createFromServerArray([
|
||||
'REQUEST_METHOD' => 'GET',
|
||||
'PHP_AUTH_DIGEST' => $header,
|
||||
'REQUEST_URI' => '/',
|
||||
]);
|
||||
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractDigestMock();
|
||||
$this->assertEquals(
|
||||
[true, 'principals/user'],
|
||||
$backend->check($request, $response)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function testRequireAuth() {
|
||||
|
||||
$request = new HTTP\Request();
|
||||
$response = new HTTP\Response();
|
||||
|
||||
$backend = new AbstractDigestMock();
|
||||
$backend->setRealm('writing unittests on a saturday night');
|
||||
$backend->challenge($request, $response);
|
||||
|
||||
$this->assertStringStartsWith(
|
||||
'Digest realm="writing unittests on a saturday night"',
|
||||
$response->getHeader('WWW-Authenticate')
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class AbstractDigestMock extends AbstractDigest {
|
||||
|
||||
function getDigestHash($realm, $userName) {
|
||||
|
||||
switch ($userName) {
|
||||
case 'null' : return null;
|
||||
case 'false' : return false;
|
||||
case 'array' : return [];
|
||||
case 'user' : return 'HELLO';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user