1
0

CacheTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Files_Sharing\Tests;
  8. use OC\Files\Cache\Cache;
  9. use OC\Files\Filesystem;
  10. use OC\Files\Storage\Storage;
  11. use OC\Files\Storage\Temporary;
  12. use OC\Files\Storage\Wrapper\Jail;
  13. use OC\Files\View;
  14. use OCA\Files_Sharing\SharedStorage;
  15. use OCP\Constants;
  16. use OCP\Share\IShare;
  17. /**
  18. * Class CacheTest
  19. *
  20. * @group DB
  21. */
  22. class CacheTest extends TestCase {
  23. /**
  24. * @var View
  25. */
  26. public $user2View;
  27. /** @var Cache */
  28. protected $ownerCache;
  29. /** @var Cache */
  30. protected $sharedCache;
  31. /** @var Storage */
  32. protected $ownerStorage;
  33. /** @var Storage */
  34. protected $sharedStorage;
  35. /** @var \OCP\Share\IManager */
  36. protected $shareManager;
  37. protected function setUp(): void {
  38. parent::setUp();
  39. $this->shareManager = \OC::$server->getShareManager();
  40. $userManager = \OC::$server->getUserManager();
  41. $userManager->get(self::TEST_FILES_SHARING_API_USER1)->setDisplayName('User One');
  42. $userManager->get(self::TEST_FILES_SHARING_API_USER2)->setDisplayName('User Two');
  43. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  44. $this->user2View = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
  45. // prepare user1's dir structure
  46. $this->view->mkdir('container');
  47. $this->view->mkdir('container/shareddir');
  48. $this->view->mkdir('container/shareddir/subdir');
  49. $this->view->mkdir('container/shareddir/emptydir');
  50. $textData = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  51. $this->view->file_put_contents('container/not shared.txt', $textData);
  52. $this->view->file_put_contents('container/shared single file.txt', $textData);
  53. $this->view->file_put_contents('container/shareddir/bar.txt', $textData);
  54. $this->view->file_put_contents('container/shareddir/subdir/another.txt', $textData);
  55. $this->view->file_put_contents('container/shareddir/subdir/another too.txt', $textData);
  56. $this->view->file_put_contents('container/shareddir/subdir/not a text file.xml', '<xml></xml>');
  57. $this->view->file_put_contents('simplefile.txt', $textData);
  58. [$this->ownerStorage,] = $this->view->resolvePath('');
  59. $this->ownerCache = $this->ownerStorage->getCache();
  60. $this->ownerStorage->getScanner()->scan('');
  61. // share "shareddir" with user2
  62. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  63. $node = $rootFolder->get('container/shareddir');
  64. $share = $this->shareManager->newShare();
  65. $share->setNode($node)
  66. ->setShareType(IShare::TYPE_USER)
  67. ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
  68. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  69. ->setPermissions(Constants::PERMISSION_ALL);
  70. $share = $this->shareManager->createShare($share);
  71. $share->setStatus(IShare::STATUS_ACCEPTED);
  72. $this->shareManager->updateShare($share);
  73. $node = $rootFolder->get('container/shared single file.txt');
  74. $share = $this->shareManager->newShare();
  75. $share->setNode($node)
  76. ->setShareType(IShare::TYPE_USER)
  77. ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
  78. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  79. ->setPermissions(Constants::PERMISSION_ALL & ~(Constants::PERMISSION_CREATE | Constants::PERMISSION_DELETE));
  80. $share = $this->shareManager->createShare($share);
  81. $share->setStatus(IShare::STATUS_ACCEPTED);
  82. $this->shareManager->updateShare($share);
  83. // login as user2
  84. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  85. // retrieve the shared storage
  86. $secondView = new View('/' . self::TEST_FILES_SHARING_API_USER2);
  87. [$this->sharedStorage,] = $secondView->resolvePath('files/shareddir');
  88. $this->sharedCache = $this->sharedStorage->getCache();
  89. }
  90. protected function tearDown(): void {
  91. if ($this->sharedCache) {
  92. $this->sharedCache->clear();
  93. }
  94. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  95. $shares = $this->shareManager->getSharesBy(self::TEST_FILES_SHARING_API_USER1, IShare::TYPE_USER);
  96. foreach ($shares as $share) {
  97. $this->shareManager->deleteShare($share);
  98. }
  99. $this->view->deleteAll('container');
  100. $this->ownerCache->clear();
  101. parent::tearDown();
  102. }
  103. public function searchDataProvider() {
  104. return [
  105. ['%another%',
  106. [
  107. ['name' => 'another too.txt', 'path' => 'subdir/another too.txt'],
  108. ['name' => 'another.txt', 'path' => 'subdir/another.txt'],
  109. ]
  110. ],
  111. ['%Another%',
  112. [
  113. ['name' => 'another too.txt', 'path' => 'subdir/another too.txt'],
  114. ['name' => 'another.txt', 'path' => 'subdir/another.txt'],
  115. ]
  116. ],
  117. ['%dir%',
  118. [
  119. ['name' => 'emptydir', 'path' => 'emptydir'],
  120. ['name' => 'subdir', 'path' => 'subdir'],
  121. ['name' => 'shareddir', 'path' => ''],
  122. ]
  123. ],
  124. ['%Dir%',
  125. [
  126. ['name' => 'emptydir', 'path' => 'emptydir'],
  127. ['name' => 'subdir', 'path' => 'subdir'],
  128. ['name' => 'shareddir', 'path' => ''],
  129. ]
  130. ],
  131. ['%txt%',
  132. [
  133. ['name' => 'bar.txt', 'path' => 'bar.txt'],
  134. ['name' => 'another too.txt', 'path' => 'subdir/another too.txt'],
  135. ['name' => 'another.txt', 'path' => 'subdir/another.txt'],
  136. ]
  137. ],
  138. ['%Txt%',
  139. [
  140. ['name' => 'bar.txt', 'path' => 'bar.txt'],
  141. ['name' => 'another too.txt', 'path' => 'subdir/another too.txt'],
  142. ['name' => 'another.txt', 'path' => 'subdir/another.txt'],
  143. ]
  144. ],
  145. ['%',
  146. [
  147. ['name' => 'bar.txt', 'path' => 'bar.txt'],
  148. ['name' => 'emptydir', 'path' => 'emptydir'],
  149. ['name' => 'subdir', 'path' => 'subdir'],
  150. ['name' => 'another too.txt', 'path' => 'subdir/another too.txt'],
  151. ['name' => 'another.txt', 'path' => 'subdir/another.txt'],
  152. ['name' => 'not a text file.xml', 'path' => 'subdir/not a text file.xml'],
  153. ['name' => 'shareddir', 'path' => ''],
  154. ]
  155. ],
  156. ['%nonexistent%',
  157. [
  158. ]
  159. ],
  160. ];
  161. }
  162. /**
  163. * we cannot use a dataProvider because that would cause the stray hook detection to remove the hooks
  164. * that were added in setUpBeforeClass.
  165. */
  166. public function testSearch(): void {
  167. foreach ($this->searchDataProvider() as $data) {
  168. [$pattern, $expectedFiles] = $data;
  169. $results = $this->sharedStorage->getCache()->search($pattern);
  170. $this->verifyFiles($expectedFiles, $results);
  171. }
  172. }
  173. /**
  174. * Test searching by mime type
  175. */
  176. public function testSearchByMime(): void {
  177. $results = $this->sharedStorage->getCache()->searchByMime('text');
  178. $check = [
  179. [
  180. 'name' => 'bar.txt',
  181. 'path' => 'bar.txt'
  182. ],
  183. [
  184. 'name' => 'another too.txt',
  185. 'path' => 'subdir/another too.txt'
  186. ],
  187. [
  188. 'name' => 'another.txt',
  189. 'path' => 'subdir/another.txt'
  190. ],
  191. ];
  192. $this->verifyFiles($check, $results);
  193. }
  194. public function testGetFolderContentsInRoot(): void {
  195. $results = $this->user2View->getDirectoryContent('/');
  196. $results = (array_filter($results, function ($file) {
  197. return $file->getName() !== 'welcome.txt';
  198. }));
  199. // we should get the shared items "shareddir" and "shared single file.txt"
  200. // additional root will always contain the example file "welcome.txt",
  201. // so this will be part of the result
  202. $this->verifyFiles(
  203. [
  204. [
  205. 'name' => 'shareddir',
  206. 'path' => 'files/shareddir',
  207. 'mimetype' => 'httpd/unix-directory',
  208. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  209. 'displayname_owner' => 'User One',
  210. ],
  211. [
  212. 'name' => 'shared single file.txt',
  213. 'path' => 'files/shared single file.txt',
  214. 'mimetype' => 'text/plain',
  215. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  216. 'displayname_owner' => 'User One',
  217. ],
  218. ],
  219. $results
  220. );
  221. }
  222. public function testGetFolderContentsInSubdir(): void {
  223. $results = $this->user2View->getDirectoryContent('/shareddir');
  224. $this->verifyFiles(
  225. [
  226. [
  227. 'name' => 'bar.txt',
  228. 'path' => 'bar.txt',
  229. 'mimetype' => 'text/plain',
  230. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  231. 'displayname_owner' => 'User One',
  232. ],
  233. [
  234. 'name' => 'emptydir',
  235. 'path' => 'emptydir',
  236. 'mimetype' => 'httpd/unix-directory',
  237. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  238. 'displayname_owner' => 'User One',
  239. ],
  240. [
  241. 'name' => 'subdir',
  242. 'path' => 'subdir',
  243. 'mimetype' => 'httpd/unix-directory',
  244. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  245. 'displayname_owner' => 'User One',
  246. ],
  247. ],
  248. $results
  249. );
  250. }
  251. /**
  252. * This covers a bug where the share owners name was propagated
  253. * to the recipient in the recent files API response where the
  254. * share recipient has a different target set
  255. *
  256. * https://github.com/nextcloud/server/issues/39879
  257. */
  258. public function testShareRenameOriginalFileInRecentResults(): void {
  259. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  260. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  261. $node = $rootFolder->get('simplefile.txt');
  262. $share = $this->shareManager->newShare();
  263. $share->setNode($node)
  264. ->setShareType(IShare::TYPE_USER)
  265. ->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
  266. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  267. ->setPermissions(Constants::PERMISSION_READ);
  268. $share = $this->shareManager->createShare($share);
  269. $share->setStatus(IShare::STATUS_ACCEPTED);
  270. $this->shareManager->updateShare($share);
  271. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  272. $node->move(self::TEST_FILES_SHARING_API_USER1 . '/files/simplefile2.txt');
  273. self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
  274. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER3);
  275. $recents = $rootFolder->getRecent(10);
  276. self::assertEquals([
  277. 'welcome.txt',
  278. 'simplefile.txt'
  279. ], array_map(function ($node) {
  280. return $node->getFileInfo()['name'];
  281. }, $recents));
  282. }
  283. public function testGetFolderContentsWhenSubSubdirShared(): void {
  284. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  285. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  286. $node = $rootFolder->get('container/shareddir/subdir');
  287. $share = $this->shareManager->newShare();
  288. $share->setNode($node)
  289. ->setShareType(IShare::TYPE_USER)
  290. ->setSharedWith(self::TEST_FILES_SHARING_API_USER3)
  291. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  292. ->setPermissions(Constants::PERMISSION_ALL);
  293. $share = $this->shareManager->createShare($share);
  294. $share->setStatus(IShare::STATUS_ACCEPTED);
  295. $this->shareManager->updateShare($share);
  296. self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
  297. $thirdView = new View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
  298. $results = $thirdView->getDirectoryContent('/subdir');
  299. $this->verifyFiles(
  300. [
  301. [
  302. 'name' => 'another too.txt',
  303. 'path' => 'another too.txt',
  304. 'mimetype' => 'text/plain',
  305. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  306. 'displayname_owner' => 'User One',
  307. ],
  308. [
  309. 'name' => 'another.txt',
  310. 'path' => 'another.txt',
  311. 'mimetype' => 'text/plain',
  312. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  313. 'displayname_owner' => 'User One',
  314. ],
  315. [
  316. 'name' => 'not a text file.xml',
  317. 'path' => 'not a text file.xml',
  318. 'mimetype' => 'application/xml',
  319. 'uid_owner' => self::TEST_FILES_SHARING_API_USER1,
  320. 'displayname_owner' => 'User One',
  321. ],
  322. ],
  323. $results
  324. );
  325. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  326. $this->shareManager->deleteShare($share);
  327. }
  328. /**
  329. * Check if 'results' contains the expected 'examples' only.
  330. *
  331. * @param array $examples array of example files
  332. * @param array $results array of files
  333. */
  334. private function verifyFiles($examples, $results) {
  335. $this->assertEquals(count($examples), count($results));
  336. foreach ($examples as $example) {
  337. foreach ($results as $key => $result) {
  338. if ($result['name'] === $example['name']) {
  339. $this->verifyKeys($example, $result);
  340. unset($results[$key]);
  341. break;
  342. }
  343. }
  344. }
  345. $this->assertEquals([], $results);
  346. }
  347. /**
  348. * verify if each value from the result matches the expected result
  349. * @param array $example array with the expected results
  350. * @param array $result array with the results
  351. */
  352. private function verifyKeys($example, $result) {
  353. foreach ($example as $key => $value) {
  354. $this->assertEquals($value, $result[$key]);
  355. }
  356. }
  357. public function testGetPathByIdDirectShare(): void {
  358. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  359. Filesystem::file_put_contents('test.txt', 'foo');
  360. $info = Filesystem::getFileInfo('test.txt');
  361. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  362. $node = $rootFolder->get('test.txt');
  363. $share = $this->shareManager->newShare();
  364. $share->setNode($node)
  365. ->setShareType(IShare::TYPE_USER)
  366. ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
  367. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  368. ->setPermissions(Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE | Constants::PERMISSION_SHARE);
  369. $share = $this->shareManager->createShare($share);
  370. $share->setStatus(IShare::STATUS_ACCEPTED);
  371. $this->shareManager->updateShare($share);
  372. \OC_Util::tearDownFS();
  373. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  374. $this->assertTrue(Filesystem::file_exists('/test.txt'));
  375. [$sharedStorage] = Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/test.txt');
  376. /**
  377. * @var SharedStorage $sharedStorage
  378. */
  379. $sharedCache = $sharedStorage->getCache();
  380. $this->assertEquals('', $sharedCache->getPathById($info->getId()));
  381. }
  382. public function testGetPathByIdShareSubFolder(): void {
  383. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  384. Filesystem::mkdir('foo');
  385. Filesystem::mkdir('foo/bar');
  386. Filesystem::touch('foo/bar/test.txt');
  387. $folderInfo = Filesystem::getFileInfo('foo');
  388. $fileInfo = Filesystem::getFileInfo('foo/bar/test.txt');
  389. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  390. $node = $rootFolder->get('foo');
  391. $share = $this->shareManager->newShare();
  392. $share->setNode($node)
  393. ->setShareType(IShare::TYPE_USER)
  394. ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
  395. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  396. ->setPermissions(Constants::PERMISSION_ALL);
  397. $share = $this->shareManager->createShare($share);
  398. $share->setStatus(IShare::STATUS_ACCEPTED);
  399. $this->shareManager->updateShare($share);
  400. \OC_Util::tearDownFS();
  401. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  402. $this->assertTrue(Filesystem::file_exists('/foo'));
  403. [$sharedStorage] = Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/foo');
  404. /**
  405. * @var SharedStorage $sharedStorage
  406. */
  407. $sharedCache = $sharedStorage->getCache();
  408. $this->assertEquals('', $sharedCache->getPathById($folderInfo->getId()));
  409. $this->assertEquals('bar/test.txt', $sharedCache->getPathById($fileInfo->getId()));
  410. }
  411. public function testNumericStorageId(): void {
  412. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  413. Filesystem::mkdir('foo');
  414. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  415. $node = $rootFolder->get('foo');
  416. $share = $this->shareManager->newShare();
  417. $share->setNode($node)
  418. ->setShareType(IShare::TYPE_USER)
  419. ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
  420. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  421. ->setPermissions(Constants::PERMISSION_ALL);
  422. $share = $this->shareManager->createShare($share);
  423. $share->setStatus(IShare::STATUS_ACCEPTED);
  424. $this->shareManager->updateShare($share);
  425. \OC_Util::tearDownFS();
  426. [$sourceStorage] = Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER1 . '/files/foo');
  427. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  428. $this->assertTrue(Filesystem::file_exists('/foo'));
  429. /** @var SharedStorage $sharedStorage */
  430. [$sharedStorage] = Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/foo');
  431. $this->assertEquals($sourceStorage->getCache()->getNumericStorageId(), $sharedStorage->getCache()->getNumericStorageId());
  432. }
  433. public function testShareJailedStorage(): void {
  434. $sourceStorage = new Temporary();
  435. $sourceStorage->mkdir('jail');
  436. $sourceStorage->mkdir('jail/sub');
  437. $sourceStorage->file_put_contents('jail/sub/foo.txt', 'foo');
  438. $jailedSource = new Jail([
  439. 'storage' => $sourceStorage,
  440. 'root' => 'jail'
  441. ]);
  442. $sourceStorage->getScanner()->scan('');
  443. $this->registerMount(self::TEST_FILES_SHARING_API_USER1, $jailedSource, '/' . self::TEST_FILES_SHARING_API_USER1 . '/files/foo');
  444. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  445. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  446. $node = $rootFolder->get('foo/sub');
  447. $share = $this->shareManager->newShare();
  448. $share->setNode($node)
  449. ->setShareType(IShare::TYPE_USER)
  450. ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
  451. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  452. ->setPermissions(Constants::PERMISSION_ALL);
  453. $share = $this->shareManager->createShare($share);
  454. $share->setStatus(IShare::STATUS_ACCEPTED);
  455. $this->shareManager->updateShare($share);
  456. \OC_Util::tearDownFS();
  457. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  458. $this->assertEquals('foo', Filesystem::file_get_contents('/sub/foo.txt'));
  459. Filesystem::file_put_contents('/sub/bar.txt', 'bar');
  460. /** @var SharedStorage $sharedStorage */
  461. [$sharedStorage] = Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub');
  462. $this->assertTrue($sharedStorage->getCache()->inCache('bar.txt'));
  463. $this->assertTrue($sourceStorage->getCache()->inCache('jail/sub/bar.txt'));
  464. }
  465. public function testSearchShareJailedStorage(): void {
  466. $sourceStorage = new Temporary();
  467. $sourceStorage->mkdir('jail');
  468. $sourceStorage->mkdir('jail/sub');
  469. $sourceStorage->file_put_contents('jail/sub/foo.txt', 'foo');
  470. $jailedSource = new Jail([
  471. 'storage' => $sourceStorage,
  472. 'root' => 'jail'
  473. ]);
  474. $sourceStorage->getScanner()->scan('');
  475. $this->registerMount(self::TEST_FILES_SHARING_API_USER1, $jailedSource, '/' . self::TEST_FILES_SHARING_API_USER1 . '/files/foo');
  476. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  477. $rootFolder = \OC::$server->getUserFolder(self::TEST_FILES_SHARING_API_USER1);
  478. $node = $rootFolder->get('foo/sub');
  479. $share = $this->shareManager->newShare();
  480. $share->setNode($node)
  481. ->setShareType(IShare::TYPE_USER)
  482. ->setSharedWith(self::TEST_FILES_SHARING_API_USER2)
  483. ->setSharedBy(self::TEST_FILES_SHARING_API_USER1)
  484. ->setPermissions(Constants::PERMISSION_ALL);
  485. $share = $this->shareManager->createShare($share);
  486. $share->setStatus(IShare::STATUS_ACCEPTED);
  487. $this->shareManager->updateShare($share);
  488. \OC_Util::tearDownFS();
  489. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  490. /** @var SharedStorage $sharedStorage */
  491. [$sharedStorage] = Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/sub');
  492. $results = $sharedStorage->getCache()->search('foo.txt');
  493. $this->assertCount(1, $results);
  494. }
  495. }