[Pkg-owncloud-commits] [php-sabredav] 86/220: More tests for sharing plugin + bug fixes

David Prévot taffit at moszumanska.debian.org
Thu May 12 01:21:11 UTC 2016


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

taffit pushed a commit to branch master
in repository php-sabredav.

commit 74b2478a7b48e3892d7adbff6935d33d461e8e91
Author: Evert Pot <me at evertpot.com>
Date:   Tue Mar 22 22:38:22 2016 -0400

    More tests for sharing plugin + bug fixes
---
 lib/DAV/Sharing/Plugin.php                    |   4 +
 lib/DAV/Xml/Element/Sharee.php                |   2 +-
 tests/Sabre/DAV/Mock/SharedNode.php           |  37 ++++++-
 tests/Sabre/DAV/Sharing/PluginTest.php        |   9 ++
 tests/Sabre/DAV/Sharing/ShareResourceTest.php | 153 ++++++++++++++++++++++++++
 5 files changed, 199 insertions(+), 6 deletions(-)

diff --git a/lib/DAV/Sharing/Plugin.php b/lib/DAV/Sharing/Plugin.php
index a10dd27..7fa0389 100644
--- a/lib/DAV/Sharing/Plugin.php
+++ b/lib/DAV/Sharing/Plugin.php
@@ -134,6 +134,10 @@ class Plugin extends ServerPlugin {
             $acl->checkPrivileges($path, '{DAV:}share');
         }
 
+        // By default all sharees are marked as not having responded yet.
+        foreach($sharees as $sharee) {
+            $sharee->inviteStatus = self::INVITE_NORESPONSE;
+        }
         $node->updateInvites($sharees);
 
     }
diff --git a/lib/DAV/Xml/Element/Sharee.php b/lib/DAV/Xml/Element/Sharee.php
index c9d4a88..2077c4f 100644
--- a/lib/DAV/Xml/Element/Sharee.php
+++ b/lib/DAV/Xml/Element/Sharee.php
@@ -113,7 +113,7 @@ class Sharee implements Element {
         $writer->write([
             '{DAV:}href' => $this->href,
             '{DAV:}prop' => $this->properties,
-            '{DAV:}share-access' => new ShareAccess($this->shareAccess),
+            '{DAV:}share-access' => new ShareAccess($this->access),
         ]);
         switch($this->inviteStatus) {
             case Plugin::INVITE_NORESPONSE :
diff --git a/tests/Sabre/DAV/Mock/SharedNode.php b/tests/Sabre/DAV/Mock/SharedNode.php
index 59258fb..d3a492d 100644
--- a/tests/Sabre/DAV/Mock/SharedNode.php
+++ b/tests/Sabre/DAV/Mock/SharedNode.php
@@ -9,6 +9,7 @@ class SharedNode extends \Sabre\DAV\Node implements ISharedNode {
 
     protected $name;
     protected $access;
+    protected $invites = [];
 
     function __construct($name, $access) {
 
@@ -50,7 +51,7 @@ class SharedNode extends \Sabre\DAV\Node implements ISharedNode {
      */
     function getShareResourceUri() {
 
-        throw new \Exception('Not implemented');
+        return 'urn:example:bar';
 
     }
 
@@ -64,7 +65,33 @@ class SharedNode extends \Sabre\DAV\Node implements ISharedNode {
      */
     function updateInvites(array $sharees) {
 
-        throw new \Exception('Not implemented');
+        foreach($sharees as $sharee) {
+
+            if ($sharee->access === \Sabre\DAV\Sharing\Plugin::ACCESS_NOACCESS) {
+                // Removal
+                foreach($this->invites as $k=>$invitee) {
+
+                    if ($invitee->href = $sharee->href) {
+                        unset($this->invites[$k]);
+                    }
+
+                }
+
+            } else {
+                foreach($this->invites as $k=>$invitee) {
+
+                    if ($invitee->href = $sharee->href) {
+                        // Overwriting an existing invitee
+                        $this->invites[$k] = $sharee;
+                        continue 2;
+                    }
+
+                }
+                // Adding a new invitee
+                $this->invites[] = $sharee;
+            }
+
+        }
 
     }
 
@@ -82,11 +109,11 @@ class SharedNode extends \Sabre\DAV\Node implements ISharedNode {
      *
      * * $properties
      *
-     * @return array
+     * @return \Sabre\DAV\Xml\Element\Sharee[]
      */
     function getInvites() {
 
-        throw new \Exception('Not implemented');
+        return $this->invites;
 
     }
-} 
+}
diff --git a/tests/Sabre/DAV/Sharing/PluginTest.php b/tests/Sabre/DAV/Sharing/PluginTest.php
index deb1dc8..00e619d 100644
--- a/tests/Sabre/DAV/Sharing/PluginTest.php
+++ b/tests/Sabre/DAV/Sharing/PluginTest.php
@@ -18,6 +18,15 @@ class PluginTest extends \Sabre\DAVServerTest {
 
     }
 
+    function testFeatures() {
+
+        $this->assertEquals(
+            ['resource-sharing'],
+            $this->sharingPlugin->getFeatures()
+        );
+
+    }
+
     function testProperties() {
 
         $result = $this->server->getPropertiesForPath(
diff --git a/tests/Sabre/DAV/Sharing/ShareResourceTest.php b/tests/Sabre/DAV/Sharing/ShareResourceTest.php
new file mode 100644
index 0000000..fd18cda
--- /dev/null
+++ b/tests/Sabre/DAV/Sharing/ShareResourceTest.php
@@ -0,0 +1,153 @@
+<?php
+
+namespace Sabre\DAV\Sharing;
+
+use Sabre\DAV\Mock;
+use Sabre\DAV\Xml\Element\Sharee;
+use Sabre\HTTP\Request;
+
+class ShareResourceTest extends \Sabre\DAVServerTest {
+
+    protected $setupSharing = true;
+    protected $sharingNodeMock;
+
+    function setUpTree() {
+
+        $this->tree[] = $this->sharingNodeMock = new Mock\SharedNode(
+            'shareable',
+            Plugin::ACCESS_SHAREDOWNER
+        );
+
+    }
+
+    function testShareResource() {
+
+        $body = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+<D:share-resource xmlns:D="DAV:">
+ <D:sharee>
+   <D:href>mailto:eric at example.com</D:href>
+   <D:prop>
+     <D:displayname>Eric York</D:displayname>
+   </D:prop>
+   <D:comment>Shared workspace</D:comment>
+   <D:share-access>
+     <D:read-write />
+   </D:share-access>
+ </D:sharee>
+</D:share-resource>
+XML;
+        $request = new Request('POST', '/shareable', ['Content-Type' => 'application/davsharing+xml; charset="utf-8"'], $body);
+
+        $response = $this->request($request);
+        $this->assertEquals(200, $response->getStatus(), (string)$response->getBodyAsString());
+
+        $expected = [
+            new Sharee([
+                'href' => 'mailto:eric at example.com',
+                'properties' => [
+                    '{DAV:}displayname' => 'Eric York',
+                ],
+                'access' => Plugin::ACCESS_READWRITE,
+                'comment' => 'Shared workspace',
+                'inviteStatus' => Plugin::INVITE_NORESPONSE,
+            ]) 
+        ];
+
+        $this->assertEquals(
+            $expected,
+            $this->sharingNodeMock->getInvites()
+        );
+
+    }
+
+    /**
+     * @depends testShareResource
+     */
+    function testShareResourceRemoveAccess() {
+
+        // First we just want to execute all the actions from the first
+        // test.
+        $this->testShareResource();
+
+        $body = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+<D:share-resource xmlns:D="DAV:">
+ <D:sharee>
+   <D:href>mailto:eric at example.com</D:href>
+   <D:share-access>
+     <D:no-access />
+   </D:share-access>
+ </D:sharee>
+</D:share-resource>
+XML;
+        $request = new Request('POST', '/shareable', ['Content-Type' => 'application/davsharing+xml; charset="utf-8"'], $body);
+
+        $response = $this->request($request);
+        $this->assertEquals(200, $response->getStatus(), (string)$response->getBodyAsString());
+
+        $expected = [];
+
+        $this->assertEquals(
+            $expected,
+            $this->sharingNodeMock->getInvites()
+        );
+
+
+    }
+
+    /**
+     * @depends testShareResource
+     */
+    function testShareResourceInviteProperty() {
+
+        // First we just want to execute all the actions from the first
+        // test.
+        $this->testShareResource();
+
+        $body = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+<D:propfind xmlns:D="DAV:">
+  <D:prop>
+    <D:invite />
+    <D:share-access />
+    <D:share-resource-uri />
+  </D:prop>
+</D:propfind>
+XML;
+        $request = new Request('PROPFIND', '/shareable', ['Content-Type' => 'application/xml'], $body);
+        $response = $this->request($request);
+
+        $this->assertEquals(207, $response->getStatus());
+
+        $expected = <<<XML
+<?xml version="1.0" encoding="utf-8" ?>
+<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
+  <d:response>
+    <d:href>/shareable</d:href>
+    <d:propstat>
+      <d:prop>
+        <d:invite>
+          <d:sharee>
+            <d:href>mailto:eric at example.com</d:href>
+            <d:prop>
+              <d:displayname>Eric York</d:displayname>
+            </d:prop>
+            <d:share-access><d:read-write /></d:share-access>
+            <d:invite-noresponse />
+          </d:sharee>
+        </d:invite>
+        <d:share-access><d:shared-owner /></d:share-access>
+        <d:share-resource-uri></d:share-resource-uri>
+      </d:prop>
+      <d:status>HTTP/1.1 200 OK</d:status>
+    </d:propstat>
+  </d:response>
+</d:multistatus>
+XML;
+
+        $this->assertXmlStringEqualsXmlString($expected, $response->getBodyAsString());
+
+    }
+
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-php/php-sabredav.git



More information about the Pkg-owncloud-commits mailing list