[Pkg-owncloud-commits] [php-sabredav] 104/163: Everything is working again.

David Prévot taffit at moszumanska.debian.org
Tue May 20 18:54:59 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 ebf0e97f6963414c3714e73628cd8036034ac61f
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Sat May 3 01:16:48 2014 -0400

    Everything is working again.
---
 lib/Sabre/CalDAV/SharingPlugin.php               |  2 +-
 lib/Sabre/DAV/CorePlugin.php                     |  6 +--
 lib/Sabre/DAV/PropFind.php                       | 25 +++++----
 lib/Sabre/DAV/Property/Response.php              |  2 +
 lib/Sabre/DAV/Server.php                         | 25 ++++++---
 tests/Sabre/CalDAV/JCalTransformTest.php         |  2 +-
 tests/Sabre/DAV/FSExt/ServerTest.php             | 12 ++---
 tests/Sabre/DAV/PropFindTest.php                 | 64 ++++++++++++++++++++++--
 tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php | 13 ++---
 9 files changed, 108 insertions(+), 43 deletions(-)

diff --git a/lib/Sabre/CalDAV/SharingPlugin.php b/lib/Sabre/CalDAV/SharingPlugin.php
index 5d468f9..55d8ada 100644
--- a/lib/Sabre/CalDAV/SharingPlugin.php
+++ b/lib/Sabre/CalDAV/SharingPlugin.php
@@ -148,7 +148,7 @@ class SharingPlugin extends DAV\ServerPlugin {
                 $props = $this->server->getPropertiesForPath($node->getOwner(), array(
                     '{http://sabredav.org/ns}email-address',
                     '{DAV:}displayname',
-                ), 1);
+                ), 0);
 
                 $ownerInfo = array(
                     'href' => $node->getOwner(),
diff --git a/lib/Sabre/DAV/CorePlugin.php b/lib/Sabre/DAV/CorePlugin.php
index 27e0523..9594c82 100644
--- a/lib/Sabre/DAV/CorePlugin.php
+++ b/lib/Sabre/DAV/CorePlugin.php
@@ -792,11 +792,11 @@ class CorePlugin extends ServerPlugin {
 
         if ($node instanceof IQuota) {
             $quotaInfo = null;
-            $propFind->handle('{DAV:}quota-used-bytes', function() use (&$quotaInfo) {
+            $propFind->handle('{DAV:}quota-used-bytes', function() use (&$quotaInfo, $node) {
                 $quotaInfo = $node->getQuotaInfo();
                 return $quotaInfo[0];
             });
-            $propFind->handle('{DAV:}quota-available-bytes', function() use (&$quotaInfo) {
+            $propFind->handle('{DAV:}quota-available-bytes', function() use (&$quotaInfo, $node) {
                 if (!$quotaInfo) {
                     $quotaInfo = $node->getQuotaInfo();
                 }
@@ -806,7 +806,7 @@ class CorePlugin extends ServerPlugin {
 
         $propFind->handle('{DAV:}supported-report-set', function() use ($propFind) {
             $reports = [];
-            foreach($this->server->plugins as $plugin) {
+            foreach($this->server->getPlugins() as $plugin) {
                 $reports = array_merge($reports, $plugin->getSupportedReportSet($propFind->getPath()));
             }
             return new Property\SupportedReportSet($reports);
diff --git a/lib/Sabre/DAV/PropFind.php b/lib/Sabre/DAV/PropFind.php
index 66d9de1..787ce55 100644
--- a/lib/Sabre/DAV/PropFind.php
+++ b/lib/Sabre/DAV/PropFind.php
@@ -60,7 +60,7 @@ class PropFind {
            ];
         }
 
-        foreach($properties as $propertyName) {
+        foreach($this->properties as $propertyName) {
 
             // Seeding properties with 404's.
             $this->result[$propertyName] = [404, null];
@@ -178,20 +178,20 @@ class PropFind {
     }
 
     /**
-     * Returns all propertynames that have a 404 status, and thus don't have a 
+     * Returns all propertynames that have a 404 status, and thus don't have a
      * value yet.
-     * 
-     * @return array 
+     *
+     * @return array
      */
     public function get404Properties() {
 
         if ($this->itemsLeft === 0) {
             return [];
-        } 
+        }
         $result = [];
         foreach($this->result as $propertyName=>$stuff) {
             if ($stuff[0]===404) {
-                $this->itemsLeft[] = $propertyName;
+                $result[] = $propertyName;
             }
         }
         return $result;
@@ -202,8 +202,8 @@ class PropFind {
      * Returns the full list of requested properties.
      *
      * This returns just their names, not a status or value.
-     * 
-     * @return array 
+     *
+     * @return array
      */
     public function getRequestedProperties() {
 
@@ -214,18 +214,21 @@ class PropFind {
     /**
      * Returns a result array that's often used in multistatus responses.
      *
-     * The array uses status codes as keys, and property names and value pairs 
+     * The array uses status codes as keys, and property names and value pairs
      * as the value of the top array.. such as :
      *
      * [
      *  200 => [ '{DAV:}displayname' => 'foo' ],
      * ]
      *
-     * @return array 
+     * @return array
      */
     public function getResultForMultiStatus() {
 
-        $r = [];
+        $r = [
+            200 => [],
+            404 => [],
+        ];
         foreach($this->result as $propertyName=>$info) {
             if (!isset($r[$info[0]])) {
                 $r[$info[0]] = [$propertyName => $info[1]];
diff --git a/lib/Sabre/DAV/Property/Response.php b/lib/Sabre/DAV/Property/Response.php
index d4f2946..a5b76dd 100644
--- a/lib/Sabre/DAV/Property/Response.php
+++ b/lib/Sabre/DAV/Property/Response.php
@@ -119,6 +119,8 @@ class Response extends DAV\Property implements IHref {
 
         $uri = URLUtil::encodePath($this->href);
 
+        if ($uri==='/') $uri = '';
+
         // Adding the baseurl to the beginning of the url
         $uri = $server->getBaseUri() . $uri;
 
diff --git a/lib/Sabre/DAV/Server.php b/lib/Sabre/DAV/Server.php
index 1ab31fc..a4262df 100644
--- a/lib/Sabre/DAV/Server.php
+++ b/lib/Sabre/DAV/Server.php
@@ -859,14 +859,15 @@ class Server extends EventEmitter {
         foreach($this->tree->getChildren($path) as $childNode) {
             $subPropFind = clone $propFind;
             $subPropFind->setDepth($newDepth);
-            $subPropFind->setPath($path . '/' . $childNode->getName());
+            $subPath = $path? $path . '/' . $childNode->getName() : $childNode->getName();
+            $subPropFind->setPath($subPath);
 
             $propFindRequests[] = [
                 $subPropFind,
                 $childNode
             ];
 
-            if ($newDepth===self::DEPTH_INFINITY || $newDepth>=1) {
+            if (($newDepth===self::DEPTH_INFINITY || $newDepth>=1) && $childNode instanceof ICollection) {
                 $this->addPathNodesRecursively($propFindRequests, $subPropFind);
             }
 
@@ -892,15 +893,17 @@ class Server extends EventEmitter {
         // The only two options for the depth of a propfind is 0 or 1 - as long as depth infinity is not enabled
         if (!$this->enablePropfindDepthInfinity && $depth != 0) $depth = 1;
 
-        $path = rtrim($path,'/');
-        $propFind = new PropFind(rtrim($path,'/'), $propertyNames, $depth);
+        $path = trim($path,'/');
+
+        $propFindType = $propertyNames?PropFind::NORMAL:PropFind::ALLPROPS;
+        $propFind = new PropFind($path, $propertyNames, $depth, $propFindType);
 
         // This event allows people to intercept these requests early on in the
         // process.
         //
         // We're not doing anything with the result, but this can be helpful to
         // pre-fetch certain expensive live properties.
-        $this->emit('beforeGetPropertiesForPath', [$propFind]);
+        $this->emit('beforeGetPropertiesForPath', [$propFind->getPath(), $propertyNames, $depth]);
 
         $parentNode = $this->tree->getNodeForPath($path);
         $nodes = [
@@ -963,7 +966,17 @@ class Server extends EventEmitter {
 
         foreach($nodes as $path=>$node) {
 
-            $result[$path] = $this->getPropertiesByNode($path, $node, $propertyNames);
+            $propFind = new PropFind($path, $propertyNames);
+            $r = $this->getPropertiesByNode($propFind,$node);
+            if ($r) {
+                $result[$path] = $propFind->getResultForMultiStatus();
+                $result[$path]['href'] = $path;
+
+                $resourceType = $this->getResourceTypeForNode($node);
+                if (in_array('{DAV:}collection', $resourceType) || in_array('{DAV:}principal', $resourceType)) {
+                    $result[$path]['href'].='/';
+                }
+            }
 
         }
 
diff --git a/tests/Sabre/CalDAV/JCalTransformTest.php b/tests/Sabre/CalDAV/JCalTransformTest.php
index dd69d83..abed423 100644
--- a/tests/Sabre/CalDAV/JCalTransformTest.php
+++ b/tests/Sabre/CalDAV/JCalTransformTest.php
@@ -75,7 +75,7 @@ XML;
 
         $response = $this->request($request);
 
-        $this->assertEquals(207, $response->getStatus());
+        $this->assertEquals(207, $response->getStatus(), 'Full rsponse: ' . $response->getBodyAsString());
 
         $body = $response->getBodyAsString();
 
diff --git a/tests/Sabre/DAV/FSExt/ServerTest.php b/tests/Sabre/DAV/FSExt/ServerTest.php
index 1cc9cbc..89dd1ef 100644
--- a/tests/Sabre/DAV/FSExt/ServerTest.php
+++ b/tests/Sabre/DAV/FSExt/ServerTest.php
@@ -17,15 +17,11 @@ class ServerTest extends DAV\AbstractServer{
 
     function testGet() {
 
-        $serverVars = array(
-            'REQUEST_URI'    => '/test.txt',
-            'REQUEST_METHOD' => 'GET',
-        );
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
+        $request = new HTTP\Request('GET', '/test.txt');
+        $this->server->httpRequest = $request;
         $this->server->exec();
 
+        $this->assertEquals(200, $this->response->getStatus(), 'Invalid status code received.');
         $this->assertEquals(array(
             'Content-Type' => 'application/octet-stream',
             'Content-Length' => 13,
@@ -35,7 +31,7 @@ class ServerTest extends DAV\AbstractServer{
             $this->response->headers
          );
 
-        $this->assertEquals(200, $this->response->status);
+
         $this->assertEquals('Test contents', stream_get_contents($this->response->body));
 
     }
diff --git a/tests/Sabre/DAV/PropFindTest.php b/tests/Sabre/DAV/PropFindTest.php
index 3e2ba58..9e05863 100644
--- a/tests/Sabre/DAV/PropFindTest.php
+++ b/tests/Sabre/DAV/PropFindTest.php
@@ -6,11 +6,69 @@ class PropFindTest extends \PHPUnit_Framework_TestCase {
 
     function testHandle() {
 
-        $propFind = new PropFind('foo', ['{DAV:}displayname']); 
+        $propFind = new PropFind('foo', ['{DAV:}displayname']);
         $propFind->handle('{DAV:}displayname', 'foobar');
 
-        $this->assertEquals([200 => ['{DAV:}displayname' => 'foobar']], $propFind->getResultForMultiStatus());
+        $this->assertEquals([
+            200 => ['{DAV:}displayname' => 'foobar'],
+            404 => [],
+        ], $propFind->getResultForMultiStatus());
 
-    } 
+    }
 
+    function testHandleCallBack() {
+
+        $propFind = new PropFind('foo', ['{DAV:}displayname']);
+        $propFind->handle('{DAV:}displayname', function() { return 'foobar'; });
+
+        $this->assertEquals([
+            200 => ['{DAV:}displayname' => 'foobar'],
+            404 => [],
+        ], $propFind->getResultForMultiStatus());
+
+    }
+
+    function testAllPropDefaults() {
+
+        $propFind = new PropFind('foo', ['{DAV:}displayname'], 0, PropFind::ALLPROPS);
+
+        $this->assertEquals([
+            200 => [],
+            404 => [
+                '{DAV:}getlastmodified' => null,
+                '{DAV:}getcontentlength' => null,
+                '{DAV:}resourcetype' => null,
+                '{DAV:}quota-used-bytes' => null,
+                '{DAV:}quota-available-bytes' => null,
+                '{DAV:}getetag' => null,
+                '{DAV:}getcontenttype' => null,
+            ],
+        ], $propFind->getResultForMultiStatus());
+
+    }
+
+    function testSet() {
+
+        $propFind = new PropFind('foo', ['{DAV:}displayname']);
+        $propFind->set('{DAV:}displayname', 200, 'bar');
+
+        $this->assertEquals([
+            200 => ['{DAV:}displayname' => 'bar'],
+            404 => [],
+        ], $propFind->getResultForMultiStatus());
+
+    }
+
+    function testSetUnset() {
+
+        $propFind = new PropFind('foo', ['{DAV:}displayname']);
+        $propFind->set('{DAV:}displayname', 200, 'bar');
+        $propFind->set('{DAV:}displayname', 404);
+
+        $this->assertEquals([
+            200 => [],
+            404 => ['{DAV:}displayname' => null],
+        ], $propFind->getResultForMultiStatus());
+
+    }
 }
diff --git a/tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php b/tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php
index 9c1ff97..683e897 100644
--- a/tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php
+++ b/tests/Sabre/DAV/ServerPropsInfiniteDepthTest.php
@@ -35,16 +35,10 @@ class ServerPropsInfiniteDepthTest extends AbstractServer {
 
     private function sendRequest($body) {
 
-        $serverVars = array(
-            'REQUEST_URI'    => '/',
-            'REQUEST_METHOD' => 'PROPFIND',
-            'HTTP_DEPTH'          => 'infinity',
-        );
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
+        $request = new HTTP\Request('PROPFIND', '/', ['Depth' => 'infinity']);
         $request->setBody($body);
 
-        $this->server->httpRequest = ($request);
+        $this->server->httpRequest = $request;
         $this->server->exec();
 
     }
@@ -66,10 +60,9 @@ class ServerPropsInfiniteDepthTest extends AbstractServer {
 
         $this->sendRequest("");
 
+        $this->assertEquals(207, $this->response->status, 'Incorrect status received. Full response body: ' . $this->response->getBodyAsString());
         $this->assertTrue($hasFired);
 
-        $this->assertEquals(207, $this->response->status);
-
         $this->assertEquals(array(
                 'Content-Type' => 'application/xml; charset=utf-8',
                 'DAV' => '1, 3, extended-mkcol, 2',

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