PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/apps/files_sharing/tests/sizepropagation.php

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