You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unsharechildren.php 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * @author Björn Schießle <schiessle@owncloud.com>
  4. * @author Joas Schilling <nickvergessen@owncloud.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin Appelman <icewind@owncloud.com>
  7. *
  8. * @copyright Copyright (c) 2015, ownCloud, Inc.
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\Files_sharing\Tests;
  25. use OCA\Files\Share;
  26. class UnshareChildren extends TestCase {
  27. protected $subsubfolder;
  28. const TEST_FOLDER_NAME = '/folder_share_api_test';
  29. private static $tempStorage;
  30. protected function setUp() {
  31. parent::setUp();
  32. \OCP\Util::connectHook('OC_Filesystem', 'post_delete', '\OCA\Files_Sharing\Hooks', 'unshareChildren');
  33. $this->folder = self::TEST_FOLDER_NAME;
  34. $this->subfolder = '/subfolder_share_api_test';
  35. $this->subsubfolder = '/subsubfolder_share_api_test';
  36. $this->filename = '/share-api-test';
  37. // save file with content
  38. $this->view->mkdir($this->folder);
  39. $this->view->mkdir($this->folder . $this->subfolder);
  40. $this->view->mkdir($this->folder . $this->subfolder . $this->subsubfolder);
  41. $this->view->file_put_contents($this->folder.$this->filename, $this->data);
  42. $this->view->file_put_contents($this->folder . $this->subfolder . $this->filename, $this->data);
  43. }
  44. protected function tearDown() {
  45. $this->view->deleteAll($this->folder);
  46. self::$tempStorage = null;
  47. parent::tearDown();
  48. }
  49. /**
  50. * @medium
  51. */
  52. function testUnshareChildren() {
  53. $fileInfo2 = \OC\Files\Filesystem::getFileInfo($this->folder);
  54. $result = \OCP\Share::shareItem('folder', $fileInfo2->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
  55. $this->assertTrue($result);
  56. self::loginHelper(self::TEST_FILES_SHARING_API_USER2);
  57. // one folder should be shared with the user
  58. $sharedFolders = \OCP\Share::getItemsSharedWith('folder');
  59. $this->assertSame(1, count($sharedFolders));
  60. // move shared folder to 'localDir'
  61. \OC\Files\Filesystem::mkdir('localDir');
  62. $result = \OC\Files\Filesystem::rename($this->folder, '/localDir/' . $this->folder);
  63. $this->assertTrue($result);
  64. \OC\Files\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. $sharedFolders = \OCP\Share::getItemsSharedWith('folder');
  68. $this->assertTrue(empty($sharedFolders));
  69. self::loginHelper(self::TEST_FILES_SHARING_API_USER1);
  70. // the folder for the owner should still exists
  71. $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
  72. }
  73. }