mirror of
https://codeberg.org/icewind/SearchDAV.git
synced 2026-06-03 09:34:08 +02:00
fix test
This commit is contained in:
parent
2f87fb84d3
commit
7174c02348
2 changed files with 77 additions and 58 deletions
|
|
@ -84,7 +84,8 @@ class SearchHandler {
|
|||
$response->setBody($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
$data = $this->server->generateMultiStatus(iterator_to_array($this->getPropertiesIteratorResults($results, $query->select)), false);
|
||||
$data = $this->server->generateMultiStatus(iterator_to_array($this->getPropertiesIteratorResults($results,
|
||||
$query->select)), false);
|
||||
$response->setBody($data);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -96,7 +97,7 @@ class SearchHandler {
|
|||
* @throws BadRequest
|
||||
*/
|
||||
private function getQueryForXML(BasicSearch $xml, array $allProps) {
|
||||
$orderBy = array_map(function(\SearchDAV\XML\Order $order) use ($allProps) {
|
||||
$orderBy = array_map(function (\SearchDAV\XML\Order $order) use ($allProps) {
|
||||
if (!isset($allProps[$order->property])) {
|
||||
throw new BadRequest('requested order by property is not a valid property for this scope');
|
||||
}
|
||||
|
|
@ -106,7 +107,7 @@ class SearchHandler {
|
|||
}
|
||||
return new Order($prop, $order->order);
|
||||
}, $xml->orderBy);
|
||||
$select = array_map(function($propName) use ($allProps) {
|
||||
$select = array_map(function ($propName) use ($allProps) {
|
||||
if (!isset($allProps[$propName])) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -130,7 +131,7 @@ class SearchHandler {
|
|||
* @throws BadRequest
|
||||
*/
|
||||
private function transformOperator(\SearchDAV\XML\Operator $operator, array $allProps) {
|
||||
$arguments = array_map(function($argument) use ($allProps) {
|
||||
$arguments = array_map(function ($argument) use ($allProps) {
|
||||
if (is_string($argument)) {
|
||||
if (!isset($allProps[$argument])) {
|
||||
throw new BadRequest('requested search property is not a valid property for this scope');
|
||||
|
|
@ -140,11 +141,13 @@ class SearchHandler {
|
|||
throw new BadRequest('requested search property is not searchable');
|
||||
}
|
||||
return $prop;
|
||||
} else if ($argument instanceof \SearchDAV\XML\Operator) {
|
||||
} else {
|
||||
if ($argument instanceof \SearchDAV\XML\Operator) {
|
||||
return $this->transformOperator($argument, $allProps);
|
||||
} else {
|
||||
return $argument;
|
||||
}
|
||||
}
|
||||
}, $operator->arguments);
|
||||
|
||||
return new Operator($operator->type, $arguments);
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
->willReturn('foo');
|
||||
|
||||
$request = new Request('SEARCH', 'foo', [
|
||||
'Content-Type' => 'text/plain'
|
||||
'Content-Type' => 'text/plain',
|
||||
], fopen(__DIR__ . '/nofrom.xml', 'r'));
|
||||
$response = new Response();
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
->willReturn('foo');
|
||||
|
||||
$request = new Request('SEARCH', 'bar', [
|
||||
'Content-Type' => 'text/xml'
|
||||
'Content-Type' => 'text/xml',
|
||||
], fopen(__DIR__ . '/nofrom.xml', 'r'));
|
||||
$response = new Response();
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
->willReturn('foo');
|
||||
|
||||
$request = new Request('SEARCH', 'foo', [
|
||||
'Content-Type' => 'text/xml'
|
||||
'Content-Type' => 'text/xml',
|
||||
], fopen(__DIR__ . '/invalidtype.xml', 'r'));
|
||||
$response = new Response();
|
||||
|
||||
|
|
@ -107,7 +107,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
->willReturn('foo');
|
||||
|
||||
$request = new Request('SEARCH', 'foo', [
|
||||
'Content-Type' => 'text/xml'
|
||||
'Content-Type' => 'text/xml',
|
||||
], fopen(__DIR__ . '/nofrom.xml', 'r'));
|
||||
$response = new Response();
|
||||
|
||||
|
|
@ -171,7 +171,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
$plugin->initialize($server);
|
||||
|
||||
$request = new Request('SEARCH', '/index.php/foo', [
|
||||
'Content-Type' => 'text/xml'
|
||||
'Content-Type' => 'text/xml',
|
||||
]);
|
||||
$request->setBaseUrl('/index.php');
|
||||
$request->setBody(fopen(__DIR__ . '/discover.xml', 'r'));
|
||||
|
|
@ -184,10 +184,12 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
$this->searchBackend->expects($this->once())
|
||||
->method('getPropertyDefinitionsForScope')
|
||||
->willReturn([
|
||||
new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||
new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true,
|
||||
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||
new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true),
|
||||
new SearchPropertyDefinition('{DAV:}displayname', true, true, true),
|
||||
new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||
new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true,
|
||||
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||
]);
|
||||
|
||||
$plugin->searchHandler($request, $response);
|
||||
|
|
@ -208,7 +210,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
$plugin->initialize($server);
|
||||
|
||||
$request = new Request('SEARCH', '/index.php/foo', [
|
||||
'Content-Type' => 'text/xml'
|
||||
'Content-Type' => 'text/xml',
|
||||
]);
|
||||
$request->setBaseUrl('/index.php');
|
||||
$request->setBody(fopen(__DIR__ . '/discover.xml', 'r'));
|
||||
|
|
@ -239,7 +241,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
$plugin->initialize($server);
|
||||
|
||||
$request = new Request('SEARCH', '/index.php/foo', [
|
||||
'Content-Type' => 'text/xml'
|
||||
'Content-Type' => 'text/xml',
|
||||
]);
|
||||
$request->setBaseUrl('/index.php');
|
||||
$request->setBody(fopen(__DIR__ . '/invaliddiscover.xml', 'r'));
|
||||
|
|
@ -266,7 +268,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
$plugin->initialize($server);
|
||||
|
||||
$request = new Request('SEARCH', '/index.php/foo', [
|
||||
'Content-Type' => 'text/xml'
|
||||
'Content-Type' => 'text/xml',
|
||||
]);
|
||||
$request->setBaseUrl('/index.php');
|
||||
$request->setBody(fopen(__DIR__ . '/basicquery.xml', 'r'));
|
||||
|
|
@ -276,17 +278,18 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
->method('isValidScope')
|
||||
->willReturn(true);
|
||||
|
||||
$lengthProp = new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER);
|
||||
$lengthProp = new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true,
|
||||
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER);
|
||||
$orderBy = [
|
||||
new \SearchDAV\Query\Order($lengthProp, \SearchDAV\Query\Order::ASC)
|
||||
new \SearchDAV\Query\Order($lengthProp, \SearchDAV\Query\Order::ASC),
|
||||
];
|
||||
$select = [$lengthProp];
|
||||
$from = [
|
||||
new Scope('/container1/', 'infinity', '/container1/')
|
||||
new Scope('/container1/', 'infinity', '/container1/'),
|
||||
];
|
||||
$where = new \SearchDAV\Query\Operator(\SearchDAV\Query\Operator::OPERATION_GREATER_THAN, [
|
||||
$lengthProp,
|
||||
new Literal(10000)
|
||||
new Literal(10000),
|
||||
]);
|
||||
$limit = new Limit();
|
||||
$query = new Query($select, $from, $where, $orderBy, $limit);
|
||||
|
|
@ -298,13 +301,13 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
new SearchResult(
|
||||
new Directory('/foo'),
|
||||
'/foo'
|
||||
)
|
||||
),
|
||||
]);
|
||||
|
||||
$this->searchBackend->expects($this->any())
|
||||
->method('getPropertyDefinitionsForScope')
|
||||
->willReturn([
|
||||
$lengthProp
|
||||
$lengthProp,
|
||||
]);
|
||||
|
||||
$plugin->searchHandler($request, $response);
|
||||
|
|
@ -325,7 +328,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
$plugin->initialize($server);
|
||||
|
||||
$request = new Request('SEARCH', '/index.php/foo', [
|
||||
'Content-Type' => 'text/xml'
|
||||
'Content-Type' => 'text/xml',
|
||||
]);
|
||||
$request->setBaseUrl('/index.php');
|
||||
$request->setBody(fopen(__DIR__ . '/nofrom.xml', 'r'));
|
||||
|
|
@ -348,13 +351,14 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
->method('getArbiterPath')
|
||||
->willReturn('foo');
|
||||
|
||||
$lengthProp = new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER);
|
||||
$lengthProp = new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true,
|
||||
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER);
|
||||
$plugin = new SearchPlugin($this->searchBackend);
|
||||
$server = new Server();
|
||||
$plugin->initialize($server);
|
||||
|
||||
$request = new Request('SEARCH', '/index.php/foo', [
|
||||
'Content-Type' => 'text/xml'
|
||||
'Content-Type' => 'text/xml',
|
||||
]);
|
||||
$request->setBaseUrl('/index.php');
|
||||
$request->setBody(fopen(__DIR__ . '/nowhere.xml', 'r'));
|
||||
|
|
@ -370,7 +374,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
|
||||
$this->searchBackend->expects($this->once())
|
||||
->method('search')
|
||||
->willReturnCallback(function(Query $query) {
|
||||
->willReturnCallback(function (Query $query) {
|
||||
$this->assertNull($query->where);
|
||||
return [];
|
||||
});
|
||||
|
|
@ -390,7 +394,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
$plugin->initialize($server);
|
||||
|
||||
$request = new Request('SEARCH', '/index.php/foo', [
|
||||
'Content-Type' => 'text/xml'
|
||||
'Content-Type' => 'text/xml',
|
||||
]);
|
||||
$request->setBaseUrl('/index.php');
|
||||
$request->setBody(fopen(__DIR__ . '/noselect.xml', 'r'));
|
||||
|
|
@ -418,7 +422,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
$plugin->initialize($server);
|
||||
|
||||
$request = new Request('SEARCH', '/index.php/foo', [
|
||||
'Content-Type' => 'text/xml'
|
||||
'Content-Type' => 'text/xml',
|
||||
]);
|
||||
$request->setBaseUrl('/index.php');
|
||||
$request->setBody(fopen(__DIR__ . '/invalid.xml', 'r'));
|
||||
|
|
@ -467,7 +471,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
$plugin->initialize($server);
|
||||
|
||||
$request = new Request('SEARCH', '/index.php/foo', [
|
||||
'Content-Type' => 'text/xml'
|
||||
'Content-Type' => 'text/xml',
|
||||
]);
|
||||
$request->setBaseUrl('/index.php');
|
||||
$request->setBody(fopen(__DIR__ . '/invalidwhere.xml', 'r'));
|
||||
|
|
@ -483,7 +487,8 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
$this->searchBackend->expects($this->once())
|
||||
->method('getPropertyDefinitionsForScope')
|
||||
->willReturn([
|
||||
new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||
new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true,
|
||||
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||
]);
|
||||
|
||||
$plugin->searchHandler($request, $response);
|
||||
|
|
@ -501,7 +506,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
$plugin->initialize($server);
|
||||
|
||||
$request = new Request('SEARCH', '/index.php/foo', [
|
||||
'Content-Type' => 'text/xml'
|
||||
'Content-Type' => 'text/xml',
|
||||
]);
|
||||
$request->setBaseUrl('/index.php');
|
||||
$request->setBody(fopen(__DIR__ . '/invalidwherenoprop.xml', 'r'));
|
||||
|
|
@ -517,8 +522,10 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
$this->searchBackend->expects($this->any())
|
||||
->method('getPropertyDefinitionsForScope')
|
||||
->willReturn([
|
||||
new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||
new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true, SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||
new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true,
|
||||
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||
new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true,
|
||||
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||
]);
|
||||
|
||||
$plugin->searchHandler($request, $response);
|
||||
|
|
@ -536,7 +543,7 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
$plugin->initialize($server);
|
||||
|
||||
$request = new Request('SEARCH', '/index.php/foo', [
|
||||
'Content-Type' => 'text/xml'
|
||||
'Content-Type' => 'text/xml',
|
||||
]);
|
||||
$request->setBaseUrl('/index.php');
|
||||
$request->setBody(fopen(__DIR__ . '/infiniteloopemptyliteral.xml', 'r'));
|
||||
|
|
@ -549,6 +556,15 @@ class SearchPluginTest extends \PHPUnit_Framework_TestCase {
|
|||
$this->searchBackend->expects($this->never())
|
||||
->method('search');
|
||||
|
||||
$this->searchBackend->expects($this->any())
|
||||
->method('getPropertyDefinitionsForScope')
|
||||
->willReturn([
|
||||
new SearchPropertyDefinition('{http://ns.nextcloud.com:}fileid', false, true, true,
|
||||
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||
new SearchPropertyDefinition('{DAV:}getcontentlength', true, true, true,
|
||||
SearchPropertyDefinition::DATATYPE_NONNEGATIVE_INTEGER),
|
||||
]);
|
||||
|
||||
$plugin->searchHandler($request, $response);
|
||||
|
||||
$this->assertEquals(400, $response->getStatus());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue