diff options
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php')
-rw-r--r-- | vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php | 262 |
1 files changed, 112 insertions, 150 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php b/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php index 043179a00..53153151b 100644 --- a/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php +++ b/vendor/sabre/dav/tests/Sabre/DAV/ServerSimpleTest.php @@ -1,90 +1,74 @@ <?php +declare(strict_types=1); + namespace Sabre\DAV; use Sabre\HTTP; -class ServerSimpleTest extends AbstractServer{ - - function testConstructArray() { - - $nodes = [ - new SimpleCollection('hello') - ]; - - $server = new Server($nodes); - $this->assertEquals($nodes[0], $server->tree->getNodeForPath('hello')); - - } - - /** - * @expectedException Sabre\DAV\Exception - */ - function testConstructIncorrectObj() { - +class ServerSimpleTest extends AbstractServer +{ + public function testConstructArray() + { $nodes = [ new SimpleCollection('hello'), - new \STDClass(), ]; $server = new Server($nodes); - + $this->assertEquals($nodes[0], $server->tree->getNodeForPath('hello')); } /** - * @expectedException Sabre\DAV\Exception + * @expectedException \Sabre\DAV\Exception */ - function testConstructInvalidArg() { - + public function testConstructInvalidArg() + { $server = new Server(1); - } - function testOptions() { - + public function testOptions() + { $request = new HTTP\Request('OPTIONS', '/'); $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'], + '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(200, $this->response->status); $this->assertEquals('', $this->response->body); - } - function testOptionsUnmapped() { - + public function testOptionsUnmapped() + { $request = new HTTP\Request('OPTIONS', '/unmapped'); $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, MKCOL'], - 'Accept-Ranges' => ['bytes'], - 'Content-Length' => ['0'], + '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(200, $this->response->status); $this->assertEquals('', $this->response->body); - } - function testNonExistantMethod() { - + public function testNonExistantMethod() + { $serverVars = [ - 'REQUEST_URI' => '/', + 'REQUEST_URI' => '/', 'REQUEST_METHOD' => 'BLABLA', ]; @@ -94,21 +78,19 @@ class ServerSimpleTest extends AbstractServer{ $this->assertEquals([ 'X-Sabre-Version' => [Version::VERSION], - 'Content-Type' => ['application/xml; charset=utf-8'], + 'Content-Type' => ['application/xml; charset=utf-8'], ], $this->response->getHeaders()); $this->assertEquals(501, $this->response->status); - - } - function testBaseUri() { - + public function testBaseUri() + { $serverVars = [ - 'REQUEST_URI' => '/blabla/test.txt', + 'REQUEST_URI' => '/blabla/test.txt', 'REQUEST_METHOD' => 'GET', ]; - $filename = $this->tempDir . '/test.txt'; + $filename = $this->tempDir.'/test.txt'; $request = HTTP\Sapi::createFromServerArray($serverVars); $this->server->setBaseUri('/blabla/'); @@ -118,26 +100,25 @@ class ServerSimpleTest extends AbstractServer{ $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)) . '"'], + 'Content-Type' => ['application/octet-stream'], + 'Content-Length' => [13], + 'Last-Modified' => [HTTP\toDate(new \DateTime('@'.filemtime($filename)))], + '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 testBaseUriAddSlash() { - + public function testBaseUriAddSlash() + { $tests = [ - '/' => '/', - '/foo' => '/foo/', - '/foo/' => '/foo/', - '/foo/bar' => '/foo/bar/', + '/' => '/', + '/foo' => '/foo/', + '/foo/' => '/foo/', + '/foo/bar' => '/foo/bar/', '/foo/bar/' => '/foo/bar/', ]; @@ -145,92 +126,86 @@ class ServerSimpleTest extends AbstractServer{ $this->server->setBaseUri($test); $this->assertEquals($result, $this->server->getBaseUri()); - } - } - function testCalculateUri() { - + public function testCalculateUri() + { $uris = [ 'http://www.example.org/root/somepath', '/root/somepath', '/root/somepath/', + '//root/somepath/', + '///root///somepath///', ]; $this->server->setBaseUri('/root/'); foreach ($uris as $uri) { - $this->assertEquals('somepath', $this->server->calculateUri($uri)); - } $this->server->setBaseUri('/root'); foreach ($uris as $uri) { - $this->assertEquals('somepath', $this->server->calculateUri($uri)); - } $this->assertEquals('', $this->server->calculateUri('/root')); - } + $this->server->setBaseUri('/'); + + foreach ($uris as $uri) { + $this->assertEquals('root/somepath', $this->server->calculateUri($uri)); + } - function testCalculateUriSpecialChars() { + $this->assertEquals('', $this->server->calculateUri('')); + } + public function testCalculateUriSpecialChars() + { $uris = [ 'http://www.example.org/root/%C3%A0fo%C3%B3', '/root/%C3%A0fo%C3%B3', - '/root/%C3%A0fo%C3%B3/' + '/root/%C3%A0fo%C3%B3/', ]; $this->server->setBaseUri('/root/'); foreach ($uris as $uri) { - $this->assertEquals("\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri)); - } $this->server->setBaseUri('/root'); foreach ($uris as $uri) { - $this->assertEquals("\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri)); - } $this->server->setBaseUri('/'); foreach ($uris as $uri) { - $this->assertEquals("root/\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri)); - } - } /** * @expectedException \Sabre\DAV\Exception\Forbidden */ - function testCalculateUriBreakout() { - + public function testCalculateUriBreakout() + { $uri = '/path1/'; $this->server->setBaseUri('/path2/'); $this->server->calculateUri($uri); - } - /** - */ - function testGuessBaseUri() { - + public function testGuessBaseUri() + { $serverVars = [ + 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/index.php/root', - 'PATH_INFO' => '/root', + 'PATH_INFO' => '/root', ]; $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); @@ -238,17 +213,17 @@ class ServerSimpleTest extends AbstractServer{ $server->httpRequest = $httpRequest; $this->assertEquals('/index.php/', $server->guessBaseUri()); - } /** * @depends testGuessBaseUri */ - function testGuessBaseUriPercentEncoding() { - + public function testGuessBaseUriPercentEncoding() + { $serverVars = [ + 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/index.php/dir/path2/path%20with%20spaces', - 'PATH_INFO' => '/dir/path2/path with spaces', + 'PATH_INFO' => '/dir/path2/path with spaces', ]; $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); @@ -256,7 +231,6 @@ class ServerSimpleTest extends AbstractServer{ $server->httpRequest = $httpRequest; $this->assertEquals('/index.php/', $server->guessBaseUri()); - } /** @@ -279,11 +253,12 @@ class ServerSimpleTest extends AbstractServer{ }*/ - function testGuessBaseUri2() { - + public function testGuessBaseUri2() + { $serverVars = [ + 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/index.php/root/', - 'PATH_INFO' => '/root/', + 'PATH_INFO' => '/root/', ]; $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); @@ -291,12 +266,12 @@ class ServerSimpleTest extends AbstractServer{ $server->httpRequest = $httpRequest; $this->assertEquals('/index.php/', $server->guessBaseUri()); - } - function testGuessBaseUriNoPathInfo() { - + public function testGuessBaseUriNoPathInfo() + { $serverVars = [ + 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/index.php/root', ]; @@ -305,32 +280,26 @@ class ServerSimpleTest extends AbstractServer{ $server->httpRequest = $httpRequest; $this->assertEquals('/', $server->guessBaseUri()); - } - function testGuessBaseUriNoPathInfo2() { - - $serverVars = [ - 'REQUEST_URI' => '/a/b/c/test.php', - ]; - - $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); + public function testGuessBaseUriNoPathInfo2() + { + $httpRequest = new HTTP\Request('GET', '/a/b/c/test.php'); $server = new Server(); $server->httpRequest = $httpRequest; $this->assertEquals('/', $server->guessBaseUri()); - } - /** * @depends testGuessBaseUri */ - function testGuessBaseUriQueryString() { - + public function testGuessBaseUriQueryString() + { $serverVars = [ + 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/index.php/root?query_string=blabla', - 'PATH_INFO' => '/root', + 'PATH_INFO' => '/root', ]; $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); @@ -338,18 +307,18 @@ class ServerSimpleTest extends AbstractServer{ $server->httpRequest = $httpRequest; $this->assertEquals('/index.php/', $server->guessBaseUri()); - } /** * @depends testGuessBaseUri * @expectedException \Sabre\DAV\Exception */ - function testGuessBaseUriBadConfig() { - + public function testGuessBaseUriBadConfig() + { $serverVars = [ + 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/index.php/root/heyyy', - 'PATH_INFO' => '/root', + 'PATH_INFO' => '/root', ]; $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); @@ -357,19 +326,18 @@ class ServerSimpleTest extends AbstractServer{ $server->httpRequest = $httpRequest; $server->guessBaseUri(); - } - function testTriggerException() { - + public function testTriggerException() + { $serverVars = [ - 'REQUEST_URI' => '/', + 'REQUEST_URI' => '/', 'REQUEST_METHOD' => 'FOO', ]; $httpRequest = HTTP\Sapi::createFromServerArray($serverVars); $this->server->httpRequest = $httpRequest; - $this->server->on('beforeMethod', [$this, 'exceptionTrigger']); + $this->server->on('beforeMethod:*', [$this, 'exceptionTrigger']); $this->server->exec(); $this->assertEquals([ @@ -377,19 +345,17 @@ class ServerSimpleTest extends AbstractServer{ ], $this->response->getHeaders()); $this->assertEquals(500, $this->response->status); - } - function exceptionTrigger($request, $response) { - + public function exceptionTrigger($request, $response) + { throw new Exception('Hola'); - } - function testReportNotFound() { - + public function testReportNotFound() + { $serverVars = [ - 'REQUEST_URI' => '/', + 'REQUEST_URI' => '/', 'REQUEST_METHOD' => 'REPORT', ]; @@ -400,19 +366,18 @@ class ServerSimpleTest extends AbstractServer{ $this->assertEquals([ 'X-Sabre-Version' => [Version::VERSION], - 'Content-Type' => ['application/xml; charset=utf-8'], + 'Content-Type' => ['application/xml; charset=utf-8'], ], $this->response->getHeaders() ); - $this->assertEquals(415, $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() { - + public function testReportIntercepted() + { $serverVars = [ - 'REQUEST_URI' => '/', + 'REQUEST_URI' => '/', 'REQUEST_METHOD' => 'REPORT', ]; @@ -424,52 +389,49 @@ class ServerSimpleTest extends AbstractServer{ $this->assertEquals([ 'X-Sabre-Version' => [Version::VERSION], - 'testheader' => ['testvalue'], + 'testheader' => ['testvalue'], ], $this->response->getHeaders() ); - $this->assertEquals(418, $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, $result, $path) { - - if ($reportName == '{http://www.rooftopsolutions.nl/NS}myreport') { + public function reportHandler($reportName, $result, $path) + { + if ('{http://www.rooftopsolutions.nl/NS}myreport' == $reportName) { $this->server->httpResponse->setStatus(418); $this->server->httpResponse->setHeader('testheader', 'testvalue'); + return false; + } else { + return; } - else return; - } - function testGetPropertiesForChildren() { - + public function testGetPropertiesForChildren() + { $result = $this->server->getPropertiesForChildren('', [ '{DAV:}getcontentlength', ]); $expected = [ 'test.txt' => ['{DAV:}getcontentlength' => 13], - 'dir/' => [], + 'dir/' => [], ]; $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); + public 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()); - } - } |