[Pkg-owncloud-commits] [php-sabredav] 16/148: WIP on CalDAV
David Prévot
taffit at moszumanska.debian.org
Wed Apr 15 01:37:03 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit 18ef522ffafb2767e8b7fe544a604591712f50f1
Author: Evert Pot <me at evertpot.com>
Date: Fri Feb 6 00:07:51 2015 -0500
WIP on CalDAV
---
lib/CalDAV/Backend/PDO.php | 12 +--
lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php | 32 ++++---
lib/DAVACL/Plugin.php | 2 +-
lib/DAVACL/Xml/Property/Principal.php | 2 +-
tests/Sabre/CalDAV/Backend/AbstractPDOTest.php | 12 +--
.../Notifications/Notification/InviteTest.php | 2 +-
.../CalDAV/Property/ScheduleCalendarTranspTest.php | 99 ----------------------
.../Property/SupportedCalendarComponentSetTest.php | 67 ---------------
tests/Sabre/DAV/Xml/XmlTest.php | 7 ++
9 files changed, 40 insertions(+), 195 deletions(-)
diff --git a/lib/CalDAV/Backend/PDO.php b/lib/CalDAV/Backend/PDO.php
index 1fde1ab..68be859 100644
--- a/lib/CalDAV/Backend/PDO.php
+++ b/lib/CalDAV/Backend/PDO.php
@@ -130,7 +130,7 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport, S
* Many clients also require:
* {urn:ietf:params:xml:ns:caldav}supported-calendar-component-set
* For this property, you can just return an instance of
- * Sabre\CalDAV\Property\SupportedCalendarComponentSet.
+ * Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet.
*
* If you return {http://sabredav.org/ns}read-only and set the value to 1,
* ACL will automatically be put in read-only mode.
@@ -167,8 +167,8 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport, S
'principaluri' => $row['principaluri'],
'{' . CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($row['synctoken']?$row['synctoken']:'0'),
'{http://sabredav.org/ns}sync-token' => $row['synctoken']?$row['synctoken']:'0',
- '{' . CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new CalDAV\Property\SupportedCalendarComponentSet($components),
- '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-calendar-transp' => new CalDAV\Property\ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
+ '{' . CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet($components),
+ '{' . CalDAV\Plugin::NS_CALDAV . '}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp($row['transparent']?'transparent':'opaque'),
];
@@ -216,8 +216,8 @@ class PDO extends AbstractBackend implements SyncSupport, SubscriptionSupport, S
if (!isset($properties[$sccs])) {
$values[':components'] = 'VEVENT,VTODO';
} else {
- if (!($properties[$sccs] instanceof CalDAV\Property\SupportedCalendarComponentSet)) {
- throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Property\SupportedCalendarComponentSet');
+ if (!($properties[$sccs] instanceof CalDAV\Xml\Property\SupportedCalendarComponentSet)) {
+ throw new DAV\Exception('The ' . $sccs . ' property must be of type: \Sabre\CalDAV\Xml\Property\SupportedCalendarComponentSet');
}
$values[':components'] = implode(',',$properties[$sccs]->getValue());
}
@@ -982,7 +982,7 @@ SQL;
'source' => $row['source'],
'lastmodified' => $row['lastmodified'],
- '{' . CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new CalDAV\Property\SupportedCalendarComponentSet(['VTODO', 'VEVENT']),
+ '{' . CalDAV\Plugin::NS_CALDAV . '}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet(['VTODO', 'VEVENT']),
];
foreach($this->subscriptionPropertyMap as $xmlName=>$dbName) {
diff --git a/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php b/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php
index 82bacb4..6ec9d8f 100644
--- a/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php
+++ b/lib/CalDAV/Xml/Property/ScheduleCalendarTransp.php
@@ -42,7 +42,7 @@ class ScheduleCalendarTransp implements Element {
*
* @param string $value
*/
- public function __construct($value) {
+ function __construct($value) {
if ($value !== self::TRANSPARENT && $value !== self::OPAQUE) {
throw new \InvalidArgumentException('The value must either be specified as "transparent" or "opaque"');
@@ -56,28 +56,32 @@ class ScheduleCalendarTransp implements Element {
*
* @return string
*/
- public function getValue() {
+ function getValue() {
return $this->value;
}
/**
- * The serialize method is called during xml writing.
+ * The xmlSerialize metod is called during xml writing.
*
- * It should use the $writer argument to encode this object into XML.
+ * Use the $writer argument to write its own xml serialization.
*
- * Important note: it is not needed to create the parent element. The
- * parent element is already created, and we only have to worry about
- * attributes, child elements and text (if any).
+ * An important note: do _not_ create a parent element. Any element
+ * implementing XmlSerializble should only ever write what's considered
+ * its 'inner xml'.
*
- * Important note 2: If you are writing any new elements, you are also
- * responsible for closing them.
+ * The parent of the current element is responsible for writing a
+ * containing element.
+ *
+ * This allows serializers to be re-used for different element names.
+ *
+ * If you are opening new elements, you must also close them again.
*
* @param Writer $writer
* @return void
*/
- public function serializeXml(Writer $writer) {
+ function xmlSerialize(Writer $writer) {
switch($this->value) {
case self::TRANSPARENT :
@@ -99,8 +103,8 @@ class ScheduleCalendarTransp implements Element {
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
- * Important note 2: You are responsible for advancing the reader to the
- * next element. Not doing anything will result in a never-ending loop.
+ * You are responsible for advancing the reader to the next element. Not
+ * doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
@@ -111,9 +115,9 @@ class ScheduleCalendarTransp implements Element {
* @param Reader $reader
* @return mixed
*/
- static public function deserializeXml(Reader $reader) {
+ static function xmlDeserialize(Reader $reader) {
- $elems = Elements::deserializeXml($reader);
+ $elems = Elements::xmlDeserialize($reader);
$value = null;
diff --git a/lib/DAVACL/Plugin.php b/lib/DAVACL/Plugin.php
index 4298f1c..f8d9ae5 100644
--- a/lib/DAVACL/Plugin.php
+++ b/lib/DAVACL/Plugin.php
@@ -933,7 +933,7 @@ class Plugin extends DAV\ServerPlugin {
/* Adding ACL properties */
if ($node instanceof IACL) {
$propFind->handle('{DAV:}owner', function() use ($node) {
- return new DAV\Property\Href($node->getOwner() . '/');
+ return new DAV\Xml\Property\Href($node->getOwner() . '/');
});
}
diff --git a/lib/DAVACL/Xml/Property/Principal.php b/lib/DAVACL/Xml/Property/Principal.php
index 521f56c..4d9d26d 100644
--- a/lib/DAVACL/Xml/Property/Principal.php
+++ b/lib/DAVACL/Xml/Property/Principal.php
@@ -127,7 +127,7 @@ class Principal extends DAV\Xml\Property\Href {
/**
* The deserialize method is called during xml parsing.
*
- * This method is called statictly, this is because in theory this method
+ * This method is called staticly, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
diff --git a/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php b/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
index 896b428..9dcfdea 100644
--- a/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
+++ b/tests/Sabre/CalDAV/Backend/AbstractPDOTest.php
@@ -35,9 +35,9 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$backend = new PDO($this->pdo);
$returnedId = $backend->createCalendar('principals/user2','somerandomid',array(
- '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new CalDAV\Property\SupportedCalendarComponentSet(array('VEVENT')),
+ '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet(array('VEVENT')),
'{DAV:}displayname' => 'Hello!',
- '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Property\ScheduleCalendarTransp('transparent'),
+ '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp('transparent'),
));
$calendars = $backend->getCalendarsForUser('principals/user2');
@@ -46,7 +46,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
'uri' => 'somerandomid',
'{DAV:}displayname' => 'Hello!',
'{urn:ietf:params:xml:ns:caldav}calendar-description' => '',
- '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Property\ScheduleCalendarTransp('transparent'),
+ '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp('transparent'),
);
$this->assertInternalType('array',$calendars);
@@ -73,7 +73,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$propPatch = new PropPatch([
'{DAV:}displayname' => 'myCalendar',
- '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Property\ScheduleCalendarTransp('transparent'),
+ '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp('transparent'),
]);
// Updating the calendar
@@ -94,7 +94,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
'{urn:ietf:params:xml:ns:caldav}calendar-description' => '',
'{urn:ietf:params:xml:ns:caldav}calendar-timezone' => '',
'{http://calendarserver.org/ns/}getctag' => 'http://sabre.io/ns/sync/2',
- '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Property\ScheduleCalendarTransp('transparent'),
+ '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Xml\Property\ScheduleCalendarTransp('transparent'),
);
$this->assertInternalType('array',$calendars);
@@ -143,7 +143,7 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
$backend = new PDO($this->pdo);
$returnedId = $backend->createCalendar('principals/user2','somerandomid',array(
- '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new CalDAV\Property\SupportedCalendarComponentSet(array('VEVENT')),
+ '{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new CalDAV\Xml\Property\SupportedCalendarComponentSet(array('VEVENT')),
'{DAV:}displayname' => 'Hello!',
));
diff --git a/tests/Sabre/CalDAV/Notifications/Notification/InviteTest.php b/tests/Sabre/CalDAV/Notifications/Notification/InviteTest.php
index d2c114f..744e602 100644
--- a/tests/Sabre/CalDAV/Notifications/Notification/InviteTest.php
+++ b/tests/Sabre/CalDAV/Notifications/Notification/InviteTest.php
@@ -166,7 +166,7 @@ FOO
'readOnly' => false,
'hostUrl' => 'calendar',
'organizer' => 'mailto:user1 at fruux.com',
- 'supportedComponents' => new CalDAV\Property\SupportedCalendarComponentSet(array('VEVENT','VTODO')),
+ 'supportedComponents' => new CalDAV\Xml\Property\SupportedCalendarComponentSet(['VEVENT','VTODO']),
),
<<<FOO
<?xml version="1.0" encoding="UTF-8"?>
diff --git a/tests/Sabre/CalDAV/Property/ScheduleCalendarTranspTest.php b/tests/Sabre/CalDAV/Property/ScheduleCalendarTranspTest.php
deleted file mode 100644
index 68db9c8..0000000
--- a/tests/Sabre/CalDAV/Property/ScheduleCalendarTranspTest.php
+++ /dev/null
@@ -1,99 +0,0 @@
-<?php
-
-namespace Sabre\CalDAV\Property;
-
-use Sabre\CalDAV;
-use Sabre\DAV;
-
-class ScheduleCalendarTranspTest extends \PHPUnit_Framework_TestCase {
-
- function testSimple() {
-
- $sccs = new ScheduleCalendarTransp('transparent');
- $this->assertEquals('transparent', $sccs->getValue());
-
- }
-
- /**
- * @expectedException InvalidArgumentException
- */
- function testBadArg() {
-
- $sccs = new ScheduleCalendarTransp('foo');
-
- }
-
- function values() {
-
- return array(
- array('transparent'),
- array('opaque'),
- );
-
- }
-
- /**
- * @depends testSimple
- * @dataProvider values
- */
- function testSerialize($value) {
-
- $property = new ScheduleCalendarTransp($value);
-
- $doc = new \DOMDocument();
- $root = $doc->createElement('d:root');
- $root->setAttribute('xmlns:d','DAV:');
- $root->setAttribute('xmlns:cal',CalDAV\Plugin::NS_CALDAV);
-
- $doc->appendChild($root);
- $server = new DAV\Server();
-
- $property->serialize($server, $root);
-
- $xml = $doc->saveXML();
-
- $this->assertEquals(
-'<?xml version="1.0"?>
-<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '">' .
-'<cal:' . $value . '/>' .
-'</d:root>
-', $xml);
-
- }
-
- /**
- * @depends testSimple
- * @dataProvider values
- */
- function testUnserializer($value) {
-
- $xml = '<?xml version="1.0"?>
-<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '">' .
-'<cal:'.$value.'/>' .
-'</d:root>';
-
- $dom = DAV\XMLUtil::loadDOMDocument($xml);
-
- $property = ScheduleCalendarTransp::unserialize($dom->firstChild, array());
-
- $this->assertTrue($property instanceof ScheduleCalendarTransp);
- $this->assertEquals($value, $property->getValue());
-
- }
-
- /**
- * @depends testSimple
- */
- function testUnserializerBadData() {
-
- $xml = '<?xml version="1.0"?>
-<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '">' .
-'<cal:foo/>' .
-'</d:root>';
-
- $dom = DAV\XMLUtil::loadDOMDocument($xml);
-
- $this->assertNull(ScheduleCalendarTransp::unserialize($dom->firstChild, array()));
-
- }
-}
diff --git a/tests/Sabre/CalDAV/Property/SupportedCalendarComponentSetTest.php b/tests/Sabre/CalDAV/Property/SupportedCalendarComponentSetTest.php
deleted file mode 100644
index 6028ce6..0000000
--- a/tests/Sabre/CalDAV/Property/SupportedCalendarComponentSetTest.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-
-namespace Sabre\CalDAV\Property;
-
-class SupportedCalendarComponentSetTest extends \PHPUnit_Framework_TestCase {
-
- function testSimple() {
-
- $sccs = new SupportedCalendarComponentSet(array('VEVENT'));
- $this->assertEquals(array('VEVENT'), $sccs->getValue());
-
- }
-
- /**
- * @depends testSimple
- */
- function testSerialize() {
-
- $property = new SupportedCalendarComponentSet(array('VEVENT','VJOURNAL'));
-
- $doc = new \DOMDocument();
- $root = $doc->createElement('d:root');
- $root->setAttribute('xmlns:d','DAV:');
- $root->setAttribute('xmlns:cal',\Sabre\CalDAV\Plugin::NS_CALDAV);
-
- $doc->appendChild($root);
- $server = new \Sabre\DAV\Server();
-
- $property->serialize($server, $root);
-
- $xml = $doc->saveXML();
-
- $this->assertEquals(
-'<?xml version="1.0"?>
-<d:root xmlns:d="DAV:" xmlns:cal="' . \Sabre\CalDAV\Plugin::NS_CALDAV . '">' .
-'<cal:comp name="VEVENT"/>' .
-'<cal:comp name="VJOURNAL"/>' .
-'</d:root>
-', $xml);
-
- }
-
- /**
- * @depends testSimple
- */
- function testUnserializer() {
-
- $xml = '<?xml version="1.0"?>
-<d:root xmlns:d="DAV:" xmlns:cal="' . \Sabre\CalDAV\Plugin::NS_CALDAV . '">' .
-'<cal:comp name="VEVENT"/>' .
-'<cal:comp name="VJOURNAL"/>' .
-'</d:root>';
-
- $dom = \Sabre\DAV\XMLUtil::loadDOMDocument($xml);
-
- $property = SupportedCalendarComponentSet::unserialize($dom->firstChild, array());
-
- $this->assertTrue($property instanceof SupportedCalendarComponentSet);
- $this->assertEquals(array(
- 'VEVENT',
- 'VJOURNAL',
- ),
- $property->getValue());
-
- }
-
-}
diff --git a/tests/Sabre/DAV/Xml/XmlTest.php b/tests/Sabre/DAV/Xml/XmlTest.php
new file mode 100644
index 0000000..4818886
--- /dev/null
+++ b/tests/Sabre/DAV/Xml/XmlTest.php
@@ -0,0 +1,7 @@
+<?php
+
+namespace Sabre\DAV\Xml;
+
+abstract class XmlTest extends \PHPUnit_Framework_TestCase {
+
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list