[Pkg-owncloud-commits] [php-sabredav] 21/148: Moved notifications to new xml framework.

David Prévot taffit at moszumanska.debian.org
Wed Apr 15 01:37:04 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 f47061fa0b2af8c9bd417bbdca2b090c3679763a
Author: Evert Pot <me at evertpot.com>
Date:   Fri Feb 6 21:18:45 2015 -0500

    Moved notifications to new xml framework.
---
 lib/CalDAV/Backend/NotificationSupport.php         |  11 +-
 lib/CalDAV/Notifications/INotificationType.php     |  44 -----
 lib/CalDAV/Notifications/Node.php                  |   5 +-
 .../Notifications/Notification/InviteReply.php     | 218 ---------------------
 .../Notifications/Notification/SystemStatus.php    | 182 -----------------
 lib/CalDAV/Notifications/Plugin.php                |  18 +-
 lib/CalDAV/Xml/Notification/InviteReply.php        |  47 ++---
 lib/CalDAV/Xml/Notification/SystemStatus.php       |  20 +-
 lib/DAV/XMLUtil.php                                |  18 +-
 tests/Sabre/CalDAV/Backend/MockSharing.php         |  24 +--
 .../CalDAV/ExpandEventsDTSTARTandDTENDTest.php     |   6 +-
 .../Sabre/CalDAV/Notifications/CollectionTest.php  |   2 +-
 tests/Sabre/CalDAV/Notifications/NodeTest.php      |  10 +-
 .../Notification/SystemStatusTest.php              |  61 ------
 tests/Sabre/CalDAV/Notifications/PluginTest.php    |  30 +--
 .../Notification/InviteReplyTest.php               |  47 +++--
 .../CalDAV/Xml/Notification/SystemStatusTest.php   |  67 +++++++
 17 files changed, 199 insertions(+), 611 deletions(-)

diff --git a/lib/CalDAV/Backend/NotificationSupport.php b/lib/CalDAV/Backend/NotificationSupport.php
index 47de1b0..6ccac64 100644
--- a/lib/CalDAV/Backend/NotificationSupport.php
+++ b/lib/CalDAV/Backend/NotificationSupport.php
@@ -2,6 +2,8 @@
 
 namespace Sabre\CalDAV\Backend;
 
+use Sabre\CalDAV\Xml\Notification\NotificationInterface;
+
 /**
  * Adds caldav notification support to a backend.
  *
@@ -25,11 +27,8 @@ interface NotificationSupport extends BackendInterface {
     /**
      * 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
+     * @return NotificationInterface[]
      */
     function getNotificationsForPrincipal($principalUri);
 
@@ -39,9 +38,9 @@ interface NotificationSupport extends BackendInterface {
      * This may be called by a client once it deems a notification handled.
      *
      * @param string $principalUri
-     * @param \Sabre\CalDAV\Notifications\INotificationType $notification
+     * @param NotificationInterface $notification
      * @return void
      */
-    function deleteNotification($principalUri, \Sabre\CalDAV\Notifications\INotificationType $notification);
+    function deleteNotification($principalUri, NotificationInterface $notification);
 
 }
diff --git a/lib/CalDAV/Notifications/INotificationType.php b/lib/CalDAV/Notifications/INotificationType.php
deleted file mode 100644
index 17c8add..0000000
--- a/lib/CalDAV/Notifications/INotificationType.php
+++ /dev/null
@@ -1,44 +0,0 @@
-<?php
-
-namespace Sabre\CalDAV\Notifications;
-use Sabre\DAV;
-
-/**
- * This interface reflects a single notification type.
- *
- * @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 INotificationType extends DAV\PropertyInterface {
-
-    /**
-     * This method serializes the entire notification, as it is used in the
-     * response body.
-     *
-     * @param DAV\Server $server
-     * @param \DOMElement $node
-     * @return void
-     */
-    function serializeBody(DAV\Server $server, \DOMElement $node);
-
-    /**
-     * Returns a unique id for this notification
-     *
-     * This is just the base url. This should generally be some kind of unique
-     * id.
-     *
-     * @return string
-     */
-    function getId();
-
-    /**
-     * Returns the ETag for this notification.
-     *
-     * The ETag must be surrounded by literal double-quotes.
-     *
-     * @return string
-     */
-    function getETag();
-
-}
diff --git a/lib/CalDAV/Notifications/Node.php b/lib/CalDAV/Notifications/Node.php
index 644ea0d..c88fcf5 100644
--- a/lib/CalDAV/Notifications/Node.php
+++ b/lib/CalDAV/Notifications/Node.php
@@ -4,6 +4,7 @@ namespace Sabre\CalDAV\Notifications;
 
 use Sabre\DAV;
 use Sabre\CalDAV;
