UnshareChildrenTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Björn Schießle <bjoern@schiessle.org>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Morris Jobke <hey@morrisjobke.de>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Müller <thomas.mueller@tmit.eu>
  11. *
  12. * @license AGPL-3.0
  13. *
  14. * This code is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License, version 3,
  16. * as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License, version 3,
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>
  25. *
  26. */
  27. namespace OCA\Files_Sharing\Tests;
  28. /**
  29. * Class UnshareChildrenTest
  30. *
  31. * @group DB
  32. *
  33. * @package OCA\Files_Sharing\Tests
  34. */
  35. class UnshareChildrenTest extends TestCase {
  36. protected $subsubfolder;
  37. const TEST_FOLDER_NAME = '/folder_share_api_test';
  38. private static $tempStorage;
  39. protected function setUp(): void {
  40. parent::setUp();
  41. \OCP\Util::connectHook('OC_Filesystem', 'post_delete', '\OCA\Files_Sharing\Hooks', 'unshareChildren');
  42. $this->folder = self::TEST_FOLDER_NAME;
  43. $this->subfolder = '/subfolder_share_api_test';
  44. $this->subsubfolder = '/subsubfolder_share_api_test';
  45. $this->filename = '/share-api-test';
  46. // save file with content
  47. $this->view->mkdir($this->folder);
  48. $this->view->mkdir($this->folder . $this->subfolder);
  49. $this->view->mkdir($this->folder . $this->subfolder . $this->subsubfolder);
  50. $this->view->file_put_contents($this->folder . $this->filename, $this->data);
  51. $this->view->file_put_contents($this->folder . $this->subfolder . $this->filename, $this->data);
  52. }
  53. protected function tearDown(): void {
  54. if ($this->view) {
  55. $this->view->deleteAll($this->folder);
  56. }
  57. self::$tempStorage = null;
  58. parent::tearDown();
  59. }
  60. /**
  61. * @medium
  62. */
  63. public function testUnshareChildren() {
  64. $fileInfo2 = \OC\Files\Filesystem::getFileInfo($this->folder);
  65. $this->share(
  66. \OCP\Share::SHARE_TYPE_USER,
  67. $this->folder,
  68. self::TEST_FILES_SHARING_API_USER1,
  69. self::TEST_FILES_SHARING_API_USER2,
  70. \OCP\Constants::PERMISSION_ALL
  71. );
  72. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  73. // one folder should be shared with the user
  74. $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_USER);
  75. $this->assertCount(1, $shares);
  76. // move shared folder to 'localDir'
  77. \OC\Files\Filesystem::mkdir('localDir');
  78. $result = \OC\Files\Filesystem::rename($this->folder, '/localDir/' . $this->folder);
  79. $this->assertTrue($result);
  80. \OC\Files\Filesystem::unlink('localDir');
  81. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  82. // after the parent directory was deleted the share should be unshared
  83. $shares = $this->shareManager->getSharedWith(self::TEST_FILES_SHARING_API_USER2, \OCP\Share::SHARE_TYPE_USER);
  84. $this->assertEmpty($shares);
  85. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  86. // the folder for the owner should still exists
  87. $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
  88. }
  89. }