mirror of
https://codeberg.org/icewind/SearchDAV.git
synced 2026-06-03 09:34:08 +02:00
"where" is optional
This commit is contained in:
parent
e8cf5e7644
commit
aeb7610589
3 changed files with 15 additions and 11 deletions
|
|
@ -62,11 +62,6 @@ class SearchHandler {
|
||||||
}
|
}
|
||||||
/** @var BasicSearch $query */
|
/** @var BasicSearch $query */
|
||||||
$query = $xml['{DAV:}basicsearch'];
|
$query = $xml['{DAV:}basicsearch'];
|
||||||
if (!$query->where) {
|
|
||||||
$response->setStatus(400);
|
|
||||||
$response->setBody('Parse error: Missing {DAV:}where from {DAV:}basicsearch');
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!$query->select) {
|
if (!$query->select) {
|
||||||
$response->setStatus(400);
|
$response->setStatus(400);
|
||||||
$response->setBody('Parse error: Missing {DAV:}select from {DAV:}basicsearch');
|
$response->setBody('Parse error: Missing {DAV:}select from {DAV:}basicsearch');
|
||||||
|
|
@ -123,7 +118,7 @@ class SearchHandler {
|
||||||
}, $xml->select);
|
}, $xml->select);
|
||||||
$select = array_filter($select);
|
$select = array_filter($select);
|
||||||
|
|
||||||
$where = $this->transformOperator($xml->where, $allProps);
|
$where = $xml->where ? $this->transformOperator($xml->where, $allProps) : null;
|
||||||
|
|
||||||
return new Query($select, $xml->from, $where, $orderBy, $xml->limit);
|
return new Query($select, $xml->from, $where, $orderBy, $xml->limit);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,11 +65,11 @@ class Query {
|
||||||
* Query constructor.
|
* Query constructor.
|
||||||
* @param SearchPropertyDefinition[] $select
|
* @param SearchPropertyDefinition[] $select
|
||||||
* @param Scope[] $from
|
* @param Scope[] $from
|
||||||
* @param Operator $where
|
* @param Operator|null $where
|
||||||
* @param Order[] $orderBy
|
* @param Order[] $orderBy
|
||||||
* @param Limit $limit
|
* @param Limit $limit
|
||||||
*/
|
*/
|
||||||
public function __construct(array $select, array $from, Operator $where, array $orderBy, Limit $limit) {
|
public function __construct(array $select, array $from, ?Operator $where, array $orderBy, Limit $limit) {
|
||||||
$this->select = $select;
|
$this->select = $select;
|
||||||
$this->from = $from;
|
$this->from = $from;
|
||||||
$this->where = $where;
|
$this->where = $where;
|
||||||
|
|
|
||||||
|
|
@ -348,6 +348,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
||||||
->method('getArbiterPath')
|
->method('getArbiterPath')
|
||||||
->willReturn('foo');
|
->willReturn('foo');
|
||||||
|
|
||||||
|
$lengthProp = new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER);
|
||||||
$plugin = new SearchPlugin($this->searchBackend);
|
$plugin = new SearchPlugin($this->searchBackend);
|
||||||
$server = new Server();
|
$server = new Server();
|
||||||
$plugin->initialize($server);
|
$plugin->initialize($server);
|
||||||
|
|
@ -363,12 +364,20 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
||||||
->method('isValidScope')
|
->method('isValidScope')
|
||||||
->willReturn(true);
|
->willReturn(true);
|
||||||
|
|
||||||
$this->searchBackend->expects($this->never())
|
$this->searchBackend->expects($this->any())
|
||||||
->method('search');
|
->method('getPropertyDefinitionsForScope')
|
||||||
|
->willReturn([$lengthProp]);
|
||||||
|
|
||||||
|
$this->searchBackend->expects($this->once())
|
||||||
|
->method('search')
|
||||||
|
->willReturnCallback(function(Query $query) {
|
||||||
|
$this->assertNull($query->where);
|
||||||
|
return [];
|
||||||
|
});
|
||||||
|
|
||||||
$plugin->searchHandler($request, $response);
|
$plugin->searchHandler($request, $response);
|
||||||
|
|
||||||
$this->assertEquals(400, $response->getStatus());
|
$this->assertEquals(207, $response->getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSearchQueryNoSelect() {
|
public function testSearchQueryNoSelect() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue