adjust tests

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2018-02-07 14:55:50 +01:00
parent c1ff12e234
commit e4129b0dc7
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
1 changed files with 21 additions and 17 deletions

View File

@ -38,6 +38,9 @@ use OCP\Files\IRootFolder;
use OCP\Files\Search\ISearchComparison; use OCP\Files\Search\ISearchComparison;
use OCP\IUser; use OCP\IUser;
use OCP\Share\IManager; use OCP\Share\IManager;
use SearchDAV\Backend\SearchPropertyDefinition;
use SearchDAV\Query\Limit;
use SearchDAV\Query\Query;
use SearchDAV\XML\BasicSearch; use SearchDAV\XML\BasicSearch;
use SearchDAV\XML\Literal; use SearchDAV\XML\Literal;
use SearchDAV\XML\Operator; use SearchDAV\XML\Operator;
@ -132,7 +135,7 @@ class FileSearchBackendTest extends TestCase {
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path') new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')
])); ]));
$query = $this->getBasicQuery(Operator::OPERATION_EQUAL, '{DAV:}displayname', 'foo'); $query = $this->getBasicQuery(\SearchDAV\Query\Operator::OPERATION_EQUAL, '{DAV:}displayname', 'foo');
$result = $this->search->search($query); $result = $this->search->search($query);
$this->assertCount(1, $result); $this->assertCount(1, $result);
@ -161,7 +164,7 @@ class FileSearchBackendTest extends TestCase {
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path') new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')
])); ]));
$query = $this->getBasicQuery(Operator::OPERATION_EQUAL, '{DAV:}getcontenttype', 'foo'); $query = $this->getBasicQuery(\SearchDAV\Query\Operator::OPERATION_EQUAL, '{DAV:}getcontenttype', 'foo');
$result = $this->search->search($query); $result = $this->search->search($query);
$this->assertCount(1, $result); $this->assertCount(1, $result);
@ -190,7 +193,7 @@ class FileSearchBackendTest extends TestCase {
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path') new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')
])); ]));
$query = $this->getBasicQuery(Operator::OPERATION_GREATER_THAN, FilesPlugin::SIZE_PROPERTYNAME, 10); $query = $this->getBasicQuery(\SearchDAV\Query\Operator::OPERATION_GREATER_THAN, FilesPlugin::SIZE_PROPERTYNAME, 10);
$result = $this->search->search($query); $result = $this->search->search($query);
$this->assertCount(1, $result); $this->assertCount(1, $result);
@ -219,7 +222,7 @@ class FileSearchBackendTest extends TestCase {
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path') new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')
])); ]));
$query = $this->getBasicQuery(Operator::OPERATION_GREATER_THAN, '{DAV:}getlastmodified', 10); $query = $this->getBasicQuery(\SearchDAV\Query\Operator::OPERATION_GREATER_THAN, '{DAV:}getlastmodified', 10);
$result = $this->search->search($query); $result = $this->search->search($query);
$this->assertCount(1, $result); $this->assertCount(1, $result);
@ -248,7 +251,7 @@ class FileSearchBackendTest extends TestCase {
new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path') new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path')
])); ]));
$query = $this->getBasicQuery(Operator::OPERATION_IS_COLLECTION, 'yes'); $query = $this->getBasicQuery(\SearchDAV\Query\Operator::OPERATION_IS_COLLECTION, 'yes');
$result = $this->search->search($query); $result = $this->search->search($query);
$this->assertCount(1, $result); $this->assertCount(1, $result);
@ -266,29 +269,30 @@ class FileSearchBackendTest extends TestCase {
$this->searchFolder->expects($this->never()) $this->searchFolder->expects($this->never())
->method('search'); ->method('search');
$query = $this->getBasicQuery(Operator::OPERATION_EQUAL, '{DAV:}getetag', 'foo'); $query = $this->getBasicQuery(\SearchDAV\Query\Operator::OPERATION_EQUAL, '{DAV:}getetag', 'foo');
$this->search->search($query); $this->search->search($query);
} }
private function getBasicQuery($type, $property, $value = null) { private function getBasicQuery($type, $property, $value = null) {
$query = new BasicSearch(); $scope = new \SearchDAV\Query\Scope('/', 'infinite');
$scope = new Scope('/', 'infinite');
$scope->path = '/'; $scope->path = '/';
$query->from = [$scope]; $from = [$scope];
$query->orderBy = []; $orderBy = [];
$query->select = []; $select = [];
if (is_null($value)) { if (is_null($value)) {
$query->where = new Operator( $where = new \SearchDAV\Query\Operator(
$type, $type,
[new Literal($property)] [new \SearchDAV\Query\Literal($property)]
); );
} else { } else {
$query->where = new Operator( $where = new \SearchDAV\Query\Operator(
$type, $type,
[$property, new Literal($value)] [new SearchPropertyDefinition($property, true, true, true), new \SearchDAV\Query\Literal($value)]
); );
} }
return $query; $limit = new Limit();
return new Query($select, $from, $where, $orderBy, $limit);
} }
/** /**
@ -301,7 +305,7 @@ class FileSearchBackendTest extends TestCase {
->method('getNodeForPath') ->method('getNodeForPath')
->willReturn($davNode); ->willReturn($davNode);
$query = $this->getBasicQuery(Operator::OPERATION_EQUAL, '{DAV:}displayname', 'foo'); $query = $this->getBasicQuery(\SearchDAV\Query\Operator::OPERATION_EQUAL, '{DAV:}displayname', 'foo');
$this->search->search($query); $this->search->search($query);
} }
} }