more tests

This commit is contained in:
Robin Appelman 2017-02-22 16:43:46 +01:00
commit b42b650266
13 changed files with 442 additions and 12 deletions

View file

@ -32,6 +32,7 @@ use Sabre\DAV\Xml\Element\Response;
use Sabre\DAV\Xml\Response\MultiStatus;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use Sabre\Xml\ParseException;
use Sabre\Xml\Writer;
use SearchDAV\Backend\ISearchBackend;
use SearchDAV\Backend\SearchPropertyDefinition;
@ -55,11 +56,11 @@ class SearchPlugin extends ServerPlugin {
public function __construct(ISearchBackend $searchBackend) {
$this->searchBackend = $searchBackend;
$this->queryParser = new QueryParser();
}
public function initialize(Server $server) {
$this->server = $server;
$this->queryParser = new QueryParser($this->server->xml);
$server->on('method:SEARCH', [$this, 'searchHandler']);
$server->on('afterMethod:OPTIONS', [$this, 'optionHandler']);
$server->on('propFind', [$this, 'propFindHandler']);
@ -98,7 +99,7 @@ class SearchPlugin extends ServerPlugin {
}
public function optionHandler(RequestInterface $request, ResponseInterface $response) {
if ($request->getPath() === '') {
if ($request->getPath() === $this->searchBackend->getArbiterPath()) {
$response->addHeader('DASL', '<DAV:basicsearch>');
}
}
@ -111,11 +112,21 @@ class SearchPlugin extends ServerPlugin {
return;
}
$xml = $this->queryParser->parse(
$request->getBody(),
$request->getUrl(),
$documentType
);
if ($request->getPath() !== $this->searchBackend->getArbiterPath()) {
return;
}
try {
$xml = $this->queryParser->parse(
$request->getBody(),
$request->getUrl(),
$documentType
);
} catch (ParseException $e) {
$response->setStatus(400);
$response->setBody('Parse error: ' . $e->getMessage());
return false;
}
switch ($documentType) {
case '{DAV:}searchrequest':

View file

@ -21,6 +21,7 @@
namespace SearchDAV\XML;
use Sabre\Xml\ParseException;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
@ -62,10 +63,15 @@ class BasicSearch implements XmlDeserializable {
$search = new self();
$elements = \Sabre\Xml\Deserializer\keyValue($reader);
$search->select = isset($elements['{DAV:}select']) ? $elements['{DAV:}select'] : null;
$search->from = isset($elements['{DAV:}from']) ? $elements['{DAV:}from'] : null;
if (!isset($elements['{DAV:}from'])) {
throw new ParseException('Missing {DAV:}from when parsing {DAV:}basicsearch');
}
$search->select = isset($elements['{DAV:}select']) ? $elements['{DAV:}select'] : [];
$search->from = $elements['{DAV:}from'];
$search->where = isset($elements['{DAV:}where']) ? $elements['{DAV:}where'] : null;
$search->orderBy = isset($elements['{DAV:}orderby']) ? $elements['{DAV:}orderby'] : null;
$search->orderBy = isset($elements['{DAV:}orderby']) ? $elements['{DAV:}orderby'] : [];
return $search;
}

View file

@ -49,7 +49,7 @@ class QueryDiscoverResponse extends Response {
if ($this->schema) {
$writer->writeElement('{DAV:}query-schema', [
'{DAV:basicsearchschema}' => $this->schema
'{DAV:}basicsearchschema' => $this->schema
]);
}
}

View file

@ -53,10 +53,12 @@ class Scope implements XmlDeserializable {
/**
* @param string $href
* @param int|string $depth
* @param string|null $path
*/
public function __construct($href = '', $depth = 1) {
public function __construct($href = '', $depth = 1, $path = null) {
$this->href = $href;
$this->depth = $depth;
$this->path = $path;
}
static function xmlDeserialize(Reader $reader) {