diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2019-12-05 11:04:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-05 11:04:33 +0100 |
commit | 63cb31542d9db663f627a17278030b18ed61bc6a (patch) | |
tree | 624c5fce9492da4b4f6836a4a1415ba979055af0 /apps/dav/tests/unit | |
parent | 90401e573e44a4a44d4ce1dc47b534cfb4a9ff1f (diff) | |
parent | bf50342c10dd3093417329865008e7be605135c5 (diff) | |
download | nextcloud-server-63cb31542d9db663f627a17278030b18ed61bc6a.tar.gz nextcloud-server-63cb31542d9db663f627a17278030b18ed61bc6a.zip |
Merge pull request #17941 from nextcloud/search-by-owner
Allow filtering the search results to the users home storage
Diffstat (limited to 'apps/dav/tests/unit')
-rw-r--r-- | apps/dav/tests/unit/Files/FileSearchBackendTest.php | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/apps/dav/tests/unit/Files/FileSearchBackendTest.php b/apps/dav/tests/unit/Files/FileSearchBackendTest.php index 723fb9f4049..d4b70d61c6f 100644 --- a/apps/dav/tests/unit/Files/FileSearchBackendTest.php +++ b/apps/dav/tests/unit/Files/FileSearchBackendTest.php @@ -35,7 +35,9 @@ use OCA\DAV\Files\FileSearchBackend; use OCP\Files\FileInfo; use OCP\Files\Folder; use OCP\Files\IRootFolder; +use OCP\Files\Search\ISearchBinaryOperator; use OCP\Files\Search\ISearchComparison; +use OCP\Files\Search\ISearchQuery; use OCP\IUser; use OCP\Share\IManager; use SearchDAV\Backend\SearchPropertyDefinition; @@ -308,4 +310,81 @@ class FileSearchBackendTest extends TestCase { $query = $this->getBasicQuery(\SearchDAV\Query\Operator::OPERATION_EQUAL, '{DAV:}displayname', 'foo'); $this->search->search($query); } + + public function testSearchLimitOwnerBasic() { + $this->tree->expects($this->any()) + ->method('getNodeForPath') + ->willReturn($this->davFolder); + + /** @var ISearchQuery|null $receivedQuery */ + $receivedQuery = null; + $this->searchFolder + ->method('search') + ->will($this->returnCallback(function ($query) use (&$receivedQuery) { + $receivedQuery = $query; + return [ + new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path') + ]; + })); + + $query = $this->getBasicQuery(\SearchDAV\Query\Operator::OPERATION_EQUAL, FilesPlugin::OWNER_ID_PROPERTYNAME, $this->user->getUID()); + $this->search->search($query); + + $this->assertNotNull($receivedQuery); + $this->assertTrue($receivedQuery->limitToHome()); + + /** @var ISearchBinaryOperator $operator */ + $operator = $receivedQuery->getSearchOperation(); + $this->assertInstanceOf(ISearchBinaryOperator::class, $operator); + $this->assertEquals(ISearchBinaryOperator::OPERATOR_AND, $operator->getType()); + $this->assertEmpty($operator->getArguments()); + } + + public function testSearchLimitOwnerNested() { + $this->tree->expects($this->any()) + ->method('getNodeForPath') + ->willReturn($this->davFolder); + + /** @var ISearchQuery|null $receivedQuery */ + $receivedQuery = null; + $this->searchFolder + ->method('search') + ->will($this->returnCallback(function ($query) use (&$receivedQuery) { + $receivedQuery = $query; + return [ + new \OC\Files\Node\Folder($this->rootFolder, $this->view, '/test/path') + ]; + })); + + $query = $this->getBasicQuery(\SearchDAV\Query\Operator::OPERATION_EQUAL, FilesPlugin::OWNER_ID_PROPERTYNAME, $this->user->getUID()); + $query->where = new \SearchDAV\Query\Operator( + \SearchDAV\Query\Operator::OPERATION_AND, + [ + new \SearchDAV\Query\Operator( + \SearchDAV\Query\Operator::OPERATION_EQUAL, + [new SearchPropertyDefinition('{DAV:}getcontenttype', true, true, true), new \SearchDAV\Query\Literal('image/png')] + ), + new \SearchDAV\Query\Operator( + \SearchDAV\Query\Operator::OPERATION_EQUAL, + [new SearchPropertyDefinition(FilesPlugin::OWNER_ID_PROPERTYNAME, true, true, true), new \SearchDAV\Query\Literal($this->user->getUID())] + ) + ] + ); + $this->search->search($query); + + $this->assertNotNull($receivedQuery); + $this->assertTrue($receivedQuery->limitToHome()); + + /** @var ISearchBinaryOperator $operator */ + $operator = $receivedQuery->getSearchOperation(); + $this->assertInstanceOf(ISearchBinaryOperator::class, $operator); + $this->assertEquals(ISearchBinaryOperator::OPERATOR_AND, $operator->getType()); + $this->assertCount(2, $operator->getArguments()); + + /** @var ISearchBinaryOperator $operator */ + $operator = $operator->getArguments()[1]; + $this->assertInstanceOf(ISearchBinaryOperator::class, $operator); + $this->assertEquals(ISearchBinaryOperator::OPERATOR_AND, $operator->getType()); + $this->assertEmpty($operator->getArguments()); + } } |