diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-03-25 16:37:46 +0100 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2014-06-04 16:08:59 +0200 |
commit | da889ff029446119cf6159e75c48ef83be7de7e8 (patch) | |
tree | b88399936d4e4ec24145739db4cc9c1e3e09c833 /tests | |
parent | b5f0a179187bb3f10a939518c6eba72593c1f7a5 (diff) | |
download | nextcloud-server-da889ff029446119cf6159e75c48ef83be7de7e8.tar.gz nextcloud-server-da889ff029446119cf6159e75c48ef83be7de7e8.zip |
Added experimental switch to count external storage data in quota
This includes all mountpoints except the Shared one in
the used space calculation.
Added unit tests for ext storage inclusion in quota calculation
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/helperstorage.php | 145 |
1 files changed, 124 insertions, 21 deletions
diff --git a/tests/lib/helperstorage.php b/tests/lib/helperstorage.php index 010a54e3bb0..4fdd9dd6b9b 100644 --- a/tests/lib/helperstorage.php +++ b/tests/lib/helperstorage.php @@ -15,35 +15,78 @@ class Test_Helper_Storage extends PHPUnit_Framework_TestCase { public function setUp() { $this->user = 'user_' . uniqid(); + \OC_User::createUser($this->user, $this->user); + \OC\Files\Filesystem::tearDown(); + \OC_User::setUserId($this->user); \OC\Files\Filesystem::init($this->user, '/' . $this->user . '/files'); + \OC\Files\Filesystem::clearMounts(); + + $this->storageMock = null; + } + + public function tearDown() { + $this->user = null; + if ($this->storageMock) { + $this->storageMock->getCache()->clear(); + $this->storageMock = null; + } + \OC\Files\Filesystem::tearDown(); + + \OC_User::setUserId(''); + \OC_User::deleteUser($this->user); + \OC_Preferences::deleteUser($this->user); + } + + /** + * Returns a storage mock that returns the given value as + * free space + * + * @param int $freeSpace free space value + * @return \OC\Files\Storage\Storage + */ + private function getStorageMock($freeSpace = 12) { $this->storageMock = $this->getMock( '\OC\Files\Storage\Temporary', array('free_space'), array('') ); - \OC\Files\Filesystem::clearMounts(); $this->storageMock->expects($this->once()) ->method('free_space') ->will($this->returnValue(12)); + return $this->storageMock; } - public function tearDown() { - $this->user = null; + /** + * Test getting the storage info + */ + function testGetStorageInfo() { + $homeStorage = $this->getStorageMock(12); + \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files'); + $homeStorage->file_put_contents('test.txt', '01234'); - $this->storageMock->getCache()->clear(); - \OC\Files\Filesystem::tearDown(); + $storageInfo = \OC_Helper::getStorageInfo(''); + $this->assertEquals(12, $storageInfo['free']); + $this->assertEquals(5, $storageInfo['used']); + $this->assertEquals(17, $storageInfo['total']); } /** - * Test getting the storage info + * Test getting the storage info, ignoring extra mount points */ - function testGetStorageInfo() { - \OC\Files\Filesystem::mount($this->storageMock, array(), '/' . $this->user . '/files'); - $this->storageMock->file_put_contents('test.txt', '01234'); + function testGetStorageInfoExcludingExtStorage() { + $homeStorage = $this->getStorageMock(12); + \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files'); + $homeStorage->file_put_contents('test.txt', '01234'); + + $extStorage = new \OC\Files\Storage\Temporary(array()); + $extStorage->file_put_contents('extfile.txt', 'abcdefghijklmnopq'); + $extStorage->getScanner()->scan(''); // update root size + + \OC\Files\Filesystem::mount($extStorage, array(), '/' . $this->user . '/files/ext'); $storageInfo = \OC_Helper::getStorageInfo(''); $this->assertEquals(12, $storageInfo['free']); @@ -52,17 +95,75 @@ class Test_Helper_Storage extends PHPUnit_Framework_TestCase { } /** + * Test getting the storage info, including extra mount points + */ + function testGetStorageInfoIncludingExtStorage() { + $homeStorage = new \OC\Files\Storage\Temporary(array()); + \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files'); + $homeStorage->file_put_contents('test.txt', '01234'); + + $extStorage = new \OC\Files\Storage\Temporary(array()); + $extStorage->file_put_contents('extfile.txt', 'abcdefghijklmnopq'); + $extStorage->getScanner()->scan(''); // update root size + + \OC\Files\Filesystem::mount($extStorage, array(), '/' . $this->user . '/files/ext'); + + $oldConfig = \OC_Config::getValue('quota_include_external_storage', false); + \OC_Config::setValue('quota_include_external_storage', 'true'); + + $config = \OC::$server->getConfig(); + $userQuota = $config->setUserValue($this->user, 'files', 'quota', '25'); + + $storageInfo = \OC_Helper::getStorageInfo(''); + $this->assertEquals(3, $storageInfo['free']); + $this->assertEquals(22, $storageInfo['used']); + $this->assertEquals(25, $storageInfo['total']); + + \OC_Config::setValue('quota_include_external_storage', $oldConfig); + $userQuota = $config->setUserValue($this->user, 'files', 'quota', 'default'); + } + + /** + * Test getting the storage info excluding extra mount points + * when user has no quota set, even when quota ext storage option + * was set + */ + function testGetStorageInfoIncludingExtStorageWithNoUserQuota() { + $homeStorage = $this->getStorageMock(12); + \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files'); + $homeStorage->file_put_contents('test.txt', '01234'); + + $extStorage = new \OC\Files\Storage\Temporary(array()); + $extStorage->file_put_contents('extfile.txt', 'abcdefghijklmnopq'); + $extStorage->getScanner()->scan(''); // update root size + + \OC\Files\Filesystem::mount($extStorage, array(), '/' . $this->user . '/files/ext'); + + $oldConfig = \OC_Config::getValue('quota_include_external_storage', false); + \OC_Config::setValue('quota_include_external_storage', 'true'); + + $storageInfo = \OC_Helper::getStorageInfo(''); + $this->assertEquals(12, $storageInfo['free']); + $this->assertEquals(5, $storageInfo['used']); + $this->assertEquals(17, $storageInfo['total']); + + \OC_Config::setValue('quota_include_external_storage', $oldConfig); + } + + + /** * Test getting the storage info with quota enabled */ function testGetStorageInfoWithQuota() { - $this->storageMock->file_put_contents('test.txt', '01234'); - $this->storageMock = new \OC\Files\Storage\Wrapper\Quota( + $homeStorage = $this->getStorageMock(12); + $homeStorage->file_put_contents('test.txt', '01234'); + $homeStorage = new \OC\Files\Storage\Wrapper\Quota( array( - 'storage' => $this->storageMock, + 'storage' => $homeStorage, 'quota' => 7 ) ); - \OC\Files\Filesystem::mount($this->storageMock, array(), '/' . $this->user . '/files'); + \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files'); $storageInfo = \OC_Helper::getStorageInfo(''); $this->assertEquals(2, $storageInfo['free']); @@ -74,14 +175,15 @@ class Test_Helper_Storage extends PHPUnit_Framework_TestCase { * Test getting the storage info when data exceeds quota */ function testGetStorageInfoWhenSizeExceedsQuota() { - $this->storageMock->file_put_contents('test.txt', '0123456789'); - $this->storageMock = new \OC\Files\Storage\Wrapper\Quota( + $homeStorage = $this->getStorageMock(12); + $homeStorage->file_put_contents('test.txt', '0123456789'); + $homeStorage = new \OC\Files\Storage\Wrapper\Quota( array( - 'storage' => $this->storageMock, + 'storage' => $homeStorage, 'quota' => 7 ) ); - \OC\Files\Filesystem::mount($this->storageMock, array(), '/' . $this->user . '/files'); + \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files'); $storageInfo = \OC_Helper::getStorageInfo(''); $this->assertEquals(0, $storageInfo['free']); @@ -95,14 +197,15 @@ class Test_Helper_Storage extends PHPUnit_Framework_TestCase { * free storage space is less than the quota */ function testGetStorageInfoWhenFreeSpaceLessThanQuota() { - $this->storageMock->file_put_contents('test.txt', '01234'); - $this->storageMock = new \OC\Files\Storage\Wrapper\Quota( + $homeStorage = $this->getStorageMock(12); + $homeStorage->file_put_contents('test.txt', '01234'); + $homeStorage = new \OC\Files\Storage\Wrapper\Quota( array( - 'storage' => $this->storageMock, + 'storage' => $homeStorage, 'quota' => 18 ) ); - \OC\Files\Filesystem::mount($this->storageMock, array(), '/' . $this->user . '/files'); + \OC\Files\Filesystem::mount($homeStorage, array(), '/' . $this->user . '/files'); $storageInfo = \OC_Helper::getStorageInfo(''); $this->assertEquals(12, $storageInfo['free']); |