mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-22 20:15:17 +00:00
346 lines
9.8 KiB
PHP
346 lines
9.8 KiB
PHP
<?php
|
|
|
|
namespace Sabre\DAV;
|
|
|
|
use Sabre\HTTP;
|
|
|
|
class ServerMKCOLTest extends AbstractServer {
|
|
|
|
function testMkcol() {
|
|
|
|
$serverVars = array(
|
|
'REQUEST_URI' => '/testcol',
|
|
'REQUEST_METHOD' => 'MKCOL',
|
|
);
|
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
|
$request->setBody("");
|
|
$this->server->httpRequest = ($request);
|
|
$this->server->exec();
|
|
|
|
$this->assertEquals(array(
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
'Content-Length' => ['0'],
|
|
),$this->response->getHeaders());
|
|
|
|
$this->assertEquals(201, $this->response->status);
|
|
$this->assertEquals('', $this->response->body);
|
|
$this->assertTrue(is_dir($this->tempDir . '/testcol'));
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testMkcol
|
|
*/
|
|
function testMKCOLUnknownBody() {
|
|
|
|
$serverVars = array(
|
|
'REQUEST_URI' => '/testcol',
|
|
'REQUEST_METHOD' => 'MKCOL',
|
|
);
|
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
|
$request->setBody("Hello");
|
|
$this->server->httpRequest = ($request);
|
|
$this->server->exec();
|
|
|
|
$this->assertEquals(array(
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
),$this->response->getHeaders());
|
|
|
|
$this->assertEquals(415, $this->response->status);
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testMkcol
|
|
*/
|
|
function testMKCOLBrokenXML() {
|
|
|
|
$serverVars = array(
|
|
'REQUEST_URI' => '/testcol',
|
|
'REQUEST_METHOD' => 'MKCOL',
|
|
'HTTP_CONTENT_TYPE' => 'application/xml',
|
|
);
|
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
|
$request->setBody("Hello");
|
|
$this->server->httpRequest = ($request);
|
|
$this->server->exec();
|
|
|
|
$this->assertEquals(array(
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
),$this->response->getHeaders());
|
|
|
|
$this->assertEquals(400, $this->response->getStatus(), $this->response->getBodyAsString() );
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testMkcol
|
|
*/
|
|
function testMKCOLUnknownXML() {
|
|
|
|
$serverVars = array(
|
|
'REQUEST_URI' => '/testcol',
|
|
'REQUEST_METHOD' => 'MKCOL',
|
|
'HTTP_CONTENT_TYPE' => 'application/xml',
|
|
);
|
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
|
$request->setBody('<?xml version="1.0"?><html></html>');
|
|
$this->server->httpRequest = ($request);
|
|
$this->server->exec();
|
|
|
|
$this->assertEquals(array(
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
),$this->response->getHeaders());
|
|
|
|
$this->assertEquals(400, $this->response->getStatus());
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testMkcol
|
|
*/
|
|
function testMKCOLNoResourceType() {
|
|
|
|
$serverVars = array(
|
|
'REQUEST_URI' => '/testcol',
|
|
'REQUEST_METHOD' => 'MKCOL',
|
|
'HTTP_CONTENT_TYPE' => 'application/xml',
|
|
);
|
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
|
$request->setBody('<?xml version="1.0"?>
|
|
<mkcol xmlns="DAV:">
|
|
<set>
|
|
<prop>
|
|
<displayname>Evert</displayname>
|
|
</prop>
|
|
</set>
|
|
</mkcol>');
|
|
$this->server->httpRequest = ($request);
|
|
$this->server->exec();
|
|
|
|
$this->assertEquals(array(
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
),$this->response->getHeaders());
|
|
|
|
$this->assertEquals(400, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body);
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testMkcol
|
|
*/
|
|
function testMKCOLIncorrectResourceType() {
|
|
|
|
$serverVars = array(
|
|
'REQUEST_URI' => '/testcol',
|
|
'REQUEST_METHOD' => 'MKCOL',
|
|
'HTTP_CONTENT_TYPE' => 'application/xml',
|
|
);
|
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
|
$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();
|
|
|
|
$this->assertEquals(array(
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
),$this->response->getHeaders());
|
|
|
|
$this->assertEquals(403, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body);
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testMKCOLIncorrectResourceType
|
|
*/
|
|
function testMKCOLSuccess() {
|
|
|
|
$serverVars = array(
|
|
'REQUEST_URI' => '/testcol',
|
|
'REQUEST_METHOD' => 'MKCOL',
|
|
'HTTP_CONTENT_TYPE' => 'application/xml',
|
|
);
|
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
|
$request->setBody('<?xml version="1.0"?>
|
|
<mkcol xmlns="DAV:">
|
|
<set>
|
|
<prop>
|
|
<resourcetype><collection /></resourcetype>
|
|
</prop>
|
|
</set>
|
|
</mkcol>');
|
|
$this->server->httpRequest = ($request);
|
|
$this->server->exec();
|
|
|
|
$this->assertEquals(array(
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
'Content-Length' => ['0'],
|
|
),$this->response->getHeaders());
|
|
|
|
$this->assertEquals(201, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body);
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testMKCOLIncorrectResourceType
|
|
*/
|
|
function testMKCOLWhiteSpaceResourceType() {
|
|
|
|
$serverVars = array(
|
|
'REQUEST_URI' => '/testcol',
|
|
'REQUEST_METHOD' => 'MKCOL',
|
|
'HTTP_CONTENT_TYPE' => 'application/xml',
|
|
);
|
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
|
$request->setBody('<?xml version="1.0"?>
|
|
<mkcol xmlns="DAV:">
|
|
<set>
|
|
<prop>
|
|
<resourcetype>
|
|
<collection />
|
|
</resourcetype>
|
|
</prop>
|
|
</set>
|
|
</mkcol>');
|
|
$this->server->httpRequest = ($request);
|
|
$this->server->exec();
|
|
|
|
$this->assertEquals(array(
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
'Content-Length' => ['0'],
|
|
),$this->response->getHeaders());
|
|
|
|
$this->assertEquals(201, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body);
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testMKCOLIncorrectResourceType
|
|
*/
|
|
function testMKCOLNoParent() {
|
|
|
|
$serverVars = array(
|
|
'REQUEST_URI' => '/testnoparent/409me',
|
|
'REQUEST_METHOD' => 'MKCOL',
|
|
);
|
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
|
$request->setBody('');
|
|
|
|
$this->server->httpRequest = ($request);
|
|
$this->server->exec();
|
|
|
|
$this->assertEquals(array(
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
),$this->response->getHeaders());
|
|
|
|
$this->assertEquals(409, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body);
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testMKCOLIncorrectResourceType
|
|
*/
|
|
function testMKCOLParentIsNoCollection() {
|
|
|
|
$serverVars = array(
|
|
'REQUEST_URI' => '/test.txt/409me',
|
|
'REQUEST_METHOD' => 'MKCOL',
|
|
);
|
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
|
$request->setBody('');
|
|
|
|
$this->server->httpRequest = ($request);
|
|
$this->server->exec();
|
|
|
|
$this->assertEquals(array(
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
),$this->response->getHeaders());
|
|
|
|
$this->assertEquals(409, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body);
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testMKCOLIncorrectResourceType
|
|
*/
|
|
function testMKCOLAlreadyExists() {
|
|
|
|
$serverVars = array(
|
|
'REQUEST_URI' => '/test.txt',
|
|
'REQUEST_METHOD' => 'MKCOL',
|
|
);
|
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
|
$request->setBody('');
|
|
|
|
$this->server->httpRequest = ($request);
|
|
$this->server->exec();
|
|
|
|
$this->assertEquals(array(
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
'Allow' => ['OPTIONS, GET, HEAD, DELETE, PROPFIND, PUT, PROPPATCH, COPY, MOVE, REPORT'],
|
|
),$this->response->getHeaders());
|
|
|
|
$this->assertEquals(405, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body);
|
|
|
|
}
|
|
|
|
/**
|
|
* @depends testMKCOLSuccess
|
|
* @depends testMKCOLAlreadyExists
|
|
*/
|
|
function testMKCOLAndProps() {
|
|
|
|
$serverVars = array(
|
|
'REQUEST_URI' => '/testcol',
|
|
'REQUEST_METHOD' => 'MKCOL',
|
|
'HTTP_CONTENT_TYPE' => 'application/xml',
|
|
);
|
|
|
|
$request = HTTP\Sapi::createFromServerArray($serverVars);
|
|
$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();
|
|
|
|
$this->assertEquals(207, $this->response->status, 'Wrong statuscode received. Full response body: ' .$this->response->body);
|
|
|
|
$this->assertEquals(array(
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
),$this->response->getHeaders());
|
|
|
|
}
|
|
|
|
}
|