You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FilesReportPluginTest.php 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. <?php
  2. /**
  3. * @author Joas Schilling <nickvergessen@owncloud.com>
  4. * @author Roeland Jago Douma <rullzer@owncloud.com>
  5. * @author Vincent Petry <pvince81@owncloud.com>
  6. *
  7. * @copyright Copyright (c) 2016, ownCloud, Inc.
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\DAV\Tests\unit\Connector\Sabre;
  24. use OCA\DAV\Connector\Sabre\FilesReportPlugin as FilesReportPluginImplementation;
  25. use Sabre\DAV\Exception\NotFound;
  26. use OCP\SystemTag\ISystemTagObjectMapper;
  27. use OC\Files\View;
  28. use OCP\Files\Folder;
  29. use OCP\IGroupManager;
  30. use OCP\SystemTag\ISystemTagManager;
  31. class FilesReportPluginTest extends \Test\TestCase {
  32. /** @var \Sabre\DAV\Server|\PHPUnit_Framework_MockObject_MockObject */
  33. private $server;
  34. /** @var \Sabre\DAV\Tree|\PHPUnit_Framework_MockObject_MockObject */
  35. private $tree;
  36. /** @var ISystemTagObjectMapper|\PHPUnit_Framework_MockObject_MockObject */
  37. private $tagMapper;
  38. /** @var ISystemTagManager|\PHPUnit_Framework_MockObject_MockObject */
  39. private $tagManager;
  40. /** @var \OCP\IUserSession */
  41. private $userSession;
  42. /** @var FilesReportPluginImplementation */
  43. private $plugin;
  44. /** @var View|\PHPUnit_Framework_MockObject_MockObject **/
  45. private $view;
  46. /** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject **/
  47. private $groupManager;
  48. /** @var Folder|\PHPUnit_Framework_MockObject_MockObject **/
  49. private $userFolder;
  50. public function setUp() {
  51. parent::setUp();
  52. $this->tree = $this->getMockBuilder('\Sabre\DAV\Tree')
  53. ->disableOriginalConstructor()
  54. ->getMock();
  55. $this->view = $this->getMockBuilder('\OC\Files\View')
  56. ->disableOriginalConstructor()
  57. ->getMock();
  58. $this->server = $this->getMockBuilder('\Sabre\DAV\Server')
  59. ->setConstructorArgs([$this->tree])
  60. ->setMethods(['getRequestUri'])
  61. ->getMock();
  62. $this->groupManager = $this->getMockBuilder('\OCP\IGroupManager')
  63. ->disableOriginalConstructor()
  64. ->getMock();
  65. $this->userFolder = $this->getMockBuilder('\OCP\Files\Folder')
  66. ->disableOriginalConstructor()
  67. ->getMock();
  68. $this->tagManager = $this->getMock('\OCP\SystemTag\ISystemTagManager');
  69. $this->tagMapper = $this->getMock('\OCP\SystemTag\ISystemTagObjectMapper');
  70. $this->userSession = $this->getMock('\OCP\IUserSession');
  71. $user = $this->getMock('\OCP\IUser');
  72. $user->expects($this->any())
  73. ->method('getUID')
  74. ->will($this->returnValue('testuser'));
  75. $this->userSession->expects($this->any())
  76. ->method('getUser')
  77. ->will($this->returnValue($user));
  78. $this->plugin = new FilesReportPluginImplementation(
  79. $this->tree,
  80. $this->view,
  81. $this->tagManager,
  82. $this->tagMapper,
  83. $this->userSession,
  84. $this->groupManager,
  85. $this->userFolder
  86. );
  87. }
  88. /**
  89. * @expectedException \Sabre\DAV\Exception\ReportNotSupported
  90. */
  91. public function testOnReportInvalidNode() {
  92. $path = 'totally/unrelated/13';
  93. $this->tree->expects($this->any())
  94. ->method('getNodeForPath')
  95. ->with('/' . $path)
  96. ->will($this->returnValue($this->getMock('\Sabre\DAV\INode')));
  97. $this->server->expects($this->any())
  98. ->method('getRequestUri')
  99. ->will($this->returnValue($path));
  100. $this->plugin->initialize($this->server);
  101. $this->plugin->onReport(FilesReportPluginImplementation::REPORT_NAME, [], '/' . $path);
  102. }
  103. /**
  104. * @expectedException \Sabre\DAV\Exception\ReportNotSupported
  105. */
  106. public function testOnReportInvalidReportName() {
  107. $path = 'test';
  108. $this->tree->expects($this->any())
  109. ->method('getNodeForPath')
  110. ->with('/' . $path)
  111. ->will($this->returnValue($this->getMock('\Sabre\DAV\INode')));
  112. $this->server->expects($this->any())
  113. ->method('getRequestUri')
  114. ->will($this->returnValue($path));
  115. $this->plugin->initialize($this->server);
  116. $this->plugin->onReport('{whoever}whatever', [], '/' . $path);
  117. }
  118. public function testOnReport() {
  119. $path = 'test';
  120. $parameters = [
  121. [
  122. 'name' => '{DAV:}prop',
  123. 'value' => [
  124. ['name' => '{DAV:}getcontentlength', 'value' => ''],
  125. ['name' => '{http://owncloud.org/ns}size', 'value' => ''],
  126. ],
  127. ],
  128. [
  129. 'name' => '{http://owncloud.org/ns}filter-rules',
  130. 'value' => [
  131. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
  132. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
  133. ],
  134. ],
  135. ];
  136. $this->groupManager->expects($this->any())
  137. ->method('isAdmin')
  138. ->will($this->returnValue(true));
  139. $this->tagMapper->expects($this->at(0))
  140. ->method('getObjectIdsForTags')
  141. ->with('123', 'files')
  142. ->will($this->returnValue(['111', '222']));
  143. $this->tagMapper->expects($this->at(1))
  144. ->method('getObjectIdsForTags')
  145. ->with('456', 'files')
  146. ->will($this->returnValue(['111', '222', '333']));
  147. $reportTargetNode = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Directory')
  148. ->disableOriginalConstructor()
  149. ->getMock();
  150. $response = $this->getMockBuilder('Sabre\HTTP\ResponseInterface')
  151. ->disableOriginalConstructor()
  152. ->getMock();
  153. $response->expects($this->once())
  154. ->method('setHeader')
  155. ->with('Content-Type', 'application/xml; charset=utf-8');
  156. $response->expects($this->once())
  157. ->method('setStatus')
  158. ->with(207);
  159. $response->expects($this->once())
  160. ->method('setBody');
  161. $this->tree->expects($this->any())
  162. ->method('getNodeForPath')
  163. ->with('/' . $path)
  164. ->will($this->returnValue($reportTargetNode));
  165. $filesNode1 = $this->getMockBuilder('\OCP\Files\Folder')
  166. ->disableOriginalConstructor()
  167. ->getMock();
  168. $filesNode2 = $this->getMockBuilder('\OCP\Files\File')
  169. ->disableOriginalConstructor()
  170. ->getMock();
  171. $this->userFolder->expects($this->at(0))
  172. ->method('getById')
  173. ->with('111')
  174. ->will($this->returnValue([$filesNode1]));
  175. $this->userFolder->expects($this->at(1))
  176. ->method('getById')
  177. ->with('222')
  178. ->will($this->returnValue([$filesNode2]));
  179. $this->server->expects($this->any())
  180. ->method('getRequestUri')
  181. ->will($this->returnValue($path));
  182. $this->server->httpResponse = $response;
  183. $this->plugin->initialize($this->server);
  184. $this->plugin->onReport(FilesReportPluginImplementation::REPORT_NAME, $parameters, '/' . $path);
  185. }
  186. public function testFindNodesByFileIdsRoot() {
  187. $filesNode1 = $this->getMockBuilder('\OCP\Files\Folder')
  188. ->disableOriginalConstructor()
  189. ->getMock();
  190. $filesNode1->expects($this->once())
  191. ->method('getName')
  192. ->will($this->returnValue('first node'));
  193. $filesNode2 = $this->getMockBuilder('\OCP\Files\File')
  194. ->disableOriginalConstructor()
  195. ->getMock();
  196. $filesNode2->expects($this->once())
  197. ->method('getName')
  198. ->will($this->returnValue('second node'));
  199. $reportTargetNode = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Directory')
  200. ->disableOriginalConstructor()
  201. ->getMock();
  202. $reportTargetNode->expects($this->any())
  203. ->method('getPath')
  204. ->will($this->returnValue('/'));
  205. $this->userFolder->expects($this->at(0))
  206. ->method('getById')
  207. ->with('111')
  208. ->will($this->returnValue([$filesNode1]));
  209. $this->userFolder->expects($this->at(1))
  210. ->method('getById')
  211. ->with('222')
  212. ->will($this->returnValue([$filesNode2]));
  213. /** @var \OCA\DAV\Connector\Sabre\Directory|\PHPUnit_Framework_MockObject_MockObject $reportTargetNode */
  214. $result = $this->plugin->findNodesByFileIds($reportTargetNode, ['111', '222']);
  215. $this->assertCount(2, $result);
  216. $this->assertInstanceOf('\OCA\DAV\Connector\Sabre\Directory', $result[0]);
  217. $this->assertEquals('first node', $result[0]->getName());
  218. $this->assertInstanceOf('\OCA\DAV\Connector\Sabre\File', $result[1]);
  219. $this->assertEquals('second node', $result[1]->getName());
  220. }
  221. public function testFindNodesByFileIdsSubDir() {
  222. $filesNode1 = $this->getMockBuilder('\OCP\Files\Folder')
  223. ->disableOriginalConstructor()
  224. ->getMock();
  225. $filesNode1->expects($this->once())
  226. ->method('getName')
  227. ->will($this->returnValue('first node'));
  228. $filesNode2 = $this->getMockBuilder('\OCP\Files\File')
  229. ->disableOriginalConstructor()
  230. ->getMock();
  231. $filesNode2->expects($this->once())
  232. ->method('getName')
  233. ->will($this->returnValue('second node'));
  234. $reportTargetNode = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Directory')
  235. ->disableOriginalConstructor()
  236. ->getMock();
  237. $reportTargetNode->expects($this->any())
  238. ->method('getPath')
  239. ->will($this->returnValue('/sub1/sub2'));
  240. $subNode = $this->getMockBuilder('\OCP\Files\Folder')
  241. ->disableOriginalConstructor()
  242. ->getMock();
  243. $this->userFolder->expects($this->at(0))
  244. ->method('get')
  245. ->with('/sub1/sub2')
  246. ->will($this->returnValue($subNode));
  247. $subNode->expects($this->at(0))
  248. ->method('getById')
  249. ->with('111')
  250. ->will($this->returnValue([$filesNode1]));
  251. $subNode->expects($this->at(1))
  252. ->method('getById')
  253. ->with('222')
  254. ->will($this->returnValue([$filesNode2]));
  255. /** @var \OCA\DAV\Connector\Sabre\Directory|\PHPUnit_Framework_MockObject_MockObject $reportTargetNode */
  256. $result = $this->plugin->findNodesByFileIds($reportTargetNode, ['111', '222']);
  257. $this->assertCount(2, $result);
  258. $this->assertInstanceOf('\OCA\DAV\Connector\Sabre\Directory', $result[0]);
  259. $this->assertEquals('first node', $result[0]->getName());
  260. $this->assertInstanceOf('\OCA\DAV\Connector\Sabre\File', $result[1]);
  261. $this->assertEquals('second node', $result[1]->getName());
  262. }
  263. public function testPrepareResponses() {
  264. $requestedProps = ['{DAV:}getcontentlength', '{http://owncloud.org/ns}fileid', '{DAV:}resourcetype'];
  265. $node1 = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\Directory')
  266. ->disableOriginalConstructor()
  267. ->getMock();
  268. $node2 = $this->getMockBuilder('\OCA\DAV\Connector\Sabre\File')
  269. ->disableOriginalConstructor()
  270. ->getMock();
  271. $node1->expects($this->once())
  272. ->method('getInternalFileId')
  273. ->will($this->returnValue('111'));
  274. $node2->expects($this->once())
  275. ->method('getInternalFileId')
  276. ->will($this->returnValue('222'));
  277. $node2->expects($this->once())
  278. ->method('getSize')
  279. ->will($this->returnValue(1024));
  280. $config = $this->getMock('\OCP\IConfig');
  281. $this->server->addPlugin(
  282. new \OCA\DAV\Connector\Sabre\FilesPlugin(
  283. $this->tree,
  284. $this->view,
  285. $config
  286. )
  287. );
  288. $this->plugin->initialize($this->server);
  289. $responses = $this->plugin->prepareResponses($requestedProps, [$node1, $node2]);
  290. $this->assertCount(2, $responses);
  291. $this->assertEquals(200, $responses[0]->getHttpStatus());
  292. $this->assertEquals(200, $responses[1]->getHttpStatus());
  293. $props1 = $responses[0]->getResponseProperties();
  294. $this->assertEquals('111', $props1[200]['{http://owncloud.org/ns}fileid']);
  295. $this->assertNull($props1[404]['{DAV:}getcontentlength']);
  296. $this->assertInstanceOf('\Sabre\DAV\Xml\Property\ResourceType', $props1[200]['{DAV:}resourcetype']);
  297. $resourceType1 = $props1[200]['{DAV:}resourcetype']->getValue();
  298. $this->assertEquals('{DAV:}collection', $resourceType1[0]);
  299. $props2 = $responses[1]->getResponseProperties();
  300. $this->assertEquals('1024', $props2[200]['{DAV:}getcontentlength']);
  301. $this->assertEquals('222', $props2[200]['{http://owncloud.org/ns}fileid']);
  302. $this->assertInstanceOf('\Sabre\DAV\Xml\Property\ResourceType', $props2[200]['{DAV:}resourcetype']);
  303. $this->assertCount(0, $props2[200]['{DAV:}resourcetype']->getValue());
  304. }
  305. public function testProcessFilterRulesSingle() {
  306. $this->groupManager->expects($this->any())
  307. ->method('isAdmin')
  308. ->will($this->returnValue(true));
  309. $this->tagMapper->expects($this->exactly(1))
  310. ->method('getObjectIdsForTags')
  311. ->withConsecutive(
  312. ['123', 'files']
  313. )
  314. ->willReturnMap([
  315. ['123', 'files', 0, '', ['111', '222']],
  316. ]);
  317. $rules = [
  318. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
  319. ];
  320. $this->assertEquals(['111', '222'], $this->invokePrivate($this->plugin, 'processFilterRules', [$rules]));
  321. }
  322. public function testProcessFilterRulesAndCondition() {
  323. $this->groupManager->expects($this->any())
  324. ->method('isAdmin')
  325. ->will($this->returnValue(true));
  326. $this->tagMapper->expects($this->exactly(2))
  327. ->method('getObjectIdsForTags')
  328. ->withConsecutive(
  329. ['123', 'files'],
  330. ['456', 'files']
  331. )
  332. ->willReturnMap([
  333. ['123', 'files', 0, '', ['111', '222']],
  334. ['456', 'files', 0, '', ['222', '333']],
  335. ]);
  336. $rules = [
  337. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
  338. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
  339. ];
  340. $this->assertEquals(['222'], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules])));
  341. }
  342. public function testProcessFilterRulesAndConditionWithOneEmptyResult() {
  343. $this->groupManager->expects($this->any())
  344. ->method('isAdmin')
  345. ->will($this->returnValue(true));
  346. $this->tagMapper->expects($this->exactly(2))
  347. ->method('getObjectIdsForTags')
  348. ->withConsecutive(
  349. ['123', 'files'],
  350. ['456', 'files']
  351. )
  352. ->willReturnMap([
  353. ['123', 'files', 0, '', ['111', '222']],
  354. ['456', 'files', 0, '', []],
  355. ]);
  356. $rules = [
  357. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
  358. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
  359. ];
  360. $this->assertEquals([], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules])));
  361. }
  362. public function testProcessFilterRulesAndConditionWithFirstEmptyResult() {
  363. $this->groupManager->expects($this->any())
  364. ->method('isAdmin')
  365. ->will($this->returnValue(true));
  366. $this->tagMapper->expects($this->exactly(1))
  367. ->method('getObjectIdsForTags')
  368. ->withConsecutive(
  369. ['123', 'files'],
  370. ['456', 'files']
  371. )
  372. ->willReturnMap([
  373. ['123', 'files', 0, '', []],
  374. ['456', 'files', 0, '', ['111', '222']],
  375. ]);
  376. $rules = [
  377. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
  378. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
  379. ];
  380. $this->assertEquals([], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules])));
  381. }
  382. public function testProcessFilterRulesAndConditionWithEmptyMidResult() {
  383. $this->groupManager->expects($this->any())
  384. ->method('isAdmin')
  385. ->will($this->returnValue(true));
  386. $this->tagMapper->expects($this->exactly(2))
  387. ->method('getObjectIdsForTags')
  388. ->withConsecutive(
  389. ['123', 'files'],
  390. ['456', 'files'],
  391. ['789', 'files']
  392. )
  393. ->willReturnMap([
  394. ['123', 'files', 0, '', ['111', '222']],
  395. ['456', 'files', 0, '', ['333']],
  396. ['789', 'files', 0, '', ['111', '222']],
  397. ]);
  398. $rules = [
  399. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
  400. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
  401. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '789'],
  402. ];
  403. $this->assertEquals([], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules])));
  404. }
  405. public function testProcessFilterRulesInvisibleTagAsAdmin() {
  406. $this->groupManager->expects($this->any())
  407. ->method('isAdmin')
  408. ->will($this->returnValue(true));
  409. $tag1 = $this->getMock('\OCP\SystemTag\ISystemTag');
  410. $tag1->expects($this->any())
  411. ->method('getId')
  412. ->will($this->returnValue('123'));
  413. $tag1->expects($this->any())
  414. ->method('isUserVisible')
  415. ->will($this->returnValue(true));
  416. $tag2 = $this->getMock('\OCP\SystemTag\ISystemTag');
  417. $tag2->expects($this->any())
  418. ->method('getId')
  419. ->will($this->returnValue('123'));
  420. $tag2->expects($this->any())
  421. ->method('isUserVisible')
  422. ->will($this->returnValue(false));
  423. // no need to fetch tags to check permissions
  424. $this->tagManager->expects($this->never())
  425. ->method('getTagsByIds');
  426. $this->tagMapper->expects($this->at(0))
  427. ->method('getObjectIdsForTags')
  428. ->with('123')
  429. ->will($this->returnValue(['111', '222']));
  430. $this->tagMapper->expects($this->at(1))
  431. ->method('getObjectIdsForTags')
  432. ->with('456')
  433. ->will($this->returnValue(['222', '333']));
  434. $rules = [
  435. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
  436. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
  437. ];
  438. $this->assertEquals(['222'], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules])));
  439. }
  440. /**
  441. * @expectedException \OCP\SystemTag\TagNotFoundException
  442. */
  443. public function testProcessFilterRulesInvisibleTagAsUser() {
  444. $this->groupManager->expects($this->any())
  445. ->method('isAdmin')
  446. ->will($this->returnValue(false));
  447. $tag1 = $this->getMock('\OCP\SystemTag\ISystemTag');
  448. $tag1->expects($this->any())
  449. ->method('getId')
  450. ->will($this->returnValue('123'));
  451. $tag1->expects($this->any())
  452. ->method('isUserVisible')
  453. ->will($this->returnValue(true));
  454. $tag2 = $this->getMock('\OCP\SystemTag\ISystemTag');
  455. $tag2->expects($this->any())
  456. ->method('getId')
  457. ->will($this->returnValue('123'));
  458. $tag2->expects($this->any())
  459. ->method('isUserVisible')
  460. ->will($this->returnValue(false)); // invisible
  461. $this->tagManager->expects($this->once())
  462. ->method('getTagsByIds')
  463. ->with(['123', '456'])
  464. ->will($this->returnValue([$tag1, $tag2]));
  465. $rules = [
  466. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
  467. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
  468. ];
  469. $this->invokePrivate($this->plugin, 'processFilterRules', [$rules]);
  470. }
  471. public function testProcessFilterRulesVisibleTagAsUser() {
  472. $this->groupManager->expects($this->any())
  473. ->method('isAdmin')
  474. ->will($this->returnValue(false));
  475. $tag1 = $this->getMock('\OCP\SystemTag\ISystemTag');
  476. $tag1->expects($this->any())
  477. ->method('getId')
  478. ->will($this->returnValue('123'));
  479. $tag1->expects($this->any())
  480. ->method('isUserVisible')
  481. ->will($this->returnValue(true));
  482. $tag2 = $this->getMock('\OCP\SystemTag\ISystemTag');
  483. $tag2->expects($this->any())
  484. ->method('getId')
  485. ->will($this->returnValue('123'));
  486. $tag2->expects($this->any())
  487. ->method('isUserVisible')
  488. ->will($this->returnValue(true));
  489. $this->tagManager->expects($this->once())
  490. ->method('getTagsByIds')
  491. ->with(['123', '456'])
  492. ->will($this->returnValue([$tag1, $tag2]));
  493. $this->tagMapper->expects($this->at(0))
  494. ->method('getObjectIdsForTags')
  495. ->with('123')
  496. ->will($this->returnValue(['111', '222']));
  497. $this->tagMapper->expects($this->at(1))
  498. ->method('getObjectIdsForTags')
  499. ->with('456')
  500. ->will($this->returnValue(['222', '333']));
  501. $rules = [
  502. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '123'],
  503. ['name' => '{http://owncloud.org/ns}systemtag', 'value' => '456'],
  504. ];
  505. $this->assertEquals(['222'], array_values($this->invokePrivate($this->plugin, 'processFilterRules', [$rules])));
  506. }
  507. }