[Pkg-owncloud-commits] [php-sabredav] 39/163: ACL refactoring.

David Prévot taffit at moszumanska.debian.org
Tue May 20 18:54:52 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to annotated tag upstream/2.0.0_beta1
in repository php-sabredav.

commit 308ac5f0418e032ac5f5d320d123f5b9e58f3b4c
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Sat Apr 5 01:13:00 2014 -0400

    ACL refactoring.
---
 lib/Sabre/DAV/IProperties.php                      |   6 +-
 lib/Sabre/DAVACL/Plugin.php                        |  60 +++++------
 lib/Sabre/DAVACL/Principal.php                     |  22 ++--
 .../DAVACL/PrincipalBackend/BackendInterface.php   |  53 ++--------
 lib/Sabre/DAVACL/PrincipalBackend/PDO.php          | 111 ++++++---------------
 tests/Sabre/DAV/Mock/PropertiesCollection.php      |  48 ++++++++-
 tests/Sabre/DAVACL/ExpandPropertiesTest.php        |  59 +----------
 tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php  |  24 +----
 .../DAVACL/PrincipalBackend/AbstractPDOTest.php    |  28 +++---
 tests/Sabre/DAVACL/PrincipalBackend/Mock.php       |  71 ++++---------
 tests/Sabre/DAVACL/PrincipalTest.php               |   8 +-
 11 files changed, 180 insertions(+), 310 deletions(-)

diff --git a/lib/Sabre/DAV/IProperties.php b/lib/Sabre/DAV/IProperties.php
index 5a35cf8..005dc07 100644
--- a/lib/Sabre/DAV/IProperties.php
+++ b/lib/Sabre/DAV/IProperties.php
@@ -22,10 +22,10 @@ interface IProperties extends INode {
      * To update specific properties, call the 'handle' method on this object.
      * Read the PropPatch documentation for more information.
      *
-     * @param array $mutations
-     * @return bool|array
+     * @param PropPatch $propPatch
+     * @return void
      */
-    public function propPatch(PropPatch $proppatch);
+    public function propPatch(PropPatch $propPatch);
 
     /**
      * Returns a list of properties for this nodes.
diff --git a/lib/Sabre/DAVACL/Plugin.php b/lib/Sabre/DAVACL/Plugin.php
index 7841bc3..c930575 100644
--- a/lib/Sabre/DAVACL/Plugin.php
+++ b/lib/Sabre/DAVACL/Plugin.php
@@ -661,7 +661,7 @@ class Plugin extends DAV\ServerPlugin {
         $server->on('beforeMethod',        [$this,'beforeMethod'],20);
         $server->on('beforeBind',          [$this,'beforeBind'],20);
         $server->on('beforeUnbind',        [$this,'beforeUnbind'],20);
-        $server->on('updateProperties',    [$this,'updateProperties']);
+        $server->on('propPatch',           [$this,'propPatch']);
         $server->on('beforeUnlock',        [$this,'beforeUnlock'],20);
         $server->on('report',              [$this,'report']);
         $server->on('method:ACL',          [$this,'httpAcl']);
@@ -956,42 +956,36 @@ class Plugin extends DAV\ServerPlugin {
      * This method intercepts PROPPATCH methods and make sure the
      * group-member-set is updated correctly.
      *
-     * @param array $propertyDelta
-     * @param array $result
-     * @param DAV\INode $node
-     * @return bool
+     * @param string $path
+     * @param DAV\PropPatch $propPatch
+     * @return void
      */
-    public function updateProperties(&$propertyDelta, &$result, DAV\INode $node) {
-
-        if (!array_key_exists('{DAV:}group-member-set', $propertyDelta))
-            return;
-
-        if (is_null($propertyDelta['{DAV:}group-member-set'])) {
-            $memberSet = array();
-        } elseif ($propertyDelta['{DAV:}group-member-set'] instanceof DAV\Property\HrefList) {
-            $memberSet = array_map(
-                array($this->server,'calculateUri'),
-                $propertyDelta['{DAV:}group-member-set']->getHrefs()
-            );
-        } else {
-            throw new DAV\Exception('The group-member-set property MUST be an instance of Sabre\DAV\Property\HrefList or null');
-        }
-
-        if (!($node instanceof IPrincipal)) {
-            $result[403]['{DAV:}group-member-set'] = null;
-            unset($propertyDelta['{DAV:}group-member-set']);
-
-            // Returning false will stop the updateProperties process
-            return false;
-        }
+    public function propPatch($path, DAV\PropPatch $propPatch) {
+
+        $propPatch->handle('{DAV:}group-member-set', function($value) use ($path) {
+            if (is_null($value)) {
+                $memberSet = [];
+            } elseif ($value instanceof DAV\Property\HrefList) {
+                $memberSet = array_map(
+                    [$this->server,'calculateUri'],
+                    $value->getHrefs()
+                );
+            } else {
+                throw new DAV\Exception('The group-member-set property MUST be an instance of Sabre\DAV\Property\HrefList or null');
+            }
+            $node = $this->server->tree->getNodeForPath($path);
+            if (!($node instanceof IPrincipal)) {
+                // Fail
+                return false;
+            }
 
-        $node->setGroupMemberSet($memberSet);
-        // We must also clear our cache, just in case
+            $node->setGroupMemberSet($memberSet);
+            // We must also clear our cache, just in case
 
-        $this->principalMembershipCache = array();
+            $this->principalMembershipCache = array();
 
-        $result[200]['{DAV:}group-member-set'] = null;
-        unset($propertyDelta['{DAV:}group-member-set']);
+            return true;
+        });
 
     }
 
diff --git a/lib/Sabre/DAVACL/Principal.php b/lib/Sabre/DAVACL/Principal.php
index e90c035..e0f2e0d 100644
--- a/lib/Sabre/DAVACL/Principal.php
+++ b/lib/Sabre/DAVACL/Principal.php
@@ -185,15 +185,23 @@ class Principal extends DAV\Node implements IPrincipal, DAV\IProperties, IACL {
     }
 
     /**
-     * Updates this principals properties.
-     * 
-     * @param array $mutations
-     * @see Sabre\DAV\IProperties::updateProperties
-     * @return bool|array
+     * Updates properties on this node.
+     *
+     * This method received a PropPatch object, which contains all the
+     * information about the update.
+     *
+     * To update specific properties, call the 'handle' method on this object.
+     * Read the PropPatch documentation for more information.
+     *
+     * @param DAV\PropPatch $propPatch
+     * @return void
      */
-    public function updateProperties($mutations) {
+    public function propPatch(DAV\PropPatch $propPatch) {
 
-        return $this->principalBackend->updatePrincipal($this->principalProperties['uri'], $mutations);
+        return $this->principalBackend->updatePrincipal(
+            $this->principalProperties['uri'],
+            $propPatch
+        );
 
     }
 
diff --git a/lib/Sabre/DAVACL/PrincipalBackend/BackendInterface.php b/lib/Sabre/DAVACL/PrincipalBackend/BackendInterface.php
index 8ff2fca..c62b425 100644
--- a/lib/Sabre/DAVACL/PrincipalBackend/BackendInterface.php
+++ b/lib/Sabre/DAVACL/PrincipalBackend/BackendInterface.php
@@ -46,52 +46,19 @@ interface BackendInterface {
     /**
      * Updates one ore more webdav properties on a principal.
      *
-     * The list of mutations is supplied as an array. Each key in the array is
-     * a propertyname, such as {DAV:}displayname.
-     *
-     * Each value is the actual value to be updated. If a value is null, it
-     * must be deleted.
-     *
-     * This method should be atomic. It must either completely succeed, or
-     * completely fail. Success and failure can simply be returned as 'true' or
-     * 'false'.
-     *
-     * It is also possible to return detailed failure information. In that case
-     * an array such as this should be returned:
-     *
-     * array(
-     *   200 => array(
-     *      '{DAV:}prop1' => null,
-     *   ),
-     *   201 => array(
-     *      '{DAV:}prop2' => null,
-     *   ),
-     *   403 => array(
-     *      '{DAV:}prop3' => null,
-     *   ),
-     *   424 => array(
-     *      '{DAV:}prop4' => null,
-     *   ),
-     * );
-     *
-     * In this previous example prop1 was successfully updated or deleted, and
-     * prop2 was succesfully created.
-     *
-     * prop3 failed to update due to '403 Forbidden' and because of this prop4
-     * also could not be updated with '424 Failed dependency'.
-     *
-     * This last example was actually incorrect. While 200 and 201 could appear
-     * in 1 response, if there's any error (403) the other properties should
-     * always fail with 423 (failed dependency).
-     *
-     * But anyway, if you don't want to scratch your head over this, just
-     * return true or false.
+     * The list of mutations is stored in a Sabre\DAV\PropPatch object.
+     * To do the actual updates, you must tell this object which properties
+     * you're going to process with the handle() method.
+     *
+     * Calling the handle method is like telling the PropPatch object "I
+     * promise I can handle updating this property".
+     *
+     * Read the PropPatch documenation for more info and examples.
      *
      * @param string $path
-     * @param array $mutations
-     * @return array|bool
+     * @param \Sabre\DAV\PropPatch $propPatch
      */
-    function updatePrincipal($path, $mutations);
+    function updatePrincipal($path, \Sabre\DAV\PropPatch $propPatch);
 
     /**
      * This method is used to search for principals matching a set of
diff --git a/lib/Sabre/DAVACL/PrincipalBackend/PDO.php b/lib/Sabre/DAVACL/PrincipalBackend/PDO.php
index f2bb1b0..e1c56c3 100644
--- a/lib/Sabre/DAVACL/PrincipalBackend/PDO.php
+++ b/lib/Sabre/DAVACL/PrincipalBackend/PDO.php
@@ -181,96 +181,49 @@ class PDO extends AbstractBackend {
     /**
      * Updates one ore more webdav properties on a principal.
      *
-     * The list of mutations is supplied as an array. Each key in the array is
-     * a propertyname, such as {DAV:}displayname.
+     * The list of mutations is stored in a Sabre\DAV\PropPatch object.
+     * To do the actual updates, you must tell this object which properties
+     * you're going to process with the handle() method.
      *
-     * Each value is the actual value to be updated. If a value is null, it
-     * must be deleted.
+     * Calling the handle method is like telling the PropPatch object "I
+     * promise I can handle updating this property".
      *
-     * This method should be atomic. It must either completely succeed, or
-     * completely fail. Success and failure can simply be returned as 'true' or
-     * 'false'.
-     *
-     * It is also possible to return detailed failure information. In that case
-     * an array such as this should be returned:
-     *
-     * array(
-     *   200 => array(
-     *      '{DAV:}prop1' => null,
-     *   ),
-     *   201 => array(
-     *      '{DAV:}prop2' => null,
-     *   ),
-     *   403 => array(
-     *      '{DAV:}prop3' => null,
-     *   ),
-     *   424 => array(
-     *      '{DAV:}prop4' => null,
-     *   ),
-     * );
-     *
-     * In this previous example prop1 was successfully updated or deleted, and
-     * prop2 was succesfully created.
-     *
-     * prop3 failed to update due to '403 Forbidden' and because of this prop4
-     * also could not be updated with '424 Failed dependency'.
-     *
-     * This last example was actually incorrect. While 200 and 201 could appear
-     * in 1 response, if there's any error (403) the other properties should
-     * always fail with 423 (failed dependency).
-     *
-     * But anyway, if you don't want to scratch your head over this, just
-     * return true or false.
+     * Read the PropPatch documenation for more info and examples.
      *
      * @param string $path
-     * @param array $mutations
-     * @return array|bool
+     * @param \Sabre\DAV\PropPatch $propPatch
      */
-    public function updatePrincipal($path, $mutations) {
-
-        $updateAble = array();
-        foreach($mutations as $key=>$value) {
-
-            // We are not aware of this field, we must fail.
-            if (!isset($this->fieldMap[$key])) {
-
-                $response = array(
-                    403 => array(
-                        $key => null,
-                    ),
-                    424 => array(),
-                );
-
-                // Adding the rest to the response as a 424
-                foreach($mutations as $subKey=>$subValue) {
-                    if ($subKey !== $key) {
-                        $response[424][$subKey] = null;
-                    }
-                }
-                return $response;
-            }
+    public function updatePrincipal($path, \Sabre\DAV\PropPatch $propPatch) {
 
-            $updateAble[$this->fieldMap[$key]['dbField']] = $value;
+        $propPatch->handle(array_keys($this->fieldMap), function($properties) use ($path) {
 
-        }
+            $query = "UPDATE " . $this->tableName . " SET ";
+            $first = true;
 
-        // No fields to update
-        $query = "UPDATE " . $this->tableName . " SET ";
+            $values = [];
+
+            foreach($properties as $key=>$value) {
+
+                $dbField = $this->fieldMap[$key]['dbField'];
+
+                if (!$first) {
+                    $query.= ', ';
+                }
+                $first = false;
+                $query.=$dbField . ' = :' . $dbField;
+                $values[$dbField] = $value;
 
-        $first = true;
-        foreach($updateAble as $key => $value) {
-            if (!$first) {
-                $query.= ', ';
             }
-            $first = false;
-            $query.= "$key = :$key ";
-        }
-        $query.='WHERE uri = :uri';
-        $stmt = $this->pdo->prepare($query);
-        $updateAble['uri'] =  $path;
-        $stmt->execute($updateAble);
 
-        return true;
+            $query.=" WHERE uri = :uri";
+            $values['uri'] = $path;
+
+            $stmt = $this->pdo->prepare($query);
+            $stmt->execute($values);
+
+            return true;
+
+        });
 
     }
 
diff --git a/tests/Sabre/DAV/Mock/PropertiesCollection.php b/tests/Sabre/DAV/Mock/PropertiesCollection.php
index f40aaf2..d1fac49 100644
--- a/tests/Sabre/DAV/Mock/PropertiesCollection.php
+++ b/tests/Sabre/DAV/Mock/PropertiesCollection.php
@@ -9,15 +9,32 @@ use
 
 /**
  * A node specifically for testing property-related operations
- * 
+ *
  * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved.
- * @author Evert Pot (http://evertpot.com/) 
+ * @author Evert Pot (http://evertpot.com/)
  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
  */
 class PropertiesCollection extends Collection implements IProperties {
 
     public $failMode = false;
 
+    public $properties;
+
+    /**
+     * Creates the object
+     *
+     * @param string $name
+     * @param array $children
+     * @param array $properties
+     * @return void
+     */
+    public function __construct($name, array $children, array $properties = []) {
+
+        parent::__construct($name, $children, null);
+        $this->properties = $properties;
+
+    }
+
     /**
      * Updates properties on this node.
      *
@@ -48,11 +65,32 @@ class PropertiesCollection extends Collection implements IProperties {
 
     }
 
-    function getProperties($requestedPropeties) {
+    /**
+     * Returns a list of properties for this nodes.
+     *
+     * The properties list is a list of propertynames the client requested,
+     * encoded in clark-notation {xmlnamespace}tagname
+     *
+     * If the array is empty, it means 'all properties' were requested.
+     *
+     * Note that it's fine to liberally give properties back, instead of
+     * conforming to the list of requested properties.
+     * The Server class will filter out the extra.
+     *
+     * @param array $properties
+     * @return array
+     */
+    public function getProperties($requestedProperties) {
 
-        return array();
+        $returnedProperties = array();
+        foreach($requestedProperties as $requestedProperty) {
+            if (isset($this->properties[$requestedProperty])) {
+                $returnedProperties[$requestedProperty] =
+                    $this->properties[$requestedProperty];
+            }
+        }
+        return $returnedProperties;
 
     }
 
-
 }
diff --git a/tests/Sabre/DAVACL/ExpandPropertiesTest.php b/tests/Sabre/DAVACL/ExpandPropertiesTest.php
index aba88d6..ca32e9c 100644
--- a/tests/Sabre/DAVACL/ExpandPropertiesTest.php
+++ b/tests/Sabre/DAVACL/ExpandPropertiesTest.php
@@ -12,17 +12,17 @@ class ExpandPropertiesTest extends \PHPUnit_Framework_TestCase {
     function getServer() {
 
         $tree = array(
-            new MockPropertyNode('node1', array(
+            new DAV\Mock\PropertiesCollection('node1', [], array(
                 '{http://sabredav.org/ns}simple' => 'foo',
                 '{http://sabredav.org/ns}href'   => new DAV\Property\Href('node2'),
                 '{DAV:}displayname'     => 'Node 1',
             )),
-            new MockPropertyNode('node2', array(
+            new DAV\Mock\PropertiesCollection('node2', [], array(
                 '{http://sabredav.org/ns}simple' => 'simple',
                 '{http://sabredav.org/ns}hreflist' => new DAV\Property\HrefList(array('node1','node3')),
                 '{DAV:}displayname'     => 'Node 2',
             )),
-            new MockPropertyNode('node3', array(
+            new DAV\Mock\PropertiesCollection('node3', [], array(
                 '{http://sabredav.org/ns}simple' => 'simple',
                 '{DAV:}displayname'     => 'Node 3',
             )),
@@ -304,56 +304,3 @@ class ExpandPropertiesTest extends \PHPUnit_Framework_TestCase {
 
     }
 }
-class MockPropertyNode implements DAV\INode, DAV\IProperties {
-
-    function __construct($name, array $properties) {
-
-        $this->name = $name;
-        $this->properties = $properties;
-
-    }
-
-    function getName() {
-
-        return $this->name;
-
-    }
-
-    function getProperties($requestedProperties) {
-
-        $returnedProperties = array();
-        foreach($requestedProperties as $requestedProperty) {
-            if (isset($this->properties[$requestedProperty])) {
-                $returnedProperties[$requestedProperty] =
-                    $this->properties[$requestedProperty];
-            }
-        }
-        return $returnedProperties;
-
-    }
-
-    function delete() {
-
-        throw new DAV\Exception('Not implemented');
-
-    }
-
-    function setName($name) {
-
-        throw new DAV\Exception('Not implemented');
-
-    }
-
-    function getLastModified() {
-
-        return null;
-
-    }
-
-    function updateProperties($properties) {
-
-        throw new DAV\Exception('Not implemented');
-
-    }
-
-}
diff --git a/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php b/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php
index 5356865..e461c25 100644
--- a/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php
+++ b/tests/Sabre/DAVACL/PluginUpdatePropertiesTest.php
@@ -23,10 +23,7 @@ class PluginUpdatePropertiesTest extends \PHPUnit_Framework_TestCase {
         ));
 
         $expected = array(
-            'href' => 'foo',
-            '403' => array(
-                '{DAV:}foo' => null,
-            ),
+            '{DAV:}foo' => 403,
         );
 
         $this->assertEquals($expected, $result);
@@ -46,10 +43,7 @@ class PluginUpdatePropertiesTest extends \PHPUnit_Framework_TestCase {
         ));
 
         $expected = array(
-            'href' => 'foo',
-            '200' => array(
-                '{DAV:}group-member-set' => null,
-            ),
+            '{DAV:}group-member-set' => 204
         );
 
         $this->assertEquals($expected, $result);
@@ -70,10 +64,7 @@ class PluginUpdatePropertiesTest extends \PHPUnit_Framework_TestCase {
         ));
 
         $expected = array(
-            'href' => 'foo',
-            '200' => array(
-                '{DAV:}group-member-set' => null,
-            ),
+            '{DAV:}group-member-set' => 200
         );
 
         $this->assertEquals($expected, $result);
@@ -108,17 +99,10 @@ class PluginUpdatePropertiesTest extends \PHPUnit_Framework_TestCase {
 
         $result = $server->updateProperties('foo', array(
             '{DAV:}group-member-set' => new DAV\Property\HrefList(array('/bar','/baz'),false),
-            '{DAV:}bar' => 'baz',
         ));
 
         $expected = array(
-            'href' => 'foo',
-            '403' => array(
-                '{DAV:}group-member-set' => null,
-            ),
-            '424' => array(
-                '{DAV:}bar' => null,
-            ),
+            '{DAV:}group-member-set' => 403,
         );
 
         $this->assertEquals($expected, $result);
diff --git a/tests/Sabre/DAVACL/PrincipalBackend/AbstractPDOTest.php b/tests/Sabre/DAVACL/PrincipalBackend/AbstractPDOTest.php
index 3fe75ca..ea6bf2a 100644
--- a/tests/Sabre/DAVACL/PrincipalBackend/AbstractPDOTest.php
+++ b/tests/Sabre/DAVACL/PrincipalBackend/AbstractPDOTest.php
@@ -128,10 +128,13 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
         $pdo = $this->getPDO();
         $backend = new PDO($pdo);
 
-        $result = $backend->updatePrincipal('principals/user', array(
+        $propPatch = new DAV\PropPatch([
             '{DAV:}displayname' => 'pietje',
             '{http://sabredav.org/ns}vcard-url' => 'blabla',
-        ));
+        ]);
+
+        $backend->updatePrincipal('principals/user', $propPatch);
+        $result = $propPatch->commit();
 
         $this->assertTrue($result);
 
@@ -150,21 +153,22 @@ abstract class AbstractPDOTest extends \PHPUnit_Framework_TestCase {
         $pdo = $this->getPDO();
         $backend = new PDO($pdo);
 
-        $result = $backend->updatePrincipal('principals/user', array(
+        $propPatch = new DAV\PropPatch([
             '{DAV:}displayname' => 'pietje',
             '{http://sabredav.org/ns}vcard-url' => 'blabla',
             '{DAV:}unknown' => 'foo',
-        ));
+        ]);
+
+        $backend->updatePrincipal('principals/user', $propPatch);
+        $result = $propPatch->commit();
+
+        $this->assertFalse($result);
 
         $this->assertEquals(array(
-            424 => array(
-                '{DAV:}displayname' => null,
-                '{http://sabredav.org/ns}vcard-url' => null,
-            ),
-            403 => array(
-                '{DAV:}unknown' => null,
-            ),
-        ), $result); 
+            '{DAV:}displayname' => 424,
+            '{http://sabredav.org/ns}vcard-url' => 424,
+            '{DAV:}unknown' => 403
+        ), $propPatch->getResult());
 
         $this->assertEquals(array(
             'id' => '1',
diff --git a/tests/Sabre/DAVACL/PrincipalBackend/Mock.php b/tests/Sabre/DAVACL/PrincipalBackend/Mock.php
index 354446e..1ce97c8 100644
--- a/tests/Sabre/DAVACL/PrincipalBackend/Mock.php
+++ b/tests/Sabre/DAVACL/PrincipalBackend/Mock.php
@@ -108,52 +108,19 @@ class Mock extends AbstractBackend {
     /**
      * Updates one ore more webdav properties on a principal.
      *
-     * The list of mutations is supplied as an array. Each key in the array is
-     * a propertyname, such as {DAV:}displayname.
+     * The list of mutations is stored in a Sabre\DAV\PropPatch object.
+     * To do the actual updates, you must tell this object which properties
+     * you're going to process with the handle() method.
      *
-     * Each value is the actual value to be updated. If a value is null, it
-     * must be deleted.
+     * Calling the handle method is like telling the PropPatch object "I
+     * promise I can handle updating this property".
      *
-     * This method should be atomic. It must either completely succeed, or
-     * completely fail. Success and failure can simply be returned as 'true' or
-     * 'false'.
-     *
-     * It is also possible to return detailed failure information. In that case
-     * an array such as this should be returned:
-     *
-     * array(
-     *   200 => array(
-     *      '{DAV:}prop1' => null,
-     *   ),
-     *   201 => array(
-     *      '{DAV:}prop2' => null,
-     *   ),
-     *   403 => array(
-     *      '{DAV:}prop3' => null,
-     *   ),
-     *   424 => array(
-     *      '{DAV:}prop4' => null,
-     *   ),
-     * );
-     *
-     * In this previous example prop1 was successfully updated or deleted, and
-     * prop2 was succesfully created.
-     *
-     * prop3 failed to update due to '403 Forbidden' and because of this prop4
-     * also could not be updated with '424 Failed dependency'.
-     *
-     * This last example was actually incorrect. While 200 and 201 could appear
-     * in 1 response, if there's any error (403) the other properties should
-     * always fail with 423 (failed dependency).
-     *
-     * But anyway, if you don't want to scratch your head over this, just
-     * return true or false.
+     * Read the PropPatch documenation for more info and examples.
      *
      * @param string $path
-     * @param array $mutations
-     * @return array|bool
+     * @param \Sabre\DAV\PropPatch $propPatch
      */
-    public function updatePrincipal($path, $mutations) {
+    public function updatePrincipal($path, \Sabre\DAV\PropPatch $propPatch) {
 
         $value = null;
         foreach($this->principals as $principalIndex=>$value) {
@@ -162,21 +129,25 @@ class Mock extends AbstractBackend {
                 break;
             }
         }
-        if (!$principal) return false;
+        if (!$principal) return;
+
+        $propPatch->handleRemaining(function($mutations) use ($principal, $principalIndex) {
 
-        foreach($mutations as $prop=>$value) {
+            foreach($mutations as $prop=>$value) {
+
+                if (is_null($value) && isset($principal[$prop])) {
+                    unset($principal[$prop]);
+                } else {
+                    $principal[$prop] = $value;
+                }
 
-            if (is_null($value) && isset($principal[$prop])) {
-                unset($principal[$prop]);
-            } else {
-                $principal[$prop] = $value;
             }
 
-        }
+            $this->principals[$principalIndex] = $principal;
 
-        $this->principals[$principalIndex] = $principal;
+            return true;
 
-        return true;
+        });
 
     }
 
diff --git a/tests/Sabre/DAVACL/PrincipalTest.php b/tests/Sabre/DAVACL/PrincipalTest.php
index 2d43711..47fa6a4 100644
--- a/tests/Sabre/DAVACL/PrincipalTest.php
+++ b/tests/Sabre/DAVACL/PrincipalTest.php
@@ -75,8 +75,12 @@ class PrincipalTest extends \PHPUnit_Framework_TestCase {
 
         $principalBackend = new PrincipalBackend\Mock();
         $principal = new Principal($principalBackend, array('uri' => 'principals/admin'));
-        $result = $principal->updateProperties(array('{DAV:}yourmom'=>'test'));
-        $this->assertEquals(true,$result);
+
+        $propPatch = new DAV\PropPatch(array('{DAV:}yourmom' => 'test'));
+
+        $result = $principal->propPatch($propPatch);
+        $result = $propPatch->commit();
+        $this->assertTrue($result);
 
     }
 

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