summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2023-06-02 23:11:30 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2023-07-07 17:55:31 +0200
commit5c0a1a4b096a9feb9f215fcf87acad1456d168e0 (patch)
treead536975c2e802a31418e9a3228200ac57f0de49
parent8d252731927fa7cb129d099d0b2b80711756db61 (diff)
downloadnextcloud-server-5c0a1a4b096a9feb9f215fcf87acad1456d168e0.tar.gz
nextcloud-server-5c0a1a4b096a9feb9f215fcf87acad1456d168e0.zip
fix: search with more than one search tags
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
-rw-r--r--apps/dav/lib/Connector/Sabre/FilesReportPlugin.php26
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php500
2 files changed, 374 insertions, 152 deletions
diff --git a/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php b/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
index 2cae9d948b5..c0cd382d994 100644
--- a/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
+++ b/apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
@@ -27,7 +27,6 @@
*/
namespace OCA\DAV\Connector\Sabre;
-use OC\Files\Node\LazyFolder;
use OC\Files\View;
use OCP\App\IAppManager;
use OCP\Files\Folder;
@@ -46,7 +45,6 @@ use Sabre\DAV\Xml\Element\Response;
use Sabre\DAV\Xml\Response\MultiStatus;
class FilesReportPlugin extends ServerPlugin {
-
// namespace
public const NS_OWNCLOUD = 'http://owncloud.org/ns';
public const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
@@ -335,12 +333,28 @@ class FilesReportPlugin extends ServerPlugin {
// exposed in API yet
if (
!empty($systemTagIds)
- && ($this->userFolder instanceof \OC\Files\Node\Folder
- || $this->userFolder instanceof LazyFolder)
+ && (method_exists($this->userFolder, 'searchBySystemTag'))
) {
$tags = $this->tagManager->getTagsByIds($systemTagIds);
- $tagName = (current($tags))->getName();
- $nodes = $this->userFolder->searchBySystemTag($tagName, $this->userSession->getUser()->getUID(), $limit ?? 0, $offset ?? 0);
+ foreach ($tags as $tag) {
+ if (!$tag->isUserVisible()) {
+ // searchBySystemTag() also has the criteria to include only user visible tags. They can be skipped early nevertheless.
+ continue;
+ }
+ $tagName = $tag->getName();
+ $tmpNodes = $this->userFolder->searchBySystemTag($tagName, $this->userSession->getUser()->getUID(), $limit ?? 0, $offset ?? 0);
+ if (count($nodes) === 0) {
+ $nodes = $tmpNodes;
+ } else {
+ $nodes = array_uintersect($nodes, $tmpNodes, function (\OCP\Files\Node $a, \OCP\Files\Node $b): int {
+ return $a->getId() - $b->getId();
+ });
+ }
+ if ($nodes === []) {
+ // there cannot be a common match when nodes are empty early.
+ return $nodes;
+ }
+ }
}
return $nodes;
diff --git a/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php b/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php
index f73434b33b6..5c81757b11a 100644
--- a/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/FilesReportPluginTest.php
@@ -44,45 +44,48 @@ use OCP\IUserSession;
use OCP\SystemTag\ISystemTag;
use OCP\SystemTag\ISystemTagManager;
use OCP\SystemTag\ISystemTagObjectMapper;
+use PHPUnit\Framework\MockObject\MockObject;
use Sabre\DAV\INode;
use Sabre\DAV\Tree;
use Sabre\HTTP\ResponseInterface;
class FilesReportPluginTest extends \Test\TestCase {
- /** @var \Sabre\DAV\Server|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var \Sabre\DAV\Server|MockObject */
private $server;
- /** @var \Sabre\DAV\Tree|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var \Sabre\DAV\Tree|MockObject */
private $tree;
- /** @var ISystemTagObjectMapper|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ISystemTagObjectMapper|MockObject */
private $tagMapper;
- /** @var ISystemTagManager|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ISystemTagManager|MockObject */
private $tagManager;
- /** @var ITags|\PHPUnit\Framework\MockObject\MockObject */
+ /** @var ITags|MockObject */
private $privateTags;
+ private ITagManager|MockObject $privateTagManager;
+
/** @var \OCP\IUserSession */
private $userSession;
/** @var FilesReportPluginImplementation */
private $plugin;
- /** @var View|\PHPUnit\Framework\MockObject\MockObject **/
+ /** @var View|MockObject **/
private $view;
- /** @var IGroupManager|\PHPUnit\Framework\MockObject\MockObject **/
+ /** @var IGroupManager|MockObject **/
private $groupManager;
- /** @var Folder|\PHPUnit\Framework\MockObject\MockObject **/
+ /** @var Folder|MockObject **/
private $userFolder;
- /** @var IPreview|\PHPUnit\Framework\MockObject\MockObject * */
+ /** @var IPreview|MockObject * */
private $previewManager;
- /** @var IAppManager|\PHPUnit\Framework\MockObject\MockObject * */
+ /** @var IAppManager|MockObject * */
private $appManager;
protected function setUp(): void {
@@ -124,8 +127,8 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->tagMapper = $this->createMock(ISystemTagObjectMapper::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->privateTags = $this->createMock(ITags::class);
- $privateTagManager = $this->createMock(ITagManager::class);
- $privateTagManager->expects($this->any())
+ $this->privateTagManager = $this->createMock(ITagManager::class);
+ $this->privateTagManager->expects($this->any())
->method('load')
->with('files')
->willReturn($this->privateTags);
@@ -145,7 +148,7 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->view,
$this->tagManager,
$this->tagMapper,
- $privateTagManager,
+ $this->privateTagManager,
$this->userSession,
$this->groupManager,
$this->userFolder,
@@ -153,7 +156,7 @@ class FilesReportPluginTest extends \Test\TestCase {
);
}
- public function testOnReportInvalidNode() {
+ public function testOnReportInvalidNode(): void {
$path = 'totally/unrelated/13';
$this->tree->expects($this->any())
@@ -173,7 +176,7 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->assertNull($this->plugin->onReport(FilesReportPluginImplementation::REPORT_NAME, [], '/' . $path));
}
- public function testOnReportInvalidReportName() {
+ public function testOnReportInvalidReportName(): void {
$path = 'test';
$this->tree->expects($this->any())
@@ -193,7 +196,7 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->assertNull($this->plugin->onReport('{whoever}whatever', [], '/' . $path));
}
- public function testOnReport() {
+ public function testOnReport(): void {
$path = 'test';
$parameters = [
@@ -217,15 +220,6 @@ class FilesReportPluginTest extends \Test\TestCase {
->method('isAdmin')
->willReturn(true);
- $this->tagMapper->expects($this->at(0))
- ->method('getObjectIdsForTags')
- ->with('123', 'files')
- ->willReturn(['111', '222']);
- $this->tagMapper->expects($this->at(1))
- ->method('getObjectIdsForTags')
- ->with('456', 'files')
- ->willReturn(['111', '222', '333']);
-
$reportTargetNode = $this->getMockBuilder(Directory::class)
->disableOriginalConstructor()
->getMock();
@@ -253,21 +247,45 @@ class FilesReportPluginTest extends \Test\TestCase {
->with('/' . $path)
->willReturn($reportTargetNode);
- $filesNode1 = $this->getMockBuilder(Folder::class)
- ->disableOriginalConstructor()
- ->getMock();
- $filesNode2 = $this->getMockBuilder(File::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $filesNode1 = $this->createMock(File::class);
+ $filesNode1->expects($this->any())
+ ->method('getSize')
+ ->willReturn(12);
+ $filesNode2 = $this->createMock(Folder::class);
+ $filesNode2->expects($this->any())
+ ->method('getSize')
+ ->willReturn(10);
- $this->userFolder->expects($this->at(0))
- ->method('getById')
- ->with('111')
- ->willReturn([$filesNode1]);
- $this->userFolder->expects($this->at(1))
- ->method('getById')
- ->with('222')
- ->willReturn([$filesNode2]);
+ $tag123 = $this->createMock(ISystemTag::class);
+ $tag123->expects($this->any())
+ ->method('getName')
+ ->willReturn('OneTwoThree');
+ $tag123->expects($this->any())
+ ->method('isUserVisible')
+ ->willReturn(true);
+ $tag456 = $this->createMock(ISystemTag::class);
+ $tag456->expects($this->any())
+ ->method('getName')
+ ->willReturn('FourFiveSix');
+ $tag456->expects($this->any())
+ ->method('isUserVisible')
+ ->willReturn(true);
+
+ $this->tagManager->expects($this->once())
+ ->method('getTagsByIds')
+ ->with(['123', '456'])
+ ->willReturn([$tag123, $tag456]);
+
+ $this->userFolder->expects($this->exactly(2))
+ ->method('searchBySystemTag')
+ ->withConsecutive(
+ ['OneTwoThree'],
+ ['FourFiveSix'],
+ )
+ ->willReturnOnConsecutiveCalls(
+ [$filesNode1],
+ [$filesNode2],
+ );
$this->server->expects($this->any())
->method('getRequestUri')
@@ -278,7 +296,7 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->assertFalse($this->plugin->onReport(FilesReportPluginImplementation::REPORT_NAME, $parameters, '/' . $path));
}
- public function testFindNodesByFileIdsRoot() {
+ public function testFindNodesByFileIdsRoot(): void {
$filesNode1 = $this->getMockBuilder(Folder::class)
->disableOriginalConstructor()
->getMock();
@@ -300,16 +318,18 @@ class FilesReportPluginTest extends \Test\TestCase {
->method('getPath')
->willReturn('/');
- $this->userFolder->expects($this->at(0))
+ $this->userFolder->expects($this->exactly(2))
->method('getById')
- ->with('111')
- ->willReturn([$filesNode1]);
- $this->userFolder->expects($this->at(1))
- ->method('getById')
- ->with('222')
- ->willReturn([$filesNode2]);
+ ->withConsecutive(
+ ['111'],
+ ['222'],
+ )
+ ->willReturnOnConsecutiveCalls(
+ [$filesNode1],
+ [$filesNode2],
+ );
- /** @var \OCA\DAV\Connector\Sabre\Directory|\PHPUnit\Framework\MockObject\MockObject $reportTargetNode */
+ /** @var \OCA\DAV\Connector\Sabre\Directory|MockObject $reportTargetNode */
$result = $this->plugin->findNodesByFileIds($reportTargetNode, ['111', '222']);
$this->assertCount(2, $result);
@@ -319,7 +339,7 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->assertEquals('second node', $result[1]->getName());
}
- public function testFindNodesByFileIdsSubDir() {
+ public function testFindNodesByFileIdsSubDir(): void {
$filesNode1 = $this->getMockBuilder(Folder::class)
->disableOriginalConstructor()
->getMock();
@@ -346,21 +366,23 @@ class FilesReportPluginTest extends \Test\TestCase {
->disableOriginalConstructor()
->getMock();
- $this->userFolder->expects($this->at(0))
+ $this->userFolder->expects($this->once())
->method('get')
->with('/sub1/sub2')
->willReturn($subNode);
- $subNode->expects($this->at(0))
- ->method('getById')
- ->with('111')
- ->willReturn([$filesNode1]);
- $subNode->expects($this->at(1))
+ $subNode->expects($this->exactly(2))
->method('getById')
- ->with('222')
- ->willReturn([$filesNode2]);
+ ->withConsecutive(
+ ['111'],
+ ['222'],
+ )
+ ->willReturnOnConsecutiveCalls(
+ [$filesNode1],
+ [$filesNode2],
+ );
- /** @var \OCA\DAV\Connector\Sabre\Directory|\PHPUnit\Framework\MockObject\MockObject $reportTargetNode */
+ /** @var \OCA\DAV\Connector\Sabre\Directory|MockObject $reportTargetNode */
$result = $this->plugin->findNodesByFileIds($reportTargetNode, ['111', '222']);
$this->assertCount(2, $result);
@@ -370,7 +392,7 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->assertEquals('second node', $result[1]->getName());
}
- public function testPrepareResponses() {
+ public function testPrepareResponses(): void {
$requestedProps = ['{DAV:}getcontentlength', '{http://owncloud.org/ns}fileid', '{DAV:}resourcetype'];
$fileInfo = $this->createMock(FileInfo::class);
@@ -439,116 +461,288 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->assertCount(0, $props2[200]['{DAV:}resourcetype']->getValue());
}
- public function testProcessFilterRulesSingle() {
+ public function testProcessFilterRulesSingle(): void {
$this->groupManager->expects($this->any())
->method('isAdmin')
->willReturn(true);
- $this->tagMapper->expects($this->exactly(1))
- ->method('getObjectIdsForTags')
- ->withConsecutive(
- ['123', 'files']
- )
- ->willReturnMap([
- ['123', 'files', 0, '', ['111', '222']],
- ]);
-
$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
];
- $this->assertEquals(['111', '222'], $this->invokePrivate($this->plugin, 'processFilterRules', [$rules]));
+ $filesNode1 = $this->createMock(File::class);
+ $filesNode1->expects($this->any())
+ ->method('getSize')
+ ->willReturn(12);
+ $filesNode2 = $this->createMock(Folder::class);
+ $filesNode2->expects($this->any())
+ ->method('getSize')
+ ->willReturn(10);
+
+ $tag123 = $this->createMock(ISystemTag::class);
+ $tag123->expects($this->any())
+ ->method('getName')
+ ->willReturn('OneTwoThree');
+ $tag123->expects($this->any())
+ ->method('isUserVisible')
+ ->willReturn(true);
+
+ $this->tagManager->expects($this->once())
+ ->method('getTagsByIds')
+ ->with(['123'])
+ ->willReturn([$tag123]);
+
+ $this->userFolder->expects($this->once())
+ ->method('searchBySystemTag')
+ ->with('OneTwoThree')
+ ->willReturn([$filesNode1, $filesNode2]);
+
+ $this->assertEquals([$filesNode1, $filesNode2], $this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, 0, 0]));
}
- public function testProcessFilterRulesAndCondition() {
+ public function testProcessFilterRulesAndCondition(): void {
$this->groupManager->expects($this->any())
->method('isAdmin')
->willReturn(true);
- $this->tagMapper->expects($this->exactly(2))
- ->method('getObjectIdsForTags')
+ $filesNode1 = $this->createMock(File::class);
+ $filesNode1->expects($this->any())
+ ->method('getSize')
+ ->willReturn(12);
+ $filesNode1->expects($this->any())
+ ->method('getId')
+ ->willReturn(111);
+ $filesNode2 = $this->createMock(Folder::class);
+ $filesNode2->expects($this->any())
+ ->method('getSize')
+ ->willReturn(10);
+ $filesNode2->expects($this->any())
+ ->method('getId')
+ ->willReturn(222);
+ $filesNode3 = $this->createMock(File::class);
+ $filesNode3->expects($this->any())
+ ->method('getSize')
+ ->willReturn(14);
+ $filesNode3->expects($this->any())
+ ->method('getId')
+ ->willReturn(333);
+
+ $tag123 = $this->createMock(ISystemTag::class);
+ $tag123->expects($this->any())
+ ->method('getName')
+ ->willReturn('OneTwoThree');
+ $tag123->expects($this->any())
+ ->method('isUserVisible')
+ ->willReturn(true);
+ $tag456 = $this->createMock(ISystemTag::class);
+ $tag456->expects($this->any())
+ ->method('getName')
+ ->willReturn('FourFiveSix');
+ $tag456->expects($this->any())
+ ->method('isUserVisible')
+ ->willReturn(true);
+
+ $this->tagManager->expects($this->once())
+ ->method('getTagsByIds')
+ ->with(['123', '456'])
+ ->willReturn([$tag123, $tag456]);
+
+ $this->userFolder->expects($this->exactly(2))
+ ->method('searchBySystemTag')
->withConsecutive(
- ['123', 'files'],
- ['456', 'files']
+ ['OneTwoThree'],
+ ['FourFiveSix'],
)
- ->willReturnMap([
- ['123', 'files', 0, '', ['111', '222']],
- ['456', 'files', 0, '', ['222', '333']],
- ]);
+ ->willReturnOnConsecutiveCalls(
+ [$filesNode1, $filesNode2],
+ [$filesNode2, $filesNode3],
+ );
$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
];
- $this->assertEquals(['222'], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules])));
+ $this->assertEquals([$filesNode2], array_values($this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null])));
}
- public function testProcessFilterRulesAndConditionWithOneEmptyResult() {
+ public function testProcessFilterRulesAndConditionWithOneEmptyResult(): void {
$this->groupManager->expects($this->any())
->method('isAdmin')
->willReturn(true);
- $this->tagMapper->expects($this->exactly(2))
- ->method('getObjectIdsForTags')
+ $filesNode1 = $this->createMock(File::class);
+ $filesNode1->expects($this->any())
+ ->method('getSize')
+ ->willReturn(12);
+ $filesNode1->expects($this->any())
+ ->method('getId')
+ ->willReturn(111);
+ $filesNode2 = $this->createMock(Folder::class);
+ $filesNode2->expects($this->any())
+ ->method('getSize')
+ ->willReturn(10);
+ $filesNode2->expects($this->any())
+ ->method('getId')
+ ->willReturn(222);
+
+ $tag123 = $this->createMock(ISystemTag::class);
+ $tag123->expects($this->any())
+ ->method('getName')
+ ->willReturn('OneTwoThree');
+ $tag123->expects($this->any())
+ ->method('isUserVisible')
+ ->willReturn(true);
+ $tag456 = $this->createMock(ISystemTag::class);
+ $tag456->expects($this->any())
+ ->method('getName')
+ ->willReturn('FourFiveSix');
+ $tag456->expects($this->any())
+ ->method('isUserVisible')
+ ->willReturn(true);
+
+ $this->tagManager->expects($this->once())
+ ->method('getTagsByIds')
+ ->with(['123', '456'])
+ ->willReturn([$tag123, $tag456]);
+
+ $this->userFolder->expects($this->exactly(2))
+ ->method('searchBySystemTag')
->withConsecutive(
- ['123', 'files'],
- ['456', 'files']
+ ['OneTwoThree'],
+ ['FourFiveSix'],
)
- ->willReturnMap([
- ['123', 'files', 0, '', ['111', '222']],
- ['456', 'files', 0, '', []],
- ]);
+ ->willReturnOnConsecutiveCalls(
+ [$filesNode1, $filesNode2],
+ [],
+ );
$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
];
- $this->assertEquals([], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules])));
+ $this->assertEquals([], $this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null]));
}
- public function testProcessFilterRulesAndConditionWithFirstEmptyResult() {
+ public function testProcessFilterRulesAndConditionWithFirstEmptyResult(): void {
$this->groupManager->expects($this->any())
->method('isAdmin')
->willReturn(true);
- $this->tagMapper->expects($this->exactly(1))
- ->method('getObjectIdsForTags')
- ->withConsecutive(
- ['123', 'files'],
- ['456', 'files']
- )
- ->willReturnMap([
- ['123', 'files', 0, '', []],
- ['456', 'files', 0, '', ['111', '222']],
- ]);
+ $filesNode1 = $this->createMock(File::class);
+ $filesNode1->expects($this->any())
+ ->method('getSize')
+ ->willReturn(12);
+ $filesNode1->expects($this->any())
+ ->method('getId')
+ ->willReturn(111);
+ $filesNode2 = $this->createMock(Folder::class);
+ $filesNode2->expects($this->any())
+ ->method('getSize')
+ ->willReturn(10);
+ $filesNode2->expects($this->any())
+ ->method('getId')
+ ->willReturn(222);
+
+ $tag123 = $this->createMock(ISystemTag::class);
+ $tag123->expects($this->any())
+ ->method('getName')
+ ->willReturn('OneTwoThree');
+ $tag123->expects($this->any())
+ ->method('isUserVisible')
+ ->willReturn(true);
+ $tag456 = $this->createMock(ISystemTag::class);
+ $tag456->expects($this->any())
+ ->method('getName')
+ ->willReturn('FourFiveSix');
+ $tag456->expects($this->any())
+ ->method('isUserVisible')
+ ->willReturn(true);
+
+ $this->tagManager->expects($this->once())
+ ->method('getTagsByIds')
+ ->with(['123', '456'])
+ ->willReturn([$tag123, $tag456]);
+
+ $this->userFolder->expects($this->once())
+ ->method('searchBySystemTag')
+ ->with('OneTwoThree')
+ ->willReturnOnConsecutiveCalls(
+ [],
+ [$filesNode1, $filesNode2],
+ );
$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
];
- $this->assertEquals([], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules])));
+ $this->assertEquals([], $this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null]));
}
- public function testProcessFilterRulesAndConditionWithEmptyMidResult() {
+ public function testProcessFilterRulesAndConditionWithEmptyMidResult(): void {
$this->groupManager->expects($this->any())
->method('isAdmin')
->willReturn(true);
- $this->tagMapper->expects($this->exactly(2))
- ->method('getObjectIdsForTags')
- ->withConsecutive(
- ['123', 'files'],
- ['456', 'files'],
- ['789', 'files']
- )
- ->willReturnMap([
- ['123', 'files', 0, '', ['111', '222']],
- ['456', 'files', 0, '', ['333']],
- ['789', 'files', 0, '', ['111', '222']],
- ]);
+ $filesNode1 = $this->createMock(File::class);
+ $filesNode1->expects($this->any())
+ ->method('getSize')
+ ->willReturn(12);
+ $filesNode1->expects($this->any())
+ ->method('getId')
+ ->willReturn(111);
+ $filesNode2 = $this->createMock(Folder::class);
+ $filesNode2->expects($this->any())
+ ->method('getSize')
+ ->willReturn(10);
+ $filesNode2->expects($this->any())
+ ->method('getId')
+ ->willReturn(222);
+ $filesNode3 = $this->createMock(Folder::class);
+ $filesNode3->expects($this->any())
+ ->method('getSize')
+ ->willReturn(13);
+ $filesNode3->expects($this->any())
+ ->method('getId')
+ ->willReturn(333);
+
+ $tag123 = $this->createMock(ISystemTag::class);
+ $tag123->expects($this->any())
+ ->method('getName')
+ ->willReturn('OneTwoThree');
+ $tag123->expects($this->any())
+ ->method('isUserVisible')
+ ->willReturn(true);
+ $tag456 = $this->createMock(ISystemTag::class);
+ $tag456->expects($this->any())
+ ->method('getName')
+ ->willReturn('FourFiveSix');
+ $tag456->expects($this->any())
+ ->method('isUserVisible')
+ ->willReturn(true);
+ $tag789 = $this->createMock(ISystemTag::class);
+ $tag789->expects($this->any())
+ ->method('getName')
+ ->willReturn('SevenEightNein');
+ $tag789->expects($this->any())
+ ->method('isUserVisible')
+ ->willReturn(true);
+
+ $this->tagManager->expects($this->once())
+ ->method('getTagsByIds')
+ ->with(['123', '456', '789'])
+ ->willReturn([$tag123, $tag456, $tag789]);
+
+ $this->userFolder->expects($this->exactly(2))
+ ->method('searchBySystemTag')
+ ->withConsecutive(['OneTwoThree'], ['FourFiveSix'], ['SevenEightNein'])
+ ->willReturnOnConsecutiveCalls(
+ [$filesNode1, $filesNode2],
+ [$filesNode3],
+ [$filesNode1, $filesNode2],
+ );
$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
@@ -556,10 +750,10 @@ class FilesReportPluginTest extends \Test\TestCase {
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '789'],
];
- $this->assertEquals([], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules])));
+ $this->assertEquals([], array_values($this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null])));
}
- public function testProcessFilterRulesInvisibleTagAsAdmin() {
+ public function testProcessFilterRulesInvisibleTagAsAdmin(): void {
$this->groupManager->expects($this->any())
->method('isAdmin')
->willReturn(true);
@@ -588,25 +782,27 @@ class FilesReportPluginTest extends \Test\TestCase {
$this->tagManager->expects($this->never())
->method('getTagsByIds');
- $this->tagMapper->expects($this->at(0))
- ->method('getObjectIdsForTags')
- ->with('123')
- ->willReturn(['111', '222']);
- $this->tagMapper->expects($this->at(1))
+ $this->tagMapper->expects($this->exactly(2))
->method('getObjectIdsForTags')
- ->with('456')
- ->willReturn(['222', '333']);
+ ->withConsecutive(
+ ['123'],
+ ['456'],
+ )
+ ->willReturnOnConsecutiveCalls(
+ ['111', '222'],
+ ['222', '333'],
+ );
$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
];
- $this->assertEquals(['222'], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules])));
+ $this->assertEquals(['222'], array_values($this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null])));
}
- public function testProcessFilterRulesInvisibleTagAsUser() {
+ public function testProcessFilterRulesInvisibleTagAsUser(): void {
$this->expectException(\OCP\SystemTag\TagNotFoundException::class);
$this->groupManager->expects($this->any())
@@ -643,57 +839,69 @@ class FilesReportPluginTest extends \Test\TestCase {
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
];
- $this->invokePrivate($this->plugin, 'processFilterRules', [$rules]);
+ $this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null]);
}
- public function testProcessFilterRulesVisibleTagAsUser() {
+ public function testProcessFilterRulesVisibleTagAsUser(): void {
$this->groupManager->expects($this->any())
->method('isAdmin')
->willReturn(false);
- $tag1 = $this->getMockBuilder(ISystemTag::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $tag1 = $this->createMock(ISystemTag::class);
$tag1->expects($this->any())
->method('getId')
->willReturn('123');
$tag1->expects($this->any())
->method('isUserVisible')
->willReturn(true);
+ $tag1->expects($this->any())
+ ->method('getName')
+ ->willReturn('OneTwoThree');
- $tag2 = $this->getMockBuilder(ISystemTag::class)
- ->disableOriginalConstructor()
- ->getMock();
+ $tag2 = $this->createMock(ISystemTag::class);
$tag2->expects($this->any())
->method('getId')
->willReturn('123');
$tag2->expects($this->any())
->method('isUserVisible')
->willReturn(true);
+ $tag2->expects($this->any())
+ ->method('getName')
+ ->willReturn('FourFiveSix');
$this->tagManager->expects($this->once())
->method('getTagsByIds')
->with(['123', '456'])
->willReturn([$tag1, $tag2]);
- $this->tagMapper->expects($this->at(0))
- ->method('getObjectIdsForTags')
- ->with('123')
- ->willReturn(['111', '222']);
- $this->tagMapper->expects($this->at(1))
- ->method('getObjectIdsForTags')
- ->with('456')
- ->willReturn(['222', '333']);
+ $filesNode1 = $this->createMock(File::class);
+ $filesNode1->expects($this->any())
+ ->method('getSize')
+ ->willReturn(12);
+ $filesNode2 = $this->createMock(Folder::class);
+ $filesNode2->expects($this->any())
+ ->method('getSize')
+ ->willReturn(10);
+
+ $this->tagManager->expects($this->once())
+ ->method('getTagsByIds')
+ ->with(['123', '456'])
+ ->willReturn([$tag1, $tag2]);
+
+ // main assertion: only user visible tags are being passed through.
+ $this->userFolder->expects($this->exactly(1))
+ ->method('searchBySystemTag')
+ ->with('FourFiveSix', $this->anything(), $this->anything(), $this->anything());
$rules = [
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
];
- $this->assertEquals(['222'], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules])));
+ $this->invokePrivate($this->plugin, 'processFilterRulesForFileNodes', [$rules, null, null]);
}
- public function testProcessFavoriteFilter() {
+ public function testProcessFavoriteFilter(): void {
$rules = [
['name' => '{http://owncloud.org/ns}favorite', 'value' => '1'],
];
@@ -702,7 +910,7 @@ class FilesReportPluginTest extends \Test\TestCase {
->method('getFavorites')
->willReturn(['456', '789']);
- $this->assertEquals(['456', '789'], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules])));
+ $this->assertEquals(['456', '789'], array_values($this->invokePrivate($this->plugin, 'processFilterRulesForFileIDs', [$rules])));
}
public function filesBaseUriProvider() {
@@ -718,7 +926,7 @@ class FilesReportPluginTest extends \Test\TestCase {
/**
* @dataProvider filesBaseUriProvider
*/
- public function testFilesBaseUri($uri, $reportPath, $expectedUri) {
+ public function testFilesBaseUri($uri, $reportPath, $expectedUri): void {
$this->assertEquals($expectedUri, $this->invokePrivate($this->plugin, 'getFilesBaseUri', [$uri, $reportPath]));
}
}