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.

sizepropagation.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * @author Morris Jobke <hey@morrisjobke.de>
  4. * @author Robin Appelman <icewind@owncloud.com>
  5. *
  6. * @copyright Copyright (c) 2015, ownCloud, Inc.
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCA\Files_sharing\Tests;
  23. use OC\Files\View;
  24. class SizePropagation extends TestCase {
  25. public function testSizePropagationWhenOwnerChangesFile() {
  26. $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
  27. $recipientView = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
  28. $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
  29. $ownerView = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
  30. $ownerView->mkdir('/sharedfolder/subfolder');
  31. $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar');
  32. $sharedFolderInfo = $ownerView->getFileInfo('/sharedfolder', false);
  33. \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31);
  34. $ownerRootInfo = $ownerView->getFileInfo('', false);
  35. $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
  36. $this->assertTrue($recipientView->file_exists('/sharedfolder/subfolder/foo.txt'));
  37. $recipientRootInfo = $recipientView->getFileInfo('', false);
  38. // when file changed as owner
  39. $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
  40. $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar');
  41. // size of recipient's root stays the same
  42. $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
  43. $newRecipientRootInfo = $recipientView->getFileInfo('', false);
  44. $this->assertEquals($recipientRootInfo->getSize(), $newRecipientRootInfo->getSize());
  45. // size of owner's root increases
  46. $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
  47. $newOwnerRootInfo = $ownerView->getFileInfo('', false);
  48. $this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize());
  49. }
  50. public function testSizePropagationWhenRecipientChangesFile() {
  51. $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
  52. $recipientView = new View('/' . self::TEST_FILES_SHARING_API_USER1 . '/files');
  53. $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
  54. $ownerView = new View('/' . self::TEST_FILES_SHARING_API_USER2 . '/files');
  55. $ownerView->mkdir('/sharedfolder/subfolder');
  56. $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar');
  57. $sharedFolderInfo = $ownerView->getFileInfo('/sharedfolder', false);
  58. \OCP\Share::shareItem('folder', $sharedFolderInfo->getId(), \OCP\Share::SHARE_TYPE_USER, self::TEST_FILES_SHARING_API_USER1, 31);
  59. $ownerRootInfo = $ownerView->getFileInfo('', false);
  60. $this->loginHelper(self::TEST_FILES_SHARING_API_USER1);
  61. $this->assertTrue($recipientView->file_exists('/sharedfolder/subfolder/foo.txt'));
  62. $recipientRootInfo = $recipientView->getFileInfo('', false);
  63. // when file changed as recipient
  64. $recipientView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar');
  65. // size of recipient's root stays the same
  66. $newRecipientRootInfo = $recipientView->getFileInfo('', false);
  67. $this->assertEquals($recipientRootInfo->getSize(), $newRecipientRootInfo->getSize());
  68. // size of owner's root increases
  69. $this->loginHelper(self::TEST_FILES_SHARING_API_USER2);
  70. $newOwnerRootInfo = $ownerView->getFileInfo('', false);
  71. $this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize());
  72. }
  73. }