[Pkg-owncloud-commits] [php-sabredav] 33/148: Moved proppatch to the new system.
David Prévot
taffit at moszumanska.debian.org
Wed Apr 15 01:37:08 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 663594a8176013390a0d95f3120e338384aff498
Author: Evert Pot <me at evertpot.com>
Date: Sun Feb 8 19:46:18 2015 -0500
Moved proppatch to the new system.
---
lib/DAV/CorePlugin.php | 5 ++-
lib/DAV/Server.php | 57 ------------------------
lib/DAV/XMLUtil.php | 5 ++-
lib/DAV/Xml/Request/PropPatch.php | 32 ++-----------
tests/Sabre/DAV/HTTPPreferParsingTest.php | 22 +++------
tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php | 21 ---------
tests/Sabre/DAV/ServerPropsTest.php | 27 +++++------
7 files changed, 31 insertions(+), 138 deletions(-)
diff --git a/lib/DAV/CorePlugin.php b/lib/DAV/CorePlugin.php
index 0a3df85..e92cdcf 100644
--- a/lib/DAV/CorePlugin.php
+++ b/lib/DAV/CorePlugin.php
@@ -375,9 +375,10 @@ class CorePlugin extends ServerPlugin {
$path = $request->getPath();
- $newProperties = $this->server->parsePropPatchRequest(
+ $propPatch = $this->server->xml->parse(
$request->getBodyAsString()
- );
+ )['value'];
+ $newProperties = $propPatch->properties;
$result = $this->server->updateProperties($path, $newProperties);
diff --git a/lib/DAV/Server.php b/lib/DAV/Server.php
index 11b28b3..ab2327a 100644
--- a/lib/DAV/Server.php
+++ b/lib/DAV/Server.php
@@ -94,16 +94,6 @@ class Server extends EventEmitter {
*/
public $xmlNamespaces = null;
- /**
- * The propertymap can be used to map properties from
- * requests to property classes.
- *
- * @var array
- */
- public $propertyMap = [
- '{DAV:}resourcetype' => 'Sabre\\DAV\\Property\\ResourceType',
- ];
-
public $protectedProperties = [
// RFC4918
'{DAV:}getcontentlength',
@@ -1667,51 +1657,4 @@ class Server extends EventEmitter {
}
- /**
- * This method parses a PropPatch request
- *
- * PropPatch changes the properties for a resource. This method
- * returns a list of properties.
- *
- * The keys in the returned array contain the property name (e.g.: {DAV:}displayname,
- * and the value contains the property value. If a property is to be removed the value
- * will be null.
- *
- * @param string $body xml body
- * @return array list of properties in need of updating or deletion
- */
- function parsePropPatchRequest($body) {
-
- //We'll need to change the DAV namespace declaration to something else in order to make it parsable
- $dom = XMLUtil::loadDOMDocument($body);
-
- $newProperties = [];
-
- foreach($dom->firstChild->childNodes as $child) {
-
- if ($child->nodeType !== XML_ELEMENT_NODE) continue;
-
- $operation = XMLUtil::toClarkNotation($child);
-
- if ($operation!=='{DAV:}set' && $operation!=='{DAV:}remove') continue;
-
- $innerProperties = XMLUtil::parseProperties($child, $this->propertyMap);
-
- foreach($innerProperties as $propertyName=>$propertyValue) {
-
- if ($operation==='{DAV:}remove') {
- $propertyValue = null;
- }
-
- $newProperties[$propertyName] = $propertyValue;
-
- }
-
- }
-
- return $newProperties;
-
- }
- // }}}
-
}
diff --git a/lib/DAV/XMLUtil.php b/lib/DAV/XMLUtil.php
index 9879ac6..3048cc6 100644
--- a/lib/DAV/XMLUtil.php
+++ b/lib/DAV/XMLUtil.php
@@ -27,8 +27,9 @@ class XMLUtil {
'{DAV:}remove' => 'Sabre\\Xml\\Element\\KeyValue',
// Requests
- '{DAV:}propfind' => 'Sabre\\DAV\\Xml\\Request\\PropFind',
- '{DAV:}mkcol' => 'Sabre\\DAV\\Xml\\Request\\MkCol',
+ '{DAV:}propfind' => 'Sabre\\DAV\\Xml\\Request\\PropFind',
+ '{DAV:}propertyupdate' => 'Sabre\\DAV\\Xml\\Request\\PropPatch',
+ '{DAV:}mkcol' => 'Sabre\\DAV\\Xml\\Request\\MkCol',
// Properties
'{DAV:}resourcetype' => 'Sabre\\DAV\\Xml\\Property\\ResourceType',
diff --git a/lib/DAV/Xml/Request/PropPatch.php b/lib/DAV/Xml/Request/PropPatch.php
index b41eb5f..c080a44 100644
--- a/lib/DAV/Xml/Request/PropPatch.php
+++ b/lib/DAV/Xml/Request/PropPatch.php
@@ -2,11 +2,8 @@
namespace Sabre\DAV\Xml\Request;
-use
- Sabre\Xml\Element,
- Sabre\Xml\Reader,
- Sabre\Xml\Writer,
- Sabre\DAV\Exception\CannotSerialize;
+use Sabre\Xml\XmlDeserializable;
+use Sabre\Xml\Reader;
/**
* WebDAV PROPPATCH request parser.
@@ -19,7 +16,7 @@ use
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
*/
-class PropPatch implements Element {
+class PropPatch implements XmlDeserializable {
/**
* The list of properties that will be updated and removed.
@@ -31,27 +28,6 @@ class PropPatch implements Element {
public $properties = [];
/**
- * The serialize method is called during xml writing.
- *
- * It should use the $writer argument to encode this object into XML.
- *
- * 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).
- *
- * Important note 2: If you are writing any new elements, you are also
- * responsible for closing them.
- *
- * @param Writer $writer
- * @return void
- */
- public function xmlSerialize(Writer $writer) {
-
- throw new CannotSerialize('This element cannot be serialized.');
-
- }
-
- /**
* The deserialize method is called during xml parsing.
*
* This method is called statictly, this is because in theory this method
@@ -72,7 +48,7 @@ class PropPatch implements Element {
* @param Reader $reader
* @return mixed
*/
- static public function xmlDeserialize(Reader $reader) {
+ static function xmlDeserialize(Reader $reader) {
$self = new self();
diff --git a/tests/Sabre/DAV/HTTPPreferParsingTest.php b/tests/Sabre/DAV/HTTPPreferParsingTest.php
index 3f61c87..4f9e1d4 100644
--- a/tests/Sabre/DAV/HTTPPreferParsingTest.php
+++ b/tests/Sabre/DAV/HTTPPreferParsingTest.php
@@ -142,27 +142,23 @@ BLA
function testproppatchMinimal() {
- $request = HTTP\Sapi::createFromServerArray(array(
- 'REQUEST_METHOD' => 'PROPPATCH',
- 'REQUEST_URI' => '/',
- 'HTTP_PREFER' => 'return-minimal',
- ));
+ $request = new HTTP\Request('PROPPATCH','/', ['Prefer' => 'return-minimal']);
$request->setBody(<<<BLA
<?xml version="1.0"?>
-<d:proppatch xmlns:d="DAV:">
+<d:propertyupdate xmlns:d="DAV:">
<d:set>
<d:prop>
<d:something>nope!</d:something>
</d:prop>
</d:set>
-</d:proppatch>
+</d:propertyupdate>
BLA
);
$this->server->on('propPatch', function($path, PropPatch $propPatch) {
$propPatch->handle('{DAV:}something', function($props) {
- return true;
+ return true;
});
});
@@ -176,20 +172,16 @@ BLA
function testproppatchMinimalError() {
- $request = HTTP\Sapi::createFromServerArray(array(
- 'REQUEST_METHOD' => 'PROPPATCH',
- 'REQUEST_URI' => '/',
- 'HTTP_PREFER' => 'return-minimal',
- ));
+ $request = new HTTP\Request('PROPPATCH','/', ['Prefer' => 'return-minimal']);
$request->setBody(<<<BLA
<?xml version="1.0"?>
-<d:proppatch xmlns:d="DAV:">
+<d:propertyupdate xmlns:d="DAV:">
<d:set>
<d:prop>
<d:something>nope!</d:something>
</d:prop>
</d:set>
-</d:proppatch>
+</d:propertyupdate>
BLA
);
diff --git a/tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php b/tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php
index 053db53..f00b21c 100644
--- a/tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php
+++ b/tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php
@@ -163,25 +163,4 @@ class ServerPropsInfiniteDepthTest extends AbstractServer {
}
- /**
- */
- public function testParsePropPatchRequest() {
-
- $body = '<?xml version="1.0"?>
-<d:propertyupdate xmlns:d="DAV:" xmlns:s="http://sabredav.org/NS/test">
- <d:set><d:prop><s:someprop>somevalue</s:someprop></d:prop></d:set>
- <d:remove><d:prop><s:someprop2 /></d:prop></d:remove>
- <d:set><d:prop><s:someprop3>removeme</s:someprop3></d:prop></d:set>
- <d:remove><d:prop><s:someprop3 /></d:prop></d:remove>
-</d:propertyupdate>';
-
- $result = $this->server->parsePropPatchRequest($body);
- $this->assertEquals(array(
- '{http://sabredav.org/NS/test}someprop' => 'somevalue',
- '{http://sabredav.org/NS/test}someprop2' => null,
- '{http://sabredav.org/NS/test}someprop3' => null,
- ), $result);
-
- }
-
}
diff --git a/tests/Sabre/DAV/ServerPropsTest.php b/tests/Sabre/DAV/ServerPropsTest.php
index f625c9e..50e60e7 100644
--- a/tests/Sabre/DAV/ServerPropsTest.php
+++ b/tests/Sabre/DAV/ServerPropsTest.php
@@ -41,7 +41,7 @@ class ServerPropsTest extends AbstractServer {
}
- public function testPropFindEmptyBody() {
+ function testPropFindEmptyBody() {
$this->sendRequest("");
$this->assertEquals(207, $this->response->status);
@@ -67,7 +67,7 @@ class ServerPropsTest extends AbstractServer {
}
- public function testPropFindEmptyBodyFile() {
+ function testPropFindEmptyBodyFile() {
$this->sendRequest("", '/test2.txt', []);
$this->assertEquals(207, $this->response->status);
@@ -178,7 +178,7 @@ class ServerPropsTest extends AbstractServer {
}
- public function testParsePropPatchRequest() {
+ function testParsePropPatchRequest() {
$body = '<?xml version="1.0"?>
<d:propertyupdate xmlns:d="DAV:" xmlns:s="http://sabredav.org/NS/test">
@@ -188,16 +188,17 @@ class ServerPropsTest extends AbstractServer {
<d:remove><d:prop><s:someprop3 /></d:prop></d:remove>
</d:propertyupdate>';
- $result = $this->server->parsePropPatchRequest($body);
- $this->assertEquals(array(
+ $result = $this->server->xml->parse($body);
+ $result = $result['value']->properties;
+ $this->assertEquals([
'{http://sabredav.org/NS/test}someprop' => 'somevalue',
'{http://sabredav.org/NS/test}someprop2' => null,
'{http://sabredav.org/NS/test}someprop3' => null,
- ), $result);
+ ], $result);
}
- public function testUpdateProperties() {
+ function testUpdateProperties() {
$props = array(
'{http://sabredav.org/NS/test}someprop' => 'somevalue',
@@ -211,7 +212,7 @@ class ServerPropsTest extends AbstractServer {
}
- public function testUpdatePropertiesProtected() {
+ function testUpdatePropertiesProtected() {
$props = array(
'{http://sabredav.org/NS/test}someprop' => 'somevalue',
@@ -227,7 +228,7 @@ class ServerPropsTest extends AbstractServer {
}
- public function testUpdatePropertiesFail1() {
+ function testUpdatePropertiesFail1() {
$dir = new Mock\PropertiesCollection('root', []);
$dir->failMode = 'updatepropsfalse';
@@ -250,7 +251,7 @@ class ServerPropsTest extends AbstractServer {
/**
* @depends testUpdateProperties
*/
- public function testUpdatePropertiesFail2() {
+ function testUpdatePropertiesFail2() {
$dir = new Mock\PropertiesCollection('root', []);
$dir->failMode = 'updatepropsarray';
@@ -274,7 +275,7 @@ class ServerPropsTest extends AbstractServer {
* @depends testUpdateProperties
* @expectedException \UnexpectedValueException
*/
- public function testUpdatePropertiesFail3() {
+ function testUpdatePropertiesFail3() {
$dir = new Mock\PropertiesCollection('root', []);
$dir->failMode = 'updatepropsobj';
@@ -294,7 +295,7 @@ class ServerPropsTest extends AbstractServer {
* @depends testParsePropPatchRequest
* @depends testUpdateProperties
*/
- public function testPropPatch() {
+ function testPropPatch() {
$serverVars = array(
'REQUEST_URI' => '/',
@@ -343,7 +344,7 @@ class ServerPropsTest extends AbstractServer {
/**
* @depends testPropPatch
*/
- public function testPropPatchAndFetch() {
+ function testPropPatchAndFetch() {
$this->testPropPatch();
$xml = '<?xml version="1.0"?>
--
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