[Pkg-owncloud-commits] [php-sabredav] 69/148: No longer relying on DOM for parsing anywhere.
David Prévot
taffit at moszumanska.debian.org
Wed Apr 15 01:37:16 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 579437f527ff89fa481d050d59d3329480a7c433
Author: Evert Pot <me at evertpot.com>
Date: Wed Mar 18 20:36:17 2015 -0400
No longer relying on DOM for parsing anywhere.
---
lib/DAV/Locks/Plugin.php | 22 ++-
lib/DAV/XMLUtil.php | 157 ---------------------
lib/DAV/Xml/Request/Lock.php | 75 ++++++++++
tests/Sabre/CalDAV/PluginTest.php | 288 +++++++++++++++++---------------------
tests/Sabre/DAV/XMLUtilTest.php | 234 -------------------------------
5 files changed, 212 insertions(+), 564 deletions(-)
diff --git a/lib/DAV/Locks/Plugin.php b/lib/DAV/Locks/Plugin.php
index f3f0709..5ab1283 100644
--- a/lib/DAV/Locks/Plugin.php
+++ b/lib/DAV/Locks/Plugin.php
@@ -59,6 +59,9 @@ class Plugin extends DAV\ServerPlugin {
function initialize(DAV\Server $server) {
$this->server = $server;
+
+ $this->server->xml->elementMap['{DAV:}lockinfo'] = 'Sabre\\DAV\\Xml\\Request\\Lock';
+
$server->on('method:LOCK', [$this, 'httpLock']);
$server->on('method:UNLOCK', [$this, 'httpUnlock']);
$server->on('validateTokens', [$this, 'validateTokens']);
@@ -560,25 +563,16 @@ class Plugin extends DAV\ServerPlugin {
*/
protected function parseLockRequest($body) {
- // Fixes an XXE vulnerability on PHP versions older than 5.3.23 or
- // 5.4.13.
- $previous = libxml_disable_entity_loader(true);
-
-
- $xml = simplexml_load_string(
- DAV\XMLUtil::convertDAVNamespace($body),
- null,
- LIBXML_NOWARNING);
- libxml_disable_entity_loader($previous);
+ $result = $this->server->xml->parse(
+ $body
+ );
- $xml->registerXPathNamespace('d','urn:DAV');
$lockInfo = new LockInfo();
- $children = $xml->children("urn:DAV");
- $lockInfo->owner = (string)$children->owner;
+ $lockInfo->owner = $result['value']->owner;
$lockInfo->token = DAV\UUIDUtil::getUUID();
- $lockInfo->scope = count($xml->xpath('d:lockscope/d:exclusive'))>0 ? LockInfo::EXCLUSIVE : LockInfo::SHARED;
+ $lockInfo->scope = $result['value']->scope;
return $lockInfo;
diff --git a/lib/DAV/XMLUtil.php b/lib/DAV/XMLUtil.php
index 3048cc6..5075bfe 100644
--- a/lib/DAV/XMLUtil.php
+++ b/lib/DAV/XMLUtil.php
@@ -105,39 +105,6 @@ class XMLUtil {
}
/**
- * Returns the 'clark notation' for an element.
- *
- * For example, and element encoded as:
- * <b:myelem xmlns:b="http://www.example.org/" />
- * will be returned as:
- * {http://www.example.org}myelem
- *
- * This format is used throughout the SabreDAV sourcecode.
- * Elements encoded with the urn:DAV namespace will
- * be returned as if they were in the DAV: namespace. This is to avoid
- * compatibility problems.
- *
- * This function will return null if a nodetype other than an Element is passed.
- *
- * @param \DOMNode $dom
- * @return string
- */
- static function toClarkNotation(\DOMNode $dom) {
-
- if ($dom->nodeType !== XML_ELEMENT_NODE) return null;
-
- // Mapping back to the real namespace, in case it was dav
- if ($dom->namespaceURI=='urn:DAV')
- $ns = 'DAV:';
- else
- $ns = $dom->namespaceURI;
-
- // Mapping to clark notation
- return '{' . $ns . '}' . $dom->localName;
-
- }
-
- /**
* Parses a clark-notation string, and returns the namespace and element
* name components.
*
@@ -160,128 +127,4 @@ class XMLUtil {
}
- /**
- * This method takes an XML document (as string) and converts all instances of the
- * DAV: namespace to urn:DAV
- *
- * This is unfortunately needed, because the DAV: namespace violates the xml namespaces
- * spec, and causes the DOM to throw errors
- *
- * @param string $xmlDocument
- * @return array|string|null
- */
- static function convertDAVNamespace($xmlDocument) {
-
- // This is used to map the DAV: namespace to urn:DAV. This is needed, because the DAV:
- // namespace is actually a violation of the XML namespaces specification, and will cause errors
- return preg_replace("/xmlns(:[A-Za-z0-9_]*)?=(\"|\')DAV:(\\2)/","xmlns\\1=\\2urn:DAV\\2",$xmlDocument);
-
- }
-
- /**
- * This method provides a generic way to load a DOMDocument for WebDAV use.
- *
- * This method throws a Sabre\DAV\Exception\BadRequest exception for any xml errors.
- * It does not preserve whitespace, and it converts the DAV: namespace to urn:DAV.
- *
- * @param string $xml
- * @throws Sabre\DAV\Exception\BadRequest
- * @return DOMDocument
- */
- static function loadDOMDocument($xml) {
-
- if (empty($xml))
- throw new Exception\BadRequest('Empty XML document sent');
-
- // The BitKinex client sends xml documents as UTF-16. PHP 5.3.1 (and presumably lower)
- // does not support this, so we must intercept this and convert to UTF-8.
- if (substr($xml,0,12) === "\x3c\x00\x3f\x00\x78\x00\x6d\x00\x6c\x00\x20\x00") {
-
- // Note: the preceeding byte sequence is "<?xml" encoded as UTF_16, without the BOM.
- $xml = iconv('UTF-16LE','UTF-8',$xml);
-
- // Because the xml header might specify the encoding, we must also change this.
- // This regex looks for the string encoding="UTF-16" and replaces it with
- // encoding="UTF-8".
- $xml = preg_replace('|<\?xml([^>]*)encoding="UTF-16"([^>]*)>|u','<?xml\1encoding="UTF-8"\2>',$xml);
-
- }
-
- // Retaining old error setting
- $oldErrorSetting = libxml_use_internal_errors(true);
- // Fixes an XXE vulnerability on PHP versions older than 5.3.23 or
- // 5.4.13.
- $oldEntityLoaderSetting = libxml_disable_entity_loader(true);
-
- // Clearing any previous errors
- libxml_clear_errors();
-
- $dom = new \DOMDocument();
-
- // We don't generally care about any whitespace
- $dom->preserveWhiteSpace = false;
-
- $dom->loadXML(self::convertDAVNamespace($xml),LIBXML_NOWARNING | LIBXML_NOERROR);
-
- if ($error = libxml_get_last_error()) {
- libxml_clear_errors();
- throw new Exception\BadRequest('The request body had an invalid XML body. (message: ' . $error->message . ', errorcode: ' . $error->code . ', line: ' . $error->line . ')');
- }
-
- // Restoring old mechanism for error handling
- if ($oldErrorSetting===false) libxml_use_internal_errors(false);
- if ($oldEntityLoaderSetting===false) libxml_disable_entity_loader(false);
-
- return $dom;
-
- }
-
- /**
- * Parses all WebDAV properties out of a DOM Element
- *
- * Generally WebDAV properties are enclosed in {DAV:}prop elements. This
- * method helps by going through all these and pulling out the actual
- * propertynames, making them array keys and making the property values,
- * well.. the array values.
- *
- * If no value was given (self-closing element) null will be used as the
- * value. This is used in for example PROPFIND requests.
- *
- * Complex values are supported through the propertyMap argument. The
- * propertyMap should have the clark-notation properties as it's keys, and
- * classnames as values.
- *
- * When any of these properties are found, the unserialize() method will be
- * (statically) called. The result of this method is used as the value.
- *
- * @param \DOMElement $parentNode
- * @param array $propertyMap
- * @return array
- */
- static function parseProperties(\DOMElement $parentNode, array $propertyMap = []) {
-
- $propList = [];
- foreach($parentNode->childNodes as $propNode) {
-
- if (self::toClarkNotation($propNode)!=='{DAV:}prop') continue;
-
- foreach($propNode->childNodes as $propNodeData) {
-
- /* If there are no elements in here, we actually get 1 text node, this special case is dedicated to netdrive */
- if ($propNodeData->nodeType != XML_ELEMENT_NODE) continue;
-
- $propertyName = self::toClarkNotation($propNodeData);
- if (isset($propertyMap[$propertyName])) {
- $propList[$propertyName] = call_user_func([$propertyMap[$propertyName],'unserialize'],$propNodeData, $propertyMap);
- } else {
- $propList[$propertyName] = $propNodeData->textContent;
- }
- }
-
-
- }
- return $propList;
-
- }
-
}
diff --git a/lib/DAV/Xml/Request/Lock.php b/lib/DAV/Xml/Request/Lock.php
new file mode 100644
index 0000000..9070d6e
--- /dev/null
+++ b/lib/DAV/Xml/Request/Lock.php
@@ -0,0 +1,75 @@
+<?php
+
+namespace Sabre\DAV\Xml\Request;
+
+use Sabre\DAV\Locks\LockInfo;
+use Sabre\Xml\Element\KeyValue;
+use Sabre\Xml\Reader;
+use Sabre\Xml\XmlDeserializable;
+
+/**
+ * WebDAV LOCK request parser.
+ *
+ * This class parses the {DAV:}lockinfo request, as defined in:
+ *
+ * http://tools.ietf.org/html/rfc4918#section-9.10
+ *
+ * @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 Lock implements XmlDeserializable {
+
+ /**
+ * Owner of the lock
+ *
+ * @var string
+ */
+ public $owner;
+
+ /**
+ * Scope of the lock.
+ *
+ * Either LockInfo::SHARED or LockInfo::EXCLUSIVE
+ * @var int
+ */
+ public $scope;
+
+ /**
+ * 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.
+ *
+ * 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 function xmlDeserialize(Reader $reader) {
+
+ $values = KeyValue::xmlDeserialize($reader);
+ $new = new self();
+ $new->owner = !empty($values['{DAV:}owner'])?$values['{DAV:}owner']:null;
+ $new->scope = LockInfo::SHARED;
+
+ if (isset($values['{DAV:}lockscope'])) {
+ foreach($values['{DAV:}lockscope'] as $elem) {
+ if ($elem['name'] === '{DAV:}exclusive') $new->scope = LockInfo::EXCLUSIVE;
+ }
+ }
+ return $new;
+
+ }
+
+}
diff --git a/tests/Sabre/CalDAV/PluginTest.php b/tests/Sabre/CalDAV/PluginTest.php
index 61b5deb..7134b90 100644
--- a/tests/Sabre/CalDAV/PluginTest.php
+++ b/tests/Sabre/CalDAV/PluginTest.php
@@ -1,9 +1,13 @@
<?php
namespace Sabre\CalDAV;
-use Sabre\DAVACL;
-use Sabre\DAV;
-use Sabre\HTTP;
+
+use
+ Sabre\DAVACL,
+ Sabre\DAV,
+ Sabre\HTTP,
+ DateTime,
+ DateTimeZone;
class PluginTest extends \PHPUnit_Framework_TestCase {
@@ -559,38 +563,27 @@ END:VCALENDAR';
$this->server->httpRequest = $request;
$this->server->exec();
- $this->assertEquals(207, $this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body);
-
- $xml = simplexml_load_string(DAV\XMLUtil::convertDAVNamespace($this->response->body));
-
- $xml->registerXPathNamespace('d','urn:DAV');
- $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
-
- $check = array(
- '/d:multistatus',
- '/d:multistatus/d:response',
- '/d:multistatus/d:response/d:href',
- '/d:multistatus/d:response/d:propstat',
- '/d:multistatus/d:response/d:propstat/d:prop',
- '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
- '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data',
- '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
- );
-
- foreach($check as $v1=>$v2) {
+ $this->assertEquals(207, $this->response->status,'Invalid HTTP status received. Full response body');
- $xpath = is_int($v1)?$v2:$v1;
+ $expectedIcal = TestUtil::getTestCalendarData();
- $result = $xml->xpath($xpath);
- $this->assertEquals(1,count($result));
+ $expected = <<<XML
+<?xml version="1.0"?>
+<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
+<d:response>
+ <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
+ <d:propstat>
+ <d:prop>
+ <x1:calendar-data xmlns:x1="urn:ietf:params:xml:ns:caldav">$expectedIcal</x1:calendar-data>
+ <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
+ </d:prop>
+ <d:status>HTTP/1.1 200 OK</d:status>
+ </d:propstat>
+</d:response>
+</d:multistatus>
+XML;
- if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
-
- }
-
- // The response object should have a reference to the Asia/Seoul
- // timezone.
- $this->assertTrue(strpos($this->response->body,'Asia/Seoul')!==false);
+ $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
}
@@ -623,34 +616,31 @@ END:VCALENDAR';
$this->assertEquals(207, $this->response->status,'Invalid HTTP status received. Full response body: ' . $this->response->body);
- $xml = simplexml_load_string(DAV\XMLUtil::convertDAVNamespace($this->response->body));
-
- $xml->registerXPathNamespace('d','urn:DAV');
- $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
-
- $check = array(
- '/d:multistatus',
- '/d:multistatus/d:response',
- '/d:multistatus/d:response/d:href',
- '/d:multistatus/d:response/d:propstat',
- '/d:multistatus/d:response/d:propstat/d:prop',
- '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
- '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data',
- '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
+ $expectedIcal = TestUtil::getTestCalendarData();
+ $expectedIcal = \Sabre\VObject\Reader::read($expectedIcal);
+ $expectedIcal->expand(
+ new DateTime('2011-01-01 00:00:00', new DateTimeZone('UTC')),
+ new DateTime('2011-12-31 23:59:59', new DateTimeZone('UTC'))
);
-
- foreach($check as $v1=>$v2) {
-
- $xpath = is_int($v1)?$v2:$v1;
-
- $result = $xml->xpath($xpath);
- $this->assertEquals(1,count($result));
-
- if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
-
- }
- // The response object should no longer hold references to timezones.
- $this->assertTrue(strpos($this->response->body,'Asia/Seoul')===false);
+ $expectedIcal = str_replace("\r\n", "
\n", $expectedIcal->serialize());
+
+ $expected = <<<XML
+<?xml version="1.0"?>
+<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
+<d:response>
+ <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
+ <d:propstat>
+ <d:prop>
+ <x1:calendar-data xmlns:x1="urn:ietf:params:xml:ns:caldav">$expectedIcal</x1:calendar-data>
+ <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
+ </d:prop>
+ <d:status>HTTP/1.1 200 OK</d:status>
+ </d:propstat>
+</d:response>
+</d:multistatus>
+XML;
+
+ $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
}
@@ -688,32 +678,31 @@ END:VCALENDAR';
$this->assertEquals(207, $this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
- $xml = simplexml_load_string(DAV\XMLUtil::convertDAVNamespace($this->response->body));
-
- $xml->registerXPathNamespace('d','urn:DAV');
- $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
-
- $check = array(
- '/d:multistatus',
- '/d:multistatus/d:response',
- '/d:multistatus/d:response/d:href',
- '/d:multistatus/d:response/d:propstat',
- '/d:multistatus/d:response/d:propstat/d:prop',
- '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
- '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data',
- '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
+ $expectedIcal = TestUtil::getTestCalendarData();
+ $expectedIcal = \Sabre\VObject\Reader::read($expectedIcal);
+ $expectedIcal->expand(
+ new DateTime('2000-01-01 00:00:00', new DateTimeZone('UTC')),
+ new DateTime('2010-12-31 23:59:59', new DateTimeZone('UTC'))
);
-
- foreach($check as $v1=>$v2) {
-
- $xpath = is_int($v1)?$v2:$v1;
-
- $result = $xml->xpath($xpath);
- $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body);
-
- if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
-
- }
+ $expectedIcal = str_replace("\r\n", "
\n", $expectedIcal->serialize());
+
+ $expected = <<<XML
+<?xml version="1.0"?>
+<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
+<d:response>
+ <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
+ <d:propstat>
+ <d:prop>
+ <x1:calendar-data xmlns:x1="urn:ietf:params:xml:ns:caldav">$expectedIcal</x1:calendar-data>
+ <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
+ </d:prop>
+ <d:status>HTTP/1.1 200 OK</d:status>
+ </d:propstat>
+</d:response>
+</d:multistatus>
+XML;
+
+ $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
}
@@ -747,31 +736,22 @@ END:VCALENDAR';
$this->assertEquals(207, $this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
- $xml = simplexml_load_string(DAV\XMLUtil::convertDAVNamespace($this->response->body));
-
- $xml->registerXPathNamespace('d','urn:DAV');
- $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
-
- $check = array(
- '/d:multistatus',
- '/d:multistatus/d:response',
- '/d:multistatus/d:response/d:href',
- '/d:multistatus/d:response/d:propstat',
- '/d:multistatus/d:response/d:propstat/d:prop',
- '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
- '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
- );
-
- foreach($check as $v1=>$v2) {
-
- $xpath = is_int($v1)?$v2:$v1;
-
- $result = $xml->xpath($xpath);
- $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body);
-
- if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
-
- }
+ $expected = <<<XML
+<?xml version="1.0"?>
+<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
+<d:response>
+ <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
+ <d:propstat>
+ <d:prop>
+ <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
+ </d:prop>
+ <d:status>HTTP/1.1 200 OK</d:status>
+ </d:propstat>
+</d:response>
+</d:multistatus>
+XML;
+
+ $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
}
@@ -836,32 +816,31 @@ END:VCALENDAR';
$this->assertEquals(207, $this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
- $xml = simplexml_load_string(DAV\XMLUtil::convertDAVNamespace($this->response->body));
-
- $xml->registerXPathNamespace('d','urn:DAV');
- $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
-
- $check = array(
- '/d:multistatus',
- '/d:multistatus/d:response',
- '/d:multistatus/d:response/d:href',
- '/d:multistatus/d:response/d:propstat',
- '/d:multistatus/d:response/d:propstat/d:prop',
- '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
- '/d:multistatus/d:response/d:propstat/d:prop/c:calendar-data',
- '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
+ $expectedIcal = TestUtil::getTestCalendarData();
+ $expectedIcal = \Sabre\VObject\Reader::read($expectedIcal);
+ $expectedIcal->expand(
+ new DateTime('2000-01-01 00:00:00', new DateTimeZone('UTC')),
+ new DateTime('2010-12-31 23:59:59', new DateTimeZone('UTC'))
);
-
- foreach($check as $v1=>$v2) {
-
- $xpath = is_int($v1)?$v2:$v1;
-
- $result = $xml->xpath($xpath);
- $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body);
-
- if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
-
- }
+ $expectedIcal = str_replace("\r\n", "
\n", $expectedIcal->serialize());
+
+ $expected = <<<XML
+<?xml version="1.0"?>
+<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
+<d:response>
+ <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
+ <d:propstat>
+ <d:prop>
+ <x1:calendar-data xmlns:x1="urn:ietf:params:xml:ns:caldav">$expectedIcal</x1:calendar-data>
+ <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
+ </d:prop>
+ <d:status>HTTP/1.1 200 OK</d:status>
+ </d:propstat>
+</d:response>
+</d:multistatus>
+XML;
+
+ $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
}
@@ -896,31 +875,22 @@ END:VCALENDAR';
$this->assertEquals(207, $this->response->status,'Received an unexpected status. Full response body: ' . $this->response->body);
- $xml = simplexml_load_string(DAV\XMLUtil::convertDAVNamespace($this->response->body));
-
- $xml->registerXPathNamespace('d','urn:DAV');
- $xml->registerXPathNamespace('c','urn:ietf:params:xml:ns:caldav');
-
- $check = array(
- '/d:multistatus',
- '/d:multistatus/d:response',
- '/d:multistatus/d:response/d:href',
- '/d:multistatus/d:response/d:propstat',
- '/d:multistatus/d:response/d:propstat/d:prop',
- '/d:multistatus/d:response/d:propstat/d:prop/d:getetag',
- '/d:multistatus/d:response/d:propstat/d:status' => 'HTTP/1.1 200 OK',
- );
-
- foreach($check as $v1=>$v2) {
-
- $xpath = is_int($v1)?$v2:$v1;
-
- $result = $xml->xpath($xpath);
- $this->assertEquals(1,count($result), 'We expected 1 ' . $xpath . ' elements. We\'ve found ' . count($result) . '. Full result: ' . $this->response->body);
-
- if (!is_int($v1)) $this->assertEquals($v2,(string)$result[0]);
-
- }
+ $expected = <<<XML
+<?xml version="1.0"?>
+<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
+<d:response>
+ <d:href>/calendars/user1/UUID-123467/UUID-2345</d:href>
+ <d:propstat>
+ <d:prop>
+ <d:getetag>"e207e33c10e5fb9c12cfb35b5d9116e1"</d:getetag>
+ </d:prop>
+ <d:status>HTTP/1.1 200 OK</d:status>
+ </d:propstat>
+</d:response>
+</d:multistatus>
+XML;
+
+ $this->assertXmlStringEqualsXmlString($expected, $this->response->getBodyAsString());
}
diff --git a/tests/Sabre/DAV/XMLUtilTest.php b/tests/Sabre/DAV/XMLUtilTest.php
index ef152ea..95c6a4a 100644
--- a/tests/Sabre/DAV/XMLUtilTest.php
+++ b/tests/Sabre/DAV/XMLUtilTest.php
@@ -4,240 +4,6 @@ namespace Sabre\DAV;
class XMLUtilTest extends \PHPUnit_Framework_TestCase {
- function testToClarkNotation() {
-
- $dom = new \DOMDocument();
- $dom->loadXML('<?xml version="1.0"?><test1 xmlns="http://www.example.org/">Testdoc</test1>');
-
- $this->assertEquals(
- '{http://www.example.org/}test1',
- XMLUtil::toClarkNotation($dom->firstChild)
- );
-
- }
-
- function testToClarkNotation2() {
-
- $dom = new \DOMDocument();
- $dom->loadXML('<?xml version="1.0"?><s:test1 xmlns:s="http://www.example.org/">Testdoc</s:test1>');
-
- $this->assertEquals(
- '{http://www.example.org/}test1',
- XMLUtil::toClarkNotation($dom->firstChild)
- );
-
- }
-
- function testToClarkNotationDAVNamespace() {
-
- $dom = new \DOMDocument();
- $dom->loadXML('<?xml version="1.0"?><s:test1 xmlns:s="urn:DAV">Testdoc</s:test1>');
-
- $this->assertEquals(
- '{DAV:}test1',
- XMLUtil::toClarkNotation($dom->firstChild)
- );
-
- }
-
- function testToClarkNotationNoElem() {
-
- $dom = new \DOMDocument();
- $dom->loadXML('<?xml version="1.0"?><s:test1 xmlns:s="urn:DAV">Testdoc</s:test1>');
-
- $this->assertNull(
- XMLUtil::toClarkNotation($dom->firstChild->firstChild)
- );
-
- }
-
- function testConvertDAVNamespace() {
-
- $xml='<?xml version="1.0"?><document xmlns="DAV:">blablabla</document>';
- $this->assertEquals(
- '<?xml version="1.0"?><document xmlns="urn:DAV">blablabla</document>',
- XMLUtil::convertDAVNamespace($xml)
- );
-
- }
-
- function testConvertDAVNamespace2() {
-
- $xml='<?xml version="1.0"?><s:document xmlns:s="DAV:">blablabla</s:document>';
- $this->assertEquals(
- '<?xml version="1.0"?><s:document xmlns:s="urn:DAV">blablabla</s:document>',
- XMLUtil::convertDAVNamespace($xml)
- );
-
- }
-
- function testConvertDAVNamespace3() {
-
- $xml='<?xml version="1.0"?><s:document xmlns="http://bla" xmlns:s="DAV:" xmlns:z="http://othernamespace">blablabla</s:document>';
- $this->assertEquals(
- '<?xml version="1.0"?><s:document xmlns="http://bla" xmlns:s="urn:DAV" xmlns:z="http://othernamespace">blablabla</s:document>',
- XMLUtil::convertDAVNamespace($xml)
- );
-
- }
-
- function testConvertDAVNamespace4() {
-
- $xml='<?xml version="1.0"?><document xmlns=\'DAV:\'>blablabla</document>';
- $this->assertEquals(
- '<?xml version="1.0"?><document xmlns=\'urn:DAV\'>blablabla</document>',
- XMLUtil::convertDAVNamespace($xml)
- );
-
- }
-
- function testConvertDAVNamespaceMixedQuotes() {
-
- $xml='<?xml version="1.0"?><document xmlns=\'DAV:" xmlns="Another attribute\'>blablabla</document>';
- $this->assertEquals(
- $xml,
- XMLUtil::convertDAVNamespace($xml)
- );
-
- }
-
- /**
- * @depends testConvertDAVNamespace
- */
- function testLoadDOMDocument() {
-
- $xml='<?xml version="1.0"?><document></document>';
- $dom = XMLUtil::loadDOMDocument($xml);
- $this->assertTrue($dom instanceof \DOMDocument);
-
- }
-
- /**
- * @depends testLoadDOMDocument
- * @expectedException Sabre\DAV\Exception\BadRequest
- */
- function testLoadDOMDocumentEmpty() {
-
- XMLUtil::loadDOMDocument('');
-
- }
-
- /**
- * @expectedException Sabre\DAV\Exception\BadRequest
- * @depends testLoadDOMDocument
- */
- function testLoadDOMDocumentInvalid() {
-
- $xml='<?xml version="1.0"?><document></docu';
- $dom = XMLUtil::loadDOMDocument($xml);
-
- }
-
- /**
- * @depends testLoadDOMDocument
- */
- function testLoadDOMDocumentUTF16() {
-
- $xml='<?xml version="1.0" encoding="UTF-16"?><root xmlns="DAV:">blabla</root>';
- $xml = iconv('UTF-8','UTF-16LE',$xml);
- $dom = XMLUtil::loadDOMDocument($xml);
- $this->assertEquals('blabla',$dom->firstChild->nodeValue);
-
- }
-
- /**
- * @depends testLoadDOMDocument
- */
- function testParseProperties() {
-
- $xml='<?xml version="1.0"?>
-<root xmlns="DAV:">
- <prop>
- <displayname>Calendars</displayname>
- </prop>
-</root>';
-
- $dom = XMLUtil::loadDOMDocument($xml);
- $properties = XMLUtil::parseProperties($dom->firstChild);
-
- $this->assertEquals(array(
- '{DAV:}displayname' => 'Calendars',
- ), $properties);
-
-
-
- }
-
- /**
- * @depends testParseProperties
- */
- function testParsePropertiesEmpty() {
-
- $xml='<?xml version="1.0"?>
-<root xmlns="DAV:" xmlns:s="http://www.rooftopsolutions.nl/example">
- <prop>
- <displayname>Calendars</displayname>
- </prop>
- <prop>
- <s:example />
- </prop>
-</root>';
-
- $dom = XMLUtil::loadDOMDocument($xml);
- $properties = XMLUtil::parseProperties($dom->firstChild);
-
- $this->assertEquals(array(
- '{DAV:}displayname' => 'Calendars',
- '{http://www.rooftopsolutions.nl/example}example' => null
- ), $properties);
-
- }
-
-
- /**
- * @depends testParseProperties
- */
- function testParsePropertiesComplex() {
-
- $xml='<?xml version="1.0"?>
-<root xmlns="DAV:">
- <prop>
- <displayname>Calendars</displayname>
- </prop>
- <prop>
- <someprop>Complex value <b>right here</b></someprop>
- </prop>
-</root>';
-
- $dom = XMLUtil::loadDOMDocument($xml);
- $properties = XMLUtil::parseProperties($dom->firstChild);
-
- $this->assertEquals(array(
- '{DAV:}displayname' => 'Calendars',
- '{DAV:}someprop' => 'Complex value right here',
- ), $properties);
-
- }
-
-
- /**
- * @depends testParseProperties
- */
- function testParsePropertiesNoProperties() {
-
- $xml='<?xml version="1.0"?>
-<root xmlns="DAV:">
- <prop>
- </prop>
-</root>';
-
- $dom = XMLUtil::loadDOMDocument($xml);
- $properties = XMLUtil::parseProperties($dom->firstChild);
-
- $this->assertEquals(array(), $properties);
-
- }
-
function testParseClarkNotation() {
$this->assertEquals(array(
--
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