[Pkg-owncloud-commits] [php-sabredav] 26/148: Migrated 'allowed-sharing-modes'.

David Prévot taffit at moszumanska.debian.org
Wed Apr 15 01:37:05 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 915f19caaf54d9e3373ad91127cd4ca770cb6961
Author: Evert Pot <me at evertpot.com>
Date:   Fri Feb 6 23:35:28 2015 -0500

    Migrated 'allowed-sharing-modes'.
---
 lib/CalDAV/Property/AllowedSharingModes.php        | 74 ----------------------
 lib/CalDAV/SharingPlugin.php                       |  2 +-
 lib/CalDAV/Xml/Property/AllowedSharingModes.php    | 51 +++++----------
 .../CalDAV/Property/AllowedSharingModesTest.php    | 47 --------------
 tests/Sabre/CalDAV/SharingPluginTest.php           |  2 +-
 .../Xml/Property/AllowedSharingModesTest.php       | 38 +++++++++++
 6 files changed, 55 insertions(+), 159 deletions(-)

diff --git a/lib/CalDAV/Property/AllowedSharingModes.php b/lib/CalDAV/Property/AllowedSharingModes.php
deleted file mode 100644
index e7b4d46..0000000
--- a/lib/CalDAV/Property/AllowedSharingModes.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-
-namespace Sabre\CalDAV\Property;
-
-use Sabre\DAV;
-
-/**
- * AllowedSharingModes
- *
- * This property encodes the 'allowed-sharing-modes' property, as defined by
- * the 'caldav-sharing-02' spec, in the http://calendarserver.org/ns/
- * namespace.
- *
- * This property is a representation of the supported-calendar_component-set
- * property in the CalDAV namespace. It simply requires an array of components,
- * such as VEVENT, VTODO
- *
- * @see https://trac.calendarserver.org/browser/CalendarServer/trunk/doc/Extensions/caldav-sharing-02.txt
- * @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 AllowedSharingModes extends DAV\Property {
-
-    /**
-     * Whether or not a calendar can be shared with another user
-     *
-     * @var bool
-     */
-    protected $canBeShared;
-
-    /**
-     * Whether or not the calendar can be placed on a public url.
-     *
-     * @var bool
-     */
-    protected $canBePublished;
-
-    /**
-     * Constructor
-     *
-     * @param bool $canBeShared
-     * @param bool $canBePublished
-     * @return void
-     */
-    function __construct($canBeShared, $canBePublished) {
-
-        $this->canBeShared = $canBeShared;
-        $this->canBePublished = $canBePublished;
-
-    }
-
-    /**
-     * Serializes the property in a DOMDocument
-     *
-     * @param DAV\Server $server
-     * @param \DOMElement $node
-     * @return void
-     */
-    function serialize(DAV\Server $server, \DOMElement $node) {
-
-        $doc = $node->ownerDocument;
-        if ($this->canBeShared) {
-            $xcomp = $doc->createElement('cs:can-be-shared');
-            $node->appendChild($xcomp);
-        }
-        if ($this->canBePublished) {
-            $xcomp = $doc->createElement('cs:can-be-published');
-            $node->appendChild($xcomp);
-        }
-
-    }
-
-}
diff --git a/lib/CalDAV/SharingPlugin.php b/lib/CalDAV/SharingPlugin.php
index 890376e..61bc371 100644
--- a/lib/CalDAV/SharingPlugin.php
+++ b/lib/CalDAV/SharingPlugin.php
@@ -183,7 +183,7 @@ class SharingPlugin extends DAV\ServerPlugin {
                 }
             }
             $propFind->handle('{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes', function() {
-                return new Property\AllowedSharingModes(true,false);
+                return new Xml\Property\AllowedSharingModes(true,false);
             });
 
         }
diff --git a/lib/CalDAV/Xml/Property/AllowedSharingModes.php b/lib/CalDAV/Xml/Property/AllowedSharingModes.php
index 984d138..efc41e9 100644
--- a/lib/CalDAV/Xml/Property/AllowedSharingModes.php
+++ b/lib/CalDAV/Xml/Property/AllowedSharingModes.php
@@ -3,10 +3,9 @@
 namespace Sabre\CalDAV\Xml\Property;
 
 use
-    Sabre\Xml\Element,
+    Sabre\Xml\XmlSerializable,
     Sabre\Xml\Reader,
     Sabre\Xml\Writer,
-    Sabre\DAV\Exception\CannotDeserialize,
     Sabre\CalDAV\Plugin;
 
 /**
@@ -25,7 +24,7 @@ use
  * @author Evert Pot (http://www.rooftopsolutions.nl/)
  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  */
