[Pkg-owncloud-commits] [php-sabredav] 92/148: Lots of new tests.

David Prévot taffit at moszumanska.debian.org
Wed Apr 15 01:37:21 UTC 2015


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

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

commit 9588bc79788cacbe7e3373fbceafb905dab11e6d
Author: Evert Pot <me at evertpot.com>
Date:   Fri Mar 27 11:25:57 2015 -0700

    Lots of new tests.
---
 tests/Sabre/DAV/HttpGetTest.php                    | 199 +++++++++++++++++++++
 tests/Sabre/DAV/HttpPutTest.php                    |  26 +--
 tests/Sabre/DAV/Mock/Collection.php                |  14 +-
 tests/Sabre/DAV/Mock/File.php                      |  16 +-
 .../Sabre/DAV/Mock/{File.php => StreamingFile.php} |  83 ++-------
 tests/Sabre/DAV/ServerSimpleTest.php               | 175 ------------------
 tests/Sabre/DAV/Xml/Property/LockDiscoveryTest.php |  85 +++++++++
 tests/Sabre/DAV/Xml/Request/PropFindTest.php       |  49 +++++
 tests/Sabre/DAV/Xml/Request/SyncCollectionTest.php |  95 ++++++++++
 9 files changed, 471 insertions(+), 271 deletions(-)

diff --git a/tests/Sabre/DAV/HttpGetTest.php b/tests/Sabre/DAV/HttpGetTest.php
new file mode 100644
index 0000000..71db51a
--- /dev/null
+++ b/tests/Sabre/DAV/HttpGetTest.php
@@ -0,0 +1,199 @@
+<?php
+
+namespace Sabre\DAV;
+
+use Sabre\DAVServerTest;
+use Sabre\HTTP;
+
+/**
+ * Tests related to the PUT request.
+ *
+ * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
+ * @author Evert Pot (http://evertpot.com/)
+ * @license http://sabre.io/license/ Modified BSD License
+ */
+class HttpGetTest extends DAVServerTest {
+
+    /**
+     * Sets up the DAV tree.
+     *
+     * @return void
+     */
+    function setUpTree() {
+
+        $this->tree = new Mock\Collection('root', [
+            'file1' => 'foo',
+            new Mock\Collection('dir', []),
+            new Mock\StreamingFile('streaming', 'stream') 
+        ]);
+
+    }
+
+    function testGet() {
+
+        $request = new HTTP\Request('GET', '/file1');
+        $response = $this->request($request);
+
+        $this->assertEquals(200, $response->getStatus());
+
+        // Removing Last-Modified because it keeps changing.
+        $response->removeHeader('Last-Modified');
+
+        $this->assertEquals(
+            [
+                'X-Sabre-Version' => [Version::VERSION],
+                'Content-Type'    => ['application/octet-stream'],
+                'Content-Length'  => [3],
+                'ETag'            => ['"' . md5('foo') . '"'],
+            ],
+            $response->getHeaders()
+        );
+
+        $this->assertEquals('foo', $response->getBodyAsString());
+
+    }
+
+    function testGetHttp10() {
+
+        $request = new HTTP\Request('GET', '/file1');
+        $request->setHttpVersion('1.0');
+        $response = $this->request($request);
+
+        $this->assertEquals(200, $response->getStatus());
+
+        // Removing Last-Modified because it keeps changing.
+        $response->removeHeader('Last-Modified');
+
+        $this->assertEquals(
+            [
+                'X-Sabre-Version' => [Version::VERSION],
+                'Content-Type'    => ['application/octet-stream'],
+                'Content-Length'  => [3],
+                'ETag'            => ['"' . md5('foo') . '"'],
+            ],
+            $response->getHeaders()
+        );
+
+        $this->assertEquals('1.0', $response->getHttpVersion());
+
+        $this->assertEquals('foo', $response->getBodyAsString());
+
+    }
+
+    function testGet404() {
+
+        $request = new HTTP\Request('GET', '/notfound');
+        $response = $this->request($request);
+
+        $this->assertEquals(404, $response->getStatus());
+
+    }
+
+    function testGet404_aswell() {
+
+        $request = new HTTP\Request('GET', '/file1/subfile');
+        $response = $this->request($request);
+
+        $this->assertEquals(404, $response->getStatus());
+
+    }
+
+    /**
+     * We automatically normalize double slashes.
+     */
+    function testGetDoubleSlash() {
+
+        $request = new HTTP\Request('GET', '//file1');
+        $response = $this->request($request);
+
+        $this->assertEquals(200, $response->getStatus());
+
+        // Removing Last-Modified because it keeps changing.
+        $response->removeHeader('Last-Modified');
+
+        $this->assertEquals(
+            [
+                'X-Sabre-Version' => [Version::VERSION],
+                'Content-Type'    => ['application/octet-stream'],
+                'Content-Length'  => [3],
+                'ETag'            => ['"' . md5('foo') . '"'],
+            ],
+            $response->getHeaders()
+        );
+
+        $this->assertEquals('foo', $response->getBodyAsString());
+
+    }
+
+    /**
+     * HEAD is identical to GET, but it's missing a body
+     */
+    function testHEAD() {
+
+        $request = new HTTP\Request('HEAD', '//file1');
+        $response = $this->request($request);
+
+        $this->assertEquals(200, $response->getStatus());
+
+        // Removing Last-Modified because it keeps changing.
+        $response->removeHeader('Last-Modified');
+
+        $this->assertEquals(
+            [
+                'X-Sabre-Version' => [Version::VERSION],
+                'Content-Type'    => ['application/octet-stream'],
+                'Content-Length'  => [3],
+                'ETag'            => ['"' . md5('foo') . '"'],
+            ],
+            $response->getHeaders()
+        );
+
+        $this->assertEquals('', $response->getBodyAsString());
+
+    }
+
+    function testGetCollection() {
+
+        $request = new HTTP\Request('GET', '/dir');
+        $response = $this->request($request);
+
+        $this->assertEquals(501, $response->getStatus());
+
+    }
+
+    /**
+     * According to the specs, HEAD should behave identical to GET. But, broken
+     * clients needs HEAD requests on collections to respond with a 200, so
+     * that's what we do.
+     */
+    function testHEADCollection() {
+
+        $request = new HTTP\Request('HEAD', '/dir');
+        $response = $this->request($request);
+
+        $this->assertEquals(200, $response->getStatus());
+
+    }
+
+    function testGetStreaming() {
+
+        $request = new HTTP\Request('GET', '/streaming');
+        $response = $this->request($request);
+
+        $this->assertEquals(200, $response->getStatus());
+
+        // Removing Last-Modified because it keeps changing.
+        $response->removeHeader('Last-Modified');
+
+        $this->assertEquals(
+            [
+                'X-Sabre-Version' => [Version::VERSION],
+                'Content-Type'    => ['application/octet-stream'],
+            ],
+            $response->getHeaders()
+        );
+
+        $this->assertEquals('stream', $response->getBodyAsString());
+
+    }
+}
diff --git a/tests/Sabre/DAV/HttpPutTest.php b/tests/Sabre/DAV/HttpPutTest.php
index fcf6eee..727e11b 100644
--- a/tests/Sabre/DAV/HttpPutTest.php
+++ b/tests/Sabre/DAV/HttpPutTest.php
@@ -19,7 +19,7 @@ class HttpPutTest extends DAVServerTest {
      *
      * @return void
      */
-    public function setUpTree() {
+    function setUpTree() {
 
         $this->tree = new Mock\Collection('root', [
             'file1' => 'foo',
@@ -30,7 +30,7 @@ class HttpPutTest extends DAVServerTest {
     /**
      * A successful PUT of a new file.
      */
-    public function testPut() {
+    function testPut() {
 
         $request = new HTTP\Request('PUT', '/file2', [], 'hello');
 
@@ -59,7 +59,7 @@ class HttpPutTest extends DAVServerTest {
      *
      * @depends testPut
      */
-    public function testPutExisting() {
+    function testPutExisting() {
 
         $request = new HTTP\Request('PUT', '/file1', [], 'bar');
 
@@ -88,7 +88,7 @@ class HttpPutTest extends DAVServerTest {
      *
      * @depends testPutExisting
      */
-    public function testPutExistingIfMatchStar() {
+    function testPutExistingIfMatchStar() {
 
         $request = new HTTP\Request(
             'PUT',
@@ -122,7 +122,7 @@ class HttpPutTest extends DAVServerTest {
      *
      * @depends testPutExisting
      */
-    public function testPutExistingIfMatchCorrect() {
+    function testPutExistingIfMatchCorrect() {
 
         $request = new HTTP\Request(
             'PUT',
@@ -156,7 +156,7 @@ class HttpPutTest extends DAVServerTest {
      *
      * @depends testPut
      */
-    public function testPutContentRange() {
+    function testPutContentRange() {
 
         $request = new HTTP\Request(
             'PUT',
@@ -175,7 +175,7 @@ class HttpPutTest extends DAVServerTest {
      *
      * @depends testPut
      */
-    public function testPutIfNoneMatchStar() {
+    function testPutIfNoneMatchStar() {
 
         $request = new HTTP\Request(
             'PUT',
@@ -209,7 +209,7 @@ class HttpPutTest extends DAVServerTest {
      *
      * @depends testPut
      */
-    public function testPutIfMatchStar() {
+    function testPutIfMatchStar() {
 
         $request = new HTTP\Request(
             'PUT',
@@ -229,7 +229,7 @@ class HttpPutTest extends DAVServerTest {
      *
      * @depends testPut
      */
-    public function testPutExistingIfNoneMatchStar() {
+    function testPutExistingIfNoneMatchStar() {
 
         $request = new HTTP\Request(
             'PUT',
@@ -250,7 +250,7 @@ class HttpPutTest extends DAVServerTest {
      *
      * @depends testPut
      */
-    public function testPutNoParent() {
+    function testPutNoParent() {
 
         $request = new HTTP\Request(
             'PUT',
@@ -271,7 +271,7 @@ class HttpPutTest extends DAVServerTest {
      *
      * @depends testPut
      */
-    public function testFinderPutSuccess() {
+    function testFinderPutSuccess() {
 
         $request = new HTTP\Request(
             'PUT',
@@ -304,7 +304,7 @@ class HttpPutTest extends DAVServerTest {
      *
      * @depends testFinderPutSuccess
      */
-    public function testFinderPutFail() {
+    function testFinderPutFail() {
 
         $request = new HTTP\Request(
             'PUT',
@@ -324,7 +324,7 @@ class HttpPutTest extends DAVServerTest {
      *
      * @depends testPut
      */
-    public function testPutIntercept() {
+    function testPutIntercept() {
 
         $this->server->on('beforeBind', function($uri) {
             $this->server->httpResponse->setStatus(418);
diff --git a/tests/Sabre/DAV/Mock/Collection.php b/tests/Sabre/DAV/Mock/Collection.php
index bc18708..90ec8bb 100644
--- a/tests/Sabre/DAV/Mock/Collection.php
+++ b/tests/Sabre/DAV/Mock/Collection.php
@@ -32,7 +32,7 @@ class Collection extends DAV\Collection {
      * @param array $children
      * @return void
      */
-    public function __construct($name, array $children = array(), Collection $parent = null) {
+    function __construct($name, array $children = array(), Collection $parent = null) {
 
         $this->name = $name;
         $this->children = $children;
@@ -47,7 +47,7 @@ class Collection extends DAV\Collection {
      *
      * @return string
      */
-    public function getName() {
+    function getName() {
 
         return $this->name;
 
@@ -77,7 +77,7 @@ class Collection extends DAV\Collection {
      * @param resource|string $data Initial payload
      * @return null|string
      */
-    public function createFile($name, $data = null) {
+    function createFile($name, $data = null) {
 
         if (is_resource($data)) {
             $data = stream_get_contents($data);
@@ -93,7 +93,7 @@ class Collection extends DAV\Collection {
      * @param string $name
      * @return void
      */
-    public function createDirectory($name) {
+    function createDirectory($name) {
 
         $this->children[$name] = array();
 
@@ -104,7 +104,7 @@ class Collection extends DAV\Collection {
      *
      * @return \Sabre\DAV\INode[]
      */
-    public function getChildren() {
+    function getChildren() {
 
         $result = array();
         foreach($this->children as $key=>$value) {
@@ -129,7 +129,7 @@ class Collection extends DAV\Collection {
      * @param string $name
      * @return void
      */
-    public function deleteChild($name) {
+    function deleteChild($name) {
 
         foreach($this->children as $key=>$value) {
 
@@ -152,7 +152,7 @@ class Collection extends DAV\Collection {
      *
      * @return void
      */
-    public function delete() {
+    function delete() {
 
         foreach($this->getChildren() as $child) {
             $this->deleteChild($child->getName());
diff --git a/tests/Sabre/DAV/Mock/File.php b/tests/Sabre/DAV/Mock/File.php
index d5e8a8d..14df32f 100644
--- a/tests/Sabre/DAV/Mock/File.php
+++ b/tests/Sabre/DAV/Mock/File.php
@@ -26,7 +26,7 @@ class File extends DAV\File {
      * @param array $children
      * @return void
      */
-    public function __construct($name, $contents, Collection $parent) {
+    function __construct($name, $contents, Collection $parent = null) {
 
         $this->name = $name;
         $this->put($contents);
@@ -41,7 +41,7 @@ class File extends DAV\File {
      *
      * @return string
      */
-    public function getName() {
+    function getName() {
 
         return $this->name;
 
@@ -67,7 +67,7 @@ class File extends DAV\File {
      * @param resource $data
      * @return string|null
      */
-    public function put($data) {
+    function put($data) {
 
         if (is_resource($data)) {
             $data = stream_get_contents($data);
@@ -84,7 +84,7 @@ class File extends DAV\File {
      *
      * @return mixed
      */
-    public function get() {
+    function get() {
 
         return $this->contents;
 
@@ -95,7 +95,7 @@ class File extends DAV\File {
      *
      * @return void
      */
-    public function setName($newName) {
+    function setName($newName) {
 
         $this->parent->deleteChild($this->name);
         $this->name = $newName;
@@ -112,7 +112,7 @@ class File extends DAV\File {
      *
      * @return void
      */
-    public function getETag() {
+    function getETag() {
 
         return '"' . md5($this->contents) . '"';
 
@@ -123,7 +123,7 @@ class File extends DAV\File {
      *
      * @return int
      */
-    public function getSize() {
+    function getSize() {
 
         return strlen($this->contents);
 
@@ -134,7 +134,7 @@ class File extends DAV\File {
      *
      * @return void
      */
-    public function delete() {
+    function delete() {
 
         $this->parent->deleteChild($this->name);
 
diff --git a/tests/Sabre/DAV/Mock/File.php b/tests/Sabre/DAV/Mock/StreamingFile.php
similarity index 53%
copy from tests/Sabre/DAV/Mock/File.php
copy to tests/Sabre/DAV/Mock/StreamingFile.php
index d5e8a8d..90770b4 100644
--- a/tests/Sabre/DAV/Mock/File.php
+++ b/tests/Sabre/DAV/Mock/StreamingFile.php
@@ -5,47 +5,16 @@ namespace Sabre\DAV\Mock;
 use Sabre\DAV;
 
 /**
- * Mock File
+ * Mock Streaming File File
  *
- * See the Collection in this directory for more details.
+ * Works similar to the mock file, but this one works with streams and has no
+ * content-length or etags.
  *
  * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
  * @author Evert Pot (http://evertpot.com/)
  * @license http://sabre.io/license/ Modified BSD License
  */
-class File extends DAV\File {
-
-    protected $name;
-    protected $contents;
-    protected $parent;
-
-    /**
-     * Creates the object
-     *
-     * @param string $name
-     * @param array $children
-     * @return void
-     */
-    public function __construct($name, $contents, Collection $parent) {
-
-        $this->name = $name;
-        $this->put($contents);
-        $this->parent = $parent;
-
-    }
-
-    /**
-     * Returns the name of the node.
-     *
-     * This is used to generate the url.
-     *
-     * @return string
-     */
-    public function getName() {
-
-        return $this->name;
-
-    }
+class StreamingFile extends File {
 
     /**
      * Updates the data
@@ -67,13 +36,15 @@ class File extends DAV\File {
      * @param resource $data
      * @return string|null
      */
-    public function put($data) {
+    function put($data) {
 
-        if (is_resource($data)) {
-            $data = stream_get_contents($data);
+        if (is_string($data)) {
+            $stream = fopen('php://memory','r+');
+            fwrite($stream, $data);
+            rewind($stream);
+            $data = $stream;
         }
         $this->contents = $data;
-        return '"' . md5($data) . '"';
 
     }
 
@@ -84,26 +55,13 @@ class File extends DAV\File {
      *
      * @return mixed
      */
-    public function get() {
+    function get() {
 
         return $this->contents;
 
     }
 
     /**
-     * Changes the name of the node.
-     *
-     * @return void
-     */
-    public function setName($newName) {
-
-        $this->parent->deleteChild($this->name);
-        $this->name = $newName;
-        $this->parent->createFile($newName, $this->contents);
-
-    }
-
-    /**
      * Returns the ETag for a file
      *
      * An ETag is a unique identifier representing the current version of the file. If the file changes, the ETag MUST change.
@@ -112,9 +70,9 @@ class File extends DAV\File {
      *
      * @return void
      */
-    public function getETag() {
+    function getETag() {
 
-        return '"' . md5($this->contents) . '"';
+        return null;
 
     }
 
@@ -123,20 +81,9 @@ class File extends DAV\File {
      *
      * @return int
      */
-    public function getSize() {
-
-        return strlen($this->contents);
-
-    }
-
-    /**
-     * Delete the node
-     *
-     * @return void
-     */
-    public function delete() {
+    function getSize() {
 
-        $this->parent->deleteChild($this->name);
+        return null;
 
     }
 
diff --git a/tests/Sabre/DAV/ServerSimpleTest.php b/tests/Sabre/DAV/ServerSimpleTest.php
index afec5b5..cbe9017 100644
--- a/tests/Sabre/DAV/ServerSimpleTest.php
+++ b/tests/Sabre/DAV/ServerSimpleTest.php
@@ -40,151 +40,6 @@ class ServerSimpleTest extends AbstractServer{
 
     }
 
-    function testGet() {
-
-        $serverVars = [
-            'REQUEST_URI'    => '/test.txt',
-            'REQUEST_METHOD' => 'GET',
-        ];
-        $filename = $this->tempDir . '/test.txt';
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-        $this->server->exec();
-
-        $this->assertEquals([
-            'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type'    => ['application/octet-stream'],
-            'Content-Length'  => [13],
-            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
-            ],
-            $this->response->getHeaders()
-         );
-
-        $this->assertEquals(200, $this->response->status);
-        $this->assertEquals('Test contents', stream_get_contents($this->response->body));
-
-    }
-
-    function testGetHttp10() {
-
-        $serverVars = [
-            'REQUEST_URI'     => '/test.txt',
-            'REQUEST_METHOD'  => 'GET',
-            'SERVER_PROTOCOL' => 'HTTP/1.0',
-        ];
-        $filename = $this->tempDir . '/test.txt';
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-        $this->server->exec();
-
-        $this->assertEquals([
-            'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type'    => ['application/octet-stream'],
-            'Content-Length'  => [13],
-            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
-            ],
-            $this->response->getHeaders()
-         );
-
-        $this->assertEquals(200, $this->response->status);
-        $this->assertEquals('1.0', $this->response->getHttpVersion());
-        $this->assertEquals('Test contents', stream_get_contents($this->response->body));
-
-    }
-
-    function testGetDoesntExist() {
-
-        $serverVars = [
-            'REQUEST_URI'    => '/test.txt_randomblbla',
-            'REQUEST_METHOD' => 'GET',
-        ];
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-        $this->server->exec();
-        $this->assertEquals(404, $this->response->status);
-
-    }
-
-    function testGetDoesntExist2() {
-
-        $serverVars = [
-            'REQUEST_URI'    => '/test.txt/randomblbla',
-            'REQUEST_METHOD' => 'GET',
-        ];
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-        $this->server->exec();
-        $this->assertEquals(404, $this->response->status);
-
-    }
-
-    /**
-     * This test should have the exact same result as testGet.
-     *
-     * The idea is that double slashes // are converted to single ones /
-     *
-     */
-    function testGetDoubleSlash() {
-
-        $serverVars = [
-            'REQUEST_URI'    => '//test.txt',
-            'REQUEST_METHOD' => 'GET',
-        ];
-        $filename = $this->tempDir . '/test.txt';
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-        $this->server->exec();
-
-        $this->assertEquals([
-            'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type'    => ['application/octet-stream'],
-            'Content-Length'  => [13],
-            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt')))],
-            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
-            ],
-            $this->response->getHeaders()
-         );
-
-        $this->assertEquals(200, $this->response->status);
-        $this->assertEquals('Test contents', stream_get_contents($this->response->body));
-
-    }
-
-
-    function testHEAD() {
-
-        $serverVars = [
-            'REQUEST_URI'    => '/test.txt',
-            'REQUEST_METHOD' => 'HEAD',
-        ];
-        $filename = $this->tempDir . '/test.txt';
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-        $this->server->exec();
-
-        $this->assertEquals([
-            'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type'    => ['application/octet-stream'],
-            'Content-Length'  => [13],
-            'Last-Modified'   => [HTTP\Util::toHTTPDate(new \DateTime('@' .  filemtime($this->tempDir . '/test.txt')))],
-            'ETag'            => ['"' . sha1(fileinode($filename) . filesize($filename) . filemtime($filename)) . '"'],
-            ],
-            $this->response->getHeaders()
-         );
-
-        $this->assertEquals(200, $this->response->status);
-        $this->assertEquals('', $this->response->body);
-
-    }
-
     function testOptions() {
 
         $request = new HTTP\Request('OPTIONS', '/');
@@ -247,36 +102,6 @@ class ServerSimpleTest extends AbstractServer{
 
     }
 
-    function testGETOnCollection() {
-
-        $serverVars = [
-            'REQUEST_URI'    => '/',
-            'REQUEST_METHOD' => 'GET',
-        ];
-
-        $request = HTTP\Sapi::createFromServerArray($serverVars);
-        $this->server->httpRequest = ($request);
-        $this->server->exec();
-
-        $this->assertEquals([
-            'X-Sabre-Version' => [Version::VERSION],
-            'Content-Type'    => ['application/xml; charset=utf-8'],
-        ],$this->response->getHeaders());
-
-        $this->assertEquals(501, $this->response->status);
-
-    }
-
-    function testHEADOnCollection() {
-
-        $request = new HTTP\Request('HEAD', '/');
-        $this->server->httpRequest = ($request);
-        $this->server->exec();
-
-        $this->assertEquals(200, $this->response->status);
-
-    }
-
     function testBaseUri() {
 
         $serverVars = [
diff --git a/tests/Sabre/DAV/Xml/Property/LockDiscoveryTest.php b/tests/Sabre/DAV/Xml/Property/LockDiscoveryTest.php
new file mode 100644
index 0000000..ac21379
--- /dev/null
+++ b/tests/Sabre/DAV/Xml/Property/LockDiscoveryTest.php
@@ -0,0 +1,85 @@
+<?php
+
+namespace Sabre\DAV\Xml\Property;
+
+use Sabre\DAV\Xml\XmlTest;
+use Sabre\DAV\Locks\LockInfo;
+class LockDiscoveryTest extends XmlTest {
+
+    function testSerialize() {
+
+        $lock = new LockInfo();
+        $lock->owner = 'hello';
+        $lock->token = 'blabla';
+        $lock->timeout = 600;
+        $lock->created = strtotime('2015-03-25 19:21:00');
+        $lock->scope = LockInfo::EXCLUSIVE;
+        $lock->depth = 0;
+        $lock->uri = 'hi';
+
+        $prop = new LockDiscovery([$lock]);
+
+        $xml = $this->write(['{DAV:}root' => $prop]);
+
+        $this->assertXmlStringEqualsXmlString(
+'<?xml version="1.0"?>
+<d:root xmlns:d="DAV:">
+  <d:activelock>
+  <d:lockscope><d:exclusive /></d:lockscope>
+  <d:locktype><d:write /></d:locktype>
+  <d:lockroot>
+    <d:href>/hi</d:href>
+  </d:lockroot>
+  <d:depth>0</d:depth>
+  <d:timeout>Second-600</d:timeout>
+  <d:locktoken>
+    <d:href>opaquelocktoken:blabla</d:href>
+  </d:locktoken>
+  <d:owner>hello</d:owner>
+
+  
+</d:activelock>
+</d:root>
+', $xml);
+
+    }
+    
+    function testSerializeShared() {
+
+        $lock = new LockInfo();
+        $lock->owner = 'hello';
+        $lock->token = 'blabla';
+        $lock->timeout = 600;
+        $lock->created = strtotime('2015-03-25 19:21:00');
+        $lock->scope = LockInfo::SHARED;
+        $lock->depth = 0;
+        $lock->uri = 'hi';
+
+        $prop = new LockDiscovery([$lock]);
+
+        $xml = $this->write(['{DAV:}root' => $prop]);
+
+        $this->assertXmlStringEqualsXmlString(
+'<?xml version="1.0"?>
+<d:root xmlns:d="DAV:">
+  <d:activelock>
+  <d:lockscope><d:shared /></d:lockscope>
+  <d:locktype><d:write /></d:locktype>
+  <d:lockroot>
+    <d:href>/hi</d:href>
+  </d:lockroot>
+  <d:depth>0</d:depth>
+  <d:timeout>Second-600</d:timeout>
+  <d:locktoken>
+    <d:href>opaquelocktoken:blabla</d:href>
+  </d:locktoken>
+  <d:owner>hello</d:owner>
+
+  
+</d:activelock>
+</d:root>
+', $xml);
+
+    }
+
+}
diff --git a/tests/Sabre/DAV/Xml/Request/PropFindTest.php b/tests/Sabre/DAV/Xml/Request/PropFindTest.php
new file mode 100644
index 0000000..844fe7c
--- /dev/null
+++ b/tests/Sabre/DAV/Xml/Request/PropFindTest.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Sabre\DAV\Xml\Request;
+
+use Sabre\DAV\Xml\XmlTest;
+
+class PropFindTest extends XmlTest {
+
+    function testDeserializeProp() {
+
+        $xml = '<?xml version="1.0"?>
+<d:root xmlns:d="DAV:">
+    <d:prop>
+        <d:hello />
+    </d:prop>
+</d:root>
+';
+
+        $result = $this->parse($xml, ['{DAV:}root' => 'Sabre\\DAV\\Xml\\Request\PropFind']);
+
+        $propFind = new PropFind();
+        $propFind->properties = ['{DAV:}hello'];
+
+        $this->assertEquals($propFind, $result['value']);
+
+
+    }
+
+    function testDeserializeAllProp() {
+
+        $xml = '<?xml version="1.0"?>
+<d:root xmlns:d="DAV:">
+    <d:allprop />
+</d:root>
+';
+
+        $result = $this->parse($xml, ['{DAV:}root' => 'Sabre\\DAV\\Xml\\Request\PropFind']);
+
+        $propFind = new PropFind();
+        $propFind->allProp = true;
+
+        $this->assertEquals($propFind, $result['value']);
+
+
+    }
+
+
+}
+
diff --git a/tests/Sabre/DAV/Xml/Request/SyncCollectionTest.php b/tests/Sabre/DAV/Xml/Request/SyncCollectionTest.php
new file mode 100644
index 0000000..e33bdc5
--- /dev/null
+++ b/tests/Sabre/DAV/Xml/Request/SyncCollectionTest.php
@@ -0,0 +1,95 @@
+<?php
+
+namespace Sabre\DAV\Xml\Request;
+
+use Sabre\DAV\Xml\XmlTest;
+
+class SyncCollectionReportTest extends XmlTest {
+
+    function testDeserializeProp() {
+
+        $xml = '<?xml version="1.0"?>
+<d:sync-collection xmlns:d="DAV:">
+    <d:sync-token />
+    <d:sync-level>1</d:sync-level>
+    <d:prop>
+        <d:foo />
+    </d:prop>
+</d:sync-collection>
+';
+
+        $result = $this->parse($xml, ['{DAV:}sync-collection' => 'Sabre\\DAV\\Xml\\Request\SyncCollectionReport']);
+
+        $elem = new SyncCollectionReport();
+        $elem->syncLevel = 1;
+        $elem->properties = ['{DAV:}foo'];
+
+        $this->assertEquals($elem, $result['value']);
+
+    }
+
+
+    function testDeserializeLimit() {
+
+        $xml = '<?xml version="1.0"?>
+<d:sync-collection xmlns:d="DAV:">
+    <d:sync-token />
+    <d:sync-level>1</d:sync-level>
+    <d:prop>
+        <d:foo />
+    </d:prop>
+    <d:limit><d:nresults>5</d:nresults></d:limit>
+</d:sync-collection>
+';
+
+        $result = $this->parse($xml, ['{DAV:}sync-collection' => 'Sabre\\DAV\\Xml\\Request\SyncCollectionReport']);
+
+        $elem = new SyncCollectionReport();
+        $elem->syncLevel = 1;
+        $elem->properties = ['{DAV:}foo'];
+        $elem->limit = 5;
+
+        $this->assertEquals($elem, $result['value']);
+
+    }
+
+
+    function testDeserializeInfinity() {
+
+        $xml = '<?xml version="1.0"?>
+<d:sync-collection xmlns:d="DAV:">
+    <d:sync-token />
+    <d:sync-level>infinity</d:sync-level>
+    <d:prop>
+        <d:foo />
+    </d:prop>
+</d:sync-collection>
+';
+
+        $result = $this->parse($xml, ['{DAV:}sync-collection' => 'Sabre\\DAV\\Xml\\Request\SyncCollectionReport']);
+
+        $elem = new SyncCollectionReport();
+        $elem->syncLevel = \Sabre\DAV\Server::DEPTH_INFINITY;
+        $elem->properties = ['{DAV:}foo'];
+
+        $this->assertEquals($elem, $result['value']);
+
+    }
+
+    /**
+     * @expectedException \Sabre\DAV\Exception\BadRequest
+     */
+    function testDeserializeMissingElem() {
+
+        $xml = '<?xml version="1.0"?>
+<d:sync-collection xmlns:d="DAV:">
+    <d:sync-token />
+</d:sync-collection>
+';
+
+        $result = $this->parse($xml, ['{DAV:}sync-collection' => 'Sabre\\DAV\\Xml\\Request\SyncCollectionReport']);
+
+    }
+
+}
+

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