[Pkg-owncloud-commits] [php-sabredav] 19/148: Moved Invite notification to new xml system.

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 abb1d72345eafd820ae6f3e3e1aed15d0d5628f2
Author: Evert Pot <me at evertpot.com>
Date:   Fri Feb 6 01:06:50 2015 -0500

    Moved Invite notification to new xml system.
---
 lib/CalDAV/Notifications/Notification/Invite.php   | 324 ---------------------
 lib/CalDAV/Xml/Notification/Invite.php             |  12 +-
 .../Xml/Notification/NotificationInterface.php     |   9 +-
 .../Notification/InviteTest.php                    |  54 ++--
 tests/Sabre/DAV/Xml/XmlTest.php                    |  15 +
 5 files changed, 55 insertions(+), 359 deletions(-)

diff --git a/lib/CalDAV/Notifications/Notification/Invite.php b/lib/CalDAV/Notifications/Notification/Invite.php
deleted file mode 100644
index 055500d..0000000
--- a/lib/CalDAV/Notifications/Notification/Invite.php
+++ /dev/null
@@ -1,324 +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-notification 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 Invite 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;
-
-    /**
-     * A url to the recipient of the notification. This can be an email
-     * address (mailto:), or a principal url.
-     *
-     * @var string
-     */
-    protected $href;
-
-    /**
-     * The type of message, see the SharingPlugin::STATUS_* constants.
-     *
-     * @var int
-     */
-    protected $type;
-
-    /**
-     * True if access to a calendar is read-only.
-     *
-     * @var bool
-     */
-    protected $readOnly;
-
-    /**
-     * A url to the shared calendar.
-     *
-     * @var string
-     */
-    protected $hostUrl;
-
-    /**
-     * Url to the sharer of the calendar
-     *
-     * @var string
-     */
-    protected $organizer;
-
-    /**
-     * The name of the sharer.
-     *
-     * @var string
-     */
-    protected $commonName;
-
-    /**
-     * The name of the sharer.
-     *
-     * @var string
-     */
-    protected $firstName;
-
-    /**
-     * The name of the sharer.
-     *
-     * @var string
-     */
-    protected $lastName;
-
-    /**
-     * A description of the share request
-     *
-     * @var string
-     */
-    protected $summary;
-
-    /**
-     * The Etag for the notification
-     *
-     * @var string
-     */
-    protected $etag;
-
-    /**
-     * The list of supported components
-     *
-     * @var Sabre\CalDAV\Property\SupportedCalendarComponentSet
-     */
-    protected $supportedComponents;
-
-    /**
-     * Creates the Invite 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.
-     *   * type         - The type of notification, see SharingPlugin::STATUS_*
-     *                    constants for details.
-     *   * readOnly     - This must be set to true, if this is an invite for
-     *                    read-only access to a calendar.
-     *   * hostUrl      - A url to the shared calendar.
-     *   * organizer    - Url to the sharer principal.
-     *   * commonName   - The real name of the sharer (optional).
-     *   * firstName    - The first name of the sharer (optional).
-     *   * lastName     - The last name of the sharer (optional).
-     *   * summary      - Description of the share, can be the same as the
-     *                    calendar, but may also be modified (optional).
-     *   * supportedComponents - An instance of
-     *                    Sabre\CalDAV\Property\SupportedCalendarComponentSet.
-     *                    This allows the client to determine which components
-     *                    will be supported in the shared calendar. This is
-     *                    also optional.
-     *
-     * @param array $values All the options
-     */
-    function __construct(array $values) {
-
-        $required = [
-            'id',
-            'etag',
-            'href',
-            'dtStamp',
-            'type',
-            'readOnly',
-            'hostUrl',
-            'organizer',
-        ];
-        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-notification');
-        $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-notification');
-        $node->appendChild($prop);
-
-        $uid = $doc->createElement('cs:uid');
-        $uid->appendChild( $doc->createTextNode($this->id) );
-        $prop->appendChild($uid);
-
-        $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;
-            case SharingPlugin::STATUS_DELETED :
-                $nodeName = 'cs:invite-deleted';
-                break;
-            case SharingPlugin::STATUS_NORESPONSE :
-                $nodeName = 'cs:invite-noresponse';
-                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);
-
-        $access = $doc->createElement('cs:access');
-        if ($this->readOnly) {
-            $access->appendChild($doc->createElement('cs:read'));
-        } else {
-            $access->appendChild($doc->createElement('cs:read-write'));
-        }
-        $prop->appendChild($access);
-
-        $organizerUrl  = $doc->createElement('cs:organizer');
-        // If the organizer contains a 'mailto:' part, it means it should be
-        // treated as absolute.
-        if (strtolower(substr($this->organizer,0,7))==='mailto:') {
-            $organizerHref = new DAV\Property\Href($this->organizer, false);
-        } else {
-            $organizerHref = new DAV\Property\Href($this->organizer, true);
-        }
-        $organizerHref->serialize($server, $organizerUrl);
-
-        if ($this->commonName) {
-            $commonName = $doc->createElement('cs:common-name');
-            $commonName->appendChild($doc->createTextNode($this->commonName));
-            $organizerUrl->appendChild($commonName);
-
-            $commonNameOld = $doc->createElement('cs:organizer-cn');
-            $commonNameOld->appendChild($doc->createTextNode($this->commonName));
-            $prop->appendChild($commonNameOld);
-
-        }
-        if ($this->firstName) {
-            $firstName = $doc->createElement('cs:first-name');
-            $firstName->appendChild($doc->createTextNode($this->firstName));
-            $organizerUrl->appendChild($firstName);
-
-            $firstNameOld = $doc->createElement('cs:organizer-first');
-            $firstNameOld->appendChild($doc->createTextNode($this->firstName));
-            $prop->appendChild($firstNameOld);
-        }
-        if ($this->lastName) {
-            $lastName = $doc->createElement('cs:last-name');
-            $lastName->appendChild($doc->createTextNode($this->lastName));
-            $organizerUrl->appendChild($lastName);
-
-            $lastNameOld = $doc->createElement('cs:organizer-last');
-            $lastNameOld->appendChild($doc->createTextNode($this->lastName));
-            $prop->appendChild($lastNameOld);
-        }
-        $prop->appendChild($organizerUrl);
-
-        if ($this->summary) {
-            $summary = $doc->createElement('cs:summary');
-            $summary->appendChild($doc->createTextNode($this->summary));
-            $prop->appendChild($summary);
-        }
-        if ($this->supportedComponents) {
-
-            $xcomp = $doc->createElement('cal:supported-calendar-component-set');
-            $this->supportedComponents->serialize($server, $xcomp);
-            $prop->appendChild($xcomp);
-
-        }
-
-    }
-
-    /**
-     * 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/Xml/Notification/Invite.php b/lib/CalDAV/Xml/Notification/Invite.php
index 6d53c88..7f11ff6 100644
--- a/lib/CalDAV/Xml/Notification/Invite.php
+++ b/lib/CalDAV/Xml/Notification/Invite.php
@@ -141,7 +141,7 @@ class Invite implements NotificationInterface {
      *
      * @param array $values All the options
      */
