UnshareChildrenTest.php 3.4 KB

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