diff options
author | Morris Jobke <hey@morrisjobke.de> | 2017-07-05 15:15:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-05 15:15:25 +0200 |
commit | 7d58bb7db513c2a488ce41efcd6833b9dfaa86da (patch) | |
tree | 3c9adb889eaf368e80c425f670ebbe148ebb3eec /tests | |
parent | efa52ec1113eeccbd3935a8c96ea23c47ca190ab (diff) | |
parent | f2b8535c7e6ab070465933ccee558dcfbeb7e8bb (diff) | |
download | nextcloud-server-7d58bb7db513c2a488ce41efcd6833b9dfaa86da.tar.gz nextcloud-server-7d58bb7db513c2a488ce41efcd6833b9dfaa86da.zip |
Merge pull request #5342 from nextcloud/userlist-used-space
show used space in user list
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Settings/Controller/UsersControllerTest.php | 80 | ||||
-rw-r--r-- | tests/lib/Files/Config/UserMountCacheTest.php | 35 |
2 files changed, 101 insertions, 14 deletions
diff --git a/tests/Settings/Controller/UsersControllerTest.php b/tests/Settings/Controller/UsersControllerTest.php index 7186ce7bebd..0780f5219c0 100644 --- a/tests/Settings/Controller/UsersControllerTest.php +++ b/tests/Settings/Controller/UsersControllerTest.php @@ -19,6 +19,7 @@ use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Utility\ITimeFactory; use OCP\BackgroundJob\IJobList; +use OCP\Files\Config\IUserMountCache; use OCP\IAvatar; use OCP\IAvatarManager; use OCP\IConfig; @@ -79,6 +80,8 @@ class UsersControllerTest extends \Test\TestCase { private $jobList; /** @var \OC\Security\IdentityProof\Manager |\PHPUnit_Framework_MockObject_MockObject */ private $securityManager; + /** @var IUserMountCache |\PHPUnit_Framework_MockObject_MockObject */ + private $userMountCache; protected function setUp() { parent::setUp(); @@ -106,6 +109,7 @@ class UsersControllerTest extends \Test\TestCase { ->will($this->returnCallback(function ($text, $parameters = []) { return vsprintf($text, $parameters); })); + $this->userMountCache = $this->createMock(IUserMountCache::class); /* * Set default avatar behaviour for whole test suite @@ -149,7 +153,8 @@ class UsersControllerTest extends \Test\TestCase { $this->timeFactory, $this->crypto, $this->securityManager, - $this->jobList + $this->jobList, + $this->userMountCache ); } else { @@ -175,7 +180,8 @@ class UsersControllerTest extends \Test\TestCase { $this->timeFactory, $this->crypto, $this->securityManager, - $this->jobList + $this->jobList, + $this->userMountCache, ] )->setMethods($mockedMethods)->getMock(); } @@ -198,7 +204,7 @@ class UsersControllerTest extends \Test\TestCase { ->method('getEMailAddress') ->will($this->returnValue('foo@bar.com')); $foo - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getQuota') ->will($this->returnValue('1024')); $foo @@ -228,7 +234,7 @@ class UsersControllerTest extends \Test\TestCase { ->method('getEMailAddress') ->will($this->returnValue('admin@bar.com')); $admin - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getQuota') ->will($this->returnValue('404')); $admin @@ -260,7 +266,7 @@ class UsersControllerTest extends \Test\TestCase { ->method('getEMailAddress') ->will($this->returnValue('bar@dummy.com')); $bar - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getQuota') ->will($this->returnValue('2323')); $bar @@ -331,6 +337,11 @@ class UsersControllerTest extends \Test\TestCase { ->method('getSubAdmin') ->will($this->returnValue($subadmin)); + $this->userMountCache + ->expects($this->once()) + ->method('getUsedSpaceForUsers') + ->will($this->returnValue(['admin' => 200, 'bar' => 2000, 'foo' => 512])); + $expectedResponse = new DataResponse( array( 0 => array( @@ -339,6 +350,7 @@ class UsersControllerTest extends \Test\TestCase { 'groups' => array('Users', 'Support'), 'subadmin' => array(), 'quota' => 1024, + 'quota_bytes' => 1024, 'storageLocation' => '/home/foo', 'lastLogin' => 500000, 'backend' => 'OC_User_Database', @@ -346,6 +358,7 @@ class UsersControllerTest extends \Test\TestCase { 'isRestoreDisabled' => false, 'isAvatarAvailable' => true, 'isEnabled' => true, + 'size' => 512, ), 1 => array( 'name' => 'admin', @@ -353,6 +366,7 @@ class UsersControllerTest extends \Test\TestCase { 'groups' => array('admins', 'Support'), 'subadmin' => array(), 'quota' => 404, + 'quota_bytes' => 404, 'storageLocation' => '/home/admin', 'lastLogin' => 12000, 'backend' => Dummy::class, @@ -360,6 +374,7 @@ class UsersControllerTest extends \Test\TestCase { 'isRestoreDisabled' => false, 'isAvatarAvailable' => false, 'isEnabled' => true, + 'size' => 200, ), 2 => array( 'name' => 'bar', @@ -367,6 +382,7 @@ class UsersControllerTest extends \Test\TestCase { 'groups' => array('External Users'), 'subadmin' => array(), 'quota' => 2323, + 'quota_bytes' => 2323, 'storageLocation' => '/home/bar', 'lastLogin' => 3999000, 'backend' => Dummy::class, @@ -374,6 +390,7 @@ class UsersControllerTest extends \Test\TestCase { 'isRestoreDisabled' => false, 'isAvatarAvailable' => true, 'isEnabled' => false, + 'size' => 2000, ), ) ); @@ -404,7 +421,7 @@ class UsersControllerTest extends \Test\TestCase { ->method('getEMailAddress') ->will($this->returnValue('foo@bar.com')); $foo - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getQuota') ->will($this->returnValue('1024')); $foo @@ -434,7 +451,7 @@ class UsersControllerTest extends \Test\TestCase { ->method('getEMailAddress') ->will($this->returnValue('admin@bar.com')); $admin - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getQuota') ->will($this->returnValue('404')); $admin @@ -466,7 +483,7 @@ class UsersControllerTest extends \Test\TestCase { ->method('getEMailAddress') ->will($this->returnValue('bar@dummy.com')); $bar - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getQuota') ->will($this->returnValue('2323')); $bar @@ -545,6 +562,11 @@ class UsersControllerTest extends \Test\TestCase { ->method('getSubAdmin') ->will($this->returnValue($subadmin)); + $this->userMountCache + ->expects($this->once()) + ->method('getUsedSpaceForUsers') + ->will($this->returnValue(['admin' => 200, 'bar' => 2000, 'foo' => 512])); + $expectedResponse = new DataResponse( [ 0 => [ @@ -553,6 +575,7 @@ class UsersControllerTest extends \Test\TestCase { 'groups' => ['SubGroup1'], 'subadmin' => [], 'quota' => 2323, + 'quota_bytes' => 2323, 'storageLocation' => '/home/bar', 'lastLogin' => 3999000, 'backend' => Dummy::class, @@ -560,6 +583,7 @@ class UsersControllerTest extends \Test\TestCase { 'isRestoreDisabled' => false, 'isAvatarAvailable' => true, 'isEnabled' => true, + 'size' => 2000, ], 1=> [ 'name' => 'foo', @@ -567,6 +591,7 @@ class UsersControllerTest extends \Test\TestCase { 'groups' => ['SubGroup2', 'SubGroup1'], 'subadmin' => [], 'quota' => 1024, + 'quota_bytes' => 1024, 'storageLocation' => '/home/foo', 'lastLogin' => 500000, 'backend' => 'OC_User_Database', @@ -574,6 +599,7 @@ class UsersControllerTest extends \Test\TestCase { 'isRestoreDisabled' => false, 'isAvatarAvailable' => true, 'isEnabled' => true, + 'size' => 512, ], 2 => [ 'name' => 'admin', @@ -581,6 +607,7 @@ class UsersControllerTest extends \Test\TestCase { 'groups' => ['SubGroup2'], 'subadmin' => [], 'quota' => 404, + 'quota_bytes' => 404, 'storageLocation' => '/home/admin', 'lastLogin' => 12000, 'backend' => Dummy::class, @@ -588,6 +615,7 @@ class UsersControllerTest extends \Test\TestCase { 'isRestoreDisabled' => false, 'isAvatarAvailable' => false, 'isEnabled' => true, + 'size' => 200, ], ] ); @@ -617,7 +645,7 @@ class UsersControllerTest extends \Test\TestCase { ->method('getEMailAddress') ->will($this->returnValue('foo@bar.com')); $foo - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getQuota') ->will($this->returnValue('1024')); $foo @@ -647,7 +675,7 @@ class UsersControllerTest extends \Test\TestCase { ->method('getEMailAddress') ->will($this->returnValue('admin@bar.com')); $admin - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getQuota') ->will($this->returnValue('404')); $admin @@ -679,7 +707,7 @@ class UsersControllerTest extends \Test\TestCase { ->method('getEMailAddress') ->will($this->returnValue('bar@dummy.com')); $bar - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getQuota') ->will($this->returnValue('2323')); $bar @@ -717,6 +745,11 @@ class UsersControllerTest extends \Test\TestCase { ->method('getSubAdmin') ->will($this->returnValue($subadmin)); + $this->userMountCache + ->expects($this->once()) + ->method('getUsedSpaceForUsers') + ->will($this->returnValue(['admin' => 200, 'bar' => 2000, 'foo' => 512])); + $expectedResponse = new DataResponse( array( 0 => array( @@ -725,6 +758,7 @@ class UsersControllerTest extends \Test\TestCase { 'groups' => array('Users', 'Support'), 'subadmin' => array(), 'quota' => 1024, + 'quota_bytes' => 1024, 'storageLocation' => '/home/foo', 'lastLogin' => 500000, 'backend' => 'OC_User_Database', @@ -732,6 +766,7 @@ class UsersControllerTest extends \Test\TestCase { 'isRestoreDisabled' => false, 'isAvatarAvailable' => true, 'isEnabled' => true, + 'size' => 512, ), 1 => array( 'name' => 'admin', @@ -739,6 +774,7 @@ class UsersControllerTest extends \Test\TestCase { 'groups' => array('admins', 'Support'), 'subadmin' => array(), 'quota' => 404, + 'quota_bytes' => 404, 'storageLocation' => '/home/admin', 'lastLogin' => 12000, 'backend' => Dummy::class, @@ -746,6 +782,7 @@ class UsersControllerTest extends \Test\TestCase { 'isRestoreDisabled' => false, 'isAvatarAvailable' => false, 'isEnabled' => true, + 'size' => 200, ), 2 => array( 'name' => 'bar', @@ -753,6 +790,7 @@ class UsersControllerTest extends \Test\TestCase { 'groups' => array('External Users'), 'subadmin' => array(), 'quota' => 2323, + 'quota_bytes' => 2323, 'storageLocation' => '/home/bar', 'lastLogin' => 3999000, 'backend' => Dummy::class, @@ -760,6 +798,7 @@ class UsersControllerTest extends \Test\TestCase { 'isRestoreDisabled' => false, 'isAvatarAvailable' => true, 'isEnabled' => true, + 'size' => 2000, ), ) ); @@ -784,7 +823,7 @@ class UsersControllerTest extends \Test\TestCase { ->method('getEMailAddress') ->will($this->returnValue(null)); $user - ->expects($this->once()) + ->expects($this->exactly(2)) ->method('getQuota') ->will($this->returnValue('none')); $user @@ -825,6 +864,11 @@ class UsersControllerTest extends \Test\TestCase { ->method('getSubAdmin') ->will($this->returnValue($subadmin)); + $this->userMountCache + ->expects($this->once()) + ->method('getUsedSpaceForUsers') + ->will($this->returnValue(['foo' => 512])); + $expectedResponse = new DataResponse( array( 0 => array( @@ -833,6 +877,7 @@ class UsersControllerTest extends \Test\TestCase { 'groups' => null, 'subadmin' => array(), 'quota' => 'none', + 'quota_bytes' => 0, 'storageLocation' => '/home/foo', 'lastLogin' => 500000, 'backend' => 'OC_User_Database', @@ -840,6 +885,7 @@ class UsersControllerTest extends \Test\TestCase { 'isRestoreDisabled' => false, 'isAvatarAvailable' => true, 'isEnabled' => true, + 'size' => 512, ) ) ); @@ -860,6 +906,11 @@ class UsersControllerTest extends \Test\TestCase { ->with('') ->will($this->returnValue([])); + $this->userMountCache + ->expects($this->once()) + ->method('getUsedSpaceForUsers') + ->will($this->returnValue([])); + $expectedResponse = new DataResponse([]); $response = $controller->index(0, 10, '','', Dummy::class); $this->assertEquals($expectedResponse, $response); @@ -915,6 +966,7 @@ class UsersControllerTest extends \Test\TestCase { 'isRestoreDisabled' => false, 'isAvatarAvailable' => true, 'isEnabled' => true, + 'quota_bytes' => false, ), Http::STATUS_CREATED ); @@ -1001,6 +1053,7 @@ class UsersControllerTest extends \Test\TestCase { 'isRestoreDisabled' => false, 'isAvatarAvailable' => true, 'isEnabled' => true, + 'quota_bytes' => false, ), Http::STATUS_CREATED ); @@ -1093,6 +1146,7 @@ class UsersControllerTest extends \Test\TestCase { 'isRestoreDisabled' => false, 'isAvatarAvailable' => true, 'isEnabled' => true, + 'quota_bytes' => false, ), Http::STATUS_CREATED ); @@ -1560,6 +1614,7 @@ class UsersControllerTest extends \Test\TestCase { 'isRestoreDisabled' => false, 'isAvatarAvailable' => true, 'isEnabled' => $enabled, + 'quota_bytes' => false, ]; return [$user, $result]; @@ -2393,6 +2448,7 @@ class UsersControllerTest extends \Test\TestCase { 'lastLogin' => 0, 'displayname' => 'John Doe', 'quota' => null, + 'quota_bytes' => false, 'subadmin' => array(), 'email' => 'abc@example.org', 'isRestoreDisabled' => false, diff --git a/tests/lib/Files/Config/UserMountCacheTest.php b/tests/lib/Files/Config/UserMountCacheTest.php index f38bd3fcdc3..f455dc987af 100644 --- a/tests/lib/Files/Config/UserMountCacheTest.php +++ b/tests/lib/Files/Config/UserMountCacheTest.php @@ -13,6 +13,7 @@ use OC\Files\Mount\MountPoint; use OC\Log; use OC\User\Manager; use OCP\Files\Config\ICachedMountInfo; +use OC\Files\Storage\Storage; use OCP\IConfig; use OCP\IDBConnection; use OCP\IUserManager; @@ -310,7 +311,7 @@ class UserMountCacheTest extends TestCase { }); } - private function createCacheEntry($internalPath, $storageId) { + private function createCacheEntry($internalPath, $storageId, $size = 0) { $internalPath = trim($internalPath, '/'); $inserted = $this->connection->insertIfNotExist('*PREFIX*filecache', [ 'storage' => $storageId, @@ -320,7 +321,7 @@ class UserMountCacheTest extends TestCase { 'name' => basename($internalPath), 'mimetype' => 0, 'mimepart' => 0, - 'size' => 0, + 'size' => $size, 'storage_mtime' => 0, 'encrypted' => 0, 'unencrypted_size' => 0, @@ -455,4 +456,34 @@ class UserMountCacheTest extends TestCase { $cachedMounts = $this->cache->getMountsForFileId($rootId); $this->assertEmpty($cachedMounts); } + + public function testGetUsedSpaceForUsers() { + $user1 = $this->userManager->get('u1'); + $user2 = $this->userManager->get('u2'); + + /** @var Storage $storage1 */ + list($storage1, $rootId) = $this->getStorage(2); + $folderId = $this->createCacheEntry('files', 2, 100); + $fileId = $this->createCacheEntry('files/foo', 2, 7); + $storage1->getCache()->put($folderId, ['size' => 100]); + $storage1->getCache()->update($fileId, ['size' => 70]); + + $mount1 = $this->getMockBuilder(MountPoint::class) + ->setConstructorArgs([$storage1, '/u1/']) + ->setMethods(['getStorageRootId', 'getNumericStorageId']) + ->getMock(); + + $mount1->expects($this->any()) + ->method('getStorageRootId') + ->will($this->returnValue($rootId)); + + $mount1->expects($this->any()) + ->method('getNumericStorageId') + ->will($this->returnValue(2)); + + $this->cache->registerMounts($user1, [$mount1]); + + $result = $this->cache->getUsedSpaceForUsers([$user1, $user2]); + $this->assertEquals(['u1' => 100], $result); + } } |