[Pkg-owncloud-commits] [php-sabredav] 25/148: Moved {DAV:}response to new xml system.

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 b36fcc27df0085fbc39df3b29600d8fe69a7cb53
Author: Evert Pot <me at evertpot.com>
Date:   Fri Feb 6 22:28:42 2015 -0500

    Moved {DAV:}response to new xml system.
---
 lib/DAV/Property/Response.php                      | 222 --------------------
 lib/DAV/Sync/Plugin.php                            |  28 +--
 lib/DAV/XMLUtil.php                                |   1 +
 tests/Sabre/DAV/Property/ResponseTest.php          | 230 ---------------------
 tests/Sabre/DAV/Sync/PluginTest.php                |  40 ++--
 tests/Sabre/DAV/Xml/Element/ResponseTest.php       | 182 ++++++++++++++++
 .../DAV/Xml/Property/SupportedMethodSetTest.php    |   4 +-
 tests/Sabre/DAV/Xml/XmlTest.php                    |   7 +
 8 files changed, 219 insertions(+), 495 deletions(-)

diff --git a/lib/DAV/Property/Response.php b/lib/DAV/Property/Response.php
deleted file mode 100644
index 3458bd2..0000000
--- a/lib/DAV/Property/Response.php
+++ /dev/null
@@ -1,222 +0,0 @@
-<?php
-
-namespace Sabre\DAV\Property;
-
-use
-    Sabre\DAV,
-    Sabre\HTTP,
-    Sabre\HTTP\URLUtil;
-
-/**
- * Response property
- *
- * This class represents the {DAV:}response XML element.
- * This is used by the Server class to encode individual items within a multistatus
- * response.
- *
- * @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 Response extends DAV\Property implements IHref {
-
-    /**
-     * Url for the response
-     *
-     * @var string
-     */
-    protected $href;
-
-    /**
-     * Propertylist, ordered by HTTP status code
-     *
-     * @var array
-     */
-    protected $responseProperties;
-
-    /**
-     * The HTTP status for an entire response.
-     *
-     * This is currently only used in WebDAV-Sync
-     *
-     * @var string
-     */
-    protected $httpStatus;
-
-    /**
-     * The href argument is a url relative to the root of the server. This
-     * class will calculate the full path.
-     *
-     * The responseProperties argument is a list of properties
-     * within an array with keys representing HTTP status codes
-     *
-     * Besides specific properties, the entire {DAV:}response element may also
-     * have a http status code.
-     * In most cases you don't need it.
-     *
-     * This is currently used by the Sync extension to indicate that a node is
-     * deleted.
-     *
-     * @param string $href
-     * @param array $responseProperties
-     * @param string $httpStatus
-     */
-    function __construct($href, array $responseProperties, $httpStatus = null) {
-
-        $this->href = $href;
-        $this->responseProperties = $responseProperties;
-        $this->httpStatus = $httpStatus;
-
-    }
-
-    /**
-     * Returns the url
-     *
-     * @return string
-     */
-    function getHref() {
-
-        return $this->href;
-
-    }
-
-    /**
-     * Returns the httpStatus value
-     *
-     * @return string
-     */
-    function getHttpStatus() {
-
-        return $this->httpStatus;
-
-    }
-
-    /**
-     * Returns the property list
-     *
-     * @return array
-     */
-    function getResponseProperties() {
-
-        return $this->responseProperties;
-
-    }
-
-    /**
-     * serialize
-     *
-     * @param DAV\Server $server
-     * @param \DOMElement $dom
-     * @return void
-     */
-    function serialize(DAV\Server $server, \DOMElement $dom) {
-
-        $document = $dom->ownerDocument;
-        $properties = $this->responseProperties;
-
-        $xresponse = $document->createElement('d:response');
-        $dom->appendChild($xresponse);
-
-        $uri = URLUtil::encodePath($this->href);
-
-        if ($uri==='/') $uri = '';
-
-        // Adding the baseurl to the beginning of the url
-        $uri = $server->getBaseUri() . $uri;
-
-        $xresponse->appendChild($document->createElement('d:href',$uri));
-
-        if ($this->httpStatus) {
-            $statusString = "HTTP/1.1 " . $this->httpStatus . " " . HTTP\Response::$statusCodes[$this->httpStatus];
-            $xresponse->appendChild($document->createElement('d:status', $statusString));
-        }
-
-        // The properties variable is an array containing properties, grouped by
-        // HTTP status
-        foreach($properties as $httpStatus=>$propertyGroup) {
-
-            // The 'href' is also in this array, and it's special cased.
-            // We will ignore it
-            if ($httpStatus=='href') continue;
-
-            // If there are no properties in this group, we can also just carry on
-            if (!count($propertyGroup)) continue;
-
-            $xpropstat = $document->createElement('d:propstat');
-            $xresponse->appendChild($xpropstat);
-
-            $xprop = $document->createElement('d:prop');
-            $xpropstat->appendChild($xprop);
-
-            $nsList = $server->xmlNamespaces;
-
-            foreach($propertyGroup as $propertyName=>$propertyValue) {
-
-                $propName = null;
-                preg_match('/^{([^}]*)}(.*)$/',$propertyName,$propName);
-
-                // special case for empty namespaces
-                if ($propName[1]=='') {
-
-                    $currentProperty = $document->createElement($propName[2]);
-                    $xprop->appendChild($currentProperty);
-                    $currentProperty->setAttribute('xmlns','');
-
-                } else {
-
-                    if (!isset($nsList[$propName[1]])) {
-                        $nsList[$propName[1]] = 'x' . count($nsList);
-                    }
-
-                    // If the namespace was defined in the top-level xml namespaces, it means
-                    // there was already a namespace declaration, and we don't have to worry about it.
-                    if (isset($server->xmlNamespaces[$propName[1]])) {
-                        $currentProperty = $document->createElement($nsList[$propName[1]] . ':' . $propName[2]);
-                    } else {
-                        $currentProperty = $document->createElementNS($propName[1],$nsList[$propName[1]].':' . $propName[2]);
-                    }
-                    $xprop->appendChild($currentProperty);
-
-                }
-
-                if (is_scalar($propertyValue)) {
-                    if ($propertyValue!=='') { // we want a self-closing xml element for empty strings.
-                        $text = $document->createTextNode($propertyValue);
-                        $currentProperty->appendChild($text);
-                    }
-                } elseif ($propertyValue instanceof DAV\PropertyInterface) {
-                    $propertyValue->serialize($server,$currentProperty);
-                } elseif (!is_null($propertyValue)) {
-                    throw new DAV\Exception('Unknown property value type: ' . gettype($propertyValue) . ' for property: ' . $propertyName);
-                }
-
-            }
-
-            $xpropstat->appendChild($document->createElement('d:status','HTTP/1.1 ' . $httpStatus . ' ' . HTTP\Response::$statusCodes[$httpStatus]));
-
-        }
-
-    }
-
-    /**
-     * Unserializes the property.
-     *
-     * This static method should return a an instance of this object.
-     *
-     * @param \DOMElement $prop
-     * @param array $propertyMap
-     * @return DAV\IProperty
-     */
-    static function unserialize(\DOMElement $prop, array $propertyMap) {
-
-        // Delegating this to the ResponseList property. It does make more
-        // sense there.
-
-        $result = ResponseList::unserialize($prop, $propertyMap);
-        $result = $result->getResponses();
-
-        return $result[0];
-
-    }
-
-}
diff --git a/lib/DAV/Sync/Plugin.php b/lib/DAV/Sync/Plugin.php
index 14fe8a9..e6c58ba 100644
--- a/lib/DAV/Sync/Plugin.php
+++ b/lib/DAV/Sync/Plugin.php
@@ -230,17 +230,6 @@ class Plugin extends DAV\ServerPlugin {
      */
     protected function sendSyncCollectionResponse($syncToken, $collectionUrl, array $added, array $modified, array $deleted, array $properties) {
 
-        $dom = new \DOMDocument('1.0','utf-8');
-        $dom->formatOutput = true;
-        $multiStatus = $dom->createElement('d:multistatus');
-        $dom->appendChild($multiStatus);
-
-        // Adding in default namespaces
-        foreach($this->server->xmlNamespaces as $namespace=>$prefix) {
-
-            $multiStatus->setAttribute('xmlns:' . $prefix,$namespace);
-
-        }
 
         $fullPaths = [];
 
@@ -250,31 +239,32 @@ class Plugin extends DAV\ServerPlugin {
             $fullPaths[] = $fullPath;
         }
 
+        $responses = [];
         foreach($this->server->getPropertiesForMultiplePaths($fullPaths, $properties) as $fullPath => $props) {
 
             // The 'Property_Response' class is responsible for generating a
             // single {DAV:}response xml element.
-            $response = new DAV\Property\Response($fullPath, $props);
-            $response->serialize($this->server, $multiStatus);
+            $responses[] = new DAV\Xml\Element\Response($fullPath, $props);
 
         }
 
+
+
         // Deleted items also show up as 'responses'. They have no properties,
         // and a single {DAV:}status element set as 'HTTP/1.1 404 Not Found'.
         foreach($deleted as $item) {
 
             $fullPath = $collectionUrl . '/' . $item;
-            $response = new DAV\Property\Response($fullPath, [], 404);
-            $response->serialize($this->server, $multiStatus);
+            $responses[] = new DAV\Xml\Element\Response($fullPath, [], 404);
 
         }
-
-        $syncToken = $dom->createElement('d:sync-token', self::SYNCTOKEN_PREFIX . $syncToken);
-        $multiStatus->appendChild($syncToken);
+        $multiStatus = new DAV\Xml\Response\MultiStatus($responses, self::SYNCTOKEN_PREFIX . $syncToken);
 
         $this->server->httpResponse->setStatus(207);
         $this->server->httpResponse->setHeader('Content-Type','application/xml; charset=utf-8');
-        $this->server->httpResponse->setBody($dom->saveXML());
+        $this->server->httpResponse->setBody(
+            $this->server->xml->write(['{DAV:}multistatus' => $multiStatus], $this->server->getBaseUri())
+        );
 
     }
 
diff --git a/lib/DAV/XMLUtil.php b/lib/DAV/XMLUtil.php
index 9d04f24..9879ac6 100644
--- a/lib/DAV/XMLUtil.php
+++ b/lib/DAV/XMLUtil.php
@@ -79,6 +79,7 @@ class XMLUtil {
     function write($output, $baseUri = null) {
 
         $writer = $this->getWriter($baseUri);
+        $writer->startDocument();
         $writer->write($output);
         return $writer->outputMemory();
 
diff --git a/tests/Sabre/DAV/Property/ResponseTest.php b/tests/Sabre/DAV/Property/ResponseTest.php
deleted file mode 100644
index 073cbb2..0000000
--- a/tests/Sabre/DAV/Property/ResponseTest.php
+++ /dev/null
@@ -1,230 +0,0 @@
-<?php
-
-namespace Sabre\DAV\Property;
-
-use Sabre\DAV;
-
-class ResponseTest extends \PHPUnit_Framework_TestCase {
-
-    function testSimple() {
-
-        $innerProps = array(
-            200 => array(
-                '{DAV:}displayname' => 'my file',
-            ),
-            404 => array(
-                '{DAV:}owner' => null,
-            )
-        );
-
-        $property = new Response('uri',$innerProps);
-
-        $this->assertEquals('uri',$property->getHref());
-        $this->assertEquals($innerProps,$property->getResponseProperties());
-
-
-    }
-
-    /**
-     * @depends testSimple
-     */
-    function testSerialize() {
-
-        $innerProps = array(
-            200 => array(
-                '{DAV:}displayname' => 'my file',
-            ),
-            404 => array(
-                '{DAV:}owner' => null,
-            )
-        );
-
-        $property = new Response('uri',$innerProps);
-
-        $doc = new \DOMDocument();
-        $root = $doc->createElement('d:root');
-        $root->setAttribute('xmlns:d','DAV:');
-
-        $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:">' .
-'<d:response>' .
-'<d:href>/uri</d:href>' .
-'<d:propstat>' .
-'<d:prop>' .
-'<d:displayname>my file</d:displayname>' .
-'</d:prop>' .
-'<d:status>HTTP/1.1 200 OK</d:status>' .
-'</d:propstat>' .
-'<d:propstat>' .
-'<d:prop>' .
-'<d:owner/>' .
-'</d:prop>' .
-'<d:status>HTTP/1.1 404 Not Found</d:status>' .
-'</d:propstat>' .
-'</d:response>' .
-'</d:root>
-', $xml);
-
-    }
-
-    /**
-     * This one is specifically for testing properties with no namespaces, which is legal xml
-     *
-     * @depends testSerialize
-     */
-    function testSerializeEmptyNamespace() {
-
-        $innerProps = array(
-            200 => array(
-                '{}propertyname' => 'value',
-            ),
-        );
-
-        $property = new Response('uri',$innerProps);
-
-        $doc = new \DOMDocument();
-        $root = $doc->createElement('d:root');
-        $root->setAttribute('xmlns:d','DAV:');
-
-        $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:">' .
-'<d:response>' .
-'<d:href>/uri</d:href>' .
-'<d:propstat>' .
-'<d:prop>' .
-'<propertyname xmlns="">value</propertyname>' .
-'</d:prop>' .
-'<d:status>HTTP/1.1 200 OK</d:status>' .
-'</d:propstat>' .
-'</d:response>' .
-'</d:root>
-', $xml);
-
-    }
-
-    /**
-     * This one is specifically for testing properties with no namespaces, which is legal xml
-     *
-     * @depends testSerialize
-     */
-    function testSerializeCustomNamespace() {
-
-        $innerProps = array(
-            200 => array(
-                '{http://sabredav.org/NS/example}propertyname' => 'value',
-            ),
-        );
-
-        $property = new Response('uri',$innerProps);
-
-        $doc = new \DOMDocument();
-        $root = $doc->createElement('d:root');
-        $root->setAttribute('xmlns:d','DAV:');
-
-        $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:">' .
-'<d:response>' .
-'<d:href>/uri</d:href>' .
-'<d:propstat>' .
-'<d:prop>' .
-'<x2:propertyname xmlns:x2="http://sabredav.org/NS/example">value</x2:propertyname>' .
-'</d:prop>' .
-'<d:status>HTTP/1.1 200 OK</d:status>' .
-'</d:propstat>' .
-'</d:response>' .
-'</d:root>
-', $xml);
-
-    }
-
-    /**
-     * @depends testSerialize
-     */
-    function testSerializeComplexProperty() {
-
-        $innerProps = array(
-            200 => array(
-                '{DAV:}link' => new Href('http://sabredav.org/', false)
-            ),
-        );
-
-        $property = new Response('uri',$innerProps);
-
-        $doc = new \DOMDocument();
-        $root = $doc->createElement('d:root');
-        $root->setAttribute('xmlns:d','DAV:');
-
-        $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:">' .
-'<d:response>' .
-'<d:href>/uri</d:href>' .
-'<d:propstat>' .
-'<d:prop>' .
-'<d:link><d:href>http://sabredav.org/</d:href></d:link>' .
-'</d:prop>' .
-'<d:status>HTTP/1.1 200 OK</d:status>' .
-'</d:propstat>' .
-'</d:response>' .
-'</d:root>
-', $xml);
-
-    }
-
-    /**
-     * @depends testSerialize
-     * @expectedException Sabre\DAV\Exception
-     */
-    function testSerializeBreak() {
-
-        $innerProps = array(
-            200 => array(
-                '{DAV:}link' => new \STDClass()
-            ),
-        );
-
-        $property = new Response('uri',$innerProps);
-
-        $doc = new \DOMDocument();
-        $root = $doc->createElement('d:root');
-        $root->setAttribute('xmlns:d','DAV:');
-
-        $doc->appendChild($root);
-        $server = new DAV\Server();
-
-        $property->serialize($server, $root);
-
-    }
-
-}
diff --git a/tests/Sabre/DAV/Sync/PluginTest.php b/tests/Sabre/DAV/Sync/PluginTest.php
index 43e32f6..8f1af80 100644
--- a/tests/Sabre/DAV/Sync/PluginTest.php
+++ b/tests/Sabre/DAV/Sync/PluginTest.php
@@ -12,14 +12,14 @@ class PluginTest extends \Sabre\DAVServerTest {
 
     protected $collection;
 
-    public function setUp() {
+    function setUp() {
 
         parent::setUp();
         $this->server->addPlugin(new Plugin());
 
     }
 
-    public function setUpTree() {
+    function setUpTree() {
 
         $this->collection =
             new MockSyncCollection('coll', [
@@ -33,7 +33,7 @@ class PluginTest extends \Sabre\DAVServerTest {
 
     }
 
-    public function testSupportedReportSet() {
+    function testSupportedReportSet() {
 
         $result = $this->server->getProperties('/coll', ['{DAV:}supported-report-set']);
         $this->assertFalse($result['{DAV:}supported-report-set']->has('{DAV:}sync-collection'));
@@ -46,7 +46,7 @@ class PluginTest extends \Sabre\DAVServerTest {
 
     }
 
-    public function testGetSyncToken() {
+    function testGetSyncToken() {
 
         $result = $this->server->getProperties('/coll', ['{DAV:}sync-token']);
         $this->assertFalse(isset($result['{DAV:}sync-token']));
@@ -64,16 +64,12 @@ class PluginTest extends \Sabre\DAVServerTest {
         $this->assertFalse(isset($result['{DAV:}sync-token']));
     }
 
-    public function testSyncInitialSyncCollection() {
+    function testSyncInitialSyncCollection() {
 
         // Making a change
         $this->collection->addChange(['file1.txt'], [], []);
 
-        $request = HTTP\Sapi::createFromServerArray([
-            'REQUEST_METHOD' => 'REPORT',
-            'REQUEST_URI'    => '/coll/',
-            'CONTENT_TYPE'    => 'application/xml',
-        ]);
+        $request = new HTTP\Request('REPORT', '/coll/', ['Content-Type' => 'application/xml']);
 
         $body = <<<BLA
 <?xml version="1.0" encoding="utf-8" ?>
@@ -125,7 +121,7 @@ BLA;
 
     }
 
-    public function testSubsequentSyncSyncCollection() {
+    function testSubsequentSyncSyncCollection() {
 
         // Making a change
         $this->collection->addChange(['file1.txt'], [], []);
@@ -184,7 +180,7 @@ BLA;
 
     }
 
-    public function testSubsequentSyncSyncCollectionLimit() {
+    function testSubsequentSyncSyncCollectionLimit() {
 
         // Making a change
         $this->collection->addChange(['file1.txt'], [], []);
@@ -236,7 +232,7 @@ BLA;
 
     }
 
-    public function testSubsequentSyncSyncCollectionDepthFallBack() {
+    function testSubsequentSyncSyncCollectionDepthFallBack() {
 
         // Making a change
         $this->collection->addChange(['file1.txt'], [], []);
@@ -297,7 +293,7 @@ BLA;
 
     }
 
-    public function testSyncNoSyncInfo() {
+    function testSyncNoSyncInfo() {
 
         $request = HTTP\Sapi::createFromServerArray([
             'REQUEST_METHOD' => 'REPORT',
@@ -326,7 +322,7 @@ BLA;
 
     }
 
-    public function testSyncNoSyncCollection() {
+    function testSyncNoSyncCollection() {
 
         $request = HTTP\Sapi::createFromServerArray([
             'REQUEST_METHOD' => 'REPORT',
@@ -355,7 +351,7 @@ BLA;
 
     }
 
-    public function testSyncInvalidToken() {
+    function testSyncInvalidToken() {
 
         $this->collection->addChange(['file1.txt'], [], []);
         $request = HTTP\Sapi::createFromServerArray([
@@ -384,7 +380,7 @@ BLA;
         $this->assertEquals(403, $response->status, 'Full response body:' . $response->body);
 
     }
-    public function testSyncInvalidTokenNoPrefix() {
+    function testSyncInvalidTokenNoPrefix() {
 
         $this->collection->addChange(['file1.txt'], [], []);
         $request = HTTP\Sapi::createFromServerArray([
@@ -414,7 +410,7 @@ BLA;
 
     }
 
-    public function testSyncNoSyncToken() {
+    function testSyncNoSyncToken() {
 
         $request = HTTP\Sapi::createFromServerArray([
             'REQUEST_METHOD' => 'REPORT',
@@ -442,7 +438,7 @@ BLA;
 
     }
 
-    public function testSyncNoProp() {
+    function testSyncNoProp() {
 
         $this->collection->addChange(['file1.txt'], [], []);
         $request = HTTP\Sapi::createFromServerArray([
@@ -469,7 +465,7 @@ BLA;
 
     }
 
-    public function testIfConditions() {
+    function testIfConditions() {
 
         $this->collection->addChange(['file1.txt'], [], []);
         $request = HTTP\Sapi::createFromServerArray([
@@ -486,7 +482,7 @@ BLA;
 
     }
 
-    public function testIfConditionsNot() {
+    function testIfConditionsNot() {
 
         $this->collection->addChange(['file1.txt'], [], []);
         $request = HTTP\Sapi::createFromServerArray([
@@ -503,7 +499,7 @@ BLA;
 
     }
 
-    public function testIfConditionsNoSyncToken() {
+    function testIfConditionsNoSyncToken() {
 
         $this->collection->addChange(['file1.txt'], [], []);
         $request = HTTP\Sapi::createFromServerArray([
diff --git a/tests/Sabre/DAV/Xml/Element/ResponseTest.php b/tests/Sabre/DAV/Xml/Element/ResponseTest.php
new file mode 100644
index 0000000..ac6b0dc
--- /dev/null
+++ b/tests/Sabre/DAV/Xml/Element/ResponseTest.php
@@ -0,0 +1,182 @@
+<?php
+
+namespace Sabre\DAV\Xml\Element;
+
+use Sabre\DAV;
+
+class ResponseTest extends DAV\Xml\XmlTest {
+
+    function testSimple() {
+
+        $innerProps = [
+            200 => [
+                '{DAV:}displayname' => 'my file',
+            ],
+            404 => [
+                '{DAV:}owner' => null,
+            ]
+        ];
+
+        $property = new Response('uri',$innerProps);
+
+        $this->assertEquals('uri',$property->getHref());
+        $this->assertEquals($innerProps,$property->getResponseProperties());
+
+
+    }
+
+    /**
+     * @depends testSimple
+     */
+    function testSerialize() {
+
+        $innerProps = [
+            200 => [
+                '{DAV:}displayname' => 'my file',
+            ],
+            404 => [
+                '{DAV:}owner' => null,
+            ]
+        ];
+
+        $property = new Response('uri',$innerProps);
+
+        $xml = $this->write(['{DAV:}root' => ['{DAV:}response' => $property]]);
+
+        $this->assertXmlStringEqualsXmlString(
+'<?xml version="1.0"?>
+<d:root xmlns:d="DAV:">
+  <d:response>
+    <d:href>/uri</d:href>
+    <d:propstat>
+      <d:prop>
+        <d:displayname>my file</d:displayname>
+      </d:prop>
+      <d:status>HTTP/1.1 200 OK</d:status>
+    </d:propstat>
+    <d:propstat>
+      <d:prop>
+        <d:owner/>
+      </d:prop>
+      <d:status>HTTP/1.1 404 Not Found</d:status>
+    </d:propstat>
+  </d:response>
+</d:root>
+', $xml);
+
+    }
+
+    /**
+     * This one is specifically for testing properties with no namespaces, which is legal xml
+     *
+     * @depends testSerialize
+     */
+    function testSerializeEmptyNamespace() {
+
+        $innerProps = [ 
+            200 => [ 
+                '{}propertyname' => 'value',
+            ],
+        ];
+
+        $property = new Response('uri',$innerProps);
+
+        $xml = $this->write(['{DAV:}root' => ['{DAV:}response' => $property]]);
+
+        $this->assertEquals(
+'<d:root xmlns:d="DAV:">
+ <d:response>
+  <d:href>/uri</d:href>
+  <d:propstat>
+   <d:prop>
+    <x1:propertyname xmlns:x1="">value</x1:propertyname>
+   </d:prop>
+   <d:status>HTTP/1.1 200 OK</d:status>
+  </d:propstat>
+ </d:response>
+</d:root>
+', $xml);
+
+    }
+
+    /**
+     * This one is specifically for testing properties with no namespaces, which is legal xml
+     *
+     * @depends testSerialize
+     */
+    function testSerializeCustomNamespace() {
+
+        $innerProps = [
+            200 => [ 
+                '{http://sabredav.org/NS/example}propertyname' => 'value',
+            ],
+        ];
+
+        $property = new Response('uri',$innerProps);
+        $xml = $this->write(['{DAV:}root' => ['{DAV:}response' => $property]]);
+
+        $this->assertXmlStringEqualsXmlString(
+'<?xml version="1.0"?>
+<d:root xmlns:d="DAV:">
+  <d:response>
+      <d:href>/uri</d:href>
+      <d:propstat>
+        <d:prop>
+          <x1:propertyname xmlns:x1="http://sabredav.org/NS/example">value</x1:propertyname>
+        </d:prop>
+      <d:status>HTTP/1.1 200 OK</d:status>
+      </d:propstat>
+  </d:response>
+</d:root>', $xml);
+
+    }
+
+    /**
+     * @depends testSerialize
+     */
+    function testSerializeComplexProperty() {
+
+        $innerProps = [ 
+            200 => [ 
+                '{DAV:}link' => new DAV\Xml\Property\Href('http://sabredav.org/', false)
+            ],
+        ];
+
+        $property = new Response('uri',$innerProps);
+        $xml = $this->write(['{DAV:}root' => ['{DAV:}response' => $property]]);
+
+        $this->assertXmlStringEqualsXmlString(
+'<?xml version="1.0"?>
+<d:root xmlns:d="DAV:">
+  <d:response>
+      <d:href>/uri</d:href>
+      <d:propstat>
+        <d:prop>
+          <d:link><d:href>http://sabredav.org/</d:href></d:link>
+        </d:prop>
+        <d:status>HTTP/1.1 200 OK</d:status>
+      </d:propstat>
+  </d:response>
+</d:root>
+', $xml);
+
+    }
+
+    /**
+     * @depends testSerialize
+     * @expectedException \InvalidArgumentException
+     */
+    function testSerializeBreak() {
+
+        $innerProps = array(
+            200 => array(
+                '{DAV:}link' => new \STDClass()
+            ),
+        );
+
+        $property = new Response('uri',$innerProps);
+        $this->write(['{DAV:}root' => ['{DAV:}response' => $property]]);
+
+    }
+
+}
diff --git a/tests/Sabre/DAV/Xml/Property/SupportedMethodSetTest.php b/tests/Sabre/DAV/Xml/Property/SupportedMethodSetTest.php
index a1b93e4..75c5c02 100644
--- a/tests/Sabre/DAV/Xml/Property/SupportedMethodSetTest.php
+++ b/tests/Sabre/DAV/Xml/Property/SupportedMethodSetTest.php
@@ -1,6 +1,6 @@
 <?php
 
-namespace Sabre\DAV\Property;
+namespace Sabre\DAV\Xml\Property;
 
 use Sabre\DAV;
 use Sabre\HTTP;
@@ -10,7 +10,7 @@ require_once 'Sabre/DAV/AbstractServer.php';
 
 class SupportedMethodSetTest extends DAV\AbstractServer {
 
-    public function sendPROPFIND($body) {
+    function sendPROPFIND($body) {
 
         $request = new HTTP\Request('PROPFIND', '/', ['Depth' => '0' ]);
         $request->setBody($body);
diff --git a/tests/Sabre/DAV/Xml/XmlTest.php b/tests/Sabre/DAV/Xml/XmlTest.php
index dd34a28..299447a 100644
--- a/tests/Sabre/DAV/Xml/XmlTest.php
+++ b/tests/Sabre/DAV/Xml/XmlTest.php
@@ -14,9 +14,16 @@ abstract class XmlTest extends \PHPUnit_Framework_TestCase {
         $writer->baseUri = '/';
         $writer->namespaceMap = $this->namespaceMap;
         $writer->openMemory();
+        $writer->setIndent(true);
         $writer->write($input);
         return $writer->outputMemory();
 
     }
 
+    function cleanUp() {
+
+        libxml_clear_errors();
+
+    }
+
 }

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