2013-10-21 22:46:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Sabre\DAV;
|
|
|
|
|
|
|
|
use Sabre\HTTP;
|
|
|
|
|
|
|
|
class ServerMKCOLTest extends AbstractServer {
|
|
|
|
|
|
|
|
function testMkcol() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/testcol',
|
|
|
|
'REQUEST_METHOD' => 'MKCOL',
|
2016-05-28 15:46:24 +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
|
|
|
$request->setBody("");
|
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
2016-05-11 00:26:44 +00:00
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
2016-05-28 15:46:24 +00:00
|
|
|
'Content-Length' => ['0'],
|
|
|
|
], $this->response->getHeaders());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(201, $this->response->status);
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->assertEquals('', $this->response->body);
|
|
|
|
$this->assertTrue(is_dir($this->tempDir . '/testcol'));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testMkcol
|
|
|
|
*/
|
|
|
|
function testMKCOLUnknownBody() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/testcol',
|
|
|
|
'REQUEST_METHOD' => 'MKCOL',
|
2016-05-28 15:46:24 +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
|
|
|
$request->setBody("Hello");
|
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
2016-05-11 00:26:44 +00:00
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
2016-05-28 15:46:24 +00:00
|
|
|
'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);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testMkcol
|
|
|
|
*/
|
|
|
|
function testMKCOLBrokenXML() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$serverVars = [
|
|
|
|
'REQUEST_URI' => '/testcol',
|
|
|
|
'REQUEST_METHOD' => 'MKCOL',
|
2013-10-21 22:46:31 +00:00
|
|
|
'HTTP_CONTENT_TYPE' => 'application/xml',
|
2016-05-28 15:46:24 +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
|
|
|
$request->setBody("Hello");
|
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
2016-05-11 00:26:44 +00:00
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
2016-05-28 15:46:24 +00:00
|
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
|
|
], $this->response->getHeaders());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(400, $this->response->getStatus(), $this->response->getBodyAsString());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testMkcol
|
|
|
|
*/
|
|
|
|
function testMKCOLUnknownXML() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$serverVars = [
|
|
|
|
'REQUEST_URI' => '/testcol',
|
|
|
|
'REQUEST_METHOD' => 'MKCOL',
|
2013-10-21 22:46:31 +00:00
|
|
|
'HTTP_CONTENT_TYPE' => 'application/xml',
|
2016-05-28 15:46:24 +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
|
|
|
$request->setBody('<?xml version="1.0"?><html></html>');
|
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
2016-05-11 00:26:44 +00:00
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
2016-05-28 15:46:24 +00:00
|
|
|
'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(400, $this->response->getStatus());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testMkcol
|
|
|
|
*/
|
|
|
|
function testMKCOLNoResourceType() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$serverVars = [
|
|
|
|
'REQUEST_URI' => '/testcol',
|
|
|
|
'REQUEST_METHOD' => 'MKCOL',
|
2013-10-21 22:46:31 +00:00
|
|
|
'HTTP_CONTENT_TYPE' => 'application/xml',
|
2016-05-28 15:46:24 +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
|
|
|
$request->setBody('<?xml version="1.0"?>
|
|
|
|
<mkcol xmlns="DAV:">
|
|
|
|
<set>
|
|
|
|
<prop>
|
|
|
|
<displayname>Evert</displayname>
|
|
|
|
</prop>
|
|
|
|
</set>
|
|
|
|
</mkcol>');
|
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
2016-05-11 00:26:44 +00:00
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
2016-05-28 15:46:24 +00:00
|
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
|
|
], $this->response->getHeaders());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(400, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-11 00:26:44 +00:00
|
|
|
* @depends testMkcol
|
2013-10-21 22:46:31 +00:00
|
|
|
*/
|
|
|
|
function testMKCOLIncorrectResourceType() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$serverVars = [
|
|
|
|
'REQUEST_URI' => '/testcol',
|
|
|
|
'REQUEST_METHOD' => 'MKCOL',
|
2013-10-21 22:46:31 +00:00
|
|
|
'HTTP_CONTENT_TYPE' => 'application/xml',
|
2016-05-28 15:46:24 +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
|
|
|
$request->setBody('<?xml version="1.0"?>
|
|
|
|
<mkcol xmlns="DAV:">
|
|
|
|
<set>
|
|
|
|
<prop>
|
|
|
|
<resourcetype><collection /><blabla /></resourcetype>
|
|
|
|
</prop>
|
|
|
|
</set>
|
|
|
|
</mkcol>');
|
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
2016-05-11 00:26:44 +00:00
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
2016-05-28 15:46:24 +00:00
|
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
|
|
], $this->response->getHeaders());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(403, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-11 00:26:44 +00:00
|
|
|
* @depends testMKCOLIncorrectResourceType
|
2013-10-21 22:46:31 +00:00
|
|
|
*/
|
|
|
|
function testMKCOLSuccess() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$serverVars = [
|
|
|
|
'REQUEST_URI' => '/testcol',
|
|
|
|
'REQUEST_METHOD' => 'MKCOL',
|
2013-10-21 22:46:31 +00:00
|
|
|
'HTTP_CONTENT_TYPE' => 'application/xml',
|
2016-05-28 15:46:24 +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
|
|
|
$request->setBody('<?xml version="1.0"?>
|
|
|
|
<mkcol xmlns="DAV:">
|
|
|
|
<set>
|
|
|
|
<prop>
|
|
|
|
<resourcetype><collection /></resourcetype>
|
|
|
|
</prop>
|
|
|
|
</set>
|
|
|
|
</mkcol>');
|
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
2016-05-11 00:26:44 +00:00
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
2016-05-28 15:46:24 +00:00
|
|
|
'Content-Length' => ['0'],
|
|
|
|
], $this->response->getHeaders());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(201, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-11 00:26:44 +00:00
|
|
|
* @depends testMKCOLIncorrectResourceType
|
2013-10-21 22:46:31 +00:00
|
|
|
*/
|
|
|
|
function testMKCOLWhiteSpaceResourceType() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$serverVars = [
|
|
|
|
'REQUEST_URI' => '/testcol',
|
|
|
|
'REQUEST_METHOD' => 'MKCOL',
|
2013-10-21 22:46:31 +00:00
|
|
|
'HTTP_CONTENT_TYPE' => 'application/xml',
|
2016-05-28 15:46:24 +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
|
|
|
$request->setBody('<?xml version="1.0"?>
|
|
|
|
<mkcol xmlns="DAV:">
|
|
|
|
<set>
|
|
|
|
<prop>
|
|
|
|
<resourcetype>
|
|
|
|
<collection />
|
|
|
|
</resourcetype>
|
|
|
|
</prop>
|
|
|
|
</set>
|
|
|
|
</mkcol>');
|
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
2016-05-11 00:26:44 +00:00
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
2016-05-28 15:46:24 +00:00
|
|
|
'Content-Length' => ['0'],
|
|
|
|
], $this->response->getHeaders());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(201, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-11 00:26:44 +00:00
|
|
|
* @depends testMKCOLIncorrectResourceType
|
2013-10-21 22:46:31 +00:00
|
|
|
*/
|
|
|
|
function testMKCOLNoParent() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/testnoparent/409me',
|
|
|
|
'REQUEST_METHOD' => 'MKCOL',
|
2016-05-28 15:46:24 +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
|
|
|
$request->setBody('');
|
|
|
|
|
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
2016-05-11 00:26:44 +00:00
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
2016-05-28 15:46:24 +00:00
|
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
|
|
], $this->response->getHeaders());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(409, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-11 00:26:44 +00:00
|
|
|
* @depends testMKCOLIncorrectResourceType
|
2013-10-21 22:46:31 +00:00
|
|
|
*/
|
|
|
|
function testMKCOLParentIsNoCollection() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/test.txt/409me',
|
|
|
|
'REQUEST_METHOD' => 'MKCOL',
|
2016-05-28 15:46:24 +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
|
|
|
$request->setBody('');
|
|
|
|
|
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
2016-05-11 00:26:44 +00:00
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
2016-05-28 15:46:24 +00:00
|
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
|
|
], $this->response->getHeaders());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(409, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-11 00:26:44 +00:00
|
|
|
* @depends testMKCOLIncorrectResourceType
|
2013-10-21 22:46:31 +00:00
|
|
|
*/
|
|
|
|
function testMKCOLAlreadyExists() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$serverVars = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_URI' => '/test.txt',
|
|
|
|
'REQUEST_METHOD' => 'MKCOL',
|
2016-05-28 15:46:24 +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
|
|
|
$request->setBody('');
|
|
|
|
|
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
2016-05-11 00:26:44 +00:00
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
2016-05-28 15:46:24 +00:00
|
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
|
|
'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT'],
|
|
|
|
], $this->response->getHeaders());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(405, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testMKCOLSuccess
|
|
|
|
* @depends testMKCOLAlreadyExists
|
|
|
|
*/
|
|
|
|
function testMKCOLAndProps() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'MKCOL',
|
|
|
|
'/testcol',
|
|
|
|
['Content-Type' => 'application/xml']
|
2013-10-21 22:46:31 +00:00
|
|
|
);
|
|
|
|
$request->setBody('<?xml version="1.0"?>
|
|
|
|
<mkcol xmlns="DAV:">
|
|
|
|
<set>
|
|
|
|
<prop>
|
|
|
|
<resourcetype><collection /></resourcetype>
|
|
|
|
<displayname>my new collection</displayname>
|
|
|
|
</prop>
|
|
|
|
</set>
|
|
|
|
</mkcol>');
|
|
|
|
$this->server->httpRequest = ($request);
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals(207, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
2016-05-11 00:26:44 +00:00
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
2016-05-28 15:46:24 +00:00
|
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
|
|
], $this->response->getHeaders());
|
|
|
|
|
|
|
|
$responseBody = $this->response->getBodyAsString();
|
|
|
|
|
|
|
|
$expected = <<<XML
|
|
|
|
<?xml version="1.0"?>
|
|
|
|
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
|
|
|
|
<d:response>
|
|
|
|
<d:href>/testcol</d:href>
|
|
|
|
<d:propstat>
|
|
|
|
<d:prop>
|
|
|
|
<d:displayname />
|
|
|
|
</d:prop>
|
|
|
|
<d:status>HTTP/1.1 403 Forbidden</d:status>
|
|
|
|
</d:propstat>
|
|
|
|
</d:response>
|
|
|
|
</d:multistatus>
|
|
|
|
XML;
|
|
|
|
|
|
|
|
$this->assertXmlStringEqualsXmlString(
|
|
|
|
$expected,
|
|
|
|
$responseBody
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|