-    public function __construct(array $values) {
+    function __construct(array $values) {
 
         $required = array(
             'id',
@@ -183,7 +183,7 @@ class Invite implements NotificationInterface {
      * @param Writer $writer
      * @return void
      */
-    public function serializeXml(Writer $writer) {
+    function xmlSerialize(Writer $writer) {
 
         $writer->writeElement('{' . CalDAV\Plugin::NS_CALENDARSERVER .'}invite-notification');
 
@@ -196,7 +196,7 @@ class Invite implements NotificationInterface {
      * @param Writer $writer
      * @return void
      */
-    public function serializeFullXml(Writer $writer) {
+    function xmlSerializeFull(Writer $writer) {
 
         $cs = '{' . CalDAV\Plugin::NS_CALENDARSERVER . '}';
 
@@ -285,7 +285,7 @@ class Invite implements NotificationInterface {
      *
      * @return string
      */
-    public function getId() {
+    function getId() {
 
         return $this->id;
 
@@ -298,7 +298,7 @@ class Invite implements NotificationInterface {
      *
      * @return string
      */
-    public function getETag() {
+    function getETag() {
 
         return $this->etag;
 
@@ -325,7 +325,7 @@ class Invite 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/NotificationInterface.php b/lib/CalDAV/Xml/Notification/NotificationInterface.php
index 06c0a67..2f1b077 100644
--- a/lib/CalDAV/Xml/Notification/NotificationInterface.php
+++ b/lib/CalDAV/Xml/Notification/NotificationInterface.php
@@ -2,9 +2,8 @@
 
 namespace Sabre\CalDAV\Xml\Notification;
 
-use
-    Sabre\Xml\Element,
-    Sabre\Xml\Writer;
+use Sabre\Xml\XmlSerializable;
+use Sabre\Xml\Writer;
 
 /**
  * This interface reflects a single notification type.
@@ -13,7 +12,7 @@ use
  * @author Evert Pot (http://evertpot.com/)
  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  */
-interface NotificationInterface extends Element {
+interface NotificationInterface extends XmlSerializable {
 
     /**
      * This method serializes the entire notification, as it is used in the
@@ -22,7 +21,7 @@ interface NotificationInterface extends Element {
      * @param Writer $writer
      * @return void
      */
-    function serializeFullXml(Writer $writer);
+    function xmlSerializeFull(Writer $writer);
 
     /**
      * Returns a unique id for this notification
diff --git a/tests/Sabre/CalDAV/Notifications/Notification/InviteTest.php b/tests/Sabre/CalDAV/Xml/Notification/InviteTest.php
similarity index 84%
rename from tests/Sabre/CalDAV/Notifications/Notification/InviteTest.php
rename to tests/Sabre/CalDAV/Xml/Notification/InviteTest.php
index 744e602..c8e7ca7 100644
--- a/tests/Sabre/CalDAV/Notifications/Notification/InviteTest.php
+++ b/tests/Sabre/CalDAV/Xml/Notification/InviteTest.php
@@ -1,11 +1,12 @@
 <?php
 
-namespace Sabre\CalDAV\Notifications\Notification;
+namespace Sabre\CalDAV\Xml\Notification;
 
 use Sabre\CalDAV;
 use Sabre\DAV;
+use Sabre\Xml\Writer;
 
-class InviteTest extends \PHPUnit_Framework_TestCase {
+class InviteTest extends DAV\Xml\XmlTest {
 
     /**
      * @dataProvider dataProvider
@@ -17,24 +18,17 @@ class InviteTest 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-notification/></cs:root>' . "\n";
+        $simpleExpected = '<cs:invite-notification xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/" />' . "\n";
+        $this->namespaceMap['http://calendarserver.org/ns/'] = 'cs';
 
-        $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());
+        $xml = $this->write($notification);
 
-        $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:');
-        $elem->setAttribute('xmlns:cal',CalDAV\Plugin::NS_CALDAV);
-        $dom->appendChild($elem);
-        $notification->serializeBody(new DAV\Server(), $elem);
-        $this->assertEquals($expected, $dom->saveXML());
+        $this->assertXmlStringEqualsXmlString($simpleExpected, $xml);
+        
+        $this->namespaceMap['urn:ietf:params:xml:ns:caldav'] = 'cal';
+        $xml = $this->writeFull($notification);
+
+        $this->assertXmlStringEqualsXmlString($expected, $xml);
 
 
     }
@@ -67,15 +61,15 @@ class InviteTest extends \PHPUnit_Framework_TestCase {
     <cs:hosturl>
       <d:href>/calendar</d:href>
     </cs:hosturl>
+    <cs:summary>Awesome stuff!</cs:summary>
     <cs:access>
       <cs:read/>
     </cs:access>
-    <cs:organizer-cn>John Doe</cs:organizer-cn>
     <cs:organizer>
       <d:href>/principal/user1</d:href>
       <cs:common-name>John Doe</cs:common-name>
     </cs:organizer>
-    <cs:summary>Awesome stuff!</cs:summary>
+    <cs:organizer-cn>John Doe</cs:organizer-cn>
   </cs:invite-notification>
 </cs:root>
 
@@ -107,14 +101,13 @@ FOO
     <cs:access>
       <cs:read/>
     </cs:access>
-    <cs:organizer-cn>John Doe</cs:organizer-cn>
     <cs:organizer>
       <d:href>/principal/user1</d:href>
       <cs:common-name>John Doe</cs:common-name>
     </cs:organizer>
+    <cs:organizer-cn>John Doe</cs:organizer-cn>
   </cs:invite-notification>
 </cs:root>
-
 FOO
             ),
             array(
@@ -144,13 +137,13 @@ FOO
     <cs:access>
       <cs:read/>
     </cs:access>
-    <cs:organizer-first>Foo</cs:organizer-first>
-    <cs:organizer-last>Bar</cs:organizer-last>
     <cs:organizer>
       <d:href>/principal/user1</d:href>
       <cs:first-name>Foo</cs:first-name>
       <cs:last-name>Bar</cs:last-name>
     </cs:organizer>
+    <cs:organizer-first>Foo</cs:organizer-first>
+    <cs:organizer-last>Bar</cs:organizer-last>
   </cs:invite-notification>
 </cs:root>
 
@@ -227,4 +220,17 @@ FOO
         ));
 
     }
+
+    function writeFull($input) {
+
+        $writer = new Writer();
+        $writer->baseUri = '/';
+        $writer->namespaceMap = $this->namespaceMap;
+        $writer->openMemory();
+        $writer->startElement('{http://calendarserver.org/ns/}root');
+        $input->xmlSerializeFull($writer);
+        $writer->endElement();
+        return $writer->outputMemory();
+
+    }
 }
diff --git a/tests/Sabre/DAV/Xml/XmlTest.php b/tests/Sabre/DAV/Xml/XmlTest.php
index 4818886..dd34a28 100644
--- a/tests/Sabre/DAV/Xml/XmlTest.php
+++ b/tests/Sabre/DAV/Xml/XmlTest.php
@@ -2,6 +2,21 @@
 
 namespace Sabre\DAV\Xml;
 
+use Sabre\Xml\Writer;
+
 abstract class XmlTest extends \PHPUnit_Framework_TestCase {
 
+    protected $namespaceMap = ['DAV:' => 'd'];
+
+    function write($input) {
+
+        $writer = new Writer();
+        $writer->baseUri = '/';
+        $writer->namespaceMap = $this->namespaceMap;
+        $writer->openMemory();
+        $writer->write($input);
+        return $writer->outputMemory();
+
+    }
+
 }

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