diff options
Diffstat (limited to 'vendor/sabre/dav/tests')
23 files changed, 958 insertions, 215 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php index 511288480..2767b5f8d 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDTest.php @@ -10,7 +10,7 @@ use Sabre\VObject; * * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). * @author Evert Pot (http://evertpot.com/) - * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + * @license http://sabre.io/license/ Modified BSD License */ class ExpandEventsDTSTARTandDTENDTest extends \Sabre\DAVServerTest { diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDbyDayTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDbyDayTest.php index d5e9ff5ab..3793cadc7 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDbyDayTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDTSTARTandDTENDbyDayTest.php @@ -9,7 +9,7 @@ use Sabre\VObject; * * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). * @author Evert Pot (http://evertpot.com/) - * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + * @license http://sabre.io/license/ Modified BSD License */ class ExpandEventsDTSTARTandDTENDbyDayTest extends \Sabre\DAVServerTest { diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDoubleEventsTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDoubleEventsTest.php index e5a13f77b..09eea5276 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDoubleEventsTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/ExpandEventsDoubleEventsTest.php @@ -13,7 +13,7 @@ use Sabre\VObject; * * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). * @author Evert Pot (http://evertpot.com/) - * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + * @license http://sabre.io/license/ Modified BSD License */ class ExpandEventsDoubleEventsTest extends \Sabre\DAVServerTest { diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php b/vendor/sabre/dav/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php index e473cdeb1..6c9a09905 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/GetEventsByTimerangeTest.php @@ -9,7 +9,7 @@ use Sabre\VObject; * * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). * @author Evert Pot (http://evertpot.com/) - * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + * @license http://sabre.io/license/ Modified BSD License */ class GetEventsByTimerangeTest extends \Sabre\DAVServerTest { diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue203Test.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue203Test.php index a27e3a9e5..21ee2f550 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue203Test.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue203Test.php @@ -10,7 +10,7 @@ use Sabre\VObject; * * @copyright Copyright (C) 2007-2014 Rooftop Solutions. All rights reserved. * @author Evert Pot (http://evertpot.com/) - * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + * @license http://sabre.io/license/ Modified BSD License */ class Issue203Test extends \Sabre\DAVServerTest { diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue205Test.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue205Test.php index d9998ef44..cd6820b57 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue205Test.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue205Test.php @@ -9,7 +9,7 @@ use Sabre\VObject; * * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). * @author Evert Pot (http://evertpot.com/) - * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + * @license http://sabre.io/license/ Modified BSD License */ class Issue205Test extends \Sabre\DAVServerTest { diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue211Test.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue211Test.php index d149a3984..cc700e50d 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue211Test.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue211Test.php @@ -9,7 +9,7 @@ use Sabre\VObject; * * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). * @author Evert Pot (http://evertpot.com/) - * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + * @license http://sabre.io/license/ Modified BSD License */ class Issue211Test extends \Sabre\DAVServerTest { diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue220Test.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue220Test.php index e97cbc4a6..ce66b6a5f 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue220Test.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue220Test.php @@ -9,7 +9,7 @@ use Sabre\HTTP; * * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). * @author Evert Pot (http://evertpot.com/) - * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + * @license http://sabre.io/license/ Modified BSD License */ class Issue220Test extends \Sabre\DAVServerTest { diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue228Test.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue228Test.php index 9345bdcb2..23371a054 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Issue228Test.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Issue228Test.php @@ -8,7 +8,7 @@ use Sabre\HTTP; * * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). * @author Evert Pot (http://evertpot.com/) - * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + * @license http://sabre.io/license/ Modified BSD License */ class Issue228Test extends \Sabre\DAVServerTest { diff --git a/vendor/sabre/dav/tests/Sabre/CalDAV/Schedule/IMip/Mock.php b/vendor/sabre/dav/tests/Sabre/CalDAV/Schedule/IMip/Mock.php index a97eb3bdd..ce0946dc8 100644 --- a/vendor/sabre/dav/tests/Sabre/CalDAV/Schedule/IMip/Mock.php +++ b/vendor/sabre/dav/tests/Sabre/CalDAV/Schedule/IMip/Mock.php @@ -14,7 +14,7 @@ namespace Sabre\CalDAV\Schedule\IMip; * * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). * @author Evert Pot (http://evertpot.com/) - * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + * @license http://sabre.io/license/ Modified BSD License */ class Mock extends \Sabre\CalDAV\Schedule\IMip { diff --git a/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php b/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php index 357675686..4bf5b343e 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/AbstractServer.php @@ -25,6 +25,7 @@ abstract class AbstractServer extends \PHPUnit_Framework_TestCase { $this->server = new Server($this->getRootNode()); $this->server->httpResponse = $this->response; $this->server->debugExceptions = true; + $this->deleteTree(SABRE_TEMPDIR,false); file_put_contents(SABRE_TEMPDIR . '/test.txt', 'Test contents'); mkdir(SABRE_TEMPDIR . '/dir'); file_put_contents(SABRE_TEMPDIR . '/dir/child.txt', 'Child contents'); diff --git a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php index 265f9f1c1..8947c6688 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/FileTest.php @@ -34,9 +34,9 @@ class FileTest extends \PHPUnit_Framework_TestCase { $file = new File(SABRE_TEMPDIR . '/file.txt'); $file->put('0000000'); - $file->putRange('111',3); + $file->patch('111', 2, 3); - $this->assertEquals('0011100',file_get_contents(SABRE_TEMPDIR . '/file.txt')); + $this->assertEquals('0001110',file_get_contents(SABRE_TEMPDIR . '/file.txt')); } @@ -48,9 +48,9 @@ class FileTest extends \PHPUnit_Framework_TestCase { $file = new File(SABRE_TEMPDIR . '/file.txt'); $file->put('0000000'); - $file->putRange($stream,3); + $file->patch($stream, 2, 3); - $this->assertEquals('0022200',file_get_contents(SABRE_TEMPDIR . '/file.txt')); + $this->assertEquals('0002220',file_get_contents(SABRE_TEMPDIR . '/file.txt')); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/HttpDeleteTest.php b/vendor/sabre/dav/tests/Sabre/DAV/HttpDeleteTest.php new file mode 100644 index 000000000..da28b6979 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/HttpDeleteTest.php @@ -0,0 +1,149 @@ +<?php + +namespace Sabre\DAV; + +use Sabre\DAVServerTest; +use Sabre\HTTP; + +/** + * Tests related to the PUT request. + * + * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved. + * @author Evert Pot (http://evertpot.com/) + * @license http://sabre.io/license/ Modified BSD License + */ +class HttpDeleteTest extends DAVServerTest { + + /** + * Sets up the DAV tree. + * + * @return void + */ + public function setUpTree() { + + $this->tree = new Mock\Collection('root', array( + 'file1' => 'foo', + 'dir' => array( + 'subfile' => 'bar', + 'subfile2' => 'baz', + ), + )); + + } + + /** + * A successful DELETE + */ + public function testDelete() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file1', + 'REQUEST_METHOD' => 'DELETE', + )); + + $response = $this->request($request); + + $this->assertEquals( + 'HTTP/1.1 204 No Content', + $response->status, + "Incorrect status code. Response body: " . $response->body + ); + + $this->assertEquals( + array( + 'Content-Length' => '0', + ), + $response->headers + ); + + } + + /** + * Deleting a Directory + */ + public function testDeleteDirectory() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/dir', + 'REQUEST_METHOD' => 'DELETE', + )); + + $response = $this->request($request); + + $this->assertEquals( + 'HTTP/1.1 204 No Content', + $response->status, + "Incorrect status code. Response body: " . $response->body + ); + + $this->assertEquals( + array( + 'Content-Length' => '0', + ), + $response->headers + ); + + } + + /** + * DELETE on a node that does not exist + */ + public function testDeleteNotFound() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file2', + 'REQUEST_METHOD' => 'DELETE', + )); + + $response = $this->request($request); + + $this->assertEquals( + 'HTTP/1.1 404 Not Found', + $response->status, + "Incorrect status code. Response body: " . $response->body + ); + + } + + /** + * DELETE with preconditions + */ + public function testDeletePreconditions() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file1', + 'REQUEST_METHOD' => 'DELETE', + 'HTTP_IF_MATCH' => '"' . md5('foo') . '"', + )); + + $response = $this->request($request); + + $this->assertEquals( + 'HTTP/1.1 204 No Content', + $response->status, + "Incorrect status code. Response body: " . $response->body + ); + + } + + /** + * DELETE with incorrect preconditions + */ + public function testDeletePreconditionsFailed() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file1', + 'REQUEST_METHOD' => 'DELETE', + 'HTTP_IF_MATCH' => '"' . md5('bar') . '"', + )); + + $response = $this->request($request); + + $this->assertEquals( + 'HTTP/1.1 412 Precondition failed', + $response->status, + "Incorrect status code. Response body: " . $response->body + ); + + } +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/HttpPutTest.php b/vendor/sabre/dav/tests/Sabre/DAV/HttpPutTest.php new file mode 100644 index 000000000..b14554595 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/HttpPutTest.php @@ -0,0 +1,362 @@ +<?php + +namespace Sabre\DAV; + +use Sabre\DAVServerTest; +use Sabre\HTTP; + +/** + * Tests related to the PUT request. + * + * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved. + * @author Evert Pot (http://evertpot.com/) + * @license http://sabre.io/license/ Modified BSD License + * @covers Sabre\DAV\Server::httpPut + * @covers Sabre\DAV\Server::createFile + * @covers Sabre\DAV\Server::checkPreconditions + */ +class HttpPutTest extends DAVServerTest { + + /** + * Sets up the DAV tree. + * + * @return void + */ + public function setUpTree() { + + $this->tree = new Mock\Collection('root', array( + 'file1' => 'foo', + )); + + } + + /** + * A successful PUT of a new file. + */ + public function testPut() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file2', + 'REQUEST_METHOD' => 'PUT', + )); + $request->setBody('hello'); + + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 201 Created', $response->status); + + $this->assertEquals( + 'hello', + $this->server->tree->getNodeForPath('file2')->get() + ); + + $this->assertEquals( + array( + 'Content-Length' => '0', + 'ETag' => '"' . md5('hello') . '"' + ), + $response->headers + ); + + } + + /** + * A successful PUT on an existing file. + * + * @depends testPut + */ + public function testPutExisting() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file1', + 'REQUEST_METHOD' => 'PUT', + )); + $request->setBody('bar'); + + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 204 No Content', $response->status); + + $this->assertEquals( + 'bar', + $this->server->tree->getNodeForPath('file1')->get() + ); + + $this->assertEquals( + array( + 'Content-Length' => '0', + 'ETag' => '"' . md5('bar') . '"' + ), + $response->headers + ); + + } + + /** + * PUT on existing file with If-Match: * + * + * @depends testPutExisting + */ + public function testPutExistingIfMatchStar() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file1', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_IF_MATCH' => '*', + )); + $request->setBody('hello'); + + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 204 No Content', $response->status); + + $this->assertEquals( + 'hello', + $this->server->tree->getNodeForPath('file1')->get() + ); + + $this->assertEquals( + array( + 'Content-Length' => '0', + 'ETag' => '"' . md5('hello') . '"' + ), + $response->headers + ); + + } + + /** + * PUT on existing file with If-Match: with a correct etag + * + * @depends testPutExisting + */ + public function testPutExistingIfMatchCorrect() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file1', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_IF_MATCH' => '"' . md5('foo') . '"', + )); + $request->setBody('hello'); + + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 204 No Content', $response->status); + + $this->assertEquals( + 'hello', + $this->server->tree->getNodeForPath('file1')->get() + ); + + $this->assertEquals( + array( + 'Content-Length' => '0', + 'ETag' => '"' . md5('hello') . '"' + ), + $response->headers + ); + + } + + /** + * PUT with Content-Range should be rejected. + * + * @depends testPut + */ + public function testPutContentRange() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file2', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_CONTENT_RANGE' => 'bytes/100-200', + )); + $request->setBody('hello'); + + $response = $this->request($request); + $this->assertEquals('HTTP/1.1 501 Not Implemented', $response->status); + + } + + /** + * PUT on non-existing file with If-None-Match: * should work. + * + * @depends testPut + */ + public function testPutIfNoneMatchStar() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file2', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_IF_NONE_MATCH' => '*', + )); + $request->setBody('hello'); + + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 201 Created', $response->status); + + $this->assertEquals( + 'hello', + $this->server->tree->getNodeForPath('file2')->get() + ); + + $this->assertEquals( + array( + 'Content-Length' => '0', + 'ETag' => '"' . md5('hello') . '"' + ), + $response->headers + ); + + } + + /** + * PUT on non-existing file with If-Match: * should fail. + * + * @depends testPut + */ + public function testPutIfMatchStar() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file2', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_IF_MATCH' => '*', + )); + $request->setBody('hello'); + + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 412 Precondition failed', $response->status); + + } + + /** + * PUT on existing file with If-None-Match: * should fail. + * + * @depends testPut + */ + public function testPutExistingIfNoneMatchStar() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file1', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_IF_NONE_MATCH' => '*', + )); + $request->setBody('hello'); + + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 412 Precondition failed', $response->status); + + } + + /** + * PUT thats created in a non-collection should be rejected. + * + * @depends testPut + */ + public function testPutNoParent() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file1/file2', + 'REQUEST_METHOD' => 'PUT', + )); + $request->setBody('hello'); + + $response = $this->request($request); + $this->assertEquals('HTTP/1.1 409 Conflict', $response->status); + + } + + /** + * Finder may sometimes make a request, which gets its content-body + * stripped. We can't always prevent this from happening, but in some cases + * we can detected this and return an error instead. + * + * @depends testPut + */ + public function testFinderPutSuccess() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file2', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '5', + )); + $request->setBody('hello'); + + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 201 Created', $response->status); + + $this->assertEquals( + 'hello', + $this->server->tree->getNodeForPath('file2')->get() + ); + + $this->assertEquals( + array( + 'Content-Length' => '0', + 'ETag' => '"' . md5('hello') . '"' + ), + $response->headers + ); + + } + + /** + * Same as the last one, but in this case we're mimicing a failed request. + * + * @depends testFinderPutSuccess + */ + public function testFinderPutFail() { + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file2', + 'REQUEST_METHOD' => 'PUT', + 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '5', + )); + $request->setBody(''); + + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 403 Forbidden', $response->status); + + } + + /** + * Plugins can intercept PUT. We need to make sure that works. + */ + public function testPutIntercept() { + + $this->server->subscribeEvent('beforeBind', array($this, 'beforeBind')); + + $request = new HTTP\Request(array( + 'REQUEST_URI' => '/file2', + 'REQUEST_METHOD' => 'PUT', + )); + $request->setBody('hello'); + + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 418 I\'m a teapot', $response->status); + + $this->assertFalse( + $this->server->tree->nodeExists('file2') + ); + + $this->assertEquals( + array( + ), + $response->headers + ); + + } + + public function beforeBind() { + + $this->server->httpResponse->sendStatus(418); + return false; + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php index a45dafdf1..caa1d0118 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/Locks/PluginTest.php @@ -914,6 +914,22 @@ class PluginTest extends DAV\AbstractServer { } + function testDeleteWithETagOnCollection() { + + $serverVars = array( + 'REQUEST_URI' => '/dir', + 'REQUEST_METHOD' => 'DELETE', + 'HTTP_IF' => '(["etag1"])', + ); + + $request = new HTTP\Request($serverVars); + $request->setBody('newbody'); + $this->server->httpRequest = $request; + $this->server->exec(); + $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); + + } + function testGetTimeoutHeader() { $request = new HTTP\Request(array( diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php b/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php new file mode 100644 index 000000000..b2613ec9f --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php @@ -0,0 +1,164 @@ +<?php + +namespace Sabre\DAV\Mock; + +use Sabre\DAV; + +/** + * Mock Collection. + * + * This collection quickly allows you to create trees of nodes. + * Children are specified as an array. + * + * Every key a filename, every array value is either: + * * an array, for a sub-collection + * * a string, for a file + * * An instance of \Sabre\DAV\INode. + * + * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved. + * @author Evert Pot (http://evertpot.com/) + * @license http://sabre.io/license/ Modified BSD License + */ +class Collection extends DAV\Collection { + + protected $name; + protected $children; + protected $parent; + + /** + * Creates the object + * + * @param string $name + * @param array $children + * @return void + */ + public function __construct($name, array $children = array(), Collection $parent = null) { + + $this->name = $name; + $this->children = $children; + $this->parent = $parent; + + } + + /** + * Returns the name of the node. + * + * This is used to generate the url. + * + * @return string + */ + public function getName() { + + return $this->name; + + } + + /** + * Creates a new file in the directory + * + * Data will either be supplied as a stream resource, or in certain cases + * as a string. Keep in mind that you may have to support either. + * + * After successful creation of the file, you may choose to return the ETag + * of the new file here. + * + * The returned ETag must be surrounded by double-quotes (The quotes should + * be part of the actual string). + * + * If you cannot accurately determine the ETag, you should not return it. + * If you don't store the file exactly as-is (you're transforming it + * somehow) you should also not return an ETag. + * + * This means that if a subsequent GET to this new file does not exactly + * return the same contents of what was submitted here, you are strongly + * recommended to omit the ETag. + * + * @param string $name Name of the file + * @param resource|string $data Initial payload + * @return null|string + */ + public function createFile($name, $data = null) { + + if (is_resource($data)) { + $data = stream_get_contents($data); + } + $this->children[$name] = $data; + return '"' . md5($data) . '"'; + + } + + /** + * Creates a new subdirectory + * + * @param string $name + * @return void + */ + public function createDirectory($name) { + + $this->children[$name] = array(); + + } + + /** + * Returns an array with all the child nodes + * + * @return \Sabre\DAV\INode[] + */ + public function getChildren() { + + $result = array(); + foreach($this->children as $key=>$value) { + + if ($value instanceof DAV\INode) { + $result[] = $value; + } elseif (is_array($value)) { + $result[] = new Collection($key, $value, $this); + } else { + $result[] = new File($key, $value, $this); + } + + } + + return $result; + + } + + /** + * Removes a childnode from this node. + * + * @param string $name + * @return void + */ + public function deleteChild($name) { + + foreach($this->children as $key=>$value) { + + if ($value instanceof DAV\INode) { + if ($value->getName() == $name) { + unset($this->children[$key]); + return; + } + } elseif ($key === $name) { + unset($this->children[$key]); + return; + } + + } + + } + + /** + * Deletes this collection and all its children,. + * + * @return void + */ + public function delete() { + + foreach($this->getChildren() as $child) { + $this->deleteChild($child->getName()); + } + $this->parent->deleteChild($this->getName()); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Mock/File.php b/vendor/sabre/dav/tests/Sabre/DAV/Mock/File.php new file mode 100644 index 000000000..2b25bbb88 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/Mock/File.php @@ -0,0 +1,130 @@ +<?php + +namespace Sabre\DAV\Mock; + +use Sabre\DAV; + +/** + * Mock File + * + * See the Collection in this directory for more details. + * + * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved. + * @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; + + } + + /** + * Updates the data + * + * The data argument is a readable stream resource. + * + * After a succesful put operation, you may choose to return an ETag. The + * etag must always be surrounded by double-quotes. These quotes must + * appear in the actual string you're returning. + * + * Clients may use the ETag from a PUT request to later on make sure that + * when they update the file, the contents haven't changed in the mean + * time. + * + * If you don't plan to store the file byte-by-byte, and you return a + * different object on a subsequent GET you are strongly recommended to not + * return an ETag, and just return null. + * + * @param resource $data + * @return string|null + */ + public function put($data) { + + if (is_resource($data)) { + $data = stream_get_contents($data); + } + $this->contents = $data; + return '"' . md5($data) . '"'; + + } + + /** + * Returns the data + * + * This method may either return a string or a readable stream resource + * + * @return mixed + */ + public function get() { + + return $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. + * + * Return null if the ETag can not effectively be determined + * + * @return void + */ + public function getETag() { + + return '"' . md5($this->contents) . '"'; + + } + + /** + * Returns the size of the node, in bytes + * + * @return int + */ + public function getSize() { + + return strlen($this->contents); + + } + + /** + * Delete the node + * + * @return void + */ + public function delete() { + + $this->parent->deleteChild($this->name); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php index 7b90429d4..32f7e4e2c 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/PluginTest.php @@ -103,7 +103,7 @@ class PluginTest extends \Sabre\DAVServerTest { ); $response = $this->request($request); - $this->assertEquals('HTTP/1.1 416 Requested Range Not Satisfiable', $response->status, 'Full response body:' . $response->body); + $this->assertEquals('HTTP/1.1 411 Length Required', $response->status, 'Full response body:' . $response->body); } @@ -123,7 +123,27 @@ class PluginTest extends \Sabre\DAVServerTest { $response = $this->request($request); $this->assertEquals('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body); - $this->assertEquals('00111000', $this->node->get()); + $this->assertEquals('00011100', $this->node->get()); + + } + + public function testPatchNoEndRange() { + + $this->node->put('00000'); + $request = new HTTP\Request(array( + 'REQUEST_METHOD' => 'PATCH', + 'REQUEST_URI' => '/partial', + 'HTTP_X_UPDATE_RANGE' => 'bytes=3-', + 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate', + 'HTTP_CONTENT_LENGTH' => 3, + )); + $request->setBody( + '111' + ); + $response = $this->request($request); + + $this->assertEquals('HTTP/1.1 204 No Content', $response->status, 'Full response body:' . $response->body); + $this->assertEquals('00111', $this->node->get()); } diff --git a/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php new file mode 100644 index 000000000..7abe69c55 --- /dev/null +++ b/vendor/sabre/dav/tests/Sabre/DAV/PartialUpdate/SpecificationTest.php @@ -0,0 +1,89 @@ +<?php + +namespace Sabre\DAV\PartialUpdate; + +use Sabre\DAV\FSExt\File; +use Sabre\DAV\Server; +use Sabre\HTTP; + +/** + * This test is an end-to-end sabredav test that goes through all + * the cases in the specification. + * + * See: http://sabre.io/dav/http-patch/ + */ +class SpecificationTest extends \PHPUnit_Framework_TestCase { + + protected $server; + + public function setUp() { + + $tree = array( + new File(SABRE_TEMPDIR . '/foobar.txt') + ); + $server = new Server($tree); + $server->debugExceptions = true; + $server->addPlugin(new Plugin()); + + $tree[0]->put('1234567890'); + + $this->server = $server; + + } + + public function tearDown() { + + \Sabre\TestUtil::clearTempDir(); + + } + + /** + * @dataProvider data + */ + public function testUpdateRange($headerValue, $httpStatus, $endResult, $contentLength = 4) { + + $vars = array( + 'REQUEST_METHOD' => 'PATCH', + 'HTTP_CONTENT_TYPE' => 'application/x-sabredav-partialupdate', + 'HTTP_X_UPDATE_RANGE' => $headerValue, + 'REQUEST_URI' => '/foobar.txt', + ); + if ($contentLength) { + $vars['HTTP_CONTENT_LENGTH'] = (string)$contentLength; + } + + $request = new HTTP\Request($vars); + + $request->setBody('----'); + $this->server->httpRequest = $request; + $this->server->httpResponse = new HTTP\ResponseMock(); + $this->server->exec(); + + $this->assertEquals($httpStatus, $this->server->httpResponse->status, 'Incorrect http status received: ' . $this->server->httpResponse->body); + if (!is_null($endResult)) { + $this->assertEquals($endResult, file_get_contents(SABRE_TEMPDIR . '/foobar.txt')); + } + + } + + public function data() { + + return array( + // Problems + array('foo', 'HTTP/1.1 400 Bad request', null), + array('bytes=0-3', 'HTTP/1.1 411 Length Required', null, 0), + array('bytes=4-1', 'HTTP/1.1 416 Requested Range Not Satisfiable', null), + + array('bytes=0-3', 'HTTP/1.1 204 No Content', '----567890'), + array('bytes=1-4', 'HTTP/1.1 204 No Content', '1----67890'), + array('bytes=0-', 'HTTP/1.1 204 No Content', '----567890'), + array('bytes=-4', 'HTTP/1.1 204 No Content', '123456----'), + array('bytes=-2', 'HTTP/1.1 204 No Content', '12345678----'), + array('bytes=2-', 'HTTP/1.1 204 No Content', '12----7890'), + array('append', 'HTTP/1.1 204 No Content', '1234567890----'), + + ); + + } + +} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerFinderBlockTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerFinderBlockTest.php deleted file mode 100644 index 180f27b2a..000000000 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerFinderBlockTest.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php - -namespace Sabre\DAV; - -use Sabre\HTTP; - -require_once 'Sabre/HTTP/ResponseMock.php'; -require_once 'Sabre/DAV/AbstractServer.php'; - -class ServerFinderBlockTest extends AbstractServer{ - - function testPut() { - - $serverVars = array( - 'REQUEST_URI' => '/testput.txt', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '20', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody('Testing finder'); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('', $this->response->body); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); - $this->assertEquals('0', $this->response->headers['Content-Length']); - - $this->assertEquals('Testing finder',file_get_contents(SABRE_TEMPDIR . '/testput.txt')); - - } - - function testPutFail() { - - $serverVars = array( - 'REQUEST_URI' => '/testput.txt', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_X_EXPECTED_ENTITY_LENGTH' => '20', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody(''); - $this->server->httpRequest = $request; - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status); - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); - - $this->assertFalse(file_exists(SABRE_TEMPDIR . '/testput.txt')); - } -} diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php index afcd5c98f..21e0ab2ea 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php @@ -175,148 +175,6 @@ class ServerSimpleTest extends AbstractServer{ } - function testPut() { - - $serverVars = array( - 'REQUEST_URI' => '/testput.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('', $this->response->body); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); - $this->assertEquals(array( - "Content-Length" => "0", - ), $this->response->headers); - - $this->assertEquals('Testing new file',file_get_contents($this->tempDir . '/testput.txt')); - - } - - function testPutAlreadyExists() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_NONE_MATCH' => '*', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); - - $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); - $this->assertNotEquals('Testing new file',file_get_contents($this->tempDir . '/test.txt')); - - } - - function testPutUpdate() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody('Testing updated file'); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('0', $this->response->headers['Content-Length']); - - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); - $this->assertEquals('', $this->response->body); - $this->assertEquals('Testing updated file',file_get_contents($this->tempDir . '/test.txt')); - - } - - function testPutNoParentCollection() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt/item.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody('Testing updated file'); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 409 Conflict',$this->response->status); - - } - - function testPutContentRange() { - - $serverVars = array( - 'REQUEST_URI' => '/testput.txt', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_CONTENT_RANGE' => 'bytes/100-200', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody('Testing new file'); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals('HTTP/1.1 501 Not Implemented',$this->response->status); - - } - - - function testDelete() { - - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'DELETE', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); - - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); - $this->assertEquals('', $this->response->body); - $this->assertFalse(file_exists($this->tempDir . '/test.txt')); - - } - - 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 = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); - $this->server->exec(); - - $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); - $this->assertEquals('', $this->response->body); - $this->assertFalse(file_exists($this->tempDir . '/col')); - - } - function testOptions() { $serverVars = array( diff --git a/vendor/sabre/dav/tests/Sabre/DAVServerTest.php b/vendor/sabre/dav/tests/Sabre/DAVServerTest.php index a92c7065a..207687d90 100644 --- a/vendor/sabre/dav/tests/Sabre/DAVServerTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAVServerTest.php @@ -3,10 +3,16 @@ namespace Sabre; require_once 'Sabre/HTTP/ResponseMock.php'; + +require_once 'Sabre/DAV/Auth/Backend/Mock.php'; +require_once 'Sabre/DAV/Mock/File.php'; +require_once 'Sabre/DAV/Mock/Collection.php'; + +require_once 'Sabre/DAVACL/PrincipalBackend/Mock.php'; + require_once 'Sabre/CalDAV/Backend/Mock.php'; + require_once 'Sabre/CardDAV/Backend/Mock.php'; -require_once 'Sabre/DAVACL/PrincipalBackend/Mock.php'; -require_once 'Sabre/DAV/Auth/Backend/Mock.php'; /** * This class may be used as a basis for other webdav-related unittests. @@ -16,7 +22,7 @@ require_once 'Sabre/DAV/Auth/Backend/Mock.php'; * * @copyright Copyright (C) 2007-2014 fruux GmbH (https://fruux.com/). * @author Evert Pot (http://evertpot.com/) - * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License + * @license http://sabre.io/license/ Modified BSD License */ abstract class DAVServerTest extends \PHPUnit_Framework_TestCase { diff --git a/vendor/sabre/dav/tests/bootstrap.php b/vendor/sabre/dav/tests/bootstrap.php index c3be7366c..a6493ce6b 100644 --- a/vendor/sabre/dav/tests/bootstrap.php +++ b/vendor/sabre/dav/tests/bootstrap.php @@ -7,9 +7,10 @@ define('SABRE_MYSQLPASS',''); set_include_path(__DIR__ . '/../lib/' . PATH_SEPARATOR . __DIR__ . PATH_SEPARATOR . get_include_path()); include __DIR__ . '/../vendor/autoload.php'; +include 'Sabre/TestUtil.php'; include 'Sabre/DAVServerTest.php'; -date_default_timezone_set('GMT'); +date_default_timezone_set('UTC'); define("SABRE_TEMPDIR",dirname(__FILE__) . '/temp/'); |