1
0

SizePropagationTest.php 4.5 KB

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