-class AllowedSharingModes implements Element {
+class AllowedSharingModes implements XmlSerializable {
 
     /**
      * Whether or not a calendar can be shared with another user
@@ -48,7 +47,7 @@ class AllowedSharingModes implements Element {
      * @param bool $canBePublished
      * @return void
      */
-    public function __construct($canBeShared, $canBePublished) {
+    function __construct($canBeShared, $canBePublished) {
 
         $this->canBeShared = $canBeShared;
         $this->canBePublished = $canBePublished;
@@ -56,21 +55,25 @@ class AllowedSharingModes implements Element {
     }
 
     /**
-     * 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) {
 
         if ($this->canBeShared) {
             $writer->writeElement('{' . Plugin::NS_CALENDARSERVER . '}can-be-shared');
@@ -81,30 +84,6 @@ class AllowedSharingModes implements Element {
 
     }
 
-    /**
-     * The deserialize method is called during xml parsing.
-     *
-     * This method is called statictly, 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
-     * 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.
-     *
-     * If you just want to skip parsing for this element altogether, you can
-     * just call $reader->next();
-     *
-     * $reader->parseInnerTree() will parse the entire sub-tree, and advance to
-     * the next element.
-     *
-     * @param Reader $reader
-     * @return mixed
-     */
-    static public function deserializeXml(Reader $reader) {
 
-        throw new CannotDeserialize('This element does not have a deserializer');
 
-    }
 }
diff --git a/tests/Sabre/CalDAV/Property/AllowedSharingModesTest.php b/tests/Sabre/CalDAV/Property/AllowedSharingModesTest.php
deleted file mode 100644
index efe4aa5..0000000
--- a/tests/Sabre/CalDAV/Property/AllowedSharingModesTest.php
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-
-namespace Sabre\CalDAV\Property;
-
-use Sabre\CalDAV;
-use Sabre\DAV;
-
-class AllowedSharingModesTest extends \PHPUnit_Framework_TestCase {
-
-    function testSimple() {
-
-        $sccs = new AllowedSharingModes(true,true);
-        $this->assertInstanceOf('Sabre\CalDAV\Property\AllowedSharingModes', $sccs);
-
-    }
-
-    /**
-     * @depends testSimple
-     */
-    function testSerialize() {
-
-        $property = new AllowedSharingModes(true,true);
-
-        $doc = new \DOMDocument();
-        $root = $doc->createElement('d:root');
-        $root->setAttribute('xmlns:d','DAV:');
-        $root->setAttribute('xmlns:cal',CalDAV\Plugin::NS_CALDAV);
-        $root->setAttribute('xmlns:cs',CalDAV\Plugin::NS_CALENDARSERVER);
-
-        $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 . '" xmlns:cs="' . CalDAV\Plugin::NS_CALENDARSERVER . '">' .
-'<cs:can-be-shared/>' .
-'<cs:can-be-published/>' .
-'</d:root>
-', $xml);
-
-    }
-
-}
diff --git a/tests/Sabre/CalDAV/SharingPluginTest.php b/tests/Sabre/CalDAV/SharingPluginTest.php
index c865ac6..3d1f9fd 100644
--- a/tests/Sabre/CalDAV/SharingPluginTest.php
+++ b/tests/Sabre/CalDAV/SharingPluginTest.php
@@ -65,7 +65,7 @@ class SharingPluginTest extends \Sabre\DAVServerTest {
         ));
 
         $this->assertInstanceOf('Sabre\\CalDAV\\Property\\Invite', $props['{' . Plugin::NS_CALENDARSERVER . '}invite']);
-        $this->assertInstanceOf('Sabre\\CalDAV\\Property\\AllowedSharingModes', $props['{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes']);
+        $this->assertInstanceOf('Sabre\\CalDAV\\Xml\\Property\\AllowedSharingModes', $props['{' . Plugin::NS_CALENDARSERVER . '}allowed-sharing-modes']);
 
     }
 
diff --git a/tests/Sabre/CalDAV/Xml/Property/AllowedSharingModesTest.php b/tests/Sabre/CalDAV/Xml/Property/AllowedSharingModesTest.php
new file mode 100644
index 0000000..375d7fe
--- /dev/null
+++ b/tests/Sabre/CalDAV/Xml/Property/AllowedSharingModesTest.php
@@ -0,0 +1,38 @@
+<?php
+
+namespace Sabre\CalDAV\Xml\Property;
+
+use Sabre\CalDAV;
+use Sabre\DAV;
+
+class AllowedSharingModesTest extends DAV\Xml\XmlTest {
+
+    function testSimple() {
+
+        $sccs = new AllowedSharingModes(true,true);
+        $this->assertInstanceOf('Sabre\CalDAV\Xml\Property\AllowedSharingModes', $sccs);
+
+    }
+
+    /**
+     * @depends testSimple
+     */
+    function testSerialize() {
+
+        $property = new AllowedSharingModes(true,true);
+
+        $this->namespaceMap[CalDAV\Plugin::NS_CALDAV] = 'cal';
+        $this->namespaceMap[CalDAV\Plugin::NS_CALENDARSERVER] = 'cs';
+        $xml = $this->write(['{DAV:}root' => $property]);
+
+        $this->assertXmlStringEqualsXmlString(
+'<?xml version="1.0"?>
+  <d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '" xmlns:cs="' . CalDAV\Plugin::NS_CALENDARSERVER . '">
+    <cs:can-be-shared/>
+    <cs:can-be-published/>
+</d:root>
+', $xml);
+
+    }
+
+}

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