+use Sabre\CalDAV\Xml\Notification\NotificationInterface;
 use Sabre\DAVACL;
 
 /**
@@ -45,9 +46,9 @@ class Node extends DAV\File implements INode, DAVACL\IACL {
      *
      * @param CalDAV\Backend\NotificationSupport $caldavBackend
      * @param string $principalUri
-     * @param CalDAV\Notifications\INotificationType $notification
+     * @param NotificationInterface $notification
      */
-    function __construct(CalDAV\Backend\NotificationSupport $caldavBackend, $principalUri, INotificationType $notification) {
+    function __construct(CalDAV\Backend\NotificationSupport $caldavBackend, $principalUri, NotificationInterface $notification) {
 
         $this->caldavBackend = $caldavBackend;
         $this->principalUri = $principalUri;
diff --git a/lib/CalDAV/Notifications/Notification/InviteReply.php b/lib/CalDAV/Notifications/Notification/InviteReply.php
deleted file mode 100644
index dec01d8..0000000
--- a/lib/CalDAV/Notifications/Notification/InviteReply.php
+++ /dev/null
@@ -1,218 +0,0 @@
-<?php
-
-namespace Sabre\CalDAV\Notifications\Notification;
-
-use Sabre\CalDAV\SharingPlugin as SharingPlugin;
-use Sabre\DAV;
-use Sabre\CalDAV;
-
-/**
- * This class represents the cs:invite-reply notification element.
- *
- * @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 InviteReply extends DAV\Property implements CalDAV\Notifications\INotificationType {
-
-    /**
-     * A unique id for the message
-     *
-     * @var string
-     */
-    protected $id;
-
-    /**
-     * Timestamp of the notification
-     *
-     * @var DateTime
-     */
-    protected $dtStamp;
-
-    /**
-     * The unique id of the notification this was a reply to.
-     *
-     * @var string
-     */
-    protected $inReplyTo;
-
-    /**
-     * A url to the recipient of the original (!) notification.
-     *
-     * @var string
-     */
-    protected $href;
-
-    /**
-     * The type of message, see the SharingPlugin::STATUS_ constants.
-     *
-     * @var int
-     */
-    protected $type;
-
-    /**
-     * A url to the shared calendar.
-     *
-     * @var string
-     */
-    protected $hostUrl;
-
-    /**
-     * A description of the share request
-     *
-     * @var string
-     */
-    protected $summary;
-
-    /**
-     * Notification Etag
-     *
-     * @var string
-     */
-    protected $etag;
-
-    /**
-     * Creates the Invite Reply Notification.
-     *
-     * This constructor receives an array with the following elements:
-     *
-     *   * id           - A unique id
-     *   * etag         - The etag
-     *   * dtStamp      - A DateTime object with a timestamp for the notification.
-     *   * inReplyTo    - This should refer to the 'id' of the notification
-     *                    this is a reply to.
-     *   * type         - The type of notification, see SharingPlugin::STATUS_*
-     *                    constants for details.
-     *   * hostUrl      - A url to the shared calendar.
-     *   * summary      - Description of the share, can be the same as the
-     *                    calendar, but may also be modified (optional).
-     */
-    function __construct(array $values) {
-
-        $required = [
-            'id',
-            'etag',
-            'href',
-            'dtStamp',
-            'inReplyTo',
-            'type',
-            'hostUrl',
-        ];
-        foreach($required as $item) {
-            if (!isset($values[$item])) {
-                throw new \InvalidArgumentException($item . ' is a required constructor option');
-            }
-        }
-
-        foreach($values as $key=>$value) {
-            if (!property_exists($this, $key)) {
-                throw new \InvalidArgumentException('Unknown option: ' . $key);
-            }
-            $this->$key = $value;
-        }
-
-    }
-
-    /**
-     * Serializes the notification as a single property.
-     *
-     * You should usually just encode the single top-level element of the
-     * notification.
-     *
-     * @param DAV\Server $server
-     * @param \DOMElement $node
-     * @return void
-     */
-    function serialize(DAV\Server $server, \DOMElement $node) {
-
-        $prop = $node->ownerDocument->createElement('cs:invite-reply');
-        $node->appendChild($prop);
-
-    }
-
-    /**
-     * This method serializes the entire notification, as it is used in the
-     * response body.
-     *
-     * @param DAV\Server $server
-     * @param \DOMElement $node
-     * @return void
-     */
-    function serializeBody(DAV\Server $server, \DOMElement $node) {
-
-        $doc = $node->ownerDocument;
-
-        $dt = $doc->createElement('cs:dtstamp');
-        $this->dtStamp->setTimezone(new \DateTimezone('GMT'));
-        $dt->appendChild($doc->createTextNode($this->dtStamp->format('Ymd\\THis\\Z')));
-        $node->appendChild($dt);
-
-        $prop = $doc->createElement('cs:invite-reply');
-        $node->appendChild($prop);
-
-        $uid = $doc->createElement('cs:uid');
-        $uid->appendChild($doc->createTextNode($this->id));
-        $prop->appendChild($uid);
-
-        $inReplyTo = $doc->createElement('cs:in-reply-to');
-        $inReplyTo->appendChild( $doc->createTextNode($this->inReplyTo) );
-        $prop->appendChild($inReplyTo);
-
-        $href = $doc->createElement('d:href');
-        $href->appendChild( $doc->createTextNode($this->href) );
-        $prop->appendChild($href);
-
-        $nodeName = null;
-        switch($this->type) {
-
-            case SharingPlugin::STATUS_ACCEPTED :
-                $nodeName = 'cs:invite-accepted';
-                break;
-            case SharingPlugin::STATUS_DECLINED :
-                $nodeName = 'cs:invite-declined';
-                break;
-
-        }
-        $prop->appendChild(
-            $doc->createElement($nodeName)
-        );
-        $hostHref = $doc->createElement('d:href', $server->getBaseUri() . $this->hostUrl);
-        $hostUrl  = $doc->createElement('cs:hosturl');
-        $hostUrl->appendChild($hostHref);
-        $prop->appendChild($hostUrl);
-
-        if ($this->summary) {
-            $summary = $doc->createElement('cs:summary');
-            $summary->appendChild($doc->createTextNode($this->summary));
-            $prop->appendChild($summary);
-        }
-
-    }
-
-    /**
-     * Returns a unique id for this notification
-     *
-     * This is just the base url. This should generally be some kind of unique
-     * id.
-     *
-     * @return string
-     */
-    function getId() {
-
-        return $this->id;
-
-    }
-
-    /**
-     * Returns the ETag for this notification.
-     *
-     * The ETag must be surrounded by literal double-quotes.
-     *
-     * @return string
-     */
-    function getETag() {
-
-        return $this->etag;
-
-    }
-}
diff --git a/lib/CalDAV/Notifications/Notification/SystemStatus.php b/lib/CalDAV/Notifications/Notification/SystemStatus.php
deleted file mode 100644
index 10d2187..0000000
--- a/lib/CalDAV/Notifications/Notification/SystemStatus.php
+++ /dev/null
@@ -1,182 +0,0 @@
-<?php
-
-namespace Sabre\CalDAV\Notifications\Notification;
-
-use Sabre\DAV;
-use Sabre\CalDAV;
-
-/**
- * SystemStatus notification
- *
- * This notification can be used to indicate to the user that the system is
- * down.
- *
- * @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 SystemStatus extends DAV\Property implements CalDAV\Notifications\INotificationType {
-
-    const TYPE_LOW = 1;
-    const TYPE_MEDIUM = 2;
-    const TYPE_HIGH = 3;
-
-    /**
-     * A unique id
-     *
-     * @var string
-     */
-    protected $id;
-
-    /**
-     * The type of alert. This should be one of the TYPE_ constants.
-     *
-     * @var int
-     */
-    protected $type;
-
-    /**
-     * A human-readable description of the problem.
-     *
-     * @var string
-     */
-    protected $description;
-
-    /**
-     * A url to a website with more information for the user.
-     *
-     * @var string
-     */
-    protected $href;
-
-    /**
-     * Notification Etag
-     *
-     * @var string
-     */
-    protected $etag;
-
-    /**
-     * Creates the notification.
-     *
-     * Some kind of unique id should be provided. This is used to generate a
-     * url.
-     *
-     * @param string $id
-     * @param string $etag
-     * @param int $type
-     * @param string $description
-     * @param string $href
-     */
-    function __construct($id, $etag, $type = self::TYPE_HIGH, $description = null, $href = null) {
-
-        $this->id = $id;
-        $this->type = $type;
-        $this->description = $description;
-        $this->href = $href;
-        $this->etag = $etag;
-
-    }
-
-    /**
-     * Serializes the notification as a single property.
-     *
-     * You should usually just encode the single top-level element of the
-     * notification.
-     *
-     * @param DAV\Server $server
-     * @param \DOMElement $node
-     * @return void
-     */
-    function serialize(DAV\Server $server, \DOMElement $node) {
-
-        switch($this->type) {
-            case self::TYPE_LOW :
-                $type = 'low';
-                break;
-            case self::TYPE_MEDIUM :
-                $type = 'medium';
-                break;
-            default :
-            case self::TYPE_HIGH :
-                $type = 'high';
-                break;
-        }
-
-        $prop = $node->ownerDocument->createElement('cs:systemstatus');
-        $prop->setAttribute('type', $type);
-
-        $node->appendChild($prop);
-
-    }
-
-    /**
-     * This method serializes the entire notification, as it is used in the
-     * response body.
-     *
-     * @param DAV\Server $server
-     * @param \DOMElement $node
-     * @return void
-     */
-    function serializeBody(DAV\Server $server, \DOMElement $node) {
-
-        switch($this->type) {
-            case self::TYPE_LOW :
-                $type = 'low';
-                break;
-            case self::TYPE_MEDIUM :
-                $type = 'medium';
-                break;
-            default :
-            case self::TYPE_HIGH :
-                $type = 'high';
-                break;
-        }
-
-        $prop = $node->ownerDocument->createElement('cs:systemstatus');
-        $prop->setAttribute('type', $type);
-
-        if ($this->description) {
-            $text = $node->ownerDocument->createTextNode($this->description);
-            $desc = $node->ownerDocument->createElement('cs:description');
-            $desc->appendChild($text);
-            $prop->appendChild($desc);
-        }
-        if ($this->href) {
-            $text = $node->ownerDocument->createTextNode($this->href);
-            $href = $node->ownerDocument->createElement('d:href');
-            $href->appendChild($text);
-            $prop->appendChild($href);
-        }
-
-        $node->appendChild($prop);
-
-    }
-
-    /**
-     * Returns a unique id for this notification
-     *
-     * This is just the base url. This should generally be some kind of unique
-     * id.
-     *
-     * @return string
-     */
-    function getId() {
-
-        return $this->id;
-
-    }
-
-    /*
-     * Returns the ETag for this notification.
-     *
-     * The ETag must be surrounded by literal double-quotes.
-     *
-     * @return string
-     */
-    function getETag() {
-
-        return $this->etag;
-
-    }
-}
diff --git a/lib/CalDAV/Notifications/Plugin.php b/lib/CalDAV/Notifications/Plugin.php
index 448345e..67a5cdb 100644
--- a/lib/CalDAV/Notifications/Plugin.php
+++ b/lib/CalDAV/Notifications/Plugin.php
@@ -137,22 +137,16 @@ class Plugin extends ServerPlugin {
         if (!$node instanceof INode)
             return;
 
-        $dom = new \DOMDocument('1.0', 'UTF-8');
-
-        $dom->formatOutput = true;
-
-        $root = $dom->createElement('cs:notification');
-        foreach($this->server->xmlNamespaces as $namespace => $prefix) {
-            $root->setAttribute('xmlns:' . $prefix, $namespace);
-        }
-
-        $dom->appendChild($root);
-        $node->getNotificationType()->serializeBody($this->server, $root);
+        $writer = $this->server->xml->getWriter();
+        $writer->startDocument('1.0', 'UTF-8');
+        $writer->startElement('{http://calendarserver.org/ns/}notification');
+        $node->getNotificationType()->xmlSerializeFull($writer);
+        $writer->endElement();
 
         $response->setHeader('Content-Type','application/xml');
         $response->setHeader('ETag',$node->getETag());
         $response->setStatus(200);
-        $response->setBody($dom->saveXML());
+        $response->setBody($writer->outputMemory());
 
         // Return false to break the event chain.
         return false;
diff --git a/lib/CalDAV/Xml/Notification/InviteReply.php b/lib/CalDAV/Xml/Notification/InviteReply.php
index 554d89c..b1a0f62 100644
--- a/lib/CalDAV/Xml/Notification/InviteReply.php
+++ b/lib/CalDAV/Xml/Notification/InviteReply.php
@@ -2,13 +2,12 @@
 
 namespace Sabre\CalDAV\Xml\Notification;
 
-use
-    Sabre\Xml\Element,
-    Sabre\Xml\Reader,
-    Sabre\Xml\Writer,
-    Sabre\DAV,
-    Sabre\CalDAV,
-    Sabre\CalDAV\SharingPlugin;
+use Sabre\Xml\Element;
+use Sabre\Xml\Reader;
+use Sabre\Xml\Writer;
+use Sabre\DAV;
+use Sabre\CalDAV;
+use Sabre\CalDAV\SharingPlugin;
 
 /**
  * This class represents the cs:invite-reply notification element.
@@ -91,9 +90,9 @@ class InviteReply implements NotificationInterface {
      *   * summary      - Description of the share, can be the same as the
      *                    calendar, but may also be modified (optional).
      */
-    public function __construct(array $values) {
+    function __construct(array $values) {
 
-        $required = array(
+        $required = [
             'id',
             'etag',
             'href',
@@ -101,7 +100,7 @@ class InviteReply implements NotificationInterface {
             'inReplyTo',
             'type',
             'hostUrl',
-        );
+        ];
         foreach($required as $item) {
             if (!isset($values[$item])) {
                 throw new \InvalidArgumentException($item . ' is a required constructor option');
@@ -118,21 +117,25 @@ class InviteReply implements NotificationInterface {
     }
 
     /**
-     * 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) {
 
         $writer->writeElement('{' . CalDAV\Plugin::NS_CALENDARSERVER .'}invite-reply');
 
@@ -145,7 +148,7 @@ class InviteReply implements NotificationInterface {
      * @param Writer $writer
      * @return void
      */
-    public function serializeFullXml(Writer $writer) {
+    function xmlSerializeFull(Writer $writer) {
 
         $cs = '{' . CalDAV\Plugin::NS_CALENDARSERVER . '}';
 
@@ -188,7 +191,7 @@ class InviteReply implements NotificationInterface {
      *
      * @return string
      */
-    public function getId() {
+    function getId() {
 
         return $this->id;
 
@@ -201,7 +204,7 @@ class InviteReply implements NotificationInterface {
      *
      * @return string
      */
-    public function getETag() {
+    function getETag() {
 
         return $this->etag;
 
@@ -228,7 +231,7 @@ class InviteReply implements NotificationInterface {
      * @param Reader $reader
      * @return mixed
      */
-    static public function deserializeXml(Reader $reader) {
+    static function deserializeXml(Reader $reader) {
 
         throw new CannotDeserialize('This element does not have a deserializer');
 
diff --git a/lib/CalDAV/Xml/Notification/SystemStatus.php b/lib/CalDAV/Xml/Notification/SystemStatus.php
index fac9259..95009ff 100644
--- a/lib/CalDAV/Xml/Notification/SystemStatus.php
+++ b/lib/CalDAV/Xml/Notification/SystemStatus.php
@@ -2,11 +2,9 @@
 
 namespace Sabre\CalDAV\Xml\Notification;
 
-use
-    Sabre\Xml\Reader,
-    Sabre\Xml\Writer,
-    Sabre\CalDAV\Plugin,
-    Sabre\DAV\Exception\CannotSerialize;
+use Sabre\Xml\Reader;
+use Sabre\Xml\Writer;
+use Sabre\CalDAV\Plugin;
 
 
 /**
@@ -72,7 +70,7 @@ class SystemStatus implements NotificationInterface {
      * @param string $description
      * @param string $href
      */
-    public function __construct($id, $etag, $type = self::TYPE_HIGH, $description = null, $href = null) {
+    function __construct($id, $etag, $type = self::TYPE_HIGH, $description = null, $href = null) {
 
         $this->id = $id;
         $this->type = $type;
@@ -97,7 +95,7 @@ class SystemStatus implements NotificationInterface {
      * @param Writer $writer
      * @return void
      */
-    public function serializeXml(Writer $writer) {
+    function xmlSerialize(Writer $writer) {
 
         switch($this->type) {
             case self::TYPE_LOW :
@@ -125,7 +123,7 @@ class SystemStatus implements NotificationInterface {
      * @param Writer $writer
      * @return void
      */
-    public function serializeFullXml(Writer $writer) {
+    function xmlSerializeFull(Writer $writer) {
 
         $cs = '{' . Plugin::NS_CALENDARSERVER .'}';
         switch($this->type) {
@@ -164,7 +162,7 @@ class SystemStatus implements NotificationInterface {
      *
      * @return string
      */
-    public function getId() {
+    function getId() {
 
         return $this->id;
 
@@ -177,7 +175,7 @@ class SystemStatus implements NotificationInterface {
      *
      * @return string
      */
-    public function getETag() {
+    function getETag() {
 
         return $this->etag;
 
@@ -204,7 +202,7 @@ class SystemStatus implements NotificationInterface {
      * @param Reader $reader
      * @return mixed
      */
-    static public function deserializeXml(Reader $reader) {
+    static function deserializeXml(Reader $reader) {
 
         throw new CannotDeserialize('This element does not have a deserializer');
 
diff --git a/lib/DAV/XMLUtil.php b/lib/DAV/XMLUtil.php
index 3e06af6..9d04f24 100644
--- a/lib/DAV/XMLUtil.php
+++ b/lib/DAV/XMLUtil.php
@@ -78,13 +78,27 @@ class XMLUtil {
      */
     function write($output, $baseUri = null) {
 
+        $writer = $this->getWriter($baseUri);
+        $writer->write($output);
+        return $writer->outputMemory();
+
+    }
+
+    /**
+     * Returns a fully configured xml writer, ready to start writing into
+     * memory.
+     *
+     * @parama string $baseUri
+     * @return XML\Writer
+     */
+    function getWriter($baseUri = null) {
+
         $writer = new XML\Writer();
         $writer->baseUri = $baseUri;
         $writer->namespaceMap = $this->namespaceMap;
         $writer->openMemory();
         $writer->setIndent(true);
-        $writer->write($output);
-        return $writer->outputMemory();
+        return $writer;
 
     }
 
diff --git a/tests/Sabre/CalDAV/Backend/MockSharing.php b/tests/Sabre/CalDAV/Backend/MockSharing.php
index f9cd8dc..2156627 100644
--- a/tests/Sabre/CalDAV/Backend/MockSharing.php
+++ b/tests/Sabre/CalDAV/Backend/MockSharing.php
@@ -1,12 +1,14 @@
 <?php
 
 namespace Sabre\CalDAV\Backend;
+
 use Sabre\DAV;
 use Sabre\CalDAV;
+use Sabre\CalDAV\Xml\Notification\NotificationInterface;
 
 class MockSharing extends Mock implements NotificationSupport, SharingSupport {
 
-    private $shares = array();
+    private $shares = [];
     private $notifications;
 
     function __construct(array $calendars = [], array $calendarData = [], array $notifications = []) {
@@ -25,12 +27,12 @@ class MockSharing extends Mock implements NotificationSupport, SharingSupport {
      * @param string $principalUri
      * @return array
      */
-    public function getNotificationsForPrincipal($principalUri) {
+    function getNotificationsForPrincipal($principalUri) {
 
         if (isset($this->notifications[$principalUri])) {
             return $this->notifications[$principalUri];
         }
-        return array();
+        return [];
 
     }
 
@@ -40,10 +42,10 @@ class MockSharing extends Mock implements NotificationSupport, SharingSupport {
      * This may be called by a client once it deems a notification handled.
      *
      * @param string $principalUri
-     * @param Sabre\CalDAV\Notifications\INotificationType $notification
+     * @param NotificationInterface $notification
      * @return void
      */
-    public function deleteNotification($principalUri, CalDAV\Notifications\INotificationType $notification) {
+    function deleteNotification($principalUri, NotificationInterface $notification) {
 
         foreach($this->notifications[$principalUri] as $key=>$value) {
             if ($notification === $value) {
@@ -76,10 +78,10 @@ class MockSharing extends Mock implements NotificationSupport, SharingSupport {
      * @param array $remove
      * @return void
      */
-    public function updateShares($calendarId, array $add, array $remove) {
+    function updateShares($calendarId, array $add, array $remove) {
 
         if (!isset($this->shares[$calendarId])) {
-            $this->shares[$calendarId] = array();
+            $this->shares[$calendarId] = [];
         }
 
         foreach($add as $val) {
@@ -113,10 +115,10 @@ class MockSharing extends Mock implements NotificationSupport, SharingSupport {
      * @param mixed $calendarId
      * @return array
      */
-    public function getShares($calendarId) {
+    function getShares($calendarId) {
 
         if (!isset($this->shares[$calendarId])) {
-            return array();
+            return [];
         }
 
         return $this->shares[$calendarId];
@@ -133,7 +135,7 @@ class MockSharing extends Mock implements NotificationSupport, SharingSupport {
      * @param string $summary A description of the reply
      * @return void
      */
-    public function shareReply($href, $status, $calendarUri, $inReplyTo, $summary = null) {
+    function shareReply($href, $status, $calendarUri, $inReplyTo, $summary = null) {
 
         // This operation basically doesn't do anything yet
         if ($status === CalDAV\SharingPlugin::STATUS_ACCEPTED) {
@@ -149,7 +151,7 @@ class MockSharing extends Mock implements NotificationSupport, SharingSupport {
      * @param bool $value
      * @return void
      */
-    public function setPublishStatus($calendarId, $value) {
+    function setPublishStatus($calendarId, $value) {
 
         foreach($this->calendars as $k=>$cal) {
             if ($cal['id'] === $calendarId) {
diff --git a/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php b/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php
index 0f86bc6..c9279cc 100644
--- a/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php
+++ b/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php
@@ -87,7 +87,11 @@ END:VCALENDAR
         );
         $body = str_replace('
','',$body);
 
-        $vObject = VObject\Reader::read($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) {
diff --git a/tests/Sabre/CalDAV/Notifications/CollectionTest.php b/tests/Sabre/CalDAV/Notifications/CollectionTest.php
index 940ab05..6803518 100644
--- a/tests/Sabre/CalDAV/Notifications/CollectionTest.php
+++ b/tests/Sabre/CalDAV/Notifications/CollectionTest.php
@@ -14,7 +14,7 @@ class CollectionTest extends \PHPUnit_Framework_TestCase {
 
         $this->principalUri = 'principals/user1';
 
-        $this->notification = new Notification\SystemStatus(1,'"1"');
+        $this->notification = new CalDAV\Xml\Notification\SystemStatus(1,'"1"');
 
         $this->caldavBackend = new CalDAV\Backend\MockSharing(array(),array(), array(
             'principals/user1' => array(
diff --git a/tests/Sabre/CalDAV/Notifications/NodeTest.php b/tests/Sabre/CalDAV/Notifications/NodeTest.php
index a0906d3..d546116 100644
--- a/tests/Sabre/CalDAV/Notifications/NodeTest.php
+++ b/tests/Sabre/CalDAV/Notifications/NodeTest.php
@@ -13,13 +13,13 @@ class NodeTest extends \PHPUnit_Framework_TestCase {
 
         $principalUri = 'principals/user1';
 
-        $this->systemStatus = new Notification\SystemStatus(1,'"1"');
+        $this->systemStatus = new CalDAV\Xml\Notification\SystemStatus(1,'"1"');
 
-        $this->caldavBackend = new CalDAV\Backend\MockSharing(array(),array(), array(
-            'principals/user1' => array(
+        $this->caldavBackend = new CalDAV\Backend\MockSharing([], [], [
+            'principals/user1' => [
                 $this->systemStatus
-            )
-        )); 
+            ]
+        ]);
 
         $node = new Node($this->caldavBackend, 'principals/user1', $this->systemStatus);
         return $node;
diff --git a/tests/Sabre/CalDAV/Notifications/Notification/SystemStatusTest.php b/tests/Sabre/CalDAV/Notifications/Notification/SystemStatusTest.php
deleted file mode 100644
index 8dc4949..0000000
--- a/tests/Sabre/CalDAV/Notifications/Notification/SystemStatusTest.php
+++ /dev/null
@@ -1,61 +0,0 @@
-<?php
-
-namespace Sabre\CalDAV\Notifications\Notification;
-
-use Sabre\CalDAV;
-use Sabre\DAV;
-
-class SystemStatusTest extends \PHPUnit_Framework_TestCase {
-
-    /**
-     * @dataProvider dataProvider
-     */
-    function testSerializers($notification, $expected1, $expected2) {
-
-        $this->assertEquals('foo', $notification->getId());
-        $this->assertEquals('"1"', $notification->getETag());
-
-
-        $dom = new \DOMDocument('1.0','UTF-8');
-        $elem = $dom->createElement('cs:root');
-        $elem->setAttribute('xmlns:cs',CalDAV\Plugin::NS_CALENDARSERVER);
-        $dom->appendChild($elem);
-        $notification->serialize(new DAV\Server(), $elem);
-        $this->assertEquals($expected1, $dom->saveXML());
-
-        $dom = new \DOMDocument('1.0','UTF-8');
-        $elem = $dom->createElement('cs:root');
-        $elem->setAttribute('xmlns:cs',CalDAV\Plugin::NS_CALENDARSERVER);
-        $dom->appendChild($elem);
-        $notification->serializeBody(new DAV\Server(), $elem);
-        $this->assertEquals($expected2, $dom->saveXML());
-
-
-    }
-
-    function dataProvider() {
-
-        return array(
-
-            array(
-                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/"><cs:systemstatus type="high"/></cs:root>' . "\n",
-            ),
-
-            array(
-                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/"><cs:systemstatus type="medium"><cs:description>bar</cs:description></cs:systemstatus></cs:root>' . "\n",
-            ),
-
-            array(
-                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/"><cs:systemstatus type="low"><d:href>http://example.org/</d:href></cs:systemstatus></cs:root>' . "\n",
-            )
-        );
-
-    }
-
-}
diff --git a/tests/Sabre/CalDAV/Notifications/PluginTest.php b/tests/Sabre/CalDAV/Notifications/PluginTest.php
index 8426373..f240955 100644
--- a/tests/Sabre/CalDAV/Notifications/PluginTest.php
+++ b/tests/Sabre/CalDAV/Notifications/PluginTest.php
@@ -1,10 +1,14 @@
 <?php
 
 namespace Sabre\CalDAV\Notifications;
-use Sabre\DAVACL;
+
 use Sabre\DAV;
+use Sabre\DAVACL;
 use Sabre\CalDAV;
+use Sabre\CalDAV\Xml\Notification\SystemStatus;
 use Sabre\HTTP;
+use Sabre\HTTP\Request;
+
 
 class PluginTest extends \PHPUnit_Framework_TestCase {
 
@@ -69,14 +73,12 @@ class PluginTest extends \PHPUnit_Framework_TestCase {
 
     function testPrincipalProperties() {
 
-        $httpRequest = HTTP\Sapi::createFromServerArray(array(
-            'HTTP_HOST' => 'sabredav.org',
-        ));
+        $httpRequest = new Request('GET', '/', ['Host' => 'sabredav.org']);
         $this->server->httpRequest = $httpRequest;
 
-        $props = $this->server->getPropertiesForPath('/principals/user1',array(
+        $props = $this->server->getPropertiesForPath('/principals/user1',[
             '{' . Plugin::NS_CALENDARSERVER . '}notification-URL',
-        ));
+        ]);
 
         $this->assertArrayHasKey(0,$props);
         $this->assertArrayHasKey(200,$props[0]);
@@ -94,7 +96,7 @@ class PluginTest extends \PHPUnit_Framework_TestCase {
         $notification = new Node(
             $this->caldavBackend,
             'principals/user1',
-            new Notification\SystemStatus('foo','"1"')
+            new SystemStatus('foo','"1"')
         );
         $propFind = new DAV\PropFind('calendars/user1/notifications', [
             '{' . Plugin::NS_CALENDARSERVER . '}notificationtype',
@@ -114,15 +116,13 @@ class PluginTest extends \PHPUnit_Framework_TestCase {
         $notification = new Node(
             $this->caldavBackend,
             'principals/user1',
-            new Notification\SystemStatus('foo','"1"')
+            new SystemStatus('foo','"1"')
         );
 
-        $server = new DAV\Server(array($notification));
+        $server = new DAV\Server([$notification]);
         $caldav = new Plugin();
 
-        $server->httpRequest = HTTP\Sapi::createFromServerArray(array(
-            'REQUEST_URI' => '/foo.xml',
-        ));
+        $server->httpRequest = new Request('GET', '/foo.xml');
         $httpResponse = new HTTP\ResponseMock();
         $server->httpResponse = $httpResponse;
 
@@ -131,15 +131,15 @@ class PluginTest extends \PHPUnit_Framework_TestCase {
         $caldav->httpGet($server->httpRequest, $server->httpResponse);
 
         $this->assertEquals(200, $httpResponse->status);
-        $this->assertEquals(array(
+        $this->assertEquals([
             'Content-Type' => ['application/xml'],
             'ETag'         => ['"1"'],
-        ), $httpResponse->getHeaders());
+        ], $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:systemstatus type="high"/>
 </cs:notification>
 ';
 
diff --git a/tests/Sabre/CalDAV/Notifications/Notification/InviteReplyTest.php b/tests/Sabre/CalDAV/Xml/Notification/InviteReplyTest.php
similarity index 74%
rename from tests/Sabre/CalDAV/Notifications/Notification/InviteReplyTest.php
rename to tests/Sabre/CalDAV/Xml/Notification/InviteReplyTest.php
index c53f68c..a5e0342 100644
--- a/tests/Sabre/CalDAV/Notifications/Notification/InviteReplyTest.php
+++ b/tests/Sabre/CalDAV/Xml/Notification/InviteReplyTest.php
@@ -1,9 +1,10 @@
 <?php
 
-namespace Sabre\CalDAV\Notifications\Notification;
+namespace Sabre\CalDAV\Xml\Notification;
 
 use Sabre\CalDAV;
 use Sabre\DAV;
+use Sabre\Xml\Writer;
 
 class InviteReplyTest extends \PHPUnit_Framework_TestCase {
 
@@ -17,23 +18,33 @@ class InviteReplyTest extends \PHPUnit_Framework_TestCase {
         $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>' . "\n";
-
-        $dom = new \DOMDocument('1.0','UTF-8');
-        $elem = $dom->createElement('cs:root');
-        $elem->setAttribute('xmlns:cs',CalDAV\Plugin::NS_CALENDARSERVER);
-        $dom->appendChild($elem);
-        $notification->serialize(new DAV\Server(), $elem);
-        $this->assertEquals($simpleExpected, $dom->saveXML());
-
-        $dom = new \DOMDocument('1.0','UTF-8');
-        $dom->formatOutput = true;
-        $elem = $dom->createElement('cs:root');
-        $elem->setAttribute('xmlns:cs',CalDAV\Plugin::NS_CALENDARSERVER);
-        $elem->setAttribute('xmlns:d','DAV:');
-        $dom->appendChild($elem);
-        $notification->serializeBody(new DAV\Server(), $elem);
-        $this->assertEquals($expected, $dom->saveXML());
+        $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->baseUri = '/';
+        $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());
 
 
     }
diff --git a/tests/Sabre/CalDAV/Xml/Notification/SystemStatusTest.php b/tests/Sabre/CalDAV/Xml/Notification/SystemStatusTest.php
new file mode 100644
index 0000000..54251e0
--- /dev/null
+++ b/tests/Sabre/CalDAV/Xml/Notification/SystemStatusTest.php
@@ -0,0 +1,67 @@
+<?php
+
+namespace Sabre\CalDAV\Xml\Notification;
+
+use Sabre\CalDAV;
+use Sabre\DAV;
+use Sabre\Xml\Writer;
+
+class SystemStatusTest extends \PHPUnit_Framework_TestCase {
+
+    /**
+     * @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",
+            ]
+        ];
+
+    }
+
+}

-- 
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