[Pkg-owncloud-commits] [php-sabredav] 29/148: Moved email-address-set property.

David Prévot taffit at moszumanska.debian.org
Wed Apr 15 01:37:06 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 55cc6a77ae85423ee72ef03534419b180c2b67f8
Author: Evert Pot <me at evertpot.com>
Date:   Sun Feb 8 17:16:31 2015 -0500

    Moved email-address-set property.
---
 lib/CalDAV/{ => Xml}/Property/EmailAddressSet.php  | 33 ++++++++++-------
 .../Xml/Property/SupportedCalendarComponentSet.php |  9 ++---
 .../Sabre/CalDAV/Property/EmailAddressSetTest.php  | 43 ----------------------
 .../CalDAV/Xml/Property/EmailAddressSetTest.php    | 40 ++++++++++++++++++++
 4 files changed, 64 insertions(+), 61 deletions(-)

diff --git a/lib/CalDAV/Property/EmailAddressSet.php b/lib/CalDAV/Xml/Property/EmailAddressSet.php
similarity index 50%
rename from lib/CalDAV/Property/EmailAddressSet.php
rename to lib/CalDAV/Xml/Property/EmailAddressSet.php
index 9daa61c..477afce 100644
--- a/lib/CalDAV/Property/EmailAddressSet.php
+++ b/lib/CalDAV/Xml/Property/EmailAddressSet.php
@@ -1,8 +1,9 @@
 <?php
 
-namespace Sabre\CalDAV\Property;
+namespace Sabre\CalDAV\Xml\Property;
 
-use Sabre\DAV;
+use Sabre\Xml\Writer;
+use Sabre\Xml\XmlSerializable;
 
 /**
  * email-address-set property
@@ -16,7 +17,7 @@ use Sabre\DAV;
  * @author Evert Pot (http://evertpot.com/)
  * @license http://sabre.io/license/ Modified BSD License
  */
-class EmailAddressSet extends DAV\Property {
+class EmailAddressSet implements XmlSerializable {
 
     /**
      * emails
@@ -48,23 +49,29 @@ class EmailAddressSet extends DAV\Property {
     }
 
     /**
-     * Serializes this property.
+     * The xmlSerialize metod is called during xml writing.
      *
-     * It will additionally prepend the href property with the server's base uri.
+     * Use the $writer argument to write its own xml serialization.
      *
-     * @param DAV\Server $server
-     * @param \DOMElement $dom
+     * An important note: do _not_ create a parent element. Any element
+     * implementing XmlSerializble should only ever write what's considered
+     * its 'inner xml'.
+     *
+     * 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
      */
-    function serialize(DAV\Server $server,\DOMElement $dom) {
-
-        $prefix = $server->xmlNamespaces['http://calendarserver.org/ns/'];
+    function xmlSerialize(Writer $writer) {
 
         foreach($this->emails as $email) {
 
-            $elem = $dom->ownerDocument->createElement($prefix . ':email-address');
-            $elem->appendChild($dom->ownerDocument->createTextNode($email));
-            $dom->appendChild($elem);
+            $writer->writeElement('{http://calendarserver.org/ns/}email-address', $email);
 
         }
 
diff --git a/lib/CalDAV/Xml/Property/SupportedCalendarComponentSet.php b/lib/CalDAV/Xml/Property/SupportedCalendarComponentSet.php
index a7652e5..24a37cc 100644
--- a/lib/CalDAV/Xml/Property/SupportedCalendarComponentSet.php
+++ b/lib/CalDAV/Xml/Property/SupportedCalendarComponentSet.php
@@ -2,11 +2,10 @@
 
 namespace Sabre\CalDAV\Xml\Property;
 
-use
-    Sabre\Xml\Element,
-    Sabre\Xml\Reader,
-    Sabre\Xml\Writer,
-    Sabre\CalDAV\Plugin;
+use Sabre\Xml\Element;
+use Sabre\Xml\Reader;
+use Sabre\Xml\Writer;
+use Sabre\CalDAV\Plugin;
 
 /**
  * SupportedCalendarComponentSet property.
diff --git a/tests/Sabre/CalDAV/Property/EmailAddressSetTest.php b/tests/Sabre/CalDAV/Property/EmailAddressSetTest.php
deleted file mode 100644
index 6af1c7e..0000000
--- a/tests/Sabre/CalDAV/Property/EmailAddressSetTest.php
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-
-namespace Sabre\CalDAV\Property;
-
-class EmailAddressSetTest extends \PHPUnit_Framework_TestCase {
-
-    function testSimple() {
-
-        $eas = new EmailAddressSet(['foo at example.org']);
-        $this->assertEquals(['foo at example.org'], $eas->getValue());
-
-    }
-
-    /**
-     * @depends testSimple
-     */
-    function testSerialize() {
-
-        $property = new EmailAddressSet(['foo at example.org']);
-
-        $doc = new \DOMDocument();
-        $root = $doc->createElement('d:root');
-        $root->setAttribute('xmlns:d','DAV:');
-        $root->setAttribute('xmlns:cs',\Sabre\CalDAV\Plugin::NS_CALENDARSERVER);
-
-        $doc->appendChild($root);
-        $server = new \Sabre\DAV\Server();
-        $server->addPlugin(new \Sabre\CalDAV\Plugin());
-
-        $property->serialize($server, $root);
-
-        $xml = $doc->saveXML();
-
-        $this->assertEquals(
-'<?xml version="1.0"?>
-<d:root xmlns:d="DAV:" xmlns:cs="' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '">' .
-'<cs:email-address>foo at example.org</cs:email-address>' .
-'</d:root>
-', $xml);
-
-    }
-
-}
diff --git a/tests/Sabre/CalDAV/Xml/Property/EmailAddressSetTest.php b/tests/Sabre/CalDAV/Xml/Property/EmailAddressSetTest.php
new file mode 100644
index 0000000..c3d8c40
--- /dev/null
+++ b/tests/Sabre/CalDAV/Xml/Property/EmailAddressSetTest.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Sabre\CalDAV\Xml\Property;
+
+use Sabre\DAV\Xml\XmlTest;
+
+class EmailAddressSetTest extends XmlTest {
+
+    protected $namespaceMap = [
+        \Sabre\CalDAV\Plugin::NS_CALENDARSERVER => 'cs',
+        'DAV:' => 'd',
+    ];
+
+    function testSimple() {
+
+        $eas = new EmailAddressSet(['foo at example.org']);
+        $this->assertEquals(['foo at example.org'], $eas->getValue());
+
+    }
+
+    /**
+     * @depends testSimple
+     */
+    function testSerialize() {
+
+        $property = new EmailAddressSet(['foo at example.org']);
+
+        $xml = $this->write([
+            '{DAV:}root' => $property
+        ]);
+
+        $this->assertXmlStringEqualsXmlString(
+'<?xml version="1.0"?>
+<d:root xmlns:d="DAV:" xmlns:cs="' . \Sabre\CalDAV\Plugin::NS_CALENDARSERVER . '">
+<cs:email-address>foo at example.org</cs:email-address>
+</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