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.

updater.php 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 Vincent Petry <pvince81@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. /**
  25. * Class Test_Files_Sharing_Updater
  26. */
  27. class Test_Files_Sharing_Updater extends OCA\Files_Sharing\Tests\TestCase {
  28. const TEST_FOLDER_NAME = '/folder_share_updater_test';
  29. public static function setUpBeforeClass() {
  30. parent::setUpBeforeClass();
  31. \OCA\Files_Sharing\Helper::registerHooks();
  32. }
  33. protected function setUp() {
  34. parent::setUp();
  35. $this->folder = self::TEST_FOLDER_NAME;
  36. $this->filename = '/share-updater-test.txt';
  37. // save file with content
  38. $this->view->file_put_contents($this->filename, $this->data);
  39. $this->view->mkdir($this->folder);
  40. $this->view->file_put_contents($this->folder . '/' . $this->filename, $this->data);
  41. }
  42. protected function tearDown() {
  43. $this->view->unlink($this->filename);
  44. $this->view->deleteAll($this->folder);
  45. parent::tearDown();
  46. }
  47. /**
  48. * test deletion of a folder which contains share mount points. Share mount
  49. * points should be unshared before the folder gets deleted so
  50. * that the mount point doesn't end up at the trash bin
  51. */
  52. function testDeleteParentFolder() {
  53. $status = \OC_App::isEnabled('files_trashbin');
  54. \OC_App::enable('files_trashbin');
  55. \OCA\Files_Trashbin\Trashbin::registerHooks();
  56. $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
  57. $this->assertTrue($fileinfo instanceof \OC\Files\FileInfo);
  58. \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
  59. $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
  60. $view = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
  61. // check if user2 can see the shared folder
  62. $this->assertTrue($view->file_exists($this->folder));
  63. $foldersShared = \OCP\Share::getItemsSharedWith('folder');
  64. $this->assertSame(1, count($foldersShared));
  65. $view->mkdir("localFolder");
  66. $view->file_put_contents("localFolder/localFile.txt", "local file");
  67. $view->rename($this->folder, 'localFolder/' . $this->folder);
  68. // share mount point should now be moved to the subfolder
  69. $this->assertFalse($view->file_exists($this->folder));
  70. $this->assertTrue($view->file_exists('localFolder/' .$this->folder));
  71. $view->unlink('localFolder');
  72. $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
  73. // shared folder should be unshared
  74. $foldersShared = \OCP\Share::getItemsSharedWith('folder');
  75. $this->assertTrue(empty($foldersShared));
  76. // trashbin should contain the local file but not the mount point
  77. $rootView = new \OC\Files\View('/' . self::TEST_FILES_SHARING_API_USER2);
  78. $trashContent = \OCA\Files_Trashbin\Helper::getTrashFiles('/', self::TEST_FILES_SHARING_API_USER2);
  79. $this->assertSame(1, count($trashContent));
  80. $firstElement = reset($trashContent);
  81. $timestamp = $firstElement['mtime'];
  82. $this->assertTrue($rootView->file_exists('files_trashbin/files/localFolder.d' . $timestamp . '/localFile.txt'));
  83. $this->assertFalse($rootView->file_exists('files_trashbin/files/localFolder.d' . $timestamp . '/' . $this->folder));
  84. //cleanup
  85. $rootView->deleteAll('files_trashin');
  86. if ($status === false) {
  87. \OC_App::disable('files_trashbin');
  88. }
  89. \OC\Files\Filesystem::getLoader()->removeStorageWrapper('oc_trashbin');
  90. }
  91. /**
  92. * if a file gets shared the etag for the recipients root should change
  93. */
  94. function testShareFile() {
  95. $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
  96. $beforeShare = \OC\Files\Filesystem::getFileInfo('');
  97. $etagBeforeShare = $beforeShare->getEtag();
  98. $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
  99. $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
  100. $result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
  101. $this->assertTrue($result);
  102. $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
  103. $afterShare = \OC\Files\Filesystem::getFileInfo('');
  104. $etagAfterShare = $afterShare->getEtag();
  105. $this->assertTrue(is_string($etagBeforeShare));
  106. $this->assertTrue(is_string($etagAfterShare));
  107. $this->assertTrue($etagBeforeShare !== $etagAfterShare);
  108. // cleanup
  109. $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
  110. $result = \OCP\Share::unshare('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
  111. $this->assertTrue($result);
  112. }
  113. /**
  114. * if a folder gets renamed all children mount points should be renamed too
  115. */
  116. function testRename() {
  117. $fileinfo = \OC\Files\Filesystem::getFileInfo($this->folder);
  118. $result = \OCP\Share::shareItem('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2, 31);
  119. $this->assertTrue($result);
  120. $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
  121. // make sure that the shared folder exists
  122. $this->assertTrue(\OC\Files\Filesystem::file_exists($this->folder));
  123. \OC\Files\Filesystem::mkdir('oldTarget');
  124. \OC\Files\Filesystem::mkdir('oldTarget/subfolder');
  125. \OC\Files\Filesystem::mkdir('newTarget');
  126. \OC\Files\Filesystem::rename($this->folder, 'oldTarget/subfolder/' . $this->folder);
  127. // re-login to make sure that the new mount points are initialized
  128. $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
  129. \OC\Files\Filesystem::rename('/oldTarget', '/newTarget/oldTarget');
  130. // re-login to make sure that the new mount points are initialized
  131. $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
  132. $this->assertTrue(\OC\Files\Filesystem::file_exists('/newTarget/oldTarget/subfolder/' . $this->folder));
  133. // cleanup
  134. $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
  135. $result = \OCP\Share::unshare('folder', $fileinfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER2);
  136. $this->assertTrue($result);
  137. }
  138. }