2013-10-21 22:46:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Sabre\DAV;
|
|
|
|
|
|
|
|
use Sabre\HTTP;
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
class HTTPPreferParsingTest extends \Sabre\DAVServerTest {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
function testParseSimple() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$httpRequest = HTTP\Sapi::createFromServerArray([
|
2013-10-21 22:46:31 +00:00
|
|
|
'HTTP_PREFER' => 'return-asynch',
|
2016-05-11 00:26:44 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$server = new Server();
|
|
|
|
$server->httpRequest = $httpRequest;
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'respond-async' => true,
|
|
|
|
'return' => null,
|
|
|
|
'handling' => null,
|
|
|
|
'wait' => null,
|
|
|
|
], $server->getHTTPPrefer());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testParseValue() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$httpRequest = HTTP\Sapi::createFromServerArray([
|
2013-10-21 22:46:31 +00:00
|
|
|
'HTTP_PREFER' => 'wait=10',
|
2016-05-11 00:26:44 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$server = new Server();
|
|
|
|
$server->httpRequest = $httpRequest;
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'respond-async' => false,
|
|
|
|
'return' => null,
|
|
|
|
'handling' => null,
|
|
|
|
'wait' => '10',
|
|
|
|
], $server->getHTTPPrefer());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testParseMultiple() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$httpRequest = HTTP\Sapi::createFromServerArray([
|
2013-10-21 22:46:31 +00:00
|
|
|
'HTTP_PREFER' => 'return-minimal, strict,lenient',
|
2016-05-11 00:26:44 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$server = new Server();
|
|
|
|
$server->httpRequest = $httpRequest;
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'respond-async' => false,
|
|
|
|
'return' => 'minimal',
|
|
|
|
'handling' => 'lenient',
|
|
|
|
'wait' => null,
|
|
|
|
], $server->getHTTPPrefer());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testParseWeirdValue() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$httpRequest = HTTP\Sapi::createFromServerArray([
|
2013-10-21 22:46:31 +00:00
|
|
|
'HTTP_PREFER' => 'BOOOH',
|
2016-05-11 00:26:44 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$server = new Server();
|
|
|
|
$server->httpRequest = $httpRequest;
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'respond-async' => false,
|
|
|
|
'return' => null,
|
|
|
|
'handling' => null,
|
|
|
|
'wait' => null,
|
|
|
|
'boooh' => true,
|
|
|
|
], $server->getHTTPPrefer());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testBrief() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$httpRequest = HTTP\Sapi::createFromServerArray([
|
2013-10-21 22:46:31 +00:00
|
|
|
'HTTP_BRIEF' => 't',
|
2016-05-11 00:26:44 +00:00
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$server = new Server();
|
|
|
|
$server->httpRequest = $httpRequest;
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'respond-async' => false,
|
|
|
|
'return' => 'minimal',
|
|
|
|
'handling' => null,
|
|
|
|
'wait' => null,
|
|
|
|
], $server->getHTTPPrefer());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* propfindMinimal
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function testpropfindMinimal() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = HTTP\Sapi::createFromServerArray([
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_METHOD' => 'PROPFIND',
|
|
|
|
'REQUEST_URI' => '/',
|
2016-05-11 00:26:44 +00:00
|
|
|
'HTTP_PREFER' => 'return-minimal',
|
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
$request->setBody(<<<BLA
|
|
|
|
<?xml version="1.0"?>
|
|
|
|
<d:propfind xmlns:d="DAV:">
|
|
|
|
<d:prop>
|
|
|
|
<d:something />
|
|
|
|
<d:resourcetype />
|
|
|
|
</d:prop>
|
|
|
|
</d:propfind>
|
|
|
|
BLA
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->request($request);
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$body = $response->getBodyAsString();
|
|
|
|
|
|
|
|
$this->assertEquals(207, $response->getStatus(), $body);
|
|
|
|
|
|
|
|
$this->assertTrue(strpos($body, 'resourcetype') !== false, $body);
|
|
|
|
$this->assertTrue(strpos($body, 'something') === false, $body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testproppatchMinimal() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = new HTTP\Request('PROPPATCH', '/', ['Prefer' => 'return-minimal']);
|
2013-10-21 22:46:31 +00:00
|
|
|
$request->setBody(<<<BLA
|
|
|
|
<?xml version="1.0"?>
|
2016-05-11 00:26:44 +00:00
|
|
|
<d:propertyupdate xmlns:d="DAV:">
|
2013-10-21 22:46:31 +00:00
|
|
|
<d:set>
|
|
|
|
<d:prop>
|
|
|
|
<d:something>nope!</d:something>
|
|
|
|
</d:prop>
|
|
|
|
</d:set>
|
2016-05-11 00:26:44 +00:00
|
|
|
</d:propertyupdate>
|
2013-10-21 22:46:31 +00:00
|
|
|
BLA
|
|
|
|
);
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->server->on('propPatch', function($path, PropPatch $propPatch) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$propPatch->handle('{DAV:}something', function($props) {
|
|
|
|
return true;
|
|
|
|
});
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
$response = $this->request($request);
|
|
|
|
|
|
|
|
$this->assertEquals(0, strlen($response->body), 'Expected empty body: ' . $response->body);
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(204, $response->status);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testproppatchMinimalError() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = new HTTP\Request('PROPPATCH', '/', ['Prefer' => 'return-minimal']);
|
2013-10-21 22:46:31 +00:00
|
|
|
$request->setBody(<<<BLA
|
|
|
|
<?xml version="1.0"?>
|
2016-05-11 00:26:44 +00:00
|
|
|
<d:propertyupdate xmlns:d="DAV:">
|
2013-10-21 22:46:31 +00:00
|
|
|
<d:set>
|
|
|
|
<d:prop>
|
|
|
|
<d:something>nope!</d:something>
|
|
|
|
</d:prop>
|
|
|
|
</d:set>
|
2016-05-11 00:26:44 +00:00
|
|
|
</d:propertyupdate>
|
2013-10-21 22:46:31 +00:00
|
|
|
BLA
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = $this->request($request);
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$body = $response->getBodyAsString();
|
|
|
|
|
|
|
|
$this->assertEquals(207, $response->status);
|
|
|
|
$this->assertTrue(strpos($body, 'something') !== false);
|
|
|
|
$this->assertTrue(strpos($body, '403 Forbidden') !== false, $body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|