From 0b02a6d123b2014705998c94ddf3d460948d3eac Mon Sep 17 00:00:00 2001 From: redmatrix Date: Tue, 10 May 2016 17:26:44 -0700 Subject: initial sabre upgrade (needs lots of work - to wit: authentication, redo the browser interface, and rework event export/import) --- .../sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php | 236 +++++++++++---------- 1 file changed, 129 insertions(+), 107 deletions(-) (limited to 'vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php') diff --git a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php index 907ede40b..63d858de1 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/FSExt/ServerTest.php @@ -17,116 +17,98 @@ class ServerTest extends DAV\AbstractServer{ function testGet() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'GET', - ); - - $request = new HTTP\Request($serverVars); - $this->server->httpRequest = ($request); + $request = new HTTP\Request('GET', '/test.txt'); + $filename = $this->tempDir . '/test.txt'; + $this->server->httpRequest = $request; $this->server->exec(); - $this->assertEquals(array( - '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 + $this->assertEquals(200, $this->response->getStatus(), 'Invalid status code received.'); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [13], + 'Last-Modified' => [HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($filename)))], + 'ETag' => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals('Test contents', stream_get_contents($this->response->body)); } function testHEAD() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'HEAD', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('HEAD', '/test.txt'); + $filename = $this->tempDir . '/test.txt'; $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - '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 + $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' => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'], + ], + $this->response->getHeaders() ); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $this->assertEquals(200,$this->response->status); $this->assertEquals('', $this->response->body); } function testPut() { - $serverVars = array( - 'REQUEST_URI' => '/testput.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('PUT', '/testput.txt'); + $filename = $this->tempDir . '/testput.txt'; $request->setBody('Testing new file'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Length' => 0, - 'ETag' => '"' . md5('Testing new file') . '"', - ), $this->response->headers); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + 'ETag' => ['"' . sha1(fileinode($filename ) . filesize($filename) . filemtime($filename)) . '"'], + ], $this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals('', $this->response->body); - $this->assertEquals('Testing new file',file_get_contents($this->tempDir . '/testput.txt')); + $this->assertEquals('Testing new file',file_get_contents($filename)); } function testPutAlreadyExists() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'PUT', - 'HTTP_IF_NONE_MATCH' => '*', - ); - - $request = new HTTP\Request($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( - 'Content-Type' => 'application/xml; charset=utf-8', - ),$this->response->headers); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Type' => ['application/xml; charset=utf-8'], + ],$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 412 Precondition failed',$this->response->status); + $this->assertEquals(412, $this->response->status); $this->assertNotEquals('Testing new file',file_get_contents($this->tempDir . '/test.txt')); } function testMkcol() { - $serverVars = array( - 'REQUEST_URI' => '/testcol', - 'REQUEST_METHOD' => 'MKCOL', - ); - - $request = new HTTP\Request($serverVars); - $request->setBody(""); + $request = new HTTP\Request('MKCOL', '/testcol'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + ],$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 201 Created',$this->response->status); + $this->assertEquals(201, $this->response->status); $this->assertEquals('', $this->response->body); $this->assertTrue(is_dir($this->tempDir . '/testcol')); @@ -134,19 +116,14 @@ class ServerTest extends DAV\AbstractServer{ function testPutUpdate() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'PUT', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('PUT', '/test.txt'); $request->setBody('Testing updated file'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals('0', $this->response->headers['Content-Length']); + $this->assertEquals('0', $this->response->getHeader('Content-Length')); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); + $this->assertEquals(204, $this->response->status); $this->assertEquals('', $this->response->body); $this->assertEquals('Testing updated file',file_get_contents($this->tempDir . '/test.txt')); @@ -154,20 +131,16 @@ class ServerTest extends DAV\AbstractServer{ function testDelete() { - $serverVars = array( - 'REQUEST_URI' => '/test.txt', - 'REQUEST_METHOD' => 'DELETE', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('DELETE', '/test.txt'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - 'Content-Length' => '0', - ),$this->response->headers); + $this->assertEquals([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + ],$this->response->getHeaders()); - $this->assertEquals('HTTP/1.1 204 No Content',$this->response->status); + $this->assertEquals(204, $this->response->status); $this->assertEquals('', $this->response->body); $this->assertFalse(file_exists($this->tempDir . '/test.txt')); @@ -175,50 +148,99 @@ 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 = new HTTP\Request($serverVars); + $request = new HTTP\Request('DELETE', '/testcol'); $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([ + 'X-Sabre-Version' => [DAV\Version::VERSION], + 'Content-Length' => ['0'], + ],$this->response->getHeaders()); + $this->assertEquals(204, $this->response->status); $this->assertEquals('', $this->response->body); - $this->assertFalse(file_exists($this->tempDir . '/col')); + $this->assertFalse(file_exists($this->tempDir . '/testcol')); } function testOptions() { - $serverVars = array( - 'REQUEST_URI' => '/', - 'REQUEST_METHOD' => 'OPTIONS', - ); - - $request = new HTTP\Request($serverVars); + $request = new HTTP\Request('OPTIONS', '/'); $this->server->httpRequest = ($request); $this->server->exec(); - $this->assertEquals(array( - '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->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->getHeaders()); - $this->assertEquals('HTTP/1.1 200 OK',$this->response->status); + $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->getHeaders()); + + $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->getHeaders()); + + $this->assertTrue( + is_dir($this->tempDir . '/tree2/tree1') + ); + + } } -- cgit v1.2.3