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.

SizePropagationTest.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Roeland Jago Douma <roeland@famdouma.nl>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. *
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OCA\Files_Sharing\Tests;
  26. use OC\Files\View;
  27. use OCP\Share\IShare;
  28. use Test\Traits\UserTrait;
  29. /**
  30. * Class SizePropagationTest
  31. *
  32. * @group DB
  33. *
  34. * @package OCA\Files_Sharing\Tests
  35. */
  36. class SizePropagationTest extends TestCase {
  37. use UserTrait;
  38. protected function setupUser($name, $password = '') {
  39. $this->createUser($name, $password);
  40. $tmpFolder = \OC::$server->getTempManager()->getTemporaryFolder();
  41. $this->registerMount($name, '\OC\Files\Storage\Local', '/' . $name, ['datadir' => $tmpFolder]);
  42. $this->loginAsUser($name);
  43. return new View('/' . $name . '/files');
  44. }
  45. public function testSizePropagationWhenOwnerChangesFile() {
  46. $recipientView = $this->setupUser(self::TEST_FILES_SHARING_API_USER1);
  47. $ownerView = $this->setupUser(self::TEST_FILES_SHARING_API_USER2);
  48. $ownerView->mkdir('/sharedfolder/subfolder');
  49. $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar');
  50. $this->share(
  51. IShare::TYPE_USER,
  52. '/sharedfolder',
  53. self::TEST_FILES_SHARING_API_USER2,
  54. self::TEST_FILES_SHARING_API_USER1,
  55. \OCP\Constants::PERMISSION_ALL
  56. );
  57. $ownerRootInfo = $ownerView->getFileInfo('', false);
  58. $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
  59. $this->assertTrue($recipientView->file_exists('/sharedfolder/subfolder/foo.txt'));
  60. $recipientRootInfo = $recipientView->getFileInfo('', false);
  61. // when file changed as owner
  62. $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
  63. $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar');
  64. // size of recipient's root stays the same
  65. $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
  66. $newRecipientRootInfo = $recipientView->getFileInfo('', false);
  67. $this->assertEquals($recipientRootInfo->getSize(), $newRecipientRootInfo->getSize());
  68. // size of owner's root increases
  69. $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
  70. $newOwnerRootInfo = $ownerView->getFileInfo('', false);
  71. $this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize());
  72. }
  73. public function testSizePropagationWhenRecipientChangesFile() {
  74. $recipientView = $this->setupUser(self::TEST_FILES_SHARING_API_USER1);
  75. $ownerView = $this->setupUser(self::TEST_FILES_SHARING_API_USER2);
  76. $ownerView->mkdir('/sharedfolder/subfolder');
  77. $ownerView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'bar');
  78. $this->share(
  79. IShare::TYPE_USER,
  80. '/sharedfolder',
  81. self::TEST_FILES_SHARING_API_USER2,
  82. self::TEST_FILES_SHARING_API_USER1,
  83. \OCP\Constants::PERMISSION_ALL
  84. );
  85. $ownerRootInfo = $ownerView->getFileInfo('', false);
  86. $this->loginAsUser(self::TEST_FILES_SHARING_API_USER1);
  87. $this->assertTrue($recipientView->file_exists('/sharedfolder/subfolder/foo.txt'));
  88. $recipientRootInfo = $recipientView->getFileInfo('', false);
  89. $recipientRootInfoWithMounts = $recipientView->getFileInfo('', true);
  90. $oldRecipientSize = $recipientRootInfoWithMounts->getSize();
  91. // when file changed as recipient
  92. $recipientView->file_put_contents('/sharedfolder/subfolder/foo.txt', 'foobar');
  93. // size of recipient's root stays the same
  94. $newRecipientRootInfo = $recipientView->getFileInfo('', false);
  95. $this->assertEquals($recipientRootInfo->getSize(), $newRecipientRootInfo->getSize());
  96. // but the size including mountpoints increases
  97. $newRecipientRootInfo = $recipientView->getFileInfo('', true);
  98. $this->assertEquals($oldRecipientSize + 3, $newRecipientRootInfo->getSize());
  99. // size of owner's root increases
  100. $this->loginAsUser(self::TEST_FILES_SHARING_API_USER2);
  101. $newOwnerRootInfo = $ownerView->getFileInfo('', false);
  102. $this->assertEquals($ownerRootInfo->getSize() + 3, $newOwnerRootInfo->getSize());
  103. }
  104. }