2013-10-21 22:46:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Sabre\DAV;
|
|
|
|
|
|
|
|
use Sabre\HTTP;
|
|
|
|
|
|
|
|
class ServerSimpleTest extends AbstractServer{
|
|
|
|
|
|
|
|
function testConstructArray() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$nodes = [
|
2013-10-21 22:46:31 +00:00
|
|
|
new SimpleCollection('hello')
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$server = new Server($nodes);
|
|
|
|
$this->assertEquals($nodes[0], $server->tree->getNodeForPath('hello'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception
|
|
|
|
*/
|
|
|
|
function testConstructIncorrectObj() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$nodes = [
|
2013-10-21 22:46:31 +00:00
|
|
|
new SimpleCollection('hello'),
|
|
|
|
new \STDClass(),
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$server = new Server($nodes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception
|
|
|
|
*/
|
|
|
|
function testConstructInvalidArg() {
|
|
|
|
|
|
|
|
$server = new Server(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
function testOptions() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = new HTTP\Request('OPTIONS', '/');
|
|
|
|
$this->server->httpRequest = $request;
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$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());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(200, $this->response->status);
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->assertEquals('', $this->response->body);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
function testOptionsUnmapped() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = new HTTP\Request('OPTIONS', '/unmapped');
|
|
|
|
$this->server->httpRequest = $request;
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$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());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(200, $this->response->status);
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->assertEquals('', $this->response->body);
|
|
|
|
|
|
|
|
}
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2013-10-21 22:46:31 +00:00
|
|
|
function testNonExistantMethod() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/',
|
|
|
|
'REQUEST_METHOD' => 'BLABLA',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
|
|
], $this->response->getHeaders());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(501, $this->response->status);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testBaseUri() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/blabla/test.txt',
|
|
|
|
'REQUEST_METHOD' => 'GET',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
|
|
|
$filename = $this->tempDir . '/test.txt';
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->server->setBaseUri('/blabla/');
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals('/blabla/', $this->server->getBaseUri());
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$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()
|
2013-10-21 22:46:31 +00:00
|
|
|
);
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(200, $this->response->status);
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->assertEquals('Test contents', stream_get_contents($this->response->body));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testBaseUriAddSlash() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$tests = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'/' => '/',
|
|
|
|
'/foo' => '/foo/',
|
|
|
|
'/foo/' => '/foo/',
|
|
|
|
'/foo/bar' => '/foo/bar/',
|
|
|
|
'/foo/bar/' => '/foo/bar/',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
foreach ($tests as $test => $result) {
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->server->setBaseUri($test);
|
|
|
|
|
|
|
|
$this->assertEquals($result, $this->server->getBaseUri());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCalculateUri() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$uris = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'http://www.example.org/root/somepath',
|
|
|
|
'/root/somepath',
|
|
|
|
'/root/somepath/',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$this->server->setBaseUri('/root/');
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
foreach ($uris as $uri) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals('somepath', $this->server->calculateUri($uri));
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->server->setBaseUri('/root');
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
foreach ($uris as $uri) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals('somepath', $this->server->calculateUri($uri));
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertEquals('', $this->server->calculateUri('/root'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCalculateUriSpecialChars() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$uris = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'http://www.example.org/root/%C3%A0fo%C3%B3',
|
|
|
|
'/root/%C3%A0fo%C3%B3',
|
|
|
|
'/root/%C3%A0fo%C3%B3/'
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$this->server->setBaseUri('/root/');
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
foreach ($uris as $uri) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals("\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri));
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->server->setBaseUri('/root');
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
foreach ($uris as $uri) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals("\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri));
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->server->setBaseUri('/');
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
foreach ($uris as $uri) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals("root/\xc3\xa0fo\xc3\xb3", $this->server->calculateUri($uri));
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
/**
|
|
|
|
* @expectedException \Sabre\DAV\Exception\Forbidden
|
|
|
|
*/
|
|
|
|
function testCalculateUriBreakout() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$uri = '/path1/';
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->server->setBaseUri('/path2/');
|
|
|
|
$this->server->calculateUri($uri);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
function testGuessBaseUri() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/index.php/root',
|
|
|
|
'PATH_INFO' => '/root',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
|
2013-10-21 22:46:31 +00:00
|
|
|
$server = new Server();
|
|
|
|
$server->httpRequest = $httpRequest;
|
|
|
|
|
|
|
|
$this->assertEquals('/index.php/', $server->guessBaseUri());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testGuessBaseUri
|
|
|
|
*/
|
|
|
|
function testGuessBaseUriPercentEncoding() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/index.php/dir/path2/path%20with%20spaces',
|
|
|
|
'PATH_INFO' => '/dir/path2/path with spaces',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
|
2013-10-21 22:46:31 +00:00
|
|
|
$server = new Server();
|
|
|
|
$server->httpRequest = $httpRequest;
|
|
|
|
|
|
|
|
$this->assertEquals('/index.php/', $server->guessBaseUri());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testGuessBaseUri
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
function testGuessBaseUriPercentEncoding2() {
|
|
|
|
|
|
|
|
$this->markTestIncomplete('This behaviour is not yet implemented');
|
2016-05-11 00:26:44 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/some%20directory+mixed/index.php/dir/path2/path%20with%20spaces',
|
|
|
|
'PATH_INFO' => '/dir/path2/path with spaces',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
|
2013-10-21 22:46:31 +00:00
|
|
|
$server = new Server();
|
|
|
|
$server->httpRequest = $httpRequest;
|
|
|
|
|
|
|
|
$this->assertEquals('/some%20directory+mixed/index.php/', $server->guessBaseUri());
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
function testGuessBaseUri2() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/index.php/root/',
|
|
|
|
'PATH_INFO' => '/root/',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
|
2013-10-21 22:46:31 +00:00
|
|
|
$server = new Server();
|
|
|
|
$server->httpRequest = $httpRequest;
|
|
|
|
|
|
|
|
$this->assertEquals('/index.php/', $server->guessBaseUri());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGuessBaseUriNoPathInfo() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/index.php/root',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
|
2013-10-21 22:46:31 +00:00
|
|
|
$server = new Server();
|
|
|
|
$server->httpRequest = $httpRequest;
|
|
|
|
|
|
|
|
$this->assertEquals('/', $server->guessBaseUri());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGuessBaseUriNoPathInfo2() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/a/b/c/test.php',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
|
2013-10-21 22:46:31 +00:00
|
|
|
$server = new Server();
|
|
|
|
$server->httpRequest = $httpRequest;
|
|
|
|
|
|
|
|
$this->assertEquals('/', $server->guessBaseUri());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testGuessBaseUri
|
|
|
|
*/
|
|
|
|
function testGuessBaseUriQueryString() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/index.php/root?query_string=blabla',
|
|
|
|
'PATH_INFO' => '/root',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
|
2013-10-21 22:46:31 +00:00
|
|
|
$server = new Server();
|
|
|
|
$server->httpRequest = $httpRequest;
|
|
|
|
|
|
|
|
$this->assertEquals('/index.php/', $server->guessBaseUri());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testGuessBaseUri
|
|
|
|
* @expectedException \Sabre\DAV\Exception
|
|
|
|
*/
|
|
|
|
function testGuessBaseUriBadConfig() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/index.php/root/heyyy',
|
|
|
|
'PATH_INFO' => '/root',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
|
2013-10-21 22:46:31 +00:00
|
|
|
$server = new Server();
|
|
|
|
$server->httpRequest = $httpRequest;
|
|
|
|
|
|
|
|
$server->guessBaseUri();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testTriggerException() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$serverVars = [
|
|
|
|
'REQUEST_URI' => '/',
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_METHOD' => 'FOO',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$httpRequest = HTTP\Sapi::createFromServerArray($serverVars);
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->server->httpRequest = $httpRequest;
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->server->on('beforeMethod', [$this, 'exceptionTrigger']);
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
|
|
], $this->response->getHeaders());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(500, $this->response->status);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
function exceptionTrigger($request, $response) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
throw new Exception('Hola');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testReportNotFound() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/',
|
|
|
|
'REQUEST_METHOD' => 'REPORT',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
2013-10-21 22:46:31 +00:00
|
|
|
$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();
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
|
|
],
|
|
|
|
$this->response->getHeaders()
|
2013-10-21 22:46:31 +00:00
|
|
|
);
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(415, $this->response->status, 'We got an incorrect status back. Full response body follows: ' . $this->response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testReportIntercepted() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/',
|
|
|
|
'REQUEST_METHOD' => 'REPORT',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->httpRequest->setBody('<?xml version="1.0"?><bla:myreport xmlns:bla="http://www.rooftopsolutions.nl/NS"></bla:myreport>');
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->server->on('report', [$this, 'reportHandler']);
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
|
|
'testheader' => ['testvalue'],
|
|
|
|
],
|
|
|
|
$this->response->getHeaders()
|
2013-10-21 22:46:31 +00:00
|
|
|
);
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(418, $this->response->status, 'We got an incorrect status back. Full response body follows: ' . $this->response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
function reportHandler($reportName, $result, $path) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
if ($reportName == '{http://www.rooftopsolutions.nl/NS}myreport') {
|
|
|
|
$this->server->httpResponse->setStatus(418);
|
|
|
|
$this->server->httpResponse->setHeader('testheader', 'testvalue');
|
2013-10-21 22:46:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetPropertiesForChildren() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$result = $this->server->getPropertiesForChildren('', [
|
2013-10-21 22:46:31 +00:00
|
|
|
'{DAV:}getcontentlength',
|
2016-05-11 00:26:44 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$expected = [
|
|
|
|
'test.txt' => ['{DAV:}getcontentlength' => 13],
|
|
|
|
'dir/' => [],
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
}
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
/**
|
|
|
|
* There are certain cases where no HTTP status may be set. We need to
|
|
|
|
* intercept these and set it to a default error message.
|
|
|
|
*/
|
2016-05-28 15:46:24 +00:00
|
|
|
function testNoHTTPStatusSet() {
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
$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());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|