1
0

UnshareChildrenTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-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 OCP\Share\IShare;
  9. /**
  10. * Class UnshareChildrenTest
  11. *
  12. * @group DB
  13. *
  14. * @package OCA\Files_Sharing\Tests
  15. */
  16. class UnshareChildrenTest extends TestCase {
  17. protected $subsubfolder;
  18. public const TEST_FOLDER_NAME = '/folder_share_api_test';
  19. private static $tempStorage;
  20. protected function setUp(): void {
  21. parent::setUp();
  22. \OCP\Util::connectHook('OC_Filesystem', 'post_delete', '\OCA\Files_Sharing\Hooks', 'unshareChildren');
  23. $this->folder = self::TEST_FOLDER_NAME;
  24. $this->subfolder = '/subfolder_share_api_test';
  25. $this->subsubfolder = '/subsubfolder_share_api_test';
  26. $this->filename = '/share-api-test';
  27. // save file with content
  28. $this->view->mkdir($this->folder);
  29. $this->view->mkdir($this->folder . $this->subfolder);
  30. $this->view->mkdir($this->folder . $this->subfolder . $this->subsubfolder);
  31. $this->view->file_put_contents($this->folder . $this->filename, $this->data);
  32. $this->view->file_put_contents($this->folder . $this->subfolder . $this->filename, $this->data);
  33. }
  34. protected function tearDown(): void {
  35. if ($this->view) {
  36. $this->view->deleteAll($this->folder);
  37. }
  38. self::$tempStorage = null;
  39. parent::tearDown();
  40. }
  41. /**
  42. * @medium
  43. */
  44. public function testUnshareChildren() {
  45. $fileInfo2 = \OC\Files\Filesystem::getFileInfo($this->folder);
  46. $this->share(
  47. IShare::TYPE_USER,
  48. $this->folder,
  49. self::TEST_FILES_SHARING_API_USER1,
  50. self::TEST_FILES_SHARING_API_USER2,
  51. \OCP\Constants::PERMISSION_ALL
  52. );
  53. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  54. // one folder should be shared with the user
  55. $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, IShare::TYPE_USER);
  56. $this->assertCount(1, $shares);
  57. // move shared folder to 'localDir'
  58. \OC\Files\Filesystem::mkdir('localDir');
  59. $result = \OC\Files\Filesystem::rename($this->folder, '/localDir/' . $this->folder);
  60. $this->assertTrue($result);
  61. \OC\Files\Filesystem::unlink('localDir');
  62. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  63. // after the parent directory was deleted the share should be unshared
  64. $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, IShare::TYPE_USER);
  65. $this->assertEmpty($shares);
  66. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  67. // the folder for the owner should still exists
  68. $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
  69. }
  70. }