[Pkg-owncloud-commits] [php-sabredav] 139/163: Added a test for the propertystorage plugin.

David Prévot taffit at moszumanska.debian.org
Tue May 20 18:55:02 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 f2ae88d88faaefcca8cf75a758bcc2dc08070bbb
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Wed May 14 23:38:12 2014 -0400

    Added a test for the propertystorage plugin.
---
 tests/Sabre/DAV/PropertyStorage/Backend/Mock.php | 84 ++++++++++++++++++++++++
 tests/Sabre/DAV/PropertyStorage/PluginTest.php   | 58 ++++++++++++++++
 2 files changed, 142 insertions(+)

diff --git a/tests/Sabre/DAV/PropertyStorage/Backend/Mock.php b/tests/Sabre/DAV/PropertyStorage/Backend/Mock.php
new file mode 100644
index 0000000..d5769aa
--- /dev/null
+++ b/tests/Sabre/DAV/PropertyStorage/Backend/Mock.php
@@ -0,0 +1,84 @@
+<?php
+
+namespace Sabre\DAV\PropertyStorage\Backend;
+
+use Sabre\DAV\PropFind;
+use Sabre\DAV\PropPatch;
+
+class Mock implements BackendInterface {
+
+    public $data = [];
+
+    /**
+     * Fetches properties for a path.
+     *
+     * This method received a PropFind object, which contains all the
+     * information about the properties that need to be fetched.
+     *
+     * Ususually you would just want to call 'get404Properties' on this object,
+     * as this will give you the _exact_ list of properties that need to be
+     * fetched, and haven't yet.
+     *
+     * @param string $path
+     * @param PropFind $propFind
+     * @return void
+     */
+    public function propFind($path, PropFind $propFind) {
+
+        if (!isset($this->data[$path])) {
+            return;
+        }
+
+        foreach($this->data[$path] as $name=>$value) {
+            $propFind->set($name, $value);
+        }
+
+    }
+
+    /**
+     * Updates properties for a path
+     *
+     * This method received a PropPatch object, which contains all the
+     * information about the update.
+     *
+     * Usually you would want to call 'handleRemaining' on this object, to get;
+     * a list of all properties that need to be stored.
+     *
+     * @param string $path
+     * @param PropPatch $propPatch
+     * @return void
+     */
+    public function propPatch($path, PropPatch $propPatch) {
+
+        if (!isset($this->data[$path])) {
+            $this->data[$path] = [];
+        }
+        $propPatch->handleRemaining(function($properties) use ($path) {
+
+            foreach($properties as $propName=>$propValue) {
+
+                if (is_null($propValue)) {
+                    unset($this->data[$path][$propName]);
+                } else {
+                    $this->data[$path][$propName] = $propValue;
+                }
+                return true;
+
+            }
+
+        });
+
+    }
+
+    /**
+     * This method is called after a node is deleted.
+     *
+     * This allows a backend to clean up all associated properties.
+     */
+    public function delete($path) {
+
+        unset($this->data[$path]);
+
+    }
+
+}
diff --git a/tests/Sabre/DAV/PropertyStorage/PluginTest.php b/tests/Sabre/DAV/PropertyStorage/PluginTest.php
new file mode 100644
index 0000000..1e2f545
--- /dev/null
+++ b/tests/Sabre/DAV/PropertyStorage/PluginTest.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Sabre\DAV\PropertyStorage;
+
+class PluginTest extends \Sabre\DAVServerTest {
+
+    protected $backend;
+
+    function setUp() {
+
+        parent::setUp();
+        $this->backend = new Backend\Mock();
+        $this->server->addPlugin(
+            new Plugin(
+                $this->backend
+            )
+        );
+
+    }
+
+    function testSetProperty() {
+
+        $this->server->updateProperties('', ['{DAV:}displayname' => 'hi']);
+        $this->assertEquals([
+            '' => [
+                '{DAV:}displayname' => 'hi',
+            ]
+        ], $this->backend->data);
+
+    }
+
+    /**
+     * @depends testSetProperty
+     */
+    function testGetProperty() {
+
+        $this->testSetProperty();
+        $result = $this->server->getProperties('', ['{DAV:}displayname']);
+
+        $this->assertEquals([
+            '{DAV:}displayname' => 'hi',
+        ], $result);
+
+    }
+
+    /**
+     * @depends testSetProperty
+     */
+    function testDelete() {
+
+        $this->testSetProperty();
+        $this->server->emit('afterUnbind', ['']);
+        $this->assertEquals([],$this->backend->data);
+
+
+    }
+
+}

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