1
0

SharedStorageTest.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-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\View;
  9. use OCA\Files_Sharing\SharedStorage;
  10. use OCA\Files_Trashbin\AppInfo\Application;
  11. use OCP\AppFramework\Bootstrap\IBootContext;
  12. use OCP\Files\NotFoundException;
  13. use OCP\Share\IShare;
  14. /**
  15. * Class SharedStorageTest
  16. *
  17. * @group DB
  18. */
  19. class SharedStorageTest extends TestCase {
  20. protected function setUp(): void {
  21. parent::setUp();
  22. // register trashbin hooks
  23. $trashbinApp = new Application();
  24. $trashbinApp->boot($this->createMock(IBootContext::class));
  25. $this->folder = '/folder_share_storage_test';
  26. $this->filename = '/share-api-storage.txt';
  27. $this->view->mkdir($this->folder);
  28. // save file with content
  29. $this->view->file_put_contents($this->filename, "root file");
  30. $this->view->file_put_contents($this->folder . $this->filename, "file in subfolder");
  31. }
  32. protected function tearDown(): void {
  33. if ($this->view) {
  34. if ($this->view->file_exists($this->folder)) {
  35. $this->view->unlink($this->folder);
  36. }
  37. if ($this->view->file_exists($this->filename)) {
  38. $this->view->unlink($this->filename);
  39. }
  40. }
  41. \OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
  42. parent::tearDown();
  43. }
  44. /**
  45. * if the parent of the mount point is gone then the mount point should move up
  46. *
  47. * @medium
  48. */
  49. public function testParentOfMountPointIsGone() {
  50. // share to user
  51. $share = $this->share(
  52. IShare::TYPE_USER,
  53. $this->folder,
  54. self::TEST_FILES_SHARING_API_USER1,
  55. self::TEST_FILES_SHARING_API_USER2,
  56. \OCP\Constants::PERMISSION_ALL
  57. );
  58. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  59. $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
  60. $this->assertTrue($user2View->file_exists($this->folder));
  61. // create a local folder
  62. $result = $user2View->mkdir('localfolder');
  63. $this->assertTrue($result);
  64. // move mount point to local folder
  65. $result = $user2View->rename($this->folder, '/localfolder/' . $this->folder);
  66. $this->assertTrue($result);
  67. // mount point in the root folder should no longer exist
  68. $this->assertFalse($user2View->is_dir($this->folder));
  69. // delete the local folder
  70. /** @var \OC\Files\Storage\Storage $storage */
  71. [$storage, $internalPath] = \OC\Files\Filesystem::resolvePath('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/localfolder');
  72. $storage->rmdir($internalPath);
  73. //enforce reload of the mount points
  74. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  75. //mount point should be back at the root
  76. $this->assertTrue($user2View->is_dir($this->folder));
  77. //cleanup
  78. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  79. $this->view->unlink($this->folder);
  80. }
  81. /**
  82. * @medium
  83. */
  84. public function testRenamePartFile() {
  85. // share to user
  86. $share = $this->share(
  87. IShare::TYPE_USER,
  88. $this->folder,
  89. self::TEST_FILES_SHARING_API_USER1,
  90. self::TEST_FILES_SHARING_API_USER2,
  91. \OCP\Constants::PERMISSION_ALL
  92. );
  93. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  94. $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
  95. $this->assertTrue($user2View->file_exists($this->folder));
  96. // create part file
  97. $result = $user2View->file_put_contents($this->folder . '/foo.txt.part', 'some test data');
  98. $this->assertTrue(is_int($result));
  99. // rename part file to real file
  100. $result = $user2View->rename($this->folder . '/foo.txt.part', $this->folder . '/foo.txt');
  101. $this->assertTrue($result);
  102. // check if the new file really exists
  103. $this->assertTrue($user2View->file_exists($this->folder . '/foo.txt'));
  104. // check if the rename also affected the owner
  105. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  106. $this->assertTrue($this->view->file_exists($this->folder . '/foo.txt'));
  107. //cleanup
  108. $this->shareManager->deleteShare($share);
  109. }
  110. public function testFilesize() {
  111. $folderSize = $this->view->filesize($this->folder);
  112. $file1Size = $this->view->filesize($this->folder . $this->filename);
  113. $file2Size = $this->view->filesize($this->filename);
  114. $share1 = $this->share(
  115. IShare::TYPE_USER,
  116. $this->folder,
  117. self::TEST_FILES_SHARING_API_USER1,
  118. self::TEST_FILES_SHARING_API_USER2,
  119. \OCP\Constants::PERMISSION_ALL
  120. );
  121. $share2 = $this->share(
  122. IShare::TYPE_USER,
  123. $this->filename,
  124. self::TEST_FILES_SHARING_API_USER1,
  125. self::TEST_FILES_SHARING_API_USER2,
  126. \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
  127. );
  128. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  129. // compare file size between user1 and user2, should always be the same
  130. $this->assertSame($folderSize, \OC\Files\Filesystem::filesize($this->folder));
  131. $this->assertSame($file1Size, \OC\Files\Filesystem::filesize($this->folder . $this->filename));
  132. $this->assertSame($file2Size, \OC\Files\Filesystem::filesize($this->filename));
  133. //cleanup
  134. $this->shareManager->deleteShare($share1);
  135. $this->shareManager->deleteShare($share2);
  136. }
  137. public function testGetPermissions() {
  138. $share = $this->share(
  139. IShare::TYPE_USER,
  140. $this->folder,
  141. self::TEST_FILES_SHARING_API_USER1,
  142. self::TEST_FILES_SHARING_API_USER2,
  143. \OCP\Constants::PERMISSION_READ
  144. );
  145. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  146. $this->assertTrue(\OC\Files\Filesystem::is_dir($this->folder));
  147. // for the share root we expect:
  148. // the read permissions (1)
  149. // the delete permission (8), to enable unshare
  150. $rootInfo = \OC\Files\Filesystem::getFileInfo($this->folder);
  151. $this->assertSame(9, $rootInfo->getPermissions());
  152. // for the file within the shared folder we expect:
  153. // the read permissions (1)
  154. $subfileInfo = \OC\Files\Filesystem::getFileInfo($this->folder . $this->filename);
  155. $this->assertSame(1, $subfileInfo->getPermissions());
  156. //cleanup
  157. $this->shareManager->deleteShare($share);
  158. }
  159. public function testFopenWithReadOnlyPermission() {
  160. $this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
  161. $share = $this->share(
  162. IShare::TYPE_USER,
  163. $this->folder,
  164. self::TEST_FILES_SHARING_API_USER1,
  165. self::TEST_FILES_SHARING_API_USER2,
  166. \OCP\Constants::PERMISSION_READ
  167. );
  168. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  169. $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
  170. // part file should be forbidden
  171. $handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
  172. $this->assertFalse($handle);
  173. // regular file forbidden
  174. $handle = $user2View->fopen($this->folder . '/test.txt', 'w');
  175. $this->assertFalse($handle);
  176. // rename forbidden
  177. $this->assertFalse($user2View->rename($this->folder . '/existing.txt', $this->folder . '/existing2.txt'));
  178. // delete forbidden
  179. $this->assertFalse($user2View->unlink($this->folder . '/existing.txt'));
  180. //cleanup
  181. $this->shareManager->deleteShare($share);
  182. }
  183. public function testFopenWithCreateOnlyPermission() {
  184. $this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
  185. $fileinfoFolder = $this->view->getFileInfo($this->folder);
  186. $share = $this->share(
  187. IShare::TYPE_USER,
  188. $this->folder,
  189. self::TEST_FILES_SHARING_API_USER1,
  190. self::TEST_FILES_SHARING_API_USER2,
  191. \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE
  192. );
  193. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  194. $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
  195. // create part file allowed
  196. $handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
  197. $this->assertNotFalse($handle);
  198. fclose($handle);
  199. // create regular file allowed
  200. $handle = $user2View->fopen($this->folder . '/test-create.txt', 'w');
  201. $this->assertNotFalse($handle);
  202. fclose($handle);
  203. // rename file never allowed
  204. $this->assertFalse($user2View->rename($this->folder . '/test-create.txt', $this->folder . '/newtarget.txt'));
  205. $this->assertFalse($user2View->file_exists($this->folder . '/newtarget.txt'));
  206. // rename file not allowed if target exists
  207. $this->assertFalse($user2View->rename($this->folder . '/newtarget.txt', $this->folder . '/existing.txt'));
  208. // overwriting file not allowed
  209. $handle = $user2View->fopen($this->folder . '/existing.txt', 'w');
  210. $this->assertFalse($handle);
  211. // overwrite forbidden (no update permission)
  212. $this->assertFalse($user2View->rename($this->folder . '/test.txt.part', $this->folder . '/existing.txt'));
  213. // delete forbidden
  214. $this->assertFalse($user2View->unlink($this->folder . '/existing.txt'));
  215. //cleanup
  216. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  217. $this->shareManager->deleteShare($share);
  218. }
  219. public function testFopenWithUpdateOnlyPermission() {
  220. $this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
  221. $share = $this->share(
  222. IShare::TYPE_USER,
  223. $this->folder,
  224. self::TEST_FILES_SHARING_API_USER1,
  225. self::TEST_FILES_SHARING_API_USER2,
  226. \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE
  227. );
  228. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  229. $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
  230. // create part file allowed
  231. $handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
  232. $this->assertNotFalse($handle);
  233. fclose($handle);
  234. // create regular file not allowed
  235. $handle = $user2View->fopen($this->folder . '/test-create.txt', 'w');
  236. $this->assertFalse($handle);
  237. // rename part file not allowed to non-existing file
  238. $this->assertFalse($user2View->rename($this->folder . '/test.txt.part', $this->folder . '/nonexist.txt'));
  239. // rename part file allowed to target existing file
  240. $this->assertTrue($user2View->rename($this->folder . '/test.txt.part', $this->folder . '/existing.txt'));
  241. $this->assertTrue($user2View->file_exists($this->folder . '/existing.txt'));
  242. // rename regular file allowed
  243. $this->assertTrue($user2View->rename($this->folder . '/existing.txt', $this->folder . '/existing-renamed.txt'));
  244. $this->assertTrue($user2View->file_exists($this->folder . '/existing-renamed.txt'));
  245. // overwriting file directly is allowed
  246. $handle = $user2View->fopen($this->folder . '/existing-renamed.txt', 'w');
  247. $this->assertNotFalse($handle);
  248. fclose($handle);
  249. // delete forbidden
  250. $this->assertFalse($user2View->unlink($this->folder . '/existing-renamed.txt'));
  251. //cleanup
  252. $this->shareManager->deleteShare($share);
  253. }
  254. public function testFopenWithDeleteOnlyPermission() {
  255. $this->view->file_put_contents($this->folder . '/existing.txt', 'foo');
  256. $share = $this->share(
  257. IShare::TYPE_USER,
  258. $this->folder,
  259. self::TEST_FILES_SHARING_API_USER1,
  260. self::TEST_FILES_SHARING_API_USER2,
  261. \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_DELETE
  262. );
  263. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  264. $user2View = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
  265. // part file should be forbidden
  266. $handle = $user2View->fopen($this->folder . '/test.txt.part', 'w');
  267. $this->assertFalse($handle);
  268. // regular file forbidden
  269. $handle = $user2View->fopen($this->folder . '/test.txt', 'w');
  270. $this->assertFalse($handle);
  271. // rename forbidden
  272. $this->assertFalse($user2View->rename($this->folder . '/existing.txt', $this->folder . '/existing2.txt'));
  273. // delete allowed
  274. $this->assertTrue($user2View->unlink($this->folder . '/existing.txt'));
  275. //cleanup
  276. $this->shareManager->deleteShare($share);
  277. }
  278. public function testMountSharesOtherUser() {
  279. $rootView = new \OC\Files\View('');
  280. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  281. // share 2 different files with 2 different users
  282. $share1 = $this->share(
  283. IShare::TYPE_USER,
  284. $this->folder,
  285. self::TEST_FILES_SHARING_API_USER1,
  286. self::TEST_FILES_SHARING_API_USER2,
  287. \OCP\Constants::PERMISSION_ALL
  288. );
  289. $share2 = $this->share(
  290. IShare::TYPE_USER,
  291. $this->filename,
  292. self::TEST_FILES_SHARING_API_USER1,
  293. self::TEST_FILES_SHARING_API_USER3,
  294. \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE
  295. );
  296. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  297. $this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder));
  298. $mountConfigManager = \OC::$server->getMountProviderCollection();
  299. $mounts = $mountConfigManager->getMountsForUser(\OC::$server->getUserManager()->get(self::TEST_FILES_SHARING_API_USER3));
  300. array_walk($mounts, [\OC\Files\Filesystem::getMountManager(), 'addMount']);
  301. $this->assertTrue($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER3 . '/files/' . $this->filename));
  302. // make sure we didn't double setup shares for user 2 or mounted the shares for user 3 in user's 2 home
  303. $this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->folder . ' (2)'));
  304. $this->assertFalse($rootView->file_exists('/' . self::TEST_FILES_SHARING_API_USER2 . '/files/' . $this->filename));
  305. //cleanup
  306. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  307. $this->view->unlink($this->folder);
  308. $this->shareManager->deleteShare($share1);
  309. $this->shareManager->deleteShare($share2);
  310. }
  311. public function testCopyFromStorage() {
  312. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  313. $share = $this->share(
  314. IShare::TYPE_USER,
  315. $this->folder,
  316. self::TEST_FILES_SHARING_API_USER1,
  317. self::TEST_FILES_SHARING_API_USER2,
  318. \OCP\Constants::PERMISSION_ALL
  319. );
  320. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  321. $view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
  322. $this->assertTrue($view->file_exists($this->folder));
  323. /**
  324. * @var \OCP\Files\Storage $sharedStorage
  325. */
  326. [$sharedStorage,] = $view->resolvePath($this->folder);
  327. $this->assertTrue($sharedStorage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage'));
  328. $sourceStorage = new \OC\Files\Storage\Temporary([]);
  329. $sourceStorage->file_put_contents('foo.txt', 'asd');
  330. $sharedStorage->copyFromStorage($sourceStorage, 'foo.txt', 'bar.txt');
  331. $this->assertTrue($sharedStorage->file_exists('bar.txt'));
  332. $this->assertEquals('asd', $sharedStorage->file_get_contents('bar.txt'));
  333. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  334. $this->view->unlink($this->folder);
  335. $this->shareManager->deleteShare($share);
  336. }
  337. public function testMoveFromStorage() {
  338. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  339. $share = $this->share(
  340. IShare::TYPE_USER,
  341. $this->folder,
  342. self::TEST_FILES_SHARING_API_USER1,
  343. self::TEST_FILES_SHARING_API_USER2,
  344. \OCP\Constants::PERMISSION_ALL
  345. );
  346. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  347. $view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
  348. $this->assertTrue($view->file_exists($this->folder));
  349. /**
  350. * @var \OCP\Files\Storage $sharedStorage
  351. */
  352. [$sharedStorage,] = $view->resolvePath($this->folder);
  353. $this->assertTrue($sharedStorage->instanceOfStorage('OCA\Files_Sharing\ISharedStorage'));
  354. $sourceStorage = new \OC\Files\Storage\Temporary([]);
  355. $sourceStorage->file_put_contents('foo.txt', 'asd');
  356. $sharedStorage->moveFromStorage($sourceStorage, 'foo.txt', 'bar.txt');
  357. $this->assertTrue($sharedStorage->file_exists('bar.txt'));
  358. $this->assertEquals('asd', $sharedStorage->file_get_contents('bar.txt'));
  359. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  360. $this->view->unlink($this->folder);
  361. $this->shareManager->deleteShare($share);
  362. }
  363. public function testNameConflict() {
  364. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  365. $view1 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
  366. $view1->mkdir('foo');
  367. self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
  368. $view3 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER3 . '/files');
  369. $view3->mkdir('foo');
  370. // share a folder with the same name from two different users to the same user
  371. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  372. $share1 = $this->share(
  373. IShare::TYPE_GROUP,
  374. 'foo',
  375. self::TEST_FILES_SHARING_API_USER1,
  376. self::TEST_FILES_SHARING_API_GROUP1,
  377. \OCP\Constants::PERMISSION_ALL
  378. );
  379. $this->shareManager->acceptShare($share1, self::TEST_FILES_SHARING_API_USER2);
  380. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  381. self::loginHelper(self::TEST_FILES_SHARING_API_USER3);
  382. $share2 = $this->share(
  383. IShare::TYPE_GROUP,
  384. 'foo',
  385. self::TEST_FILES_SHARING_API_USER3,
  386. self::TEST_FILES_SHARING_API_GROUP1,
  387. \OCP\Constants::PERMISSION_ALL
  388. );
  389. $this->shareManager->acceptShare($share2, self::TEST_FILES_SHARING_API_USER2);
  390. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  391. $view2 = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
  392. $this->assertTrue($view2->file_exists('/foo'));
  393. $this->assertTrue($view2->file_exists('/foo (2)'));
  394. $mount = $view2->getMount('/foo');
  395. $this->assertInstanceOf('\OCA\Files_Sharing\SharedMount', $mount);
  396. /** @var \OCA\Files_Sharing\SharedStorage $storage */
  397. $storage = $mount->getStorage();
  398. $this->assertEquals(self::TEST_FILES_SHARING_API_USER1, $storage->getOwner(''));
  399. $this->shareManager->deleteShare($share1);
  400. $this->shareManager->deleteShare($share2);
  401. }
  402. public function testOwnerPermissions() {
  403. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  404. $share = $this->share(
  405. IShare::TYPE_USER,
  406. $this->folder,
  407. self::TEST_FILES_SHARING_API_USER1,
  408. self::TEST_FILES_SHARING_API_USER2,
  409. \OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_DELETE
  410. );
  411. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  412. $view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
  413. $this->assertTrue($view->file_exists($this->folder));
  414. $view->file_put_contents($this->folder . '/newfile.txt', 'asd');
  415. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  416. $this->assertTrue($this->view->file_exists($this->folder . '/newfile.txt'));
  417. $this->assertEquals(\OCP\Constants::PERMISSION_ALL - \OCP\Constants::PERMISSION_CREATE,
  418. $this->view->getFileInfo($this->folder . '/newfile.txt')->getPermissions());
  419. $this->view->unlink($this->folder);
  420. $this->shareManager->deleteShare($share);
  421. }
  422. public function testInitWithNonExistingUser() {
  423. $share = $this->createMock(IShare::class);
  424. $share->method('getShareOwner')->willReturn('unexist');
  425. $ownerView = $this->createMock(View::class);
  426. $storage = new SharedStorage([
  427. 'ownerView' => $ownerView,
  428. 'superShare' => $share,
  429. 'groupedShares' => [$share],
  430. 'user' => 'user1',
  431. ]);
  432. // trigger init
  433. $this->assertInstanceOf(\OC\Files\Storage\FailedStorage::class, $storage->getSourceStorage());
  434. $this->assertInstanceOf(\OC\Files\Cache\FailedCache::class, $storage->getCache());
  435. }
  436. public function testInitWithNotFoundSource() {
  437. $share = $this->createMock(IShare::class);
  438. $share->method('getShareOwner')->willReturn(self::TEST_FILES_SHARING_API_USER1);
  439. $share->method('getNodeId')->willReturn(1);
  440. $ownerView = $this->createMock(View::class);
  441. $ownerView->method('getPath')->will($this->throwException(new NotFoundException()));
  442. $storage = new SharedStorage([
  443. 'ownerView' => $ownerView,
  444. 'superShare' => $share,
  445. 'groupedShares' => [$share],
  446. 'user' => 'user1',
  447. ]);
  448. // trigger init
  449. $this->assertInstanceOf(\OC\Files\Storage\FailedStorage::class, $storage->getSourceStorage());
  450. $this->assertInstanceOf(\OC\Files\Cache\FailedCache::class, $storage->getCache());
  451. }
  452. }