[Pkg-owncloud-commits] [php-sabredav] 234/275: moveInto is fully tested.

David Prévot taffit at moszumanska.debian.org
Thu Sep 25 14:56:14 UTC 2014


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

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

commit d2e92eca2fb0429093a0858acf03fa685b07de0b
Author: Evert Pot <evert at rooftopsolutions.nl>
Date:   Mon Sep 15 21:53:37 2014 +0100

    moveInto is fully tested.
---
 lib/DAV/FSExt/Directory.php          |   4 +-
 tests/Sabre/DAV/FSExt/ServerTest.php | 149 +++++++++++++++++++----------------
 tests/Sabre/DAV/TreeTest.php         |  77 ++++++++++++++----
 3 files changed, 146 insertions(+), 84 deletions(-)

diff --git a/lib/DAV/FSExt/Directory.php b/lib/DAV/FSExt/Directory.php
index 32aa00b..6f28b69 100644
--- a/lib/DAV/FSExt/Directory.php
+++ b/lib/DAV/FSExt/Directory.php
@@ -177,9 +177,9 @@ class Directory extends Node implements DAV\ICollection, DAV\IQuota, DAV\IMoveTa
      */
     function moveInto($targetName, $sourcePath, DAV\INode $sourceNode) {
 
-        // We only support FSExt\ICollection or FSExt\IFile objects, so
+        // We only support FSExt\Directory or FSExt\File objects, so
         // anything else we want to quickly reject.
-        if (!$sourceNode instanceof INode) {
+        if (!$sourceNode instanceof Node) {
             return false;
         }
 
diff --git a/tests/Sabre/DAV/FSExt/ServerTest.php b/tests/Sabre/DAV/FSExt/ServerTest.php
index c581238..d9fd970 100644
--- a/tests/Sabre/DAV/FSExt/ServerTest.php
+++ b/tests/Sabre/DAV/FSExt/ServerTest.php
@@ -22,13 +22,13 @@ class ServerTest extends DAV\AbstractServer{
         $this->server->exec();
 
         $this->assertEquals(200, $this->response->getStatus(), 'Invalid status code received.');
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => DAV\Version::VERSION,
             'Content-Type' => 'application/octet-stream',
             'Content-Length' => 13,
             'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
             'ETag' => '"'  .md5_file($this->tempDir . '/test.txt') . '"',
-            ),
+            ],
             $this->response->headers
          );
 
@@ -39,22 +39,17 @@ class ServerTest extends DAV\AbstractServer{
 
     function testHEAD() {
 
-        $serverVars = array(
-            'REQUEST_URI'    => '/test.txt',
-            'REQUEST_METHOD' => 'HEAD',
-        );
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
+        $request = new HTTP\Request('HEAD', '/test.txt');
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => DAV\Version::VERSION,
             'Content-Type' => 'application/octet-stream',
             'Content-Length' => 13,
             'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
             'ETag' => '"' . md5_file($this->tempDir . '/test.txt') . '"',
-            ),
+            ],
             $this->response->headers
          );
 
@@ -65,21 +60,16 @@ class ServerTest extends DAV\AbstractServer{
 
     function testPut() {
 
-        $serverVars = array(
-            'REQUEST_URI'    => '/testput.txt',
-            'REQUEST_METHOD' => 'PUT',
-        );
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
+        $request = new HTTP\Request('PUT', '/testput.txt');
         $request->setBody('Testing new file');
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => DAV\Version::VERSION,
             'Content-Length' => 0,
             'ETag'           => '"' . md5('Testing new file') . '"',
-        ), $this->response->headers);
+        ], $this->response->headers);
 
         $this->assertEquals(201, $this->response->status);
         $this->assertEquals('', $this->response->body);
@@ -89,21 +79,15 @@ class ServerTest extends DAV\AbstractServer{
 
     function testPutAlreadyExists() {
 
-        $serverVars = array(
-            'REQUEST_URI'    => '/test.txt',
-            'REQUEST_METHOD' => 'PUT',
-            'HTTP_IF_NONE_MATCH' => '*',
-        );
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
+        $request = new HTTP\Request('PUT', '/test.txt', ['If-None-Match' => '*']);
         $request->setBody('Testing new file');
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => DAV\Version::VERSION,
             'Content-Type' => 'application/xml; charset=utf-8',
-        ),$this->response->headers);
+        ],$this->response->headers);
 
         $this->assertEquals(412, $this->response->status);
         $this->assertNotEquals('Testing new file',file_get_contents($this->tempDir . '/test.txt'));
@@ -112,20 +96,14 @@ class ServerTest extends DAV\AbstractServer{
 
     function testMkcol() {
 
-        $serverVars = array(
-            'REQUEST_URI'    => '/testcol',
-            'REQUEST_METHOD' => 'MKCOL',
-        );
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $request->setBody("");
+        $request = new HTTP\Request('MKCOL', '/testcol');
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => DAV\Version::VERSION,
             'Content-Length' => '0',
-        ),$this->response->headers);
+        ],$this->response->headers);
 
         $this->assertEquals(201, $this->response->status);
         $this->assertEquals('', $this->response->body);
@@ -135,12 +113,7 @@ class ServerTest extends DAV\AbstractServer{
 
     function testPutUpdate() {
 
-        $serverVars = array(
-            'REQUEST_URI'    => '/test.txt',
-            'REQUEST_METHOD' => 'PUT',
-        );
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
+        $request = new HTTP\Request('PUT', '/test.txt');
         $request->setBody('Testing updated file');
         $this->server->httpRequest = ($request);
         $this->server->exec();
@@ -155,19 +128,14 @@ class ServerTest extends DAV\AbstractServer{
 
     function testDelete() {
 
-        $serverVars = array(
-            'REQUEST_URI'    => '/test.txt',
-            'REQUEST_METHOD' => 'DELETE',
-        );
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
+        $request = new HTTP\Request('DELETE', '/test.txt');
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => DAV\Version::VERSION,
             'Content-Length' => '0',
-        ),$this->response->headers);
+        ],$this->response->headers);
 
         $this->assertEquals(204, $this->response->status);
         $this->assertEquals('', $this->response->body);
@@ -177,22 +145,17 @@ class ServerTest extends DAV\AbstractServer{
 
     function testDeleteDirectory() {
 
-        $serverVars = array(
-            'REQUEST_URI'    => '/testcol',
-            'REQUEST_METHOD' => 'DELETE',
-        );
-
         mkdir($this->tempDir.'/testcol');
         file_put_contents($this->tempDir.'/testcol/test.txt','Hi! I\'m a file with a short lifespan');
 
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
+        $request = new HTTP\Request('DELETE', '/testcol');
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'X-Sabre-Version' => DAV\Version::VERSION,
             'Content-Length' => '0',
-        ),$this->response->headers);
+        ],$this->response->headers);
         $this->assertEquals(204, $this->response->status);
         $this->assertEquals('', $this->response->body);
         $this->assertFalse(file_exists($this->tempDir . '/col'));
@@ -201,27 +164,81 @@ class ServerTest extends DAV\AbstractServer{
 
     function testOptions() {
 
-        $serverVars = array(
-            'REQUEST_URI'    => '/',
-            'REQUEST_METHOD' => 'OPTIONS',
-        );
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
+        $request = new HTTP\Request('OPTIONS', '/');
         $this->server->httpRequest = ($request);
         $this->server->exec();
 
-        $this->assertEquals(array(
+        $this->assertEquals([
             'DAV'            => '1, 3, extended-mkcol',
             'MS-Author-Via'  => 'DAV',
             'Allow'          => 'OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT',
             'Accept-Ranges'  => 'bytes',
             'Content-Length' => '0',
             'X-Sabre-Version'=> DAV\Version::VERSION,
-        ),$this->response->headers);
+        ], $this->response->headers);
 
         $this->assertEquals(200, $this->response->status);
         $this->assertEquals('', $this->response->body);
 
     }
 
+    function testMove() {
+
+        mkdir($this->tempDir.'/testcol');
+
+        $request = new HTTP\Request('MOVE', '/test.txt', ['Destination' => '/testcol/test2.txt']);
+        $this->server->httpRequest = ($request);
+        $this->server->exec();
+
+        $this->assertEquals(201, $this->response->status);
+        $this->assertEquals('', $this->response->body);
+
+        $this->assertEquals([
+            'Content-Length' => '0',
+            'X-Sabre-Version'=> DAV\Version::VERSION,
+        ],$this->response->headers);
+
+        $this->assertTrue(
+            is_file($this->tempDir . '/testcol/test2.txt')
+        );
+
+
+    }
+
+    /**
+     * This test checks if it's possible to move a non-FSExt collection into a
+     * FSExt collection.
+     *
+     * The moveInto function *should* ignore the object and let sabredav itself
+     * execute the slow move.
+     */
+    function testMoveOtherObject() {
+
+        mkdir($this->tempDir.'/tree1');
+        mkdir($this->tempDir.'/tree2');
+
+        $tree = new DAV\Tree(new DAV\SimpleCollection('root', [
+            new DAV\FS\Directory($this->tempDir . '/tree1'),
+            new DAV\FSExt\Directory($this->tempDir . '/tree2'),
+            ]));
+        $this->server->tree = $tree;
+
+
+        $request = new HTTP\Request('MOVE', '/tree1', ['Destination' => '/tree2/tree1']);
+        $this->server->httpRequest = ($request);
+        $this->server->exec();
+
+        $this->assertEquals(201, $this->response->status);
+        $this->assertEquals('', $this->response->body);
+
+        $this->assertEquals([
+            'Content-Length' => '0',
+            'X-Sabre-Version'=> DAV\Version::VERSION,
+        ],$this->response->headers);
+
+        $this->assertTrue(
+            is_dir($this->tempDir . '/tree2/tree1')
+        );
+
+    }
 }
diff --git a/tests/Sabre/DAV/TreeTest.php b/tests/Sabre/DAV/TreeTest.php
index 18df5f9..9516c23 100644
--- a/tests/Sabre/DAV/TreeTest.php
+++ b/tests/Sabre/DAV/TreeTest.php
@@ -56,7 +56,7 @@ class TreeTest extends \PHPUnit_Framework_TestCase {
 
         $tree = new TreeMock();
         $children = $tree->getChildren('');
-        $this->assertEquals(1,count($children));
+        $this->assertEquals(2,count($children));
         $this->assertEquals('hi', $children[0]->getName());
 
     }
@@ -72,6 +72,14 @@ class TreeTest extends \PHPUnit_Framework_TestCase {
         $this->assertEquals('file', $result['hi/file']->getName());
 
     }
+    function testGetMultipleNodes2() {
+
+        $tree = new TreeMock();
+        $result = $tree->getMultipleNodes(['multi/1', 'multi/2']);
+        $this->assertArrayHasKey('multi/1', $result);
+        $this->assertArrayHasKey('multi/2', $result);
+
+    }
 
 }
 
@@ -81,19 +89,23 @@ class TreeMock extends Tree {
 
     function __construct() {
 
-        $this->nodes['hi/sub'] = new TreeDirectoryTester('sub');
-        $this->nodes['hi/file'] = new TreeFileTester('file');
-        $this->nodes['hi/file']->properties = array('test1' => 'value');
-        $this->nodes['hi/file']->data = 'foobar';
-        $this->nodes['hi'] = new TreeDirectoryTester('hi',array($this->nodes['hi/sub'], $this->nodes['hi/file']));
-        $this->nodes[''] = new TreeDirectoryTester('hi', array($this->nodes['hi']));
-
-    }
+        $file = new TreeFileTester('file');
+        $file->properties = ['test1'=>'value'];
+        $file->data = 'foobar';
 
-    function getNodeForPath($path) {
-
-        if (isset($this->nodes[$path])) return $this->nodes[$path];
-        throw new Exception\NotFound('item not found');
+        parent::__construct(
+            new TreeDirectoryTester('root', [
+                new TreeDirectoryTester('hi', [
+                    new TreeDirectoryTester('sub'),
+                    $file,
+                ]),
+                new TreeMultiGetTester('multi', [
+                    new TreeFileTester('1'),
+                    new TreeFileTester('2'),
+                    new TreeFileTester('3'),
+                ])
+            ])
+        );
 
     }
 
@@ -126,6 +138,12 @@ class TreeDirectoryTester extends SimpleCollection {
 
     }
 
+    function childExists($name) {
+
+        return !!$this->getChild($name);
+
+    }
+
     function delete() {
 
         $this->isDeleted = true;
@@ -176,16 +194,16 @@ class TreeFileTester extends File implements IProperties {
     /**
      * Updates properties on this node.
      *
-     * This method received a PropPatch object, which contains all the 
+     * 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. 
+     * To update specific properties, call the 'handle' method on this object.
      * Read the PropPatch documentation for more information.
      *
      * @param array $mutations
      * @return bool|array
      */
-    public function propPatch(PropPatch $propPatch) {
+    function propPatch(PropPatch $propPatch) {
 
         $this->properties = $propPatch->getMutations();
         $propPatch->setRemainingResultCode(200);
@@ -194,3 +212,30 @@ class TreeFileTester extends File implements IProperties {
 
 }
 
+class TreeMultiGetTester extends TreeDirectoryTester implements IMultiGet {
+
+    /**
+     * This method receives a list of paths in it's first argument.
+     * It must return an array with Node objects.
+     *
+     * If any children are not found, you do not have to return them.
+     *
+     * @return array
+     */
+    function getMultipleChildren(array $paths) {
+
+        $result = [];
+        foreach($paths as $path) {
+            try {
+                $child = $this->getChild($path);
+                $result[] = $child;
+            } catch (Exception\NotFound $e) {
+                // Do nothing
+            }
+        }
+
+        return $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