[Pkg-owncloud-commits] [php-sabredav] 122/163: Fully eliminated the beforeGetProperties event.

David Prévot taffit at moszumanska.debian.org
Tue May 20 18:55:00 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 50114b1d6887c1c9a6a87f931fe8cc46456a0f24
Author: Evert Pot <me at evertpot.com>
Date:   Wed May 7 17:33:34 2014 -0400

    Fully eliminated the beforeGetProperties event.
---
 lib/Sabre/DAV/Server.php                    |  22 --
 lib/Sabre/DAVACL/Plugin.php                 | 152 +++++---------
 tests/Sabre/DAVACL/BlockAccessTest.php      |  36 +---
 tests/Sabre/DAVACL/PluginPropertiesTest.php | 300 ++++++++++++----------------
 tests/Sabre/DAVServerTest.php               |  14 --
 tests/bootstrap.php                         |   9 +-
 6 files changed, 193 insertions(+), 340 deletions(-)

diff --git a/lib/Sabre/DAV/Server.php b/lib/Sabre/DAV/Server.php
index 22b8bfd..50bfbd7 100644
--- a/lib/Sabre/DAV/Server.php
+++ b/lib/Sabre/DAV/Server.php
@@ -1011,28 +1011,6 @@ class Server extends EventEmitter {
             '404' => [],
         ];
 
-        // Note: the beforeGetProperties is deprecated and will be removed from
-        // a future version of sabre/dav.
-        $requestedProperties = $propFind->getRequestedProperties();
-
-        $result = $this->emit('beforeGetProperties', [$propFind->getPath(), $node, &$requestedProperties, &$newProperties]);
-
-        // If any event handler returned false, it means that the operation
-        // should be stopped and this node should be completely ignored.
-        if ($result===false) {
-            return false;
-        }
-
-        foreach($newProperties as $status=>$propertyList) {
-
-            foreach($propertyList as $propertyName=>$value) {
-
-                $propFind->set($propertyName, $value, $status);
-
-            }
-
-        }
-
         $this->emit('propFind', [$propFind, $node]);
 
         if ($node instanceof IProperties && $propertyNames = $propFind->get404Properties()) {
diff --git a/lib/Sabre/DAVACL/Plugin.php b/lib/Sabre/DAVACL/Plugin.php
index cefad87..449443b 100644
--- a/lib/Sabre/DAVACL/Plugin.php
+++ b/lib/Sabre/DAVACL/Plugin.php
@@ -656,8 +656,7 @@ class Plugin extends DAV\ServerPlugin {
     public function initialize(DAV\Server $server) {
 
         $this->server = $server;
-        $server->on('beforeGetProperties',[$this,'beforeGetProperties'], 20);
-
+        $server->on('propFind',            [$this,'propFind'], 20);
         $server->on('beforeMethod',        [$this,'beforeMethod'],20);
         $server->on('beforeBind',          [$this,'beforeBind'],20);
         $server->on('beforeUnbind',        [$this,'beforeUnbind'],20);
@@ -809,28 +808,33 @@ class Plugin extends DAV\ServerPlugin {
     /**
      * Triggered before properties are looked up in specific nodes.
      *
-     * @param string $uri
+     * @param DAV\PropFind $propFind
      * @param DAV\INode $node
      * @param array $requestedProperties
      * @param array $returnedProperties
      * @TODO really should be broken into multiple methods, or even a class.
      * @return bool
      */
-    public function beforeGetProperties($uri, DAV\INode $node, &$requestedProperties, &$returnedProperties) {
+    public function propFind(DAV\PropFind $propFind, DAV\INode $node) {
 
-        // Checking the read permission
-        if (!$this->checkPrivileges($uri,'{DAV:}read',self::R_PARENT,false)) {
+        $path = $propFind->getPath();
 
+        // Checking the read permission
+        if (!$this->checkPrivileges($path,'{DAV:}read',self::R_PARENT,false)) {
             // User is not allowed to read properties
+
+            // Returning false causes the property-fetching system to pretend
+            // that the node does not exist, and will cause it to be hidden
+            // from listings such as PROPFIND or the browser plugin.
             if ($this->hideNodesFromListings) {
                 return false;
             }
 
-            // Marking all requested properties as '403'.
-            foreach($requestedProperties as $key=>$requestedProperty) {
-                unset($requestedProperties[$key]);
-                $returnedProperties[403][$requestedProperty] = null;
+            // Otherwise we simply mark every property as 403.
+            foreach($propFind->getRequestedProperties() as $requestedProperty) {
+                $propFind->set($requestedProperty, null, 403);
             }
+
             return;
 
         }
@@ -838,116 +842,70 @@ class Plugin extends DAV\ServerPlugin {
         /* Adding principal properties */
         if ($node instanceof IPrincipal) {
 
-            if (false !== ($index = array_search('{DAV:}alternate-URI-set', $requestedProperties))) {
-
-                unset($requestedProperties[$index]);
-                $returnedProperties[200]['{DAV:}alternate-URI-set'] = new DAV\Property\HrefList($node->getAlternateUriSet());
-
-            }
-            if (false !== ($index = array_search('{DAV:}principal-URL', $requestedProperties))) {
-
-                unset($requestedProperties[$index]);
-                $returnedProperties[200]['{DAV:}principal-URL'] = new DAV\Property\Href($node->getPrincipalUrl() . '/');
-
-            }
-            if (false !== ($index = array_search('{DAV:}group-member-set', $requestedProperties))) {
-
-                unset($requestedProperties[$index]);
-                $returnedProperties[200]['{DAV:}group-member-set'] = new DAV\Property\HrefList($node->getGroupMemberSet());
-
-            }
-            if (false !== ($index = array_search('{DAV:}group-membership', $requestedProperties))) {
-
-                unset($requestedProperties[$index]);
-                $returnedProperties[200]['{DAV:}group-membership'] = new DAV\Property\HrefList($node->getGroupMembership());
-
-            }
-
-            if (false !== ($index = array_search('{DAV:}displayname', $requestedProperties))) {
-
-                $returnedProperties[200]['{DAV:}displayname'] = $node->getDisplayName();
-
-            }
+            $propFind->handle('{DAV:}alternate-URI-set', function() use ($node) {
+                return new DAV\Property\HrefList($node->getAlternateUriSet());
+            });
+            $propFind->handle('{DAV:}principal-URL', function() use ($node) {
+                return new DAV\Property\Href($node->getPrincipalUrl() . '/');
+            });
+            $propFind->handle('{DAV:}group-member-set', function() use ($node) {
+                return new DAV\Property\HrefList($node->getGroupMemberSet());
+            });
+            $propFind->handle('{DAV:}group-membership', function() use ($node) {
+                return new DAV\Property\HrefList($node->getGroupMembership());
+            });
+            $propFind->handle('{DAV:}displayname', [$node, 'getDisplayName']);
 
         }
-        if (false !== ($index = array_search('{DAV:}principal-collection-set', $requestedProperties))) {
 
-            unset($requestedProperties[$index]);
+        $propFind->handle('{DAV:}principal-collection-set', function() {
+
             $val = $this->principalCollectionSet;
             // Ensuring all collections end with a slash
             foreach($val as $k=>$v) $val[$k] = $v . '/';
-            $returnedProperties[200]['{DAV:}principal-collection-set'] = new DAV\Property\HrefList($val);
-
-        }
-        if (false !== ($index = array_search('{DAV:}current-user-principal', $requestedProperties))) {
+            return new DAV\Property\HrefList($val);
 
-            unset($requestedProperties[$index]);
+        });
+        $propFind->handle('{DAV:}current-user-principal', function() {
             if ($url = $this->getCurrentUserPrincipal()) {
-                $returnedProperties[200]['{DAV:}current-user-principal'] = new Property\Principal(Property\Principal::HREF, $url . '/');
+                return new Property\Principal(Property\Principal::HREF, $url . '/');
             } else {
-                $returnedProperties[200]['{DAV:}current-user-principal'] = new Property\Principal(Property\Principal::UNAUTHENTICATED);
+                return new Property\Principal(Property\Principal::UNAUTHENTICATED);
             }
-
-        }
-        if (false !== ($index = array_search('{DAV:}supported-privilege-set', $requestedProperties))) {
-
-            unset($requestedProperties[$index]);
-            $returnedProperties[200]['{DAV:}supported-privilege-set'] = new Property\SupportedPrivilegeSet($this->getSupportedPrivilegeSet($node));
-
-        }
-        if (false !== ($index = array_search('{DAV:}current-user-privilege-set', $requestedProperties))) {
-
-            if (!$this->checkPrivileges($uri, '{DAV:}read-current-user-privilege-set', self::R_PARENT, false)) {
-                $returnedProperties[403]['{DAV:}current-user-privilege-set'] = null;
-                unset($requestedProperties[$index]);
+        });
+        $propFind->handle('{DAV:}supported-privilege-set', function() use ($node) {
+            return new Property\SupportedPrivilegeSet($this->getSupportedPrivilegeSet($node));
+        });
+        $propFind->handle('{DAV:}current-user-privilege-set', function() use ($node, $propFind, $path) {
+            if (!$this->checkPrivileges($path, '{DAV:}read-current-user-privilege-set', self::R_PARENT, false)) {
+                $propFind->set('{DAV:}current-user-privilege-set', null, 403);
             } else {
                 $val = $this->getCurrentUserPrivilegeSet($node);
                 if (!is_null($val)) {
-                    unset($requestedProperties[$index]);
-                    $returnedProperties[200]['{DAV:}current-user-privilege-set'] = new Property\CurrentUserPrivilegeSet($val);
+                    return new Property\CurrentUserPrivilegeSet($val);
                 }
             }
-
-        }
-
-        /* The ACL property contains all the permissions */
-        if (false !== ($index = array_search('{DAV:}acl', $requestedProperties))) {
-
-            if (!$this->checkPrivileges($uri, '{DAV:}read-acl', self::R_PARENT, false)) {
-
-                unset($requestedProperties[$index]);
-                $returnedProperties[403]['{DAV:}acl'] = null;
-
+        });
+        $propFind->handle('{DAV:}acl', function() use ($node, $propFind, $path) {
+            /* The ACL property contains all the permissions */
+            if (!$this->checkPrivileges($path, '{DAV:}read-acl', self::R_PARENT, false)) {
+                $propFind->set('{DAV:}acl', null, 403);
             } else {
-
                 $acl = $this->getACL($node);
                 if (!is_null($acl)) {
-                    unset($requestedProperties[$index]);
-                    $returnedProperties[200]['{DAV:}acl'] = new Property\Acl($this->getACL($node));
+                    return new Property\Acl($this->getACL($node));
                 }
-
             }
-
-        }
-
-        /* The acl-restrictions property contains information on how privileges
-         * must behave.
-         */
-        if (false !== ($index = array_search('{DAV:}acl-restrictions', $requestedProperties))) {
-            unset($requestedProperties[$index]);
-            $returnedProperties[200]['{DAV:}acl-restrictions'] = new Property\AclRestrictions();
-        }
+        });
+        $propFind->handle('{DAV:}acl-restrictions', function() {
+            return new Property\AclRestrictions();
+        });
 
         /* Adding ACL properties */
         if ($node instanceof IACL) {
-
-            if (false !== ($index = array_search('{DAV:}owner', $requestedProperties))) {
-
-                unset($requestedProperties[$index]);
-                $returnedProperties[200]['{DAV:}owner'] = new DAV\Property\Href($node->getOwner() . '/');
-
-            }
-
+            $propFind->handle('{DAV:}owner', function() use ($node) {
+                return new DAV\Property\Href($node->getOwner() . '/');
+            });
         }
 
     }
diff --git a/tests/Sabre/DAVACL/BlockAccessTest.php b/tests/Sabre/DAVACL/BlockAccessTest.php
index 5564746..be3e9da 100644
--- a/tests/Sabre/DAVACL/BlockAccessTest.php
+++ b/tests/Sabre/DAVACL/BlockAccessTest.php
@@ -162,27 +162,22 @@ class BlockAccessTest extends \PHPUnit_Framework_TestCase {
 
     }
 
-    function testBeforeGetProperties() {
+    function testPropFind() {
 
-        $requestedProperties = [
+        $propFind = new DAV\PropFind('testdir', [
             '{DAV:}displayname',
             '{DAV:}getcontentlength',
             '{DAV:}bar',
             '{DAV:}owner',
-        ];
-        $returnedProperties = [];
+        ]);
 
-        $arguments = [
-            'testdir',
-            new DAV\SimpleCollection('testdir'),
-            &$requestedProperties,
-            &$returnedProperties
-        ];
-        $r = $this->server->emit('beforeGetProperties',$arguments);
+        $r = $this->server->emit('propFind', [$propFind, new DAV\SimpleCollection('testdir')]);
         $this->assertTrue($r);
 
         $expected = [
-            '403' => [
+            200 => [],
+            404 => [],
+            403 => [
                 '{DAV:}displayname' => null,
                 '{DAV:}getcontentlength' => null,
                 '{DAV:}bar' => null,
@@ -190,30 +185,21 @@ class BlockAccessTest extends \PHPUnit_Framework_TestCase {
             ],
         ];
 
-        $this->assertEquals($expected, $returnedProperties);
-        $this->assertEquals([], $requestedProperties);
+        $this->assertEquals($expected, $propFind->getResultForMultiStatus());
 
     }
 
     function testBeforeGetPropertiesNoListing() {
 
         $this->plugin->hideNodesFromListings = true;
-
-        $requestedProperties = [
+        $propFind = new DAV\PropFind('testdir', [
             '{DAV:}displayname',
             '{DAV:}getcontentlength',
             '{DAV:}bar',
             '{DAV:}owner',
-        ];
-        $returnedProperties = [];
+        ]);
 
-        $arguments = [
-            'testdir',
-            new DAV\SimpleCollection('testdir'),
-            &$requestedProperties,
-            &$returnedProperties
-        ];
-        $r = $this->server->emit('beforeGetProperties',$arguments);
+        $r = $this->server->emit('propFind', [$propFind, new DAV\SimpleCollection('testdir')]);
         $this->assertFalse($r);
 
     }
diff --git a/tests/Sabre/DAVACL/PluginPropertiesTest.php b/tests/Sabre/DAVACL/PluginPropertiesTest.php
index 705e612..886e5a0 100644
--- a/tests/Sabre/DAVACL/PluginPropertiesTest.php
+++ b/tests/Sabre/DAVACL/PluginPropertiesTest.php
@@ -5,42 +5,37 @@ namespace Sabre\DAVACL;
 use Sabre\DAV;
 use Sabre\HTTP;
 
-
 class PluginPropertiesTest extends \PHPUnit_Framework_TestCase {
 
     function testPrincipalCollectionSet() {
 
         $plugin = new Plugin();
-        $plugin->principalCollectionSet = array(
+        $plugin->principalCollectionSet = [
             'principals1',
             'principals2',
-        );
+        ];
 
-        $requestedProperties = array(
+        $requestedProperties = [
             '{DAV:}principal-collection-set',
-        );
-
-        $returnedProperties = array(
-            200 => array(),
-            404 => array(),
-        );
+        ];
 
-        $server = new DAV\Server();
+        $server = new DAV\Server(new DAV\SimpleCollection('root'));
         $server->addPlugin($plugin);
 
-        $this->assertNull($plugin->beforeGetProperties('', new DAV\SimpleCollection('root'), $requestedProperties, $returnedProperties));
+        $result = $server->getPropertiesForPath('', $requestedProperties);
+        $result = $result[0];
 
-        $this->assertEquals(1,count($returnedProperties[200]));
-        $this->assertArrayHasKey('{DAV:}principal-collection-set',$returnedProperties[200]);
-        $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $returnedProperties[200]['{DAV:}principal-collection-set']);
+        $this->assertEquals(1,count($result[200]));
+        $this->assertArrayHasKey('{DAV:}principal-collection-set',$result[200]);
+        $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $result[200]['{DAV:}principal-collection-set']);
 
-        $expected = array(
+        $expected = [
             'principals1/',
             'principals2/',
-        );
+        ];
 
 
-        $this->assertEquals($expected, $returnedProperties[200]['{DAV:}principal-collection-set']->getHrefs());
+        $this->assertEquals($expected, $result[200]['{DAV:}principal-collection-set']->getHrefs());
 
 
     }
@@ -58,40 +53,25 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase {
             '{DAV:}current-user-principal',
         ];
 
-        $returnedProperties = [
-            200 => [],
-            404 => [],
-        ];
+        $result = $fakeServer->getPropertiesForPath('', $requestedProperties);
+        $result = $result[0];
 
-        $this->assertNull($plugin->beforeGetProperties('', new DAV\SimpleCollection('root'), $requestedProperties, $returnedProperties));
-
-        $this->assertEquals(1,count($returnedProperties[200]));
-        $this->assertArrayHasKey('{DAV:}current-user-principal',$returnedProperties[200]);
-        $this->assertInstanceOf('Sabre\DAVACL\Property\Principal', $returnedProperties[200]['{DAV:}current-user-principal']);
-        $this->assertEquals(Property\Principal::UNAUTHENTICATED, $returnedProperties[200]['{DAV:}current-user-principal']->getType());
+        $this->assertEquals(1,count($result[200]));
+        $this->assertArrayHasKey('{DAV:}current-user-principal',$result[200]);
+        $this->assertInstanceOf('Sabre\DAVACL\Property\Principal', $result[200]['{DAV:}current-user-principal']);
+        $this->assertEquals(Property\Principal::UNAUTHENTICATED, $result[200]['{DAV:}current-user-principal']->getType());
 
         // This will force the login
         $fakeServer->emit('beforeMethod', [$fakeServer->httpRequest, $fakeServer->httpResponse]);
 
+        $result = $fakeServer->getPropertiesForPath('', $requestedProperties);
+        $result = $result[0];
 
-        $requestedProperties = [
-            '{DAV:}current-user-principal',
-        ];
-
-        $returnedProperties = [
-            200 => [],
-            404 => [],
-        ];
-
-
-        $this->assertNull($plugin->beforeGetProperties('', new DAV\SimpleCollection('root'), $requestedProperties, $returnedProperties));
-
-
-        $this->assertEquals(1,count($returnedProperties[200]));
-        $this->assertArrayHasKey('{DAV:}current-user-principal',$returnedProperties[200]);
-        $this->assertInstanceOf('Sabre\DAVACL\Property\Principal', $returnedProperties[200]['{DAV:}current-user-principal']);
-        $this->assertEquals(Property\Principal::HREF, $returnedProperties[200]['{DAV:}current-user-principal']->getType());
-        $this->assertEquals('principals/admin/', $returnedProperties[200]['{DAV:}current-user-principal']->getHref());
+        $this->assertEquals(1,count($result[200]));
+        $this->assertArrayHasKey('{DAV:}current-user-principal',$result[200]);
+        $this->assertInstanceOf('Sabre\DAVACL\Property\Principal', $result[200]['{DAV:}current-user-principal']);
+        $this->assertEquals(Property\Principal::HREF, $result[200]['{DAV:}current-user-principal']->getType());
+        $this->assertEquals('principals/admin/', $result[200]['{DAV:}current-user-principal']->getHref());
 
     }
 
@@ -101,24 +81,19 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase {
         $server = new DAV\Server();
         $server->addPlugin($plugin);
 
-        $requestedProperties = array(
+        $requestedProperties = [
             '{DAV:}supported-privilege-set',
-        );
-
-        $returnedProperties = array(
-            200 => array(),
-            404 => array(),
-        );
-
+        ];
 
-        $this->assertNull($plugin->beforeGetProperties('', new DAV\SimpleCollection('root'), $requestedProperties, $returnedProperties));
+        $result = $server->getPropertiesForPath('', $requestedProperties);
+        $result = $result[0];
 
-        $this->assertEquals(1,count($returnedProperties[200]));
-        $this->assertArrayHasKey('{DAV:}supported-privilege-set',$returnedProperties[200]);
-        $this->assertInstanceOf('Sabre\\DAVACL\\Property\\SupportedPrivilegeSet', $returnedProperties[200]['{DAV:}supported-privilege-set']);
+        $this->assertEquals(1,count($result[200]));
+        $this->assertArrayHasKey('{DAV:}supported-privilege-set',$result[200]);
+        $this->assertInstanceOf('Sabre\\DAVACL\\Property\\SupportedPrivilegeSet', $result[200]['{DAV:}supported-privilege-set']);
 
         $server = new DAV\Server();
-        $prop = $returnedProperties[200]['{DAV:}supported-privilege-set'];
+        $prop = $result[200]['{DAV:}supported-privilege-set'];
 
         $dom = new \DOMDocument('1.0', 'utf-8');
         $root = $dom->createElement('d:root');
@@ -127,7 +102,7 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase {
         $prop->serialize($server, $root);
 
 
-        $xpaths = array(
+        $xpaths = [
             '/d:root' => 1,
             '/d:root/d:supported-privilege' => 1,
             '/d:root/d:supported-privilege/d:privilege' => 1,
@@ -148,7 +123,7 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase {
             '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:privilege/d:unbind' => 1,
             '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:privilege/d:unlock' => 1,
             '/d:root/d:supported-privilege/d:supported-privilege/d:supported-privilege/d:abstract' => 0,
-        );
+        ];
 
 
         // reloading because php dom sucks
@@ -169,18 +144,18 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase {
 
         $plugin = new Plugin();
 
-        $nodes = array(
-            new MockACLNode('foo', array(
-                array(
+        $nodes = [
+            new MockACLNode('foo', [
+                [
                     'principal' => 'principals/admin',
                     'privilege' => '{DAV:}read',
-                )
-            )),
-            new DAV\SimpleCollection('principals', array(
+                ]
+            ]),
+            new DAV\SimpleCollection('principals', [
                 $principal = new MockPrincipal('admin','principals/admin'),
-            )),
+            ]),
 
-        );
+        ];
 
         $server = new DAV\Server($nodes);
         $server->addPlugin($plugin);
@@ -190,21 +165,16 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase {
         // Force login
         $authPlugin->beforeMethod(new HTTP\Request(), new HTTP\Response());
 
-        $requestedProperties = array(
+        $requestedProperties = [
             '{DAV:}acl',
-        );
-
-        $returnedProperties = array(
-            200 => array(),
-            404 => array(),
-        );
-
+        ];
 
-        $this->assertNull($plugin->beforeGetProperties('foo', $nodes[0], $requestedProperties, $returnedProperties));
+        $result = $server->getPropertiesForPath('foo', $requestedProperties);
+        $result = $result[0];
 
-        $this->assertEquals(1,count($returnedProperties[200]),'The {DAV:}acl property did not return from the list. Full list: ' . print_r($returnedProperties,true));
-        $this->assertArrayHasKey('{DAV:}acl',$returnedProperties[200]);
-        $this->assertInstanceOf('Sabre\\DAVACL\\Property\\ACL', $returnedProperties[200]['{DAV:}acl']);
+        $this->assertEquals(1,count($result[200]),'The {DAV:}acl property did not return from the list. Full list: ' . print_r($result, true));
+        $this->assertArrayHasKey('{DAV:}acl',$result[200]);
+        $this->assertInstanceOf('Sabre\\DAVACL\\Property\\ACL', $result[200]['{DAV:}acl']);
 
     }
 
@@ -212,18 +182,18 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase {
 
         $plugin = new Plugin();
 
-        $nodes = array(
-            new MockACLNode('foo', array(
-                array(
+        $nodes = [
+            new MockACLNode('foo', [
+                [
                     'principal' => 'principals/admin',
                     'privilege' => '{DAV:}read',
-                )
-            )),
-            new DAV\SimpleCollection('principals', array(
+                ]
+            ]),
+            new DAV\SimpleCollection('principals', [
                 $principal = new MockPrincipal('admin','principals/admin'),
-            )),
+            ]),
 
-        );
+        ];
 
         $server = new DAV\Server($nodes);
         $server->addPlugin($plugin);
@@ -233,31 +203,26 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase {
         // Force login
         $authPlugin->beforeMethod(new HTTP\Request(), new HTTP\Response());
 
-        $requestedProperties = array(
+        $requestedProperties = [
             '{DAV:}acl-restrictions',
-        );
-
-        $returnedProperties = array(
-            200 => array(),
-            404 => array(),
-        );
-
+        ];
 
-        $this->assertNull($plugin->beforeGetProperties('foo', $nodes[0], $requestedProperties, $returnedProperties));
+        $result = $server->getPropertiesForPath('foo', $requestedProperties);
+        $result = $result[0];
 
-        $this->assertEquals(1,count($returnedProperties[200]),'The {DAV:}acl-restrictions property did not return from the list. Full list: ' . print_r($returnedProperties,true));
-        $this->assertArrayHasKey('{DAV:}acl-restrictions',$returnedProperties[200]);
-        $this->assertInstanceOf('Sabre\\DAVACL\\Property\\ACLRestrictions', $returnedProperties[200]['{DAV:}acl-restrictions']);
+        $this->assertEquals(1,count($result[200]),'The {DAV:}acl-restrictions property did not return from the list. Full list: ' . print_r($result, true));
+        $this->assertArrayHasKey('{DAV:}acl-restrictions',$result[200]);
+        $this->assertInstanceOf('Sabre\\DAVACL\\Property\\ACLRestrictions', $result[200]['{DAV:}acl-restrictions']);
 
     }
 
     function testAlternateUriSet() {
 
-        $tree = array(
-            new DAV\SimpleCollection('principals', array(
+        $tree = [
+            new DAV\SimpleCollection('principals', [
                 $principal = new MockPrincipal('user','principals/user'),
-            )),
-        );
+            ])
+        ];
 
         $fakeServer = new DAV\Server($tree);
         //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm');
@@ -265,30 +230,27 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase {
         $plugin = new Plugin();
         $fakeServer->addPlugin($plugin);
 
-        $requestedProperties = array(
+        $requestedProperties = [
             '{DAV:}alternate-URI-set',
-        );
-        $returnedProperties = array();
-
-        $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties);
-
-        $this->assertNull($result);
+        ];
+        $result = $fakeServer->getPropertiesForPath('principals/user', $requestedProperties);
+        $result = $result[0];
 
-        $this->assertTrue(isset($returnedProperties[200]));
-        $this->assertTrue(isset($returnedProperties[200]['{DAV:}alternate-URI-set']));
-        $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $returnedProperties[200]['{DAV:}alternate-URI-set']);
+        $this->assertTrue(isset($result[200]));
+        $this->assertTrue(isset($result[200]['{DAV:}alternate-URI-set']));
+        $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $result[200]['{DAV:}alternate-URI-set']);
 
-        $this->assertEquals(array(), $returnedProperties[200]['{DAV:}alternate-URI-set']->getHrefs());
+        $this->assertEquals([], $result[200]['{DAV:}alternate-URI-set']->getHrefs());
 
     }
 
     function testPrincipalURL() {
 
-        $tree = array(
-            new DAV\SimpleCollection('principals', array(
+        $tree = [
+            new DAV\SimpleCollection('principals', [
                 $principal = new MockPrincipal('user','principals/user'),
-            )),
-        );
+            ]),
+        ];
 
         $fakeServer = new DAV\Server($tree);
         //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm');
@@ -296,30 +258,28 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase {
         $plugin = new Plugin();
         $fakeServer->addPlugin($plugin);
 
-        $requestedProperties = array(
+        $requestedProperties = [
             '{DAV:}principal-URL',
-        );
-        $returnedProperties = array();
-
-        $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties);
+        ];
 
-        $this->assertNull($result);
+        $result = $fakeServer->getPropertiesForPath('principals/user', $requestedProperties);
+        $result = $result[0];
 
-        $this->assertTrue(isset($returnedProperties[200]));
-        $this->assertTrue(isset($returnedProperties[200]['{DAV:}principal-URL']));
-        $this->assertInstanceOf('Sabre\\DAV\\Property\\Href', $returnedProperties[200]['{DAV:}principal-URL']);
+        $this->assertTrue(isset($result[200]));
+        $this->assertTrue(isset($result[200]['{DAV:}principal-URL']));
+        $this->assertInstanceOf('Sabre\\DAV\\Property\\Href', $result[200]['{DAV:}principal-URL']);
 
-        $this->assertEquals('principals/user/', $returnedProperties[200]['{DAV:}principal-URL']->getHref());
+        $this->assertEquals('principals/user/', $result[200]['{DAV:}principal-URL']->getHref());
 
     }
 
     function testGroupMemberSet() {
 
-        $tree = array(
-            new DAV\SimpleCollection('principals', array(
+        $tree = [
+            new DAV\SimpleCollection('principals', [
                 $principal = new MockPrincipal('user','principals/user'),
-            )),
-        );
+            ]),
+        ];
 
         $fakeServer = new DAV\Server($tree);
         //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm');
@@ -327,81 +287,71 @@ class PluginPropertiesTest extends \PHPUnit_Framework_TestCase {
         $plugin = new Plugin();
         $fakeServer->addPlugin($plugin);
 
-        $requestedProperties = array(
+        $requestedProperties = [
             '{DAV:}group-member-set',
-        );
-        $returnedProperties = array();
-
-        $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties);
+        ];
 
-        $this->assertNull($result);
+        $result = $fakeServer->getPropertiesForPath('principals/user', $requestedProperties);
+        $result = $result[0];
 
-        $this->assertTrue(isset($returnedProperties[200]));
-        $this->assertTrue(isset($returnedProperties[200]['{DAV:}group-member-set']));
-        $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $returnedProperties[200]['{DAV:}group-member-set']);
+        $this->assertTrue(isset($result[200]));
+        $this->assertTrue(isset($result[200]['{DAV:}group-member-set']));
+        $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $result[200]['{DAV:}group-member-set']);
 
-        $this->assertEquals(array(), $returnedProperties[200]['{DAV:}group-member-set']->getHrefs());
+        $this->assertEquals([], $result[200]['{DAV:}group-member-set']->getHrefs());
 
     }
 
     function testGroupMemberShip() {
 
-        $tree = array(
-            new DAV\SimpleCollection('principals', array(
+        $tree = [
+            new DAV\SimpleCollection('principals', [
                 $principal = new MockPrincipal('user','principals/user'),
-            )),
-        );
+            ]),
+        ];
 
         $fakeServer = new DAV\Server($tree);
-        //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm');
-        //$fakeServer->addPlugin($plugin);
         $plugin = new Plugin();
         $fakeServer->addPlugin($plugin);
 
-        $requestedProperties = array(
+        $requestedProperties = [
             '{DAV:}group-membership',
-        );
-        $returnedProperties = array();
-
-        $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties);
+        ];
 
-        $this->assertNull($result);
+        $result = $fakeServer->getPropertiesForPath('principals/user', $requestedProperties);
+        $result = $result[0];
 
-        $this->assertTrue(isset($returnedProperties[200]));
-        $this->assertTrue(isset($returnedProperties[200]['{DAV:}group-membership']));
-        $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $returnedProperties[200]['{DAV:}group-membership']);
+        $this->assertTrue(isset($result[200]));
+        $this->assertTrue(isset($result[200]['{DAV:}group-membership']));
+        $this->assertInstanceOf('Sabre\\DAV\\Property\\HrefList', $result[200]['{DAV:}group-membership']);
 
-        $this->assertEquals(array(), $returnedProperties[200]['{DAV:}group-membership']->getHrefs());
+        $this->assertEquals([], $result[200]['{DAV:}group-membership']->getHrefs());
 
     }
 
     function testGetDisplayName() {
 
-        $tree = array(
-            new DAV\SimpleCollection('principals', array(
+        $tree = [
+            new DAV\SimpleCollection('principals', [
                 $principal = new MockPrincipal('user','principals/user'),
-            )),
-        );
+            ]),
+        ];
 
         $fakeServer = new DAV\Server($tree);
-        //$plugin = new DAV\Auth\Plugin(new DAV\Auth\MockBackend(),'realm');
-        //$fakeServer->addPlugin($plugin);
         $plugin = new Plugin();
         $fakeServer->addPlugin($plugin);
 
-        $requestedProperties = array(
+        $requestedProperties = [
             '{DAV:}displayname',
-        );
-        $returnedProperties = array();
-
-        $result = $plugin->beforeGetProperties('principals/user',$principal,$requestedProperties,$returnedProperties);
+        ];
 
-        $this->assertNull($result);
+        $result = $fakeServer->getPropertiesForPath('principals/user', $requestedProperties);
+        $result = $result[0];
 
-        $this->assertTrue(isset($returnedProperties[200]));
-        $this->assertTrue(isset($returnedProperties[200]['{DAV:}displayname']));
+        $this->assertTrue(isset($result[200]));
+        $this->assertTrue(isset($result[200]['{DAV:}displayname']));
 
-        $this->assertEquals('user', $returnedProperties[200]['{DAV:}displayname']);
+        $this->assertEquals('user', $result[200]['{DAV:}displayname']);
 
     }
 }
diff --git a/tests/Sabre/DAVServerTest.php b/tests/Sabre/DAVServerTest.php
index b28cb5a..9fcc773 100644
--- a/tests/Sabre/DAVServerTest.php
+++ b/tests/Sabre/DAVServerTest.php
@@ -2,20 +2,6 @@
 
 namespace Sabre;
 
-require_once 'Sabre/HTTP/ResponseMock.php';
-
-require_once 'Sabre/DAV/Auth/Backend/Mock.php';
-require_once 'Sabre/DAV/Mock/File.php';
-require_once 'Sabre/DAV/Mock/Collection.php';
-require_once 'Sabre/DAV/Mock/PropertiesCollection.php';
-
-require_once 'Sabre/DAVACL/PrincipalBackend/Mock.php';
-
-require_once 'Sabre/CalDAV/Backend/Mock.php';
-require_once 'Sabre/CalDAV/Backend/MockSubscriptionSupport.php';
-
-require_once 'Sabre/CardDAV/Backend/Mock.php';
-
 use
     Sabre\HTTP\Request,
     Sabre\HTTP\Response,
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index fda2be5..bd96535 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -2,13 +2,8 @@
 
 set_include_path(__DIR__ . '/../lib/' . PATH_SEPARATOR . __DIR__ . PATH_SEPARATOR . get_include_path());
 
-include __DIR__ . '/../vendor/autoload.php';
-include 'Sabre/TestUtil.php';
-include 'Sabre/DAVServerTest.php';
-include 'Sabre/CardDAV/Backend/AbstractPDOTest.php';
-include 'Sabre/CardDAV/TestUtil.php';
-include 'Sabre/HTTP/SapiMock.php';
-include 'Sabre/DAV/ClientMock.php';
+$autoLoader = include __DIR__ . '/../vendor/autoload.php';
+$autoLoader->add('Sabre\\', __DIR__);
 
 date_default_timezone_set('UTC');
 

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