CacheTest.php 18 KB

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