aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php')
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php454
1 files changed, 152 insertions, 302 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php
index 21e0ab2ea..66dde9db8 100644
--- a/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php
+++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php
@@ -4,17 +4,13 @@ namespace Sabre\DAV;
use Sabre\HTTP;
-require_once 'Sabre/HTTP/ResponseMock.php';
-require_once 'Sabre/DAV/AbstractServer.php';
-require_once 'Sabre/DAV/Exception.php';
-
class ServerSimpleTest extends AbstractServer{
function testConstructArray() {
- $nodes = array(
+ $nodes = [
new SimpleCollection('hello')
- );
+ ];
$server = new Server($nodes);
$this->assertEquals($nodes[0], $server->tree->getNodeForPath('hello'));
@@ -26,10 +22,10 @@ class ServerSimpleTest extends AbstractServer{
*/
function testConstructIncorrectObj() {
- $nodes = array(
+ $nodes = [
new SimpleCollection('hello'),
new \STDClass(),
- );
+ ];
$server = new Server($nodes);
@@ -44,253 +40,108 @@ class ServerSimpleTest extends AbstractServer{
}
- function testGet() {
-
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'GET',
- );
-
- $request = new HTTP\Request($serverVars);
- $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'))),
- ),
- $this->response->headers
- );
-
- $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
- $this->assertEquals('Test contents', stream_get_contents($this->response->body));
-
- }
- function testGetHttp10() {
-
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt',
- 'REQUEST_METHOD' => 'GET',
- 'SERVER_PROTOCOL' => 'HTTP/1.0',
- );
-
- $request = new HTTP\Request($serverVars);
- $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'))),
- ),
- $this->response->headers
- );
-
- $this->assertEquals('HTTP/1.0 200 OK',$this->response->status);
- $this->assertEquals('Test contents', stream_get_contents($this->response->body));
-
- }
-
- function testGetDoesntExist() {
-
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt_randomblbla',
- 'REQUEST_METHOD' => 'GET',
- );
-
- $request = new HTTP\Request($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
- $this->assertEquals('HTTP/1.1 404 Not Found',$this->response->status);
-
- }
-
- function testGetDoesntExist2() {
-
- $serverVars = array(
- 'REQUEST_URI' => '/test.txt/randomblbla',
- 'REQUEST_METHOD' => 'GET',
- );
-
- $request = new HTTP\Request($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
- $this->assertEquals('HTTP/1.1 404 Not Found',$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 = array(
- 'REQUEST_URI' => '//test.txt',
- 'REQUEST_METHOD' => 'GET',
- );
+ function testOptions() {
- $request = new HTTP\Request($serverVars);
- $this->server->httpRequest = ($request);
+ $request = new HTTP\Request('OPTIONS', '/');
+ $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'))),
- ),
- $this->response->headers
- );
-
- $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);
- $this->server->httpRequest = ($request);
- $this->server->exec();
+ $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' => [Version::VERSION],
+ ], $this->response->getHeaders());
- $this->assertEquals(array(
- 'Content-Type' => 'application/octet-stream',
- 'Content-Length' => 13,
- 'Last-Modified' => HTTP\Util::toHTTPDate(new \DateTime('@' . filemtime($this->tempDir . '/test.txt'))),
- ),
- $this->response->headers
- );
-
- $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
+ $this->assertEquals(200, $this->response->status);
$this->assertEquals('', $this->response->body);
}
- function testOptions() {
+ function testOptionsUnmapped() {
- $serverVars = array(
- 'REQUEST_URI' => '/',
- 'REQUEST_METHOD' => 'OPTIONS',
- );
+ $request = new HTTP\Request('OPTIONS', '/unmapped');
+ $this->server->httpRequest = $request;
- $request = new HTTP\Request($serverVars);
- $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' => 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, MKCOL'],
+ 'Accept-Ranges' => ['bytes'],
+ 'Content-Length' => ['0'],
+ 'X-Sabre-Version' => [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 testNonExistantMethod() {
- $serverVars = array(
+ $serverVars = [
'REQUEST_URI' => '/',
'REQUEST_METHOD' => 'BLABLA',
- );
+ ];
- $request = new HTTP\Request($serverVars);
+ $request = HTTP\Sapi::createFromServerArray($serverVars);
$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' => [Version::VERSION],
+ 'Content-Type' => ['application/xml; charset=utf-8'],
+ ], $this->response->getHeaders());
- $this->assertEquals('HTTP/1.1 501 Not Implemented',$this->response->status);
+ $this->assertEquals(501, $this->response->status);
}
- function testGETOnCollection() {
-
- $serverVars = array(
- 'REQUEST_URI' => '/',
- 'REQUEST_METHOD' => 'GET',
- );
-
- $request = new HTTP\Request($serverVars);
- $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 501 Not Implemented',$this->response->status);
-
- }
-
- function testHEADOnCollection() {
-
- $serverVars = array(
- 'REQUEST_URI' => '/',
- 'REQUEST_METHOD' => 'HEAD',
- );
-
- $request = new HTTP\Request($serverVars);
- $this->server->httpRequest = ($request);
- $this->server->exec();
-
- $this->assertEquals('HTTP/1.1 200 OK',$this->response->status);
-
- }
-
function testBaseUri() {
- $serverVars = array(
+ $serverVars = [
'REQUEST_URI' => '/blabla/test.txt',
'REQUEST_METHOD' => 'GET',
- );
+ ];
+ $filename = $this->tempDir . '/test.txt';
- $request = new HTTP\Request($serverVars);
+ $request = HTTP\Sapi::createFromServerArray($serverVars);
$this->server->setBaseUri('/blabla/');
- $this->assertEquals('/blabla/',$this->server->getBaseUri());
+ $this->assertEquals('/blabla/', $this->server->getBaseUri());
$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'))),
- ),
- $this->response->headers
+ $this->assertEquals([
+ 'X-Sabre-Version' => [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(200, $this->response->status);
$this->assertEquals('Test contents', stream_get_contents($this->response->body));
}
function testBaseUriAddSlash() {
- $tests = array(
+ $tests = [
'/' => '/',
'/foo' => '/foo/',
'/foo/' => '/foo/',
'/foo/bar' => '/foo/bar/',
'/foo/bar/' => '/foo/bar/',
- );
+ ];
- foreach($tests as $test=>$result) {
+ foreach ($tests as $test => $result) {
$this->server->setBaseUri($test);
$this->assertEquals($result, $this->server->getBaseUri());
@@ -301,25 +152,25 @@ class ServerSimpleTest extends AbstractServer{
function testCalculateUri() {
- $uris = array(
+ $uris = [
'http://www.example.org/root/somepath',
'/root/somepath',
'/root/somepath/',
- );
+ ];
$this->server->setBaseUri('/root/');
- foreach($uris as $uri) {
+ foreach ($uris as $uri) {
- $this->assertEquals('somepath',$this->server->calculateUri($uri));
+ $this->assertEquals('somepath', $this->server->calculateUri($uri));
}
$this->server->setBaseUri('/root');
- foreach($uris as $uri) {
+ foreach ($uris as $uri) {
- $this->assertEquals('somepath',$this->server->calculateUri($uri));
+ $this->assertEquals('somepath', $this->server->calculateUri($uri));
}
@@ -329,72 +180,60 @@ class ServerSimpleTest extends AbstractServer{
function testCalculateUriSpecialChars() {
- $uris = array(
+ $uris = [
'http://www.example.org/root/%C3%A0fo%C3%B3',
'/root/%C3%A0fo%C3%B3',
'/root/%C3%A0fo%C3%B3/'
- );
+ ];
$this->server->setBaseUri('/root/');
- foreach($uris as $uri) {
+ foreach ($uris as $uri) {
- $this->assertEquals("\xc3\xa0fo\xc3\xb3",$this->server->calculateUri($uri));
+ $this->assertEquals("\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri));
}
$this->server->setBaseUri('/root');
- foreach($uris as $uri) {
+ foreach ($uris as $uri) {
- $this->assertEquals("\xc3\xa0fo\xc3\xb3",$this->server->calculateUri($uri));
+ $this->assertEquals("\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri));
}
$this->server->setBaseUri('/');
- foreach($uris as $uri) {
+ foreach ($uris as $uri) {
- $this->assertEquals("root/\xc3\xa0fo\xc3\xb3",$this->server->calculateUri($uri));
+ $this->assertEquals("root/\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri));
}
}
- function testBaseUriCheck() {
-
- $uris = array(
- 'http://www.example.org/root/somepath',
- '/root/somepath',
- '/root/somepath/'
- );
-
- try {
-
- $this->server->setBaseUri('root/');
- $this->server->calculateUri('/root/testuri');
-
- $this->fail('Expected an exception');
-
- } catch (Exception\Forbidden $e) {
+ /**
+ * @expectedException \Sabre\DAV\Exception\Forbidden
+ */
+ function testCalculateUriBreakout() {
- // This was expected
+ $uri = '/path1/';
- }
+ $this->server->setBaseUri('/path2/');
+ $this->server->calculateUri($uri);
}
/**
- * @covers \Sabre\DAV\Server::guessBaseUri
*/
function testGuessBaseUri() {
- $serverVars = array(
+ $serverVars = [
'REQUEST_URI' => '/index.php/root',
'PATH_INFO' => '/root',
- );
+ ];
- $httpRequest = new HTTP\Request($serverVars);
+ $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
$server = new Server();
$server->httpRequest = $httpRequest;
@@ -404,16 +243,15 @@ class ServerSimpleTest extends AbstractServer{
/**
* @depends testGuessBaseUri
- * @covers Sabre\DAV\Server::guessBaseUri
*/
function testGuessBaseUriPercentEncoding() {
- $serverVars = array(
+ $serverVars = [
'REQUEST_URI' => '/index.php/dir/path2/path%20with%20spaces',
'PATH_INFO' => '/dir/path2/path with spaces',
- );
+ ];
- $httpRequest = new HTTP\Request($serverVars);
+ $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
$server = new Server();
$server->httpRequest = $httpRequest;
@@ -423,18 +261,17 @@ class ServerSimpleTest extends AbstractServer{
/**
* @depends testGuessBaseUri
- * @covers \Sabre\DAV\Server::guessBaseUri
*/
/*
function testGuessBaseUriPercentEncoding2() {
$this->markTestIncomplete('This behaviour is not yet implemented');
- $serverVars = array(
+ $serverVars = [
'REQUEST_URI' => '/some%20directory+mixed/index.php/dir/path2/path%20with%20spaces',
'PATH_INFO' => '/dir/path2/path with spaces',
- );
+ ];
- $httpRequest = new HTTP\Request($serverVars);
+ $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
$server = new Server();
$server->httpRequest = $httpRequest;
@@ -444,12 +281,12 @@ class ServerSimpleTest extends AbstractServer{
function testGuessBaseUri2() {
- $serverVars = array(
+ $serverVars = [
'REQUEST_URI' => '/index.php/root/',
'PATH_INFO' => '/root/',
- );
+ ];
- $httpRequest = new HTTP\Request($serverVars);
+ $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
$server = new Server();
$server->httpRequest = $httpRequest;
@@ -459,11 +296,11 @@ class ServerSimpleTest extends AbstractServer{
function testGuessBaseUriNoPathInfo() {
- $serverVars = array(
+ $serverVars = [
'REQUEST_URI' => '/index.php/root',
- );
+ ];
- $httpRequest = new HTTP\Request($serverVars);
+ $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
$server = new Server();
$server->httpRequest = $httpRequest;
@@ -473,11 +310,11 @@ class ServerSimpleTest extends AbstractServer{
function testGuessBaseUriNoPathInfo2() {
- $serverVars = array(
+ $serverVars = [
'REQUEST_URI' => '/a/b/c/test.php',
- );
+ ];
- $httpRequest = new HTTP\Request($serverVars);
+ $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
$server = new Server();
$server->httpRequest = $httpRequest;
@@ -487,17 +324,16 @@ class ServerSimpleTest extends AbstractServer{
/**
- * @covers \Sabre\DAV\Server::guessBaseUri
* @depends testGuessBaseUri
*/
function testGuessBaseUriQueryString() {
- $serverVars = array(
+ $serverVars = [
'REQUEST_URI' => '/index.php/root?query_string=blabla',
'PATH_INFO' => '/root',
- );
+ ];
- $httpRequest = new HTTP\Request($serverVars);
+ $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
$server = new Server();
$server->httpRequest = $httpRequest;
@@ -506,18 +342,17 @@ class ServerSimpleTest extends AbstractServer{
}
/**
- * @covers \Sabre\DAV\Server::guessBaseUri
* @depends testGuessBaseUri
* @expectedException \Sabre\DAV\Exception
*/
function testGuessBaseUriBadConfig() {
- $serverVars = array(
+ $serverVars = [
'REQUEST_URI' => '/index.php/root/heyyy',
'PATH_INFO' => '/root',
- );
+ ];
- $httpRequest = new HTTP\Request($serverVars);
+ $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
$server = new Server();
$server->httpRequest = $httpRequest;
@@ -527,25 +362,25 @@ class ServerSimpleTest extends AbstractServer{
function testTriggerException() {
- $serverVars = array(
- 'REQUEST_URI' => '/',
+ $serverVars = [
+ 'REQUEST_URI' => '/',
'REQUEST_METHOD' => 'FOO',
- );
+ ];
- $httpRequest = new HTTP\Request($serverVars);
+ $httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
$this->server->httpRequest = $httpRequest;
- $this->server->subscribeEvent('beforeMethod',array($this,'exceptionTrigger'));
+ $this->server->on('beforeMethod', [$this, 'exceptionTrigger']);
$this->server->exec();
- $this->assertEquals(array(
- 'Content-Type' => 'application/xml; charset=utf-8',
- ),$this->response->headers);
+ $this->assertEquals([
+ 'Content-Type' => ['application/xml; charset=utf-8'],
+ ], $this->response->getHeaders());
- $this->assertEquals('HTTP/1.1 500 Internal Server Error',$this->response->status);
+ $this->assertEquals(500, $this->response->status);
}
- function exceptionTrigger() {
+ function exceptionTrigger($request, $response) {
throw new Exception('Hola');
@@ -553,54 +388,56 @@ class ServerSimpleTest extends AbstractServer{
function testReportNotFound() {
- $serverVars = array(
+ $serverVars = [
'REQUEST_URI' => '/',
'REQUEST_METHOD' => 'REPORT',
- );
+ ];
- $request = new HTTP\Request($serverVars);
+ $request = HTTP\Sapi::createFromServerArray($serverVars);
$this->server->httpRequest = ($request);
$this->server->httpRequest->setBody('<?xml version="1.0"?><bla:myreport xmlns:bla="http://www.rooftopsolutions.nl/NS"></bla:myreport>');
$this->server->exec();
- $this->assertEquals(array(
- 'Content-Type' => 'application/xml; charset=utf-8',
- ),
- $this->response->headers
+ $this->assertEquals([
+ 'X-Sabre-Version' => [Version::VERSION],
+ 'Content-Type' => ['application/xml; charset=utf-8'],
+ ],
+ $this->response->getHeaders()
);
- $this->assertEquals('HTTP/1.1 403 Forbidden',$this->response->status,'We got an incorrect status back. Full response body follows: ' . $this->response->body);
+ $this->assertEquals(415, $this->response->status, 'We got an incorrect status back. Full response body follows: ' . $this->response->body);
}
function testReportIntercepted() {
- $serverVars = array(
+ $serverVars = [
'REQUEST_URI' => '/',
'REQUEST_METHOD' => 'REPORT',
- );
+ ];
- $request = new HTTP\Request($serverVars);
+ $request = HTTP\Sapi::createFromServerArray($serverVars);
$this->server->httpRequest = ($request);
$this->server->httpRequest->setBody('<?xml version="1.0"?><bla:myreport xmlns:bla="http://www.rooftopsolutions.nl/NS"></bla:myreport>');
- $this->server->subscribeEvent('report',array($this,'reportHandler'));
+ $this->server->on('report', [$this, 'reportHandler']);
$this->server->exec();
- $this->assertEquals(array(
- 'testheader' => 'testvalue',
- ),
- $this->response->headers
+ $this->assertEquals([
+ 'X-Sabre-Version' => [Version::VERSION],
+ 'testheader' => ['testvalue'],
+ ],
+ $this->response->getHeaders()
);
- $this->assertEquals('HTTP/1.1 418 I\'m a teapot',$this->response->status,'We got an incorrect status back. Full response body follows: ' . $this->response->body);
+ $this->assertEquals(418, $this->response->status, 'We got an incorrect status back. Full response body follows: ' . $this->response->body);
}
- function reportHandler($reportName) {
+ function reportHandler($reportName, $result, $path) {
- if ($reportName=='{http://www.rooftopsolutions.nl/NS}myreport') {
- $this->server->httpResponse->sendStatus(418);
- $this->server->httpResponse->setHeader('testheader','testvalue');
+ if ($reportName == '{http://www.rooftopsolutions.nl/NS}myreport') {
+ $this->server->httpResponse->setStatus(418);
+ $this->server->httpResponse->setHeader('testheader', 'testvalue');
return false;
}
else return;
@@ -609,16 +446,29 @@ class ServerSimpleTest extends AbstractServer{
function testGetPropertiesForChildren() {
- $result = $this->server->getPropertiesForChildren('',array(
+ $result = $this->server->getPropertiesForChildren('', [
'{DAV:}getcontentlength',
- ));
+ ]);
- $expected = array(
- 'test.txt' => array('{DAV:}getcontentlength' => 13),
- 'dir/' => array(),
- );
+ $expected = [
+ 'test.txt' => ['{DAV:}getcontentlength' => 13],
+ 'dir/' => [],
+ ];
+
+ $this->assertEquals($expected, $result);
+
+ }
- $this->assertEquals($expected,$result);
+ /**
+ * There are certain cases where no HTTP status may be set. We need to
+ * intercept these and set it to a default error message.
+ */
+ function testNoHTTPSTatusSet() {
+
+ $this->server->on('method:GET', function() { return false; }, 1);
+ $this->server->httpRequest = new HTTP\Request('GET', '/');
+ $this->server->exec();
+ $this->assertEquals(500, $this->response->getStatus());
}