HomeStorageQuotaTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. public 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) {
  44. $user->delete();
  45. }
  46. \OC::$server->getConfig()->deleteAllUserValues($user1);
  47. \OC_Util::tearDownFS();
  48. }
  49. /**
  50. * Tests that the home storage is not wrapped when no quota exists.
  51. */
  52. public function testHomeStorageWrapperWithQuota() {
  53. $user1 = $this->getUniqueID();
  54. \OC::$server->getUserManager()->createUser($user1, 'test');
  55. \OC::$server->getConfig()->setUserValue($user1, 'files', 'quota', '1024');
  56. \OC_User::setUserId($user1);
  57. \OC_Util::setupFS($user1);
  58. $userMount = \OC\Files\Filesystem::getMountManager()->find('/' . $user1 . '/');
  59. $this->assertNotNull($userMount);
  60. $this->assertTrue($userMount->getStorage()->instanceOfStorage('\OC\Files\Storage\Wrapper\Quota'));
  61. // ensure that root wasn't wrapped
  62. $rootMount = \OC\Files\Filesystem::getMountManager()->find('/');
  63. $this->assertNotNull($rootMount);
  64. $this->assertNotInstanceOf('\OC\Files\Storage\Wrapper\Quota', $rootMount->getStorage());
  65. // clean up
  66. \OC_User::setUserId('');
  67. $user = \OC::$server->getUserManager()->get($user1);
  68. if ($user !== null) {
  69. $user->delete();
  70. }
  71. \OC::$server->getConfig()->deleteAllUserValues($user1);
  72. \OC_Util::tearDownFS();
  73. }
  74. }