HomeStorageQuotaTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * @author Thomas Müller <thomas.mueller@tmit.eu>
  4. *
  5. * @copyright Copyright (c) 2015, ownCloud, Inc.
  6. * @license AGPL-3.0
  7. *
  8. * This code is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License, version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License, version 3,
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>
  19. *
  20. */
  21. namespace Test\Files\Storage;
  22. /**
  23. * Class HomeStorageQuotaTest
  24. *
  25. * @group DB
  26. */
  27. class HomeStorageQuotaTest extends \Test\TestCase {
  28. /**
  29. * Tests that the home storage is not wrapped when no quota exists.
  30. */
  31. function testHomeStorageWrapperWithoutQuota() {
  32. $user1 = $this->getUniqueID();
  33. \OC::$server->getUserManager()->createUser($user1, 'test');
  34. \OC::$server->getConfig()->setUserValue($user1, 'files', 'quota', 'none');
  35. \OC_User::setUserId($user1);
  36. \OC_Util::setupFS($user1);
  37. $userMount = \OC\Files\Filesystem::getMountManager()->find('/' . $user1 . '/');
  38. $this->assertNotNull($userMount);
  39. $this->assertNotInstanceOf('\OC\Files\Storage\Wrapper\Quota', $userMount->getStorage());
  40. // clean up
  41. \OC_User::setUserId('');
  42. $user = \OC::$server->getUserManager()->get($user1);
  43. if ($user !== null) { $user->delete(); }
  44. \OC::$server->getConfig()->deleteAllUserValues($user1);
  45. \OC_Util::tearDownFS();
  46. }
  47. /**
  48. * Tests that the home storage is not wrapped when no quota exists.
  49. */
  50. function testHomeStorageWrapperWithQuota() {
  51. $user1 = $this->getUniqueID();
  52. \OC::$server->getUserManager()->createUser($user1, 'test');
  53. \OC::$server->getConfig()->setUserValue($user1, 'files', 'quota', '1024');
  54. \OC_User::setUserId($user1);
  55. \OC_Util::setupFS($user1);
  56. $userMount = \OC\Files\Filesystem::getMountManager()->find('/' . $user1 . '/');
  57. $this->assertNotNull($userMount);
  58. $this->assertTrue($userMount->getStorage()->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota'));
  59. // ensure that root wasn't wrapped
  60. $rootMount = \OC\Files\Filesystem::getMountManager()->find('/');
  61. $this->assertNotNull($rootMount);
  62. $this->assertNotInstanceOf('\OC\Files\Storage\Wrapper\Quota', $rootMount->getStorage());
  63. // clean up
  64. \OC_User::setUserId('');
  65. $user = \OC::$server->getUserManager()->get($user1);
  66. if ($user !== null) { $user->delete(); }
  67. \OC::$server->getConfig()->deleteAllUserValues($user1);
  68. \OC_Util::tearDownFS();
  69. }
  70. }