sizepropagation.php 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. }