UnshareChildrenTest.php 3.4 KB

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