2013-10-21 22:46:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Sabre\DAV;
|
2016-05-11 00:26:44 +00:00
|
|
|
|
2013-10-21 22:46:31 +00:00
|
|
|
use Sabre\HTTP;
|
|
|
|
|
|
|
|
require_once 'Sabre/HTTP/ResponseMock.php';
|
|
|
|
require_once 'Sabre/DAV/AbstractServer.php';
|
|
|
|
|
|
|
|
class ServerPropsTest extends AbstractServer {
|
|
|
|
|
|
|
|
protected function getRootNode() {
|
|
|
|
|
|
|
|
return new FSExt\Directory(SABRE_TEMPDIR);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function setUp() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
if (file_exists(SABRE_TEMPDIR . '../.sabredav')) unlink(SABRE_TEMPDIR . '../.sabredav');
|
2013-10-21 22:46:31 +00:00
|
|
|
parent::setUp();
|
|
|
|
file_put_contents(SABRE_TEMPDIR . '/test2.txt', 'Test contents2');
|
|
|
|
mkdir(SABRE_TEMPDIR . '/col');
|
|
|
|
file_put_contents(SABRE_TEMPDIR . 'col/test.txt', 'Test contents');
|
|
|
|
$this->server->addPlugin(new Locks\Plugin(new Locks\Backend\File(SABRE_TEMPDIR . '/.locksdb')));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function tearDown() {
|
|
|
|
|
|
|
|
parent::tearDown();
|
2016-05-11 00:26:44 +00:00
|
|
|
if (file_exists(SABRE_TEMPDIR . '../.locksdb')) unlink(SABRE_TEMPDIR . '../.locksdb');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
private function sendRequest($body, $path = '/', $headers = ['Depth' => '0']) {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$request = new HTTP\Request('PROPFIND', $path, $headers, $body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->server->httpRequest = $request;
|
2013-10-21 22:46:31 +00:00
|
|
|
$this->server->exec();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
function testPropFindEmptyBody() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->sendRequest("");
|
|
|
|
$this->assertEquals(207, $this->response->status);
|
|
|
|
|
|
|
|
$this->assertEquals([
|
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
|
|
'DAV' => ['1, 3, extended-mkcol, 2'],
|
|
|
|
'Vary' => ['Brief,Prefer'],
|
|
|
|
],
|
|
|
|
$this->response->getHeaders()
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
|
|
|
|
$xml = simplexml_load_string($body);
|
|
|
|
$xml->registerXPathNamespace('d', 'urn:DAV');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
list($data) = $xml->xpath('/d:multistatus/d:response/d:href');
|
|
|
|
$this->assertEquals('/', (string)$data, 'href element should have been /');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:resourcetype');
|
|
|
|
$this->assertEquals(1, count($data));
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
}
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
function testPropFindEmptyBodyFile() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->sendRequest("", '/test2.txt', []);
|
|
|
|
$this->assertEquals(207, $this->response->status);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'X-Sabre-Version' => [Version::VERSION],
|
|
|
|
'Content-Type' => ['application/xml; charset=utf-8'],
|
|
|
|
'DAV' => ['1, 3, extended-mkcol, 2'],
|
|
|
|
'Vary' => ['Brief,Prefer'],
|
|
|
|
],
|
|
|
|
$this->response->getHeaders()
|
2013-10-21 22:46:31 +00:00
|
|
|
);
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
$xml = simplexml_load_string($body);
|
2016-05-11 00:26:44 +00:00
|
|
|
$xml->registerXPathNamespace('d', 'urn:DAV');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
list($data) = $xml->xpath('/d:multistatus/d:response/d:href');
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals('/test2.txt', (string)$data, 'href element should have been /test2.txt');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:getcontentlength');
|
|
|
|
$this->assertEquals(1, count($data));
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testSupportedLocks() {
|
|
|
|
|
|
|
|
$xml = '<?xml version="1.0"?>
|
|
|
|
<d:propfind xmlns:d="DAV:">
|
|
|
|
<d:prop>
|
|
|
|
<d:supportedlock />
|
|
|
|
</d:prop>
|
|
|
|
</d:propfind>';
|
|
|
|
|
|
|
|
$this->sendRequest($xml);
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
$xml = simplexml_load_string($body);
|
2016-05-11 00:26:44 +00:00
|
|
|
$xml->registerXPathNamespace('d', 'urn:DAV');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry');
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(2, count($data), 'We expected two \'d:lockentry\' tags');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope');
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(2, count($data), 'We expected two \'d:lockscope\' tags');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:locktype');
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(2, count($data), 'We expected two \'d:locktype\' tags');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope/d:shared');
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(1, count($data), 'We expected a \'d:shared\' tag');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:lockscope/d:exclusive');
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(1, count($data), 'We expected a \'d:exclusive\' tag');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:supportedlock/d:lockentry/d:locktype/d:write');
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(2, count($data), 'We expected two \'d:write\' tags');
|
2013-10-21 22:46:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testLockDiscovery() {
|
|
|
|
|
|
|
|
$xml = '<?xml version="1.0"?>
|
|
|
|
<d:propfind xmlns:d="DAV:">
|
|
|
|
<d:prop>
|
|
|
|
<d:lockdiscovery />
|
|
|
|
</d:prop>
|
|
|
|
</d:propfind>';
|
|
|
|
|
|
|
|
$this->sendRequest($xml);
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
$xml = simplexml_load_string($body);
|
2016-05-11 00:26:44 +00:00
|
|
|
$xml->registerXPathNamespace('d', 'urn:DAV');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$data = $xml->xpath('/d:multistatus/d:response/d:propstat/d:prop/d:lockdiscovery');
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(1, count($data), 'We expected a \'d:lockdiscovery\' tag');
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testUnknownProperty() {
|
|
|
|
|
|
|
|
$xml = '<?xml version="1.0"?>
|
|
|
|
<d:propfind xmlns:d="DAV:">
|
|
|
|
<d:prop>
|
|
|
|
<d:macaroni />
|
|
|
|
</d:prop>
|
|
|
|
</d:propfind>';
|
|
|
|
|
|
|
|
$this->sendRequest($xml);
|
2016-05-11 00:26:44 +00:00
|
|
|
$body = preg_replace("/xmlns(:[A-Za-z0-9_])?=(\"|\')DAV:(\"|\')/", "xmlns\\1=\"urn:DAV\"", $this->response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
$xml = simplexml_load_string($body);
|
2016-05-11 00:26:44 +00:00
|
|
|
$xml->registerXPathNamespace('d', 'urn:DAV');
|
|
|
|
$pathTests = [
|
2013-10-21 22:46:31 +00:00
|
|
|
'/d:multistatus',
|
|
|
|
'/d:multistatus/d:response',
|
|
|
|
'/d:multistatus/d:response/d:propstat',
|
|
|
|
'/d:multistatus/d:response/d:propstat/d:status',
|
|
|
|
'/d:multistatus/d:response/d:propstat/d:prop',
|
|
|
|
'/d:multistatus/d:response/d:propstat/d:prop/d:macaroni',
|
2016-05-11 00:26:44 +00:00
|
|
|
];
|
|
|
|
foreach ($pathTests as $test) {
|
|
|
|
$this->assertTrue(count($xml->xpath($test)) == true, 'We expected the ' . $test . ' element to appear in the response, we got: ' . $body);
|
2013-10-21 22:46:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$val = $xml->xpath('/d:multistatus/d:response/d:propstat/d:status');
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(1, count($val), $body);
|
|
|
|
$this->assertEquals('HTTP/1.1 404 Not Found', (string)$val[0]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
function testParsePropPatchRequest() {
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$body = '<?xml version="1.0"?>
|
|
|
|
<d:propertyupdate xmlns:d="DAV:" xmlns:s="http://sabredav.org/NS/test">
|
|
|
|
<d:set><d:prop><s:someprop>somevalue</s:someprop></d:prop></d:set>
|
|
|
|
<d:remove><d:prop><s:someprop2 /></d:prop></d:remove>
|
|
|
|
<d:set><d:prop><s:someprop3>removeme</s:someprop3></d:prop></d:set>
|
|
|
|
<d:remove><d:prop><s:someprop3 /></d:prop></d:remove>
|
|
|
|
</d:propertyupdate>';
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$result = $this->server->xml->parse($body);
|
|
|
|
$this->assertEquals([
|
|
|
|
'{http://sabredav.org/NS/test}someprop' => 'somevalue',
|
2013-10-21 22:46:31 +00:00
|
|
|
'{http://sabredav.org/NS/test}someprop2' => null,
|
|
|
|
'{http://sabredav.org/NS/test}someprop3' => null,
|
2016-05-11 00:26:44 +00:00
|
|
|
], $result->properties);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|