1
0

UnshareChildrenTest.php 2.6 KB

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