'/testcol',
'REQUEST_METHOD' => 'MKCOL',
];
$request = HTTP\Sapi::createFromServerArray($serverVars);
$request->setBody("");
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals([
'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 = [
'REQUEST_URI' => '/testcol',
'REQUEST_METHOD' => 'MKCOL',
];
$request = HTTP\Sapi::createFromServerArray($serverVars);
$request->setBody("Hello");
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals([
'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 = [
'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([
'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 = [
'REQUEST_URI' => '/testcol',
'REQUEST_METHOD' => 'MKCOL',
'HTTP_CONTENT_TYPE' => 'application/xml',
];
$request = HTTP\Sapi::createFromServerArray($serverVars);
$request->setBody('');
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals([
'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 = [
'REQUEST_URI' => '/testcol',
'REQUEST_METHOD' => 'MKCOL',
'HTTP_CONTENT_TYPE' => 'application/xml',
];
$request = HTTP\Sapi::createFromServerArray($serverVars);
$request->setBody('
Evert
');
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals([
'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 = [
'REQUEST_URI' => '/testcol',
'REQUEST_METHOD' => 'MKCOL',
'HTTP_CONTENT_TYPE' => 'application/xml',
];
$request = HTTP\Sapi::createFromServerArray($serverVars);
$request->setBody('
');
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals([
'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 = [
'REQUEST_URI' => '/testcol',
'REQUEST_METHOD' => 'MKCOL',
'HTTP_CONTENT_TYPE' => 'application/xml',
];
$request = HTTP\Sapi::createFromServerArray($serverVars);
$request->setBody('
');
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals([
'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 = [
'REQUEST_URI' => '/testcol',
'REQUEST_METHOD' => 'MKCOL',
'HTTP_CONTENT_TYPE' => 'application/xml',
];
$request = HTTP\Sapi::createFromServerArray($serverVars);
$request->setBody('
');
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals([
'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 = [
'REQUEST_URI' => '/testnoparent/409me',
'REQUEST_METHOD' => 'MKCOL',
];
$request = HTTP\Sapi::createFromServerArray($serverVars);
$request->setBody('');
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals([
'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 = [
'REQUEST_URI' => '/test.txt/409me',
'REQUEST_METHOD' => 'MKCOL',
];
$request = HTTP\Sapi::createFromServerArray($serverVars);
$request->setBody('');
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals([
'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 = [
'REQUEST_URI' => '/test.txt',
'REQUEST_METHOD' => 'MKCOL',
];
$request = HTTP\Sapi::createFromServerArray($serverVars);
$request->setBody('');
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals([
'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() {
$request = new HTTP\Request(
'MKCOL',
'/testcol',
['Content-Type' => 'application/xml']
);
$request->setBody('
my new collection
');
$this->server->httpRequest = ($request);
$this->server->exec();
$this->assertEquals(207, $this->response->status, 'Wrong statuscode received. Full response body: ' . $this->response->body);
$this->assertEquals([
'X-Sabre-Version' => [Version::VERSION],
'Content-Type' => ['application/xml; charset=utf-8'],
], $this->response->getHeaders());
$responseBody = $this->response->getBodyAsString();
$expected = <<
/testcol
HTTP/1.1 403 Forbidden
XML;
$this->assertXmlStringEqualsXmlString(
$expected,
$responseBody
);
}
}