[Pkg-owncloud-commits] [php-sabredav] 23/220: Merging the 'Shared' and 'Shareable' interfaces into one, sane interface.
David Prévot
taffit at moszumanska.debian.org
Thu May 12 01:21:03 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit 3c185799b3e35a0398e407cba3ca9f17fe2937ac
Author: Evert Pot <me at evertpot.com>
Date: Mon Oct 19 22:46:53 2015 -0400
Merging the 'Shared' and 'Shareable' interfaces into one, sane interface.
---
lib/CalDAV/Backend/PDO.php | 123 +++++++++++++-
lib/CalDAV/Backend/SharingSupport.php | 6 +-
lib/CalDAV/Calendar.php | 2 +-
lib/CalDAV/CalendarHome.php | 12 +-
lib/CalDAV/IShareableCalendar.php | 27 ---
lib/CalDAV/ISharedCalendar.php | 28 +---
lib/CalDAV/ShareableCalendar.php | 122 --------------
lib/CalDAV/SharedCalendar.php | 184 +++++++++++++-------
lib/DAV/Sharing/IShareableNode.php | 54 ------
lib/DAV/Sharing/ISharedNode.php | 52 +++++-
lib/DAV/Sharing/Plugin.php | 33 ++--
tests/Sabre/CalDAV/Backend/Mock.php | 54 +++---
.../CalDAV/CalendarHomeSharedCalendarsTest.php | 47 +++---
tests/Sabre/CalDAV/CalendarHomeTest.php | 45 +++--
tests/Sabre/CalDAV/CalendarObjectTest.php | 156 +++++++++--------
tests/Sabre/CalDAV/ShareableCalendarTest.php | 60 -------
tests/Sabre/CalDAV/SharedCalendarTest.php | 185 ++++++++++++---------
tests/Sabre/CalDAV/TestUtil.php | 65 +++-----
18 files changed, 600 insertions(+), 655 deletions(-)
diff --git a/lib/CalDAV/Backend/PDO.php b/lib/CalDAV/Backend/PDO.php
index 3a2741a..e109283 100644
--- a/lib/CalDAV/Backend/PDO.php
+++ b/lib/CalDAV/Backend/PDO.php
@@ -2,10 +2,11 @@
namespace Sabre\CalDAV\Backend;
-use Sabre\VObject;
use Sabre\CalDAV;
+use Sabre\CalDAV\Xml\Notification\NotificationInterface;
use Sabre\DAV;
use Sabre\DAV\Exception\Forbidden;
+use Sabre\VObject;
/**
* PDO CalDAV backend
@@ -21,8 +22,8 @@ class PDO extends AbstractBackend
implements
SyncSupport,
SubscriptionSupport,
- SchedulingSupport
- {
+ SchedulingSupport,
+ SharingSupport {
/**
* We need to specify a max date, because we need to stop *somewhere*
@@ -198,8 +199,9 @@ SQL
$stmt2 = $this->pdo->prepare('SELECT principaluri FROM ' . $this->calendarInstancesTableName . ' WHERE access = 1 AND id = ?');
$stmt2->execute([$row['id']]);
+ $calendar['share-access'] = $row['access'];
$calendar['owner_principal'] = $stmt2->fetchColumn();
- $calendar['read-only'] = $row['access'] === 3;
+ $calendar['read-only'] = $row['access'] === \Sabre\DAV\Sharing\Plugin::ACCESS_READONLY;
}
foreach ($this->propertyMap as $xmlName => $dbName) {
@@ -1314,4 +1316,117 @@ SQL;
}
+ /**
+ * Updates the list of shares.
+ *
+ * The first array is a list of people that are to be added to the
+ * calendar.
+ *
+ * Every element in the add array has the following properties:
+ * * href - A url. Usually a mailto: address
+ * * commonName - Usually a first and last name, or false
+ * * summary - A description of the share, can also be false
+ * * readOnly - A boolean value
+ *
+ * Every element in the remove array is just the address string.
+ *
+ * Note that if the calendar is currently marked as 'not shared' by and
+ * this method is called, the calendar should be 'upgraded' to a shared
+ * calendar.
+ *
+ * @param mixed $calendarId
+ * @param array $add
+ * @param array $remove
+ * @return void
+ */
+ function updateShares($calendarId, array $add, array $remove) {
+
+ throw new \Exception('Not implemented');
+
+ }
+
+ /**
+ * Returns the list of people whom this calendar is shared with.
+ *
+ * Every element in this array should have the following properties:
+ * * href - Often a mailto: address
+ * * commonName - Optional, for example a first + last name
+ * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
+ * * readOnly - boolean
+ * * summary - Optional, a description for the share
+ *
+ * This method may be called by either the original instance of the
+ * calendar, as well as the shared instances. In the case of the shared
+ * instances, it is perfectly acceptable to return an empty array in case
+ * there are privacy concerns.
+ *
+ * @param mixed $calendarId
+ * @return array
+ */
+ function getShares($calendarId) {
+
+ throw new \Exception('Not implemented');
+
+ }
+
+
+ /**
+ * This method is called when a user replied to a request to share.
+ *
+ * If the user chose to accept the share, this method should return the
+ * newly created calendar url.
+ *
+ * @param string href The sharee who is replying (often a mailto: address)
+ * @param int status One of the SharingPlugin::STATUS_* 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 null|string
+ */
+ function shareReply($href, $status, $calendarUri, $inReplyTo, $summary = null) {
+
+ throw new \Exception('Not implemented');
+
+ }
+
+ /**
+ * Publishes a calendar
+ *
+ * @param mixed $calendarId
+ * @param bool $value
+ * @return void
+ */
+ function setPublishStatus($calendarId, $value) {
+
+ throw new \Exception('Not implemented');
+
+ }
+
+ /**
+ * Returns a list of notifications for a given principal url.
+ *
+ * @param string $principalUri
+ * @return NotificationInterface[]
+ */
+ function getNotificationsForPrincipal($principalUri) {
+
+ throw new \Exception('Not implemented');
+
+ }
+
+ /**
+ * 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) {
+
+ throw new \Exception('Not implemented');
+
+ }
+
}
diff --git a/lib/CalDAV/Backend/SharingSupport.php b/lib/CalDAV/Backend/SharingSupport.php
index 6f0479a..df5453f 100644
--- a/lib/CalDAV/Backend/SharingSupport.php
+++ b/lib/CalDAV/Backend/SharingSupport.php
@@ -63,10 +63,10 @@ namespace Sabre\CalDAV\Backend;
*
* The following properties must be specified:
*
- * 1. owner-principal
+ * 1. share-access
*
- * If the calendar is shared, and the current user is not the owner, then this
- * property MUST contain information to identify the real owner.
+ * If the calendar is shared, share-access must be provided and must be one of
+ * the Sabre\DAV\Sharing\Plugin::ACCESS_ constants.
*
* 2. read-only
*
diff --git a/lib/CalDAV/Calendar.php b/lib/CalDAV/Calendar.php
index 7352a27..3319742 100644
--- a/lib/CalDAV/Calendar.php
+++ b/lib/CalDAV/Calendar.php
@@ -86,7 +86,7 @@ class Calendar implements ICalendar, DAV\IProperties, DAV\Sync\ISyncCollection,
foreach ($this->calendarInfo as $propName => $propValue) {
- if ($propName[0] === '{')
+ if (!is_null($propValue) && $propName[0] === '{')
$response[$propName] = $this->calendarInfo[$propName];
}
diff --git a/lib/CalDAV/CalendarHome.php b/lib/CalDAV/CalendarHome.php
index 93a1422..6569632 100644
--- a/lib/CalDAV/CalendarHome.php
+++ b/lib/CalDAV/CalendarHome.php
@@ -147,11 +147,7 @@ class CalendarHome implements DAV\IExtendedCollection, DAVACL\IACL {
foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
if ($calendar['uri'] === $name) {
if ($this->caldavBackend instanceof Backend\SharingSupport) {
- if (isset($calendar['{http://calendarserver.org/ns/}shared-url'])) {
- return new SharedCalendar($this->caldavBackend, $calendar);
- } else {
- return new ShareableCalendar($this->caldavBackend, $calendar);
- }
+ return new SharedCalendar($this->caldavBackend, $calendar);
} else {
return new Calendar($this->caldavBackend, $calendar);
}
@@ -198,11 +194,7 @@ class CalendarHome implements DAV\IExtendedCollection, DAVACL\IACL {
$objs = [];
foreach ($calendars as $calendar) {
if ($this->caldavBackend instanceof Backend\SharingSupport) {
- if (isset($calendar['{http://calendarserver.org/ns/}shared-url'])) {
- $objs[] = new SharedCalendar($this->caldavBackend, $calendar);
- } else {
- $objs[] = new ShareableCalendar($this->caldavBackend, $calendar);
- }
+ $objs[] = new SharedCalendar($this->caldavBackend, $calendar);
} else {
$objs[] = new Calendar($this->caldavBackend, $calendar);
}
diff --git a/lib/CalDAV/IShareableCalendar.php b/lib/CalDAV/IShareableCalendar.php
deleted file mode 100644
index c7a6dc8..0000000
--- a/lib/CalDAV/IShareableCalendar.php
+++ /dev/null
@@ -1,27 +0,0 @@
-<?php
-
-namespace Sabre\CalDAV;
-
-use Sabre\DAV\Sharing\IShareableNode;
-
-/**
- * This interface represents a Calendar that can be shared with other users.
- *
- * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
- * @author Evert Pot (http://evertpot.com/)
- * @license http://sabre.io/license/ Modified BSD License
- */
-interface IShareableCalendar extends IShareableNode {
-
- /**
- * Marks this calendar as published.
- *
- * Publishing a calendar should automatically create a read-only, public,
- * subscribable calendar.
- *
- * @param bool $value
- * @return void
- */
- function setPublishStatus($value);
-
-}
diff --git a/lib/CalDAV/ISharedCalendar.php b/lib/CalDAV/ISharedCalendar.php
index 72687e5..2aa28ff 100644
--- a/lib/CalDAV/ISharedCalendar.php
+++ b/lib/CalDAV/ISharedCalendar.php
@@ -2,6 +2,8 @@
namespace Sabre\CalDAV;
+use Sabre\DAV\Sharing\ISharedNode;
+
/**
* This interface represents a Calendar that is shared by a different user.
*
@@ -9,28 +11,16 @@ namespace Sabre\CalDAV;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-interface ISharedCalendar extends ICalendar {
-
- /**
- * This method should return the url of the owners' copy of the shared
- * calendar.
- *
- * @return string
- */
- function getSharedUrl();
+interface ISharedCalendar extends ISharedNode {
/**
- * Returns the list of people whom this calendar is shared with.
+ * Marks this calendar as published.
*
- * Every element in this array should have the following properties:
- * * href - Often a mailto: address
- * * commonName - Optional, for example a first + last name
- * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
- * * readOnly - boolean
- * * summary - Optional, a description for the share
+ * Publishing a calendar should automatically create a read-only, public,
+ * subscribable calendar.
*
- * @return array
+ * @param bool $value
+ * @return void
*/
- function getShares();
-
+ function setPublishStatus($value);
}
diff --git a/lib/CalDAV/ShareableCalendar.php b/lib/CalDAV/ShareableCalendar.php
deleted file mode 100644
index e325913..0000000
--- a/lib/CalDAV/ShareableCalendar.php
+++ /dev/null
@@ -1,122 +0,0 @@
-<?php
-
-namespace Sabre\CalDAV;
-
-/**
- * This object represents a CalDAV calendar that can be shared with other
- * users.
- *
- * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
- * @author Evert Pot (http://evertpot.com/)
- * @license http://sabre.io/license/ Modified BSD License
- */
-class ShareableCalendar extends Calendar implements IShareableCalendar {
-
- /**
- * Updates the list of shares.
- *
- * The first array is a list of people that are to be added to the
- * calendar.
- *
- * Every element in the add array has the following properties:
- * * href - A url. Usually a mailto: address
- * * commonName - Usually a first and last name, or false
- * * summary - A description of the share, can also be false
- * * readOnly - A boolean value
- *
- * Every element in the remove array is just the address string.
- *
- * @param array $add
- * @param array $remove
- * @return void
- */
- function updateShares(array $add, array $remove) {
-
- $this->caldavBackend->updateShares($this->calendarInfo['id'], $add, $remove);
-
- }
-
- /**
- * Returns the list of people whom this calendar is shared with.
- *
- * Every element in this array should have the following properties:
- * * href - Often a mailto: address
- * * commonName - Optional, for example a first + last name
- * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
- * * readOnly - boolean
- * * summary - Optional, a description for the share
- *
- * @return array
- */
- function getShares() {
-
- return $this->caldavBackend->getShares($this->calendarInfo['id']);
-
- }
-
- /**
- * Marks this calendar as published.
- *
- * Publishing a calendar should automatically create a read-only, public,
- * subscribable calendar.
- *
- * @param bool $value
- * @return void
- */
- function setPublishStatus($value) {
-
- $this->caldavBackend->setPublishStatus($this->calendarInfo['id'], $value);
-
- }
-
- /**
- * Returns a list of ACE's for this node.
- *
- * Each ACE has the following properties:
- * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
- * currently the only supported privileges
- * * 'principal', a url to the principal who owns the node
- * * 'protected' (optional), indicating that this ACE is not allowed to
- * be updated.
- *
- * @return array
- */
- function getACL() {
-
- // The top-level ACL only contains access information for the true
- // owner of the calendar, so we need to add the information for the
- // sharee.
- $acl = parent::getACL();
- $acl[] = [
- 'privilege' => '{DAV:}share',
- 'principal' => $this->calendarInfo['principaluri'],
- 'protected' => true,
- ];
- return $acl;
-
- }
-
- /**
- * Returns the list of supported privileges for this node.
- *
- * The returned data structure is a list of nested privileges.
- * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
- * standard structure.
- *
- * If null is returned from this method, the default privilege set is used,
- * which is fine for most common usecases.
- *
- * @return array|null
- */
- function getSupportedPrivilegeSet() {
-
- $default = parent::getSupportedPrivilegeSet();
- $default['aggregates'][] = [
- 'privilege' => '{DAV:}share',
- ];
-
- return $default;
-
- }
-
-}
diff --git a/lib/CalDAV/SharedCalendar.php b/lib/CalDAV/SharedCalendar.php
index 769c70d..a83ffab 100644
--- a/lib/CalDAV/SharedCalendar.php
+++ b/lib/CalDAV/SharedCalendar.php
@@ -2,6 +2,8 @@
namespace Sabre\CalDAV;
+use Sabre\DAV\Sharing\Plugin as SPlugin;
+
/**
* This object represents a CalDAV calendar that is shared by a different user.
*
@@ -12,37 +14,72 @@ namespace Sabre\CalDAV;
class SharedCalendar extends Calendar implements ISharedCalendar {
/**
- * Constructor
+ * Returns the 'access level' for the instance of this shared resource.
+ *
+ * The value should be one of the Sabre\DAV\Sharing\Plugin::ACCESS_
+ * constants.
*
- * @param Backend\BackendInterface $caldavBackend
- * @param array $calendarInfo
+ * @return int
*/
- function __construct(Backend\BackendInterface $caldavBackend, $calendarInfo) {
+ function getShareAccess() {
- $required = [
- '{http://calendarserver.org/ns/}shared-url',
- '{http://sabredav.org/ns}owner-principal',
- '{http://sabredav.org/ns}read-only',
- ];
- foreach ($required as $r) {
- if (!isset($calendarInfo[$r])) {
- throw new \InvalidArgumentException('The ' . $r . ' property must be specified for SharedCalendar(s)');
- }
- }
+ return isset($this->calendarInfo['share-access']) ? $this->calendarInfo['share-access'] : SPlugin::ACCESS_NOTSHARED;
- parent::__construct($caldavBackend, $calendarInfo);
+ }
+
+ /**
+ * Returns the list of people whom this resource is shared with.
+ *
+ * Every element in this array should have the following properties:
+ * * href - Often a mailto: address
+ * * commonName - Optional, for example a first + last name
+ * * status - See the Sabre\DAV\Sharing\Plugin::STATUS_ constants.
+ * * access - one of the Sabre\DAV\Sharing\Plugin::ACCESS_ constants.
+ *
+ * @return array
+ */
+ function getShares() {
+
+ return $this->caldavBackend->getShares($this->calendarInfo['id']);
}
/**
- * This method should return the url of the owners' copy of the shared
+ * Marks this calendar as published.
+ *
+ * Publishing a calendar should automatically create a read-only, public,
+ * subscribable calendar.
+ *
+ * @param bool $value
+ * @return void
+ */
+ function setPublishStatus($value) {
+
+ $this->caldavBackend->setPublishStatus($this->calendarInfo['id'], $value);
+
+ }
+
+ /**
+ * Updates the list of shares.
+ *
+ * The first array is a list of people that are to be added to the
* calendar.
*
- * @return string
+ * Every element in the add array has the following properties:
+ * * href - A url. Usually a mailto: address
+ * * commonName - Usually a first and last name, or false
+ * * summary - A description of the share, can also be false
+ * * readOnly - A boolean value
+ *
+ * Every element in the remove array is just the address string.
+ *
+ * @param array $add
+ * @param array $remove
+ * @return void
*/
- function getSharedUrl() {
+ function updateShares(array $add, array $remove) {
- return $this->calendarInfo['{http://calendarserver.org/ns/}shared-url'];
+ $this->caldavBackend->updateShares($this->calendarInfo['id'], $add, $remove);
}
@@ -77,29 +114,64 @@ class SharedCalendar extends Calendar implements ISharedCalendar {
// owner of the calendar, so we need to add the information for the
// sharee.
$acl = parent::getACL();
- $acl[] = [
- 'privilege' => '{DAV:}read',
- 'principal' => $this->calendarInfo['principaluri'],
- 'protected' => true,
- ];
- if ($this->calendarInfo['{http://sabredav.org/ns}read-only']) {
- $acl[] = [
- 'privilege' => '{DAV:}write-properties',
- 'principal' => $this->calendarInfo['principaluri'],
- 'protected' => true,
- ];
- } else {
- $acl[] = [
- 'privilege' => '{DAV:}write',
- 'principal' => $this->calendarInfo['principaluri'],
- 'protected' => true,
- ];
+
+ switch ($this->getShareAccess()) {
+ case SPlugin::ACCESS_NOTSHARED :
+ case SPlugin::ACCESS_OWNER :
+ $acl[] = [
+ 'privilege' => '{DAV:}share',
+ 'principal' => $this->calendarInfo['principaluri'],
+ 'protected' => true,
+ ];
+ // No break intentional!
+ case SPlugin::ACCESS_READWRITE :
+ $acl[] = [
+ 'privilege' => '{DAV:}write',
+ 'principal' => $this->calendarInfo['principaluri'],
+ 'protected' => true,
+ ];
+ // No break intentional!
+ case SPlugin::ACCESS_READONLY :
+ $acl[] = [
+ 'privilege' => '{DAV:}write-properties',
+ 'principal' => $this->calendarInfo['principaluri'],
+ 'protected' => true,
+ ];
+ $acl[] = [
+ 'privilege' => '{DAV:}write',
+ 'principal' => $this->calendarInfo['principaluri'],
+ 'protected' => true,
+ ];
+ break;
}
return $acl;
}
/**
+ * Returns the list of supported privileges for this node.
+ *
+ * The returned data structure is a list of nested privileges.
+ * See Sabre\DAVACL\Plugin::getDefaultSupportedPrivilegeSet for a simple
+ * standard structure.
+ *
+ * If null is returned from this method, the default privilege set is used,
+ * which is fine for most common usecases.
+ *
+ * @return array|null
+ */
+ function getSupportedPrivilegeSet() {
+
+ $default = parent::getSupportedPrivilegeSet();
+ $default['aggregates'][] = [
+ 'privilege' => '{DAV:}share',
+ ];
+
+ return $default;
+
+ }
+
+ /**
* This method returns the ACL's for calendar objects in this calendar.
* The result of this method automatically gets passed to the
* calendar-object nodes in the calendar.
@@ -115,33 +187,23 @@ class SharedCalendar extends Calendar implements ISharedCalendar {
'protected' => true,
];
- if (!$this->calendarInfo['{http://sabredav.org/ns}read-only']) {
- $acl[] = [
- 'privilege' => '{DAV:}write',
- 'principal' => $this->calendarInfo['principaluri'],
- 'protected' => true,
- ];
+ switch ($this->getShareAccess()) {
+ case SPlugin::ACCESS_NOTSHARED :
+ // No break intentional
+ case SPlugin::ACCESS_OWNER :
+ // No break intentional
+ case SPlugin::ACCESS_READWRITE:
+ if (!$this->calendarInfo['{http://sabredav.org/ns}read-only']) {
+ $acl[] = [
+ 'privilege' => '{DAV:}write',
+ 'principal' => $this->calendarInfo['principaluri'],
+ 'protected' => true,
+ ];
+ }
+ break;
}
- return $acl;
- }
-
-
- /**
- * Returns the list of people whom this calendar is shared with.
- *
- * Every element in this array should have the following properties:
- * * href - Often a mailto: address
- * * commonName - Optional, for example a first + last name
- * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
- * * readOnly - boolean
- * * summary - Optional, a description for the share
- *
- * @return array
- */
- function getShares() {
-
- return $this->caldavBackend->getShares($this->calendarInfo['id']);
+ return $acl;
}
diff --git a/lib/DAV/Sharing/IShareableNode.php b/lib/DAV/Sharing/IShareableNode.php
deleted file mode 100644
index 7ce7a39..0000000
--- a/lib/DAV/Sharing/IShareableNode.php
+++ /dev/null
@@ -1,54 +0,0 @@
-<?php
-
-namespace Sabre\DAV\Sharing;
-
-use Sabre\DAV\INode;
-
-/**
- * This interface represents a resource that can be shared with other users.
- *
- * This effectively is the 'sharer instance' of the node.
- *
- * @copyright Copyright (C) 2007-2015 fruux GmbH. (https://fruux.com/)
- * @author Evert Pot (http://evertpot.com/)
- * @license http://sabre.io/license/ Modified BSD License
- */
-interface IShareableNode extends INode {
-
- /**
- * Updates the list of shares.
- *
- * The first array is a list of people that are to be added to the
- * shared resource.
- *
- * Every element in the add array has the following properties:
- * * href - A url. Usually a mailto: address
- * * summary - A description of the share, can also be false
- * * readOnly - A boolean value
- *
- * In addition to that, the array might have any additional properties,
- * specified in clark-notation, such as '{DAV:}displayname'.
- *
- * Every element in the remove array is just the url of the sharee that's
- * to be removed.
- *
- * @param array $add
- * @param array $remove
- * @return void
- */
- function updateShares(array $add, array $remove);
-
- /**
- * Returns the list of people whom this resource is shared with.
- *
- * Every element in this array should have the following properties:
- * * href - Often a mailto: address
- * * commonName - Optional, for example a first + last name
- * * status - See the Sabre\DAV\Sharing\Plugin::STATUS_ constants.
- * * readOnly - boolean
- *
- * @return array
- */
- function getShares();
-
-}
diff --git a/lib/DAV/Sharing/ISharedNode.php b/lib/DAV/Sharing/ISharedNode.php
index 41a19f0..278bf5c 100644
--- a/lib/DAV/Sharing/ISharedNode.php
+++ b/lib/DAV/Sharing/ISharedNode.php
@@ -5,9 +5,9 @@ namespace Sabre\DAV\Sharing;
use Sabre\DAV\INode;
/**
- * This interface represents a resource that was shared by another user.
- *
- * This effectively is the 'sharee instance' of the node.
+ * This interface represents a resource that has sharing capabilities, either
+ * because it's possible for an owner to share the resource, or because this is
+ * an instance of a shared resource.
*
* @copyright Copyright (C) 2007-2015 fruux GmbH. (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
@@ -15,4 +15,50 @@ use Sabre\DAV\INode;
*/
interface ISharedNode extends INode {
+ /**
+ * Returns the 'access level' for the instance of this shared resource.
+ *
+ * The value should be one of the Sabre\DAV\Sharing\Plugin::ACCESS_
+ * constants.
+ *
+ * @return int
+ */
+ function getShareAccess();
+
+ /**
+ * Updates the list of shares.
+ *
+ * The first array is a list of people that are to be added to the
+ * shared resource.
+ *
+ * Every element in the add array has the following properties:
+ * * href - A url. Usually a mailto: address
+ * * summary - A description of the share, can also be false
+ * * readOnly - A boolean value
+ *
+ * In addition to that, the array might have any additional properties,
+ * specified in clark-notation, such as '{DAV:}displayname'.
+ *
+ * Every element in the remove array is just the url of the sharee that's
+ * to be removed.
+ *
+ * @param array $add
+ * @param array $remove
+ * @return void
+ */
+ function updateShares(array $add, array $remove);
+
+ /**
+ * Returns the list of people whom this resource is shared with.
+ *
+ * Every element in this array should have the following properties:
+ * * href - Often a mailto: address
+ * * commonName - Optional, for example a first + last name
+ * * status - See the Sabre\DAV\Sharing\Plugin::STATUS_ constants.
+ * * access - one of the Sabre\DAV\Sharing\Plugin::ACCESS_ constants.
+ *
+ * @return array
+ */
+ function getShares();
+
}
diff --git a/lib/DAV/Sharing/Plugin.php b/lib/DAV/Sharing/Plugin.php
index b7327aa..74be944 100644
--- a/lib/DAV/Sharing/Plugin.php
+++ b/lib/DAV/Sharing/Plugin.php
@@ -25,6 +25,11 @@ use Sabre\HTTP\ResponseInterface;
*/
class Plugin extends ServerPlugin {
+ const ACCESS_NOTSHARED = 0;
+ const ACCESS_OWNER = 1;
+ const ACCESS_READONLY = 2;
+ const ACCESS_READWRITE = 3;
+
/**
* Reference to SabreDAV server object.
*
@@ -118,7 +123,7 @@ class Plugin extends ServerPlugin {
return;
}
- if (!$node instanceof IShareableNode) {
+ if (!$node instanceof ISharedNode) {
throw new Forbidden('Sharing is not allowed on this node');
@@ -147,20 +152,28 @@ class Plugin extends ServerPlugin {
*/
function propFind(PropFind $propFind, INode $node) {
- $propFind->handle('{DAV:}share-mode', function() use ($node) {
-
- if ($node instanceof ISharedNode) {
+ if ($node instanceof ISharedNode) {
+ $propFind->handle('{DAV:}share-mode', function() use ($node) {
+ switch ($node->getShareAccess()) {
+ case self::ACCESS_NOTSHARED :
+ return null;
+ case self::ACCESS_OWNER :
+ return new Property\ShareMode(Property\ShareMode::SHAREDOWNER);
+ case self::ACCESS_READONLY :
+ return new Property\ShareMode(Property\ShareMode::SHARED);
+ case self::ACCESS_READWRITE :
+ return new Property\ShareMode(Property\ShareMode::SHARED);
- return new Property\ShareMode(Property\ShareMode::SHARED);
+ }
+ });
- } elseif ($node instanceof IShareableNode) {
+ $propFind->handle('{DAV:}share-access', function() use ($node) {
- return new Property\ShareMode(Property\ShareMode::SHAREDOWNER);
+ return new Property\ShareAccess($node->getShareAccess());
- }
-
- });
+ });
+ }
}
diff --git a/tests/Sabre/CalDAV/Backend/Mock.php b/tests/Sabre/CalDAV/Backend/Mock.php
index ea9384c..3060d19 100644
--- a/tests/Sabre/CalDAV/Backend/Mock.php
+++ b/tests/Sabre/CalDAV/Backend/Mock.php
@@ -1,6 +1,7 @@
<?php
namespace Sabre\CalDAV\Backend;
+
use Sabre\DAV;
use Sabre\CalDAV;
@@ -11,7 +12,7 @@ class Mock extends AbstractBackend {
function __construct(array $calendars = [], array $calendarData = []) {
- foreach($calendars as &$calendar) {
+ foreach ($calendars as &$calendar) {
if (!isset($calendar['id'])) {
$calendar['id'] = DAV\UUIDUtil::getUUID();
}
@@ -41,8 +42,8 @@ class Mock extends AbstractBackend {
*/
function getCalendarsForUser($principalUri) {
- $r = array();
- foreach($this->calendars as $row) {
+ $r = [];
+ foreach ($this->calendars as $row) {
if ($row['principaluri'] == $principalUri) {
$r[] = $row;
}
@@ -66,14 +67,14 @@ class Mock extends AbstractBackend {
* @param array $properties
* @return string|int
*/
- function createCalendar($principalUri,$calendarUri,array $properties) {
+ 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']),
+ 'id' => $id,
+ 'principaluri' => $principalUri,
+ 'uri' => $calendarUri,
+ '{' . CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet(['VEVENT', 'VTODO']),
], $properties);
return $id;
@@ -86,9 +87,9 @@ class Mock extends AbstractBackend {
* @param string $calendarId
* @return void
*/
- public function deleteCalendar($calendarId) {
+ function deleteCalendar($calendarId) {
- foreach($this->calendars as $k=>$calendar) {
+ foreach ($this->calendars as $k => $calendar) {
if ($calendar['id'] === $calendarId) {
unset($this->calendars[$k]);
}
@@ -118,14 +119,14 @@ class Mock extends AbstractBackend {
* @param string $calendarId
* @return array
*/
- public function getCalendarObjects($calendarId) {
+ function getCalendarObjects($calendarId) {
if (!isset($this->calendarData[$calendarId]))
- return array();
+ return [];
$objects = $this->calendarData[$calendarId];
- foreach($objects as $uri => &$object) {
+ foreach ($objects as $uri => &$object) {
$object['calendarid'] = $calendarId;
$object['uri'] = $uri;
$object['lastmodified'] = null;
@@ -146,7 +147,7 @@ class Mock extends AbstractBackend {
* @param string $objectUri
* @return array
*/
- function getCalendarObject($calendarId,$objectUri) {
+ function getCalendarObject($calendarId, $objectUri) {
if (!isset($this->calendarData[$calendarId][$objectUri])) {
throw new DAV\Exception\NotFound('Object could not be found');
@@ -167,13 +168,13 @@ class Mock extends AbstractBackend {
* @param string $calendarData
* @return void
*/
- function createCalendarObject($calendarId,$objectUri,$calendarData) {
+ function createCalendarObject($calendarId, $objectUri, $calendarData) {
- $this->calendarData[$calendarId][$objectUri] = array(
+ $this->calendarData[$calendarId][$objectUri] = [
'calendardata' => $calendarData,
- 'calendarid' => $calendarId,
- 'uri' => $objectUri,
- );
+ 'calendarid' => $calendarId,
+ 'uri' => $objectUri,
+ ];
return '"' . md5($calendarData) . '"';
}
@@ -186,13 +187,13 @@ class Mock extends AbstractBackend {
* @param string $calendarData
* @return void
*/
- function updateCalendarObject($calendarId,$objectUri,$calendarData) {
+ function updateCalendarObject($calendarId, $objectUri, $calendarData) {
- $this->calendarData[$calendarId][$objectUri] = array(
+ $this->calendarData[$calendarId][$objectUri] = [
'calendardata' => $calendarData,
- 'calendarid' => $calendarId,
- 'uri' => $objectUri,
- );
+ 'calendarid' => $calendarId,
+ 'uri' => $objectUri,
+ ];
return '"' . md5($calendarData) . '"';
}
@@ -204,10 +205,9 @@ class Mock extends AbstractBackend {
* @param string $objectUri
* @return void
*/
- function deleteCalendarObject($calendarId,$objectUri) {
-
- throw new Exception('Not implemented');
+ function deleteCalendarObject($calendarId, $objectUri) {
+ unset($this->calendarData[$calendarId][$objectUri]);
}
diff --git a/tests/Sabre/CalDAV/CalendarHomeSharedCalendarsTest.php b/tests/Sabre/CalDAV/CalendarHomeSharedCalendarsTest.php
index bfb0eae..40c5878 100644
--- a/tests/Sabre/CalDAV/CalendarHomeSharedCalendarsTest.php
+++ b/tests/Sabre/CalDAV/CalendarHomeSharedCalendarsTest.php
@@ -2,8 +2,6 @@
namespace Sabre\CalDAV;
-use Sabre\DAVACL;
-
require_once 'Sabre/CalDAV/TestUtil.php';
/**
@@ -14,29 +12,29 @@ class CalendarHomeSharedCalendarsTest extends \PHPUnit_Framework_TestCase {
function getInstance() {
- $calendars = array(
- array(
- 'id' => 1,
+ $calendars = [
+ [
+ 'id' => 1,
'principaluri' => 'principals/user1',
- ),
- array(
- 'id' => 2,
+ ],
+ [
+ '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',
- ),
- );
+ '{http://sabredav.org/ns}owner-principal' => 'principal/owner',
+ '{http://sabredav.org/ns}read-only' => false,
+ 'principaluri' => 'principals/user1',
+ ],
+ ];
$this->backend = new Backend\MockSharing(
$calendars,
- array(),
- array()
+ [],
+ []
);
- return new CalendarHome($this->backend, array(
+ return new CalendarHome($this->backend, [
'uri' => 'principals/user1'
- ));
+ ]);
}
@@ -54,27 +52,22 @@ class CalendarHomeSharedCalendarsTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals(3, count($children));
// Testing if we got all the objects back.
- $hasShareable = false;
- $hasShared = false;
+ $sharedCalendars = 0;
$hasOutbox = false;
$hasNotifications = false;
- foreach($children as $child) {
+ foreach ($children as $child) {
- if ($child instanceof IShareableCalendar) {
- $hasShareable = true;
- }
if ($child instanceof ISharedCalendar) {
- $hasShared = true;
+ $sharedCalendars++;
}
if ($child instanceof Notifications\ICollection) {
$hasNotifications = true;
}
}
- if (!$hasShareable) $this->fail('Missing node!');
- if (!$hasShared) $this->fail('Missing node!');
- if (!$hasNotifications) $this->fail('Missing node!');
+ $this->assertEquals(2, $sharedCalendars);
+ $this->assertTrue($hasNotifications);
}
diff --git a/tests/Sabre/CalDAV/CalendarHomeTest.php b/tests/Sabre/CalDAV/CalendarHomeTest.php
index 518cc99..ec238c6 100644
--- a/tests/Sabre/CalDAV/CalendarHomeTest.php
+++ b/tests/Sabre/CalDAV/CalendarHomeTest.php
@@ -2,11 +2,8 @@
namespace Sabre\CalDAV;
-use
- Sabre\DAV,
- Sabre\DAV\MkCol,
- Sabre\DAVACL;
-
+use Sabre\DAV;
+use Sabre\DAV\MkCol;
class CalendarHomeTest extends \PHPUnit_Framework_TestCase {
@@ -14,24 +11,24 @@ class CalendarHomeTest extends \PHPUnit_Framework_TestCase {
* @var Sabre\CalDAV\CalendarHome
*/
protected $usercalendars;
+
/**
- * @var Sabre\CalDAV\Backend\PDO
+ * @var Backend\BackendInterface
*/
protected $backend;
function setup() {
- if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
$this->backend = TestUtil::getBackend();
- $this->usercalendars = new CalendarHome($this->backend, array(
+ $this->usercalendars = new CalendarHome($this->backend, [
'uri' => 'principals/user1'
- ));
+ ]);
}
function testSimple() {
- $this->assertEquals('user1',$this->usercalendars->getName());
+ $this->assertEquals('user1', $this->usercalendars->getName());
}
@@ -66,33 +63,33 @@ class CalendarHomeTest extends \PHPUnit_Framework_TestCase {
function testGetACL() {
- $expected = array(
- array(
+ $expected = [
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/user1',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}write',
'principal' => 'principals/user1',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/user1/calendar-proxy-write',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}write',
'principal' => 'principals/user1/calendar-proxy-write',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/user1/calendar-proxy-read',
'protected' => true,
- ),
- );
+ ],
+ ];
$this->assertEquals($expected, $this->usercalendars->getACL());
}
@@ -102,7 +99,7 @@ class CalendarHomeTest extends \PHPUnit_Framework_TestCase {
*/
function testSetACL() {
- $this->usercalendars->setACL(array());
+ $this->usercalendars->setACL([]);
}
@@ -168,7 +165,7 @@ class CalendarHomeTest extends \PHPUnit_Framework_TestCase {
$result = $this->usercalendars->createExtendedCollection('newcalendar', $mkCol);
$this->assertNull($result);
$cals = $this->backend->getCalendarsForUser('principals/user1');
- $this->assertEquals(3,count($cals));
+ $this->assertEquals(3, count($cals));
}
diff --git a/tests/Sabre/CalDAV/CalendarObjectTest.php b/tests/Sabre/CalDAV/CalendarObjectTest.php
index 9fc1eee..248a31a 100644
--- a/tests/Sabre/CalDAV/CalendarObjectTest.php
+++ b/tests/Sabre/CalDAV/CalendarObjectTest.php
@@ -1,7 +1,6 @@
<?php
namespace Sabre\CalDAV;
-use Sabre\DAVACL;
require_once 'Sabre/CalDAV/TestUtil.php';
@@ -19,11 +18,10 @@ class CalendarObjectTest extends \PHPUnit_Framework_TestCase {
function setup() {
- if (!SABRE_HASSQLITE) $this->markTestSkipped('SQLite driver is not available');
$this->backend = TestUtil::getBackend();
$calendars = $this->backend->getCalendarsForUser('principals/user1');
- $this->assertEquals(2,count($calendars));
+ $this->assertEquals(2, count($calendars));
$this->calendar = new Calendar($this->backend, $calendars[0]);
}
@@ -40,10 +38,10 @@ class CalendarObjectTest extends \PHPUnit_Framework_TestCase {
$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; component=vevent', $children[0]->getContentType());
+ $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());
}
@@ -53,9 +51,9 @@ class CalendarObjectTest extends \PHPUnit_Framework_TestCase {
function testInvalidArg1() {
$obj = new CalendarObject(
- new Backend\Mock(array(),array()),
- array(),
- array()
+ new Backend\Mock([], []),
+ [],
+ []
);
}
@@ -66,9 +64,9 @@ class CalendarObjectTest extends \PHPUnit_Framework_TestCase {
function testInvalidArg2() {
$obj = new CalendarObject(
- new Backend\Mock(array(),array()),
- array(),
- array('calendarid' => '1')
+ new Backend\Mock([], []),
+ [],
+ ['calendarid' => '1']
);
}
@@ -96,7 +94,7 @@ class CalendarObjectTest extends \PHPUnit_Framework_TestCase {
$this->assertTrue($children[0] instanceof CalendarObject);
$newData = TestUtil::getTestCalendarData();
- $stream = fopen('php://temp','r+');
+ $stream = fopen('php://temp', 'r+');
fwrite($stream, $newData);
rewind($stream);
$children[0]->put($stream);
@@ -117,7 +115,7 @@ class CalendarObjectTest extends \PHPUnit_Framework_TestCase {
$obj->delete();
$children2 = $this->calendar->getChildren();
- $this->assertEquals(count($children)-1, count($children2));
+ $this->assertEquals(count($children) - 1, count($children2));
}
@@ -173,33 +171,33 @@ class CalendarObjectTest extends \PHPUnit_Framework_TestCase {
function testGetACL() {
- $expected = array(
- array(
+ $expected = [
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/user1',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/user1/calendar-proxy-write',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/user1/calendar-proxy-read',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}write',
'principal' => 'principals/user1',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}write',
'principal' => 'principals/user1/calendar-proxy-write',
'protected' => true,
- ),
- );
+ ],
+ ];
$children = $this->calendar->getChildren();
$this->assertTrue($children[0] instanceof CalendarObject);
@@ -213,33 +211,33 @@ class CalendarObjectTest extends \PHPUnit_Framework_TestCase {
$backend = new Backend\Mock([], []);
$calendarObject = new CalendarObject($backend, ['principaluri' => 'principals/user1'], ['calendarid' => 1, 'uri' => 'foo']);
- $expected = array(
- array(
+ $expected = [
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/user1',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}write',
'principal' => 'principals/user1',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/user1/calendar-proxy-write',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}write',
'principal' => 'principals/user1/calendar-proxy-write',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/user1/calendar-proxy-read',
'protected' => true,
- ),
- );
+ ],
+ ];
$this->assertEquals($expected, $calendarObject->getACL());
@@ -254,7 +252,7 @@ class CalendarObjectTest extends \PHPUnit_Framework_TestCase {
$this->assertTrue($children[0] instanceof CalendarObject);
$obj = $children[0];
- $obj->setACL(array());
+ $obj->setACL([]);
}
@@ -306,15 +304,15 @@ END:VCALENDAR";
function testGetRefetch() {
- $backend = new Backend\Mock(array(), array(
- 1 => array(
- 'foo' => array(
+ $backend = new Backend\Mock([], [
+ 1 => [
+ 'foo' => [
'calendardata' => 'foo',
- 'uri' => 'foo'
- ),
- )
- ));
- $obj = new CalendarObject($backend, array('id' => 1), array('uri' => 'foo'));
+ 'uri' => 'foo'
+ ],
+ ]
+ ]);
+ $obj = new CalendarObject($backend, ['id' => 1], ['uri' => 'foo']);
$this->assertEquals('foo', $obj->get());
@@ -322,15 +320,15 @@ END:VCALENDAR";
function testGetEtag1() {
- $objectInfo = array(
+ $objectInfo = [
'calendardata' => 'foo',
- 'uri' => 'foo',
- 'etag' => 'bar',
- 'calendarid' => 1
- );
+ 'uri' => 'foo',
+ 'etag' => 'bar',
+ 'calendarid' => 1
+ ];
- $backend = new Backend\Mock(array(), array());
- $obj = new CalendarObject($backend, array(), $objectInfo);
+ $backend = new Backend\Mock([], []);
+ $obj = new CalendarObject($backend, [], $objectInfo);
$this->assertEquals('bar', $obj->getETag());
@@ -338,14 +336,14 @@ END:VCALENDAR";
function testGetEtag2() {
- $objectInfo = array(
+ $objectInfo = [
'calendardata' => 'foo',
- 'uri' => 'foo',
- 'calendarid' => 1
- );
+ 'uri' => 'foo',
+ 'calendarid' => 1
+ ];
- $backend = new Backend\Mock(array(), array());
- $obj = new CalendarObject($backend, array(), $objectInfo);
+ $backend = new Backend\Mock([], []);
+ $obj = new CalendarObject($backend, [], $objectInfo);
$this->assertEquals('"' . md5('foo') . '"', $obj->getETag());
@@ -353,42 +351,42 @@ END:VCALENDAR";
function testGetSupportedPrivilegesSet() {
- $objectInfo = array(
+ $objectInfo = [
'calendardata' => 'foo',
- 'uri' => 'foo',
- 'calendarid' => 1
- );
+ 'uri' => 'foo',
+ 'calendarid' => 1
+ ];
- $backend = new Backend\Mock(array(), array());
- $obj = new CalendarObject($backend, array(), $objectInfo);
+ $backend = new Backend\Mock([], []);
+ $obj = new CalendarObject($backend, [], $objectInfo);
$this->assertNull($obj->getSupportedPrivilegeSet());
}
function testGetSize1() {
- $objectInfo = array(
+ $objectInfo = [
'calendardata' => 'foo',
- 'uri' => 'foo',
- 'calendarid' => 1
- );
+ 'uri' => 'foo',
+ 'calendarid' => 1
+ ];
- $backend = new Backend\Mock(array(), array());
- $obj = new CalendarObject($backend, array(), $objectInfo);
+ $backend = new Backend\Mock([], []);
+ $obj = new CalendarObject($backend, [], $objectInfo);
$this->assertEquals(3, $obj->getSize());
}
function testGetSize2() {
- $objectInfo = array(
- 'uri' => 'foo',
+ $objectInfo = [
+ 'uri' => 'foo',
'calendarid' => 1,
- 'size' => 4,
- );
+ 'size' => 4,
+ ];
- $backend = new Backend\Mock(array(), array());
- $obj = new CalendarObject($backend, array(), $objectInfo);
+ $backend = new Backend\Mock([], []);
+ $obj = new CalendarObject($backend, [], $objectInfo);
$this->assertEquals(4, $obj->getSize());
}
diff --git a/tests/Sabre/CalDAV/ShareableCalendarTest.php b/tests/Sabre/CalDAV/ShareableCalendarTest.php
deleted file mode 100644
index 15b869d..0000000
--- a/tests/Sabre/CalDAV/ShareableCalendarTest.php
+++ /dev/null
@@ -1,60 +0,0 @@
-<?php
-
-namespace Sabre\CalDAV;
-
-use Sabre\DAVACL;
-
-class ShareableCalendarTest extends \PHPUnit_Framework_TestCase {
-
- protected $backend;
- protected $instance;
-
- function setUp() {
-
- $props = array(
- 'id' => 1,
- );
-
- $this->backend = new Backend\MockSharing(
- array($props)
- );
- $this->backend->updateShares(1, array(
- array(
- 'href' => 'mailto:removeme at example.org',
- 'commonName' => 'To be removed',
- 'readOnly' => true,
- ),
- ), array());
-
- $this->instance = new ShareableCalendar($this->backend, $props);
-
- }
-
- function testUpdateShares() {
-
- $this->instance->updateShares(array(
- array(
- 'href' => 'mailto:test at example.org',
- 'commonName' => 'Foo Bar',
- 'summary' => 'Booh',
- 'readOnly' => false,
- ),
- ), array('mailto:removeme at example.org'));
-
- $this->assertEquals(array(array(
- 'href' => 'mailto:test at example.org',
- 'commonName' => 'Foo Bar',
- 'summary' => 'Booh',
- 'readOnly' => false,
- 'status' => SharingPlugin::STATUS_NORESPONSE,
- )), $this->instance->getShares());
-
- }
-
- function testPublish() {
-
- $this->assertNull($this->instance->setPublishStatus(true));
- $this->assertNull($this->instance->setPublishStatus(false));
-
- }
-}
diff --git a/tests/Sabre/CalDAV/SharedCalendarTest.php b/tests/Sabre/CalDAV/SharedCalendarTest.php
index 337b658..d14bd81 100644
--- a/tests/Sabre/CalDAV/SharedCalendarTest.php
+++ b/tests/Sabre/CalDAV/SharedCalendarTest.php
@@ -2,8 +2,6 @@
namespace Sabre\CalDAV;
-use Sabre\DAVACL;
-
class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
protected $backend;
@@ -11,44 +9,40 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
function getInstance(array $props = null) {
if (is_null($props)) {
- $props = array(
- 'id' => 1,
+ $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,
- 'principaluri' => 'principals/sharee',
- );
+ '{http://sabredav.org/ns}owner-principal' => 'principals/owner',
+ '{http://sabredav.org/ns}read-only' => false,
+ 'principaluri' => 'principals/sharee',
+ ];
}
$this->backend = new Backend\MockSharing(
- array($props),
- array(),
- array()
+ [$props],
+ [],
+ []
);
- $this->backend->updateShares(1, array(
- array(
- 'href' => 'mailto:removeme at example.org',
+ $this->backend->updateShares(1, [
+ [
+ 'href' => 'mailto:removeme at example.org',
'commonName' => 'To be removed',
- 'readOnly' => true,
- ),
- ), array());
+ 'readOnly' => true,
+ ],
+ ], []);
return new SharedCalendar($this->backend, $props);
}
- function testGetSharedUrl() {
- $this->assertEquals('calendars/owner/original', $this->getInstance()->getSharedUrl());
- }
-
function testGetShares() {
- $this->assertEquals(array(array(
- 'href' => 'mailto:removeme at example.org',
+ $this->assertEquals([[
+ 'href' => 'mailto:removeme at example.org',
'commonName' => 'To be removed',
- 'readOnly' => true,
- 'status' => SharingPlugin::STATUS_NORESPONSE,
- )), $this->getInstance()->getShares());
+ 'readOnly' => true,
+ 'status' => SharingPlugin::STATUS_NORESPONSE,
+ ]], $this->getInstance()->getShares());
}
@@ -58,49 +52,49 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
function testGetACL() {
- $expected = array(
- array(
+ $expected = [
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/owner',
'protected' => true,
- ),
+ ],
- array(
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/owner/calendar-proxy-write',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/owner/calendar-proxy-read',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{' . Plugin::NS_CALDAV . '}read-free-busy',
'principal' => '{DAV:}authenticated',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}write',
'principal' => 'principals/owner',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}write',
'principal' => 'principals/owner/calendar-proxy-write',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/sharee',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}write',
'principal' => 'principals/sharee',
'protected' => true,
- ),
- );
+ ],
+ ];
$this->assertEquals($expected, $this->getInstance()->getACL());
@@ -108,43 +102,43 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
function testGetChildACL() {
- $expected = array(
- array(
+ $expected = [
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/owner',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/owner/calendar-proxy-write',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/owner/calendar-proxy-read',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}write',
'principal' => 'principals/owner',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}write',
'principal' => 'principals/owner/calendar-proxy-write',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/sharee',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}write',
'principal' => 'principals/sharee',
'protected' => true,
- ),
- );
+ ],
+ ];
$this->assertEquals($expected, $this->getInstance()->getChildACL());
@@ -152,36 +146,36 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
function testGetChildACLReadOnly() {
- $expected = array(
- array(
+ $expected = [
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/owner',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/owner/calendar-proxy-write',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/owner/calendar-proxy-read',
'protected' => true,
- ),
- array(
+ ],
+ [
'privilege' => '{DAV:}read',
'principal' => 'principals/sharee',
'protected' => true,
- ),
- );
+ ],
+ ];
- $props = array(
- 'id' => 1,
+ $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' => true,
- 'principaluri' => 'principals/sharee',
- );
+ '{http://sabredav.org/ns}owner-principal' => 'principals/owner',
+ '{http://sabredav.org/ns}read-only' => true,
+ 'principaluri' => 'principals/sharee',
+ ];
$this->assertEquals($expected, $this->getInstance($props)->getChildACL());
}
@@ -189,15 +183,42 @@ class SharedCalendarTest extends \PHPUnit_Framework_TestCase {
/**
* @expectedException InvalidArgumentException
*/
- public function testCreateInstanceMissingArg() {
+ function testCreateInstanceMissingArg() {
- $this->getInstance(array(
- 'id' => 1,
+ $this->getInstance([
+ 'id' => 1,
'{http://calendarserver.org/ns/}shared-url' => 'calendars/owner/original',
- '{http://sabredav.org/ns}read-only' => false,
- 'principaluri' => 'principals/sharee',
- ));
+ '{http://sabredav.org/ns}read-only' => false,
+ 'principaluri' => 'principals/sharee',
+ ]);
}
+ function testUpdateShares() {
+
+ $this->instance->updateShares([
+ [
+ 'href' => 'mailto:test at example.org',
+ 'commonName' => 'Foo Bar',
+ 'summary' => 'Booh',
+ 'readOnly' => false,
+ ],
+ ], ['mailto:removeme at example.org']);
+
+ $this->assertEquals([[
+ 'href' => 'mailto:test at example.org',
+ 'commonName' => 'Foo Bar',
+ 'summary' => 'Booh',
+ 'readOnly' => false,
+ 'status' => SharingPlugin::STATUS_NORESPONSE,
+ ]], $this->instance->getShares());
+
+ }
+
+ function testPublish() {
+
+ $this->assertNull($this->instance->setPublishStatus(true));
+ $this->assertNull($this->instance->setPublishStatus(false));
+
+ }
}
diff --git a/tests/Sabre/CalDAV/TestUtil.php b/tests/Sabre/CalDAV/TestUtil.php
index 19acea2..673d39c 100644
--- a/tests/Sabre/CalDAV/TestUtil.php
+++ b/tests/Sabre/CalDAV/TestUtil.php
@@ -6,48 +6,29 @@ class TestUtil {
static function getBackend() {
- $backend = new Backend\PDO(self::getSQLiteDB());
- return $backend;
-
- }
-
- static function getSQLiteDB() {
-
- 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);
-
- // Yup this is definitely not 'fool proof', but good enough for now.
- $queries = explode(';', file_get_contents(__DIR__ . '/../../../examples/sql/sqlite.calendars.sql'));
- foreach($queries as $query) {
- $pdo->exec($query);
- }
- // Inserting events through a backend class.
- $backend = new Backend\PDO($pdo);
+ $backend = new Backend\Mock();
$calendarId = $backend->createCalendar(
'principals/user1',
'UUID-123467',
- array(
- '{DAV:}displayname' => 'user1 calendar',
+ [
+ '{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',
- )
+ '{http://apple.com/ns/ical/}calendar-order' => '1',
+ '{http://apple.com/ns/ical/}calendar-color' => '#FF0000',
+ ]
);
$backend->createCalendar(
'principals/user1',
'UUID-123468',
- array(
- '{DAV:}displayname' => 'user1 calendar2',
+ [
+ '{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',
- )
+ '{http://apple.com/ns/ical/}calendar-order' => '1',
+ '{http://apple.com/ns/ical/}calendar-color' => '#FF0000',
+ ]
);
$backend->createCalendarObject($calendarId, 'UUID-2345', self::getTestCalendarData());
- return $pdo;
+ return $backend;
}
@@ -80,37 +61,37 @@ TRANSP:TRANSPARENT
SUMMARY:Something here
DTSTAMP:20100228T130202Z';
- switch($type) {
+ switch ($type) {
case 1 :
- $calendarData.="\nDTSTART;TZID=Asia/Seoul:20100223T060000\nDTEND;TZID=Asia/Seoul:20100223T070000\n";
+ $calendarData .= "\nDTSTART;TZID=Asia/Seoul:20100223T060000\nDTEND;TZID=Asia/Seoul:20100223T070000\n";
break;
case 2 :
- $calendarData.="\nDTSTART:20100223T060000\nDTEND:20100223T070000\n";
+ $calendarData .= "\nDTSTART:20100223T060000\nDTEND:20100223T070000\n";
break;
case 3 :
- $calendarData.="\nDTSTART;VALUE=DATE:20100223\nDTEND;VALUE=DATE:20100223\n";
+ $calendarData .= "\nDTSTART;VALUE=DATE:20100223\nDTEND;VALUE=DATE:20100223\n";
break;
case 4 :
- $calendarData.="\nDTSTART;TZID=Asia/Seoul:20100223T060000\nDURATION:PT1H\n";
+ $calendarData .= "\nDTSTART;TZID=Asia/Seoul:20100223T060000\nDURATION:PT1H\n";
break;
case 5 :
- $calendarData.="\nDTSTART;TZID=Asia/Seoul:20100223T060000\nDURATION:-P5D\n";
+ $calendarData .= "\nDTSTART;TZID=Asia/Seoul:20100223T060000\nDURATION:-P5D\n";
break;
case 6 :
- $calendarData.="\nDTSTART;VALUE=DATE:20100223\n";
+ $calendarData .= "\nDTSTART;VALUE=DATE:20100223\n";
break;
case 7 :
- $calendarData.="\nDTSTART;VALUE=DATETIME:20100223T060000\n";
+ $calendarData .= "\nDTSTART;VALUE=DATETIME:20100223T060000\n";
break;
// No DTSTART, so intentionally broken
case 'X' :
- $calendarData.="\n";
+ $calendarData .= "\n";
break;
}
- $calendarData.='ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa at example.com
+ $calendarData .= 'ATTENDEE;PARTSTAT=NEEDS-ACTION:mailto:lisa at example.com
SEQUENCE:2
END:VEVENT
END:VCALENDAR';
@@ -121,7 +102,7 @@ END:VCALENDAR';
static function getTestTODO($type = 'due') {
- switch($type) {
+ switch ($type) {
case 'due' :
$extra = "DUE:20100104T000000Z";
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-php/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list