-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Morris Jobke <[email protected]>
- Loading branch information
1 parent
96e1dab
commit 01da4b6
Showing
1 changed file
with
68 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
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 @@ protected function setUp() { | |
->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 @@ protected function getController($isAdmin = false, $mockedMethods = []) { | |
$this->timeFactory, | ||
$this->crypto, | ||
$this->securityManager, | ||
$this->jobList | ||
$this->jobList, | ||
$this->userMountCache | ||
|
||
); | ||
} else { | ||
|
@@ -175,7 +180,8 @@ protected function getController($isAdmin = false, $mockedMethods = []) { | |
$this->timeFactory, | ||
$this->crypto, | ||
$this->securityManager, | ||
$this->jobList | ||
$this->jobList, | ||
$this->userMountCache, | ||
] | ||
)->setMethods($mockedMethods)->getMock(); | ||
} | ||
|
@@ -198,7 +204,7 @@ public function testIndexAdmin() { | |
->method('getEMailAddress') | ||
->will($this->returnValue('[email protected]')); | ||
$foo | ||
->expects($this->once()) | ||
->expects($this->exactly(2)) | ||
->method('getQuota') | ||
->will($this->returnValue('1024')); | ||
$foo | ||
|
@@ -228,7 +234,7 @@ public function testIndexAdmin() { | |
->method('getEMailAddress') | ||
->will($this->returnValue('[email protected]')); | ||
$admin | ||
->expects($this->once()) | ||
->expects($this->exactly(2)) | ||
->method('getQuota') | ||
->will($this->returnValue('404')); | ||
$admin | ||
|
@@ -256,7 +262,7 @@ public function testIndexAdmin() { | |
->method('getDisplayName') | ||
->will($this->returnValue('B. Ar')); | ||
$bar | ||
->expects($this->once()) | ||
->expects($this->exactly(2)) | ||
->method('getEMailAddress') | ||
->will($this->returnValue('[email protected]')); | ||
$bar | ||
|
@@ -331,6 +337,11 @@ public function testIndexAdmin() { | |
->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,41 +350,47 @@ public function testIndexAdmin() { | |
'groups' => array('Users', 'Support'), | ||
'subadmin' => array(), | ||
'quota' => 1024, | ||
'quota_bytes' => 1024, | ||
'storageLocation' => '/home/foo', | ||
'lastLogin' => 500000, | ||
'backend' => 'OC_User_Database', | ||
'email' => '[email protected]', | ||
'isRestoreDisabled' => false, | ||
'isAvatarAvailable' => true, | ||
'isEnabled' => true, | ||
'size' => 512, | ||
), | ||
1 => array( | ||
'name' => 'admin', | ||
'displayname' => 'S. Admin', | ||
'groups' => array('admins', 'Support'), | ||
'subadmin' => array(), | ||
'quota' => 404, | ||
'quota_bytes' => 404, | ||
'storageLocation' => '/home/admin', | ||
'lastLogin' => 12000, | ||
'backend' => Dummy::class, | ||
'email' => '[email protected]', | ||
'isRestoreDisabled' => false, | ||
'isAvatarAvailable' => false, | ||
'isEnabled' => true, | ||
'size' => 200, | ||
), | ||
2 => array( | ||
'name' => 'bar', | ||
'displayname' => 'B. Ar', | ||
'groups' => array('External Users'), | ||
'subadmin' => array(), | ||
'quota' => 2323, | ||
'quota_bytes' => 2323, | ||
'storageLocation' => '/home/bar', | ||
'lastLogin' => 3999000, | ||
'backend' => Dummy::class, | ||
'email' => '[email protected]', | ||
'isRestoreDisabled' => false, | ||
'isAvatarAvailable' => true, | ||
'isEnabled' => false, | ||
'size' => 2000, | ||
), | ||
) | ||
); | ||
|
@@ -404,7 +421,7 @@ public function testIndexSubAdmin() { | |
->method('getEMailAddress') | ||
->will($this->returnValue('[email protected]')); | ||
$foo | ||
->expects($this->once()) | ||
->expects($this->exactly(2)) | ||
->method('getQuota') | ||
->will($this->returnValue('1024')); | ||
$foo | ||
|
@@ -434,7 +451,7 @@ public function testIndexSubAdmin() { | |
->method('getEMailAddress') | ||
->will($this->returnValue('[email protected]')); | ||
$admin | ||
->expects($this->once()) | ||
->expects($this->exactly(2)) | ||
->method('getQuota') | ||
->will($this->returnValue('404')); | ||
$admin | ||
|
@@ -466,7 +483,7 @@ public function testIndexSubAdmin() { | |
->method('getEMailAddress') | ||
->will($this->returnValue('[email protected]')); | ||
$bar | ||
->expects($this->once()) | ||
->expects($this->exactly(2)) | ||
->method('getQuota') | ||
->will($this->returnValue('2323')); | ||
$bar | ||
|
@@ -545,6 +562,11 @@ public function testIndexSubAdmin() { | |
->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,41 +575,47 @@ public function testIndexSubAdmin() { | |
'groups' => ['SubGroup1'], | ||
'subadmin' => [], | ||
'quota' => 2323, | ||
'quota_bytes' => 2323, | ||
'storageLocation' => '/home/bar', | ||
'lastLogin' => 3999000, | ||
'backend' => Dummy::class, | ||
'email' => '[email protected]', | ||
'isRestoreDisabled' => false, | ||
'isAvatarAvailable' => true, | ||
'isEnabled' => true, | ||
'size' => 2000, | ||
], | ||
1=> [ | ||
'name' => 'foo', | ||
'displayname' => 'M. Foo', | ||
'groups' => ['SubGroup2', 'SubGroup1'], | ||
'subadmin' => [], | ||
'quota' => 1024, | ||
'quota_bytes' => 1024, | ||
'storageLocation' => '/home/foo', | ||
'lastLogin' => 500000, | ||
'backend' => 'OC_User_Database', | ||
'email' => '[email protected]', | ||
'isRestoreDisabled' => false, | ||
'isAvatarAvailable' => true, | ||
'isEnabled' => true, | ||
'size' => 512, | ||
], | ||
2 => [ | ||
'name' => 'admin', | ||
'displayname' => 'S. Admin', | ||
'groups' => ['SubGroup2'], | ||
'subadmin' => [], | ||
'quota' => 404, | ||
'quota_bytes' => 404, | ||
'storageLocation' => '/home/admin', | ||
'lastLogin' => 12000, | ||
'backend' => Dummy::class, | ||
'email' => '[email protected]', | ||
'isRestoreDisabled' => false, | ||
'isAvatarAvailable' => false, | ||
'isEnabled' => true, | ||
'size' => 200, | ||
], | ||
] | ||
); | ||
|
@@ -617,7 +645,7 @@ public function testIndexWithSearch() { | |
->method('getEMailAddress') | ||
->will($this->returnValue('[email protected]')); | ||
$foo | ||
->expects($this->once()) | ||
->expects($this->exactly(2)) | ||
->method('getQuota') | ||
->will($this->returnValue('1024')); | ||
$foo | ||
|
@@ -647,7 +675,7 @@ public function testIndexWithSearch() { | |
->method('getEMailAddress') | ||
->will($this->returnValue('[email protected]')); | ||
$admin | ||
->expects($this->once()) | ||
->expects($this->exactly(2)) | ||
->method('getQuota') | ||
->will($this->returnValue('404')); | ||
$admin | ||
|
@@ -679,7 +707,7 @@ public function testIndexWithSearch() { | |
->method('getEMailAddress') | ||
->will($this->returnValue('[email protected]')); | ||
$bar | ||
->expects($this->once()) | ||
->expects($this->exactly(2)) | ||
->method('getQuota') | ||
->will($this->returnValue('2323')); | ||
$bar | ||
|
@@ -717,6 +745,11 @@ public function testIndexWithSearch() { | |
->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,41 +758,47 @@ public function testIndexWithSearch() { | |
'groups' => array('Users', 'Support'), | ||
'subadmin' => array(), | ||
'quota' => 1024, | ||
'quota_bytes' => 1024, | ||
'storageLocation' => '/home/foo', | ||
'lastLogin' => 500000, | ||
'backend' => 'OC_User_Database', | ||
'email' => '[email protected]', | ||
'isRestoreDisabled' => false, | ||
'isAvatarAvailable' => true, | ||
'isEnabled' => true, | ||
'size' => 512, | ||
), | ||
1 => array( | ||
'name' => 'admin', | ||
'displayname' => 'S. Admin', | ||
'groups' => array('admins', 'Support'), | ||
'subadmin' => array(), | ||
'quota' => 404, | ||
'quota_bytes' => 404, | ||
'storageLocation' => '/home/admin', | ||
'lastLogin' => 12000, | ||
'backend' => Dummy::class, | ||
'email' => '[email protected]', | ||
'isRestoreDisabled' => false, | ||
'isAvatarAvailable' => false, | ||
'isEnabled' => true, | ||
'size' => 200, | ||
), | ||
2 => array( | ||
'name' => 'bar', | ||
'displayname' => 'B. Ar', | ||
'groups' => array('External Users'), | ||
'subadmin' => array(), | ||
'quota' => 2323, | ||
'quota_bytes' => 2323, | ||
'storageLocation' => '/home/bar', | ||
'lastLogin' => 3999000, | ||
'backend' => Dummy::class, | ||
'email' => '[email protected]', | ||
'isRestoreDisabled' => false, | ||
'isAvatarAvailable' => true, | ||
'isEnabled' => true, | ||
'size' => 2000, | ||
), | ||
) | ||
); | ||
|
@@ -784,7 +823,7 @@ public function testIndexWithBackend() { | |
->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 @@ public function testIndexWithBackend() { | |
->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,13 +877,15 @@ public function testIndexWithBackend() { | |
'groups' => null, | ||
'subadmin' => array(), | ||
'quota' => 'none', | ||
'quota_bytes' => 0, | ||
'storageLocation' => '/home/foo', | ||
'lastLogin' => 500000, | ||
'backend' => 'OC_User_Database', | ||
'email' => null, | ||
'isRestoreDisabled' => false, | ||
'isAvatarAvailable' => true, | ||
'isEnabled' => true, | ||
'size' => 512, | ||
) | ||
) | ||
); | ||
|
@@ -860,6 +906,11 @@ public function testIndexWithBackendNoUser() { | |
->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 @@ public function testCreateSuccessfulWithoutGroupAdmin() { | |
'isRestoreDisabled' => false, | ||
'isAvatarAvailable' => true, | ||
'isEnabled' => true, | ||
'quota_bytes' => false, | ||
), | ||
Http::STATUS_CREATED | ||
); | ||
|
@@ -1001,6 +1053,7 @@ public function testCreateSuccessfulWithGroupAdmin() { | |
'isRestoreDisabled' => false, | ||
'isAvatarAvailable' => true, | ||
'isEnabled' => true, | ||
'quota_bytes' => false, | ||
), | ||
Http::STATUS_CREATED | ||
); | ||
|
@@ -1093,6 +1146,7 @@ public function testCreateSuccessfulWithGroupSubAdmin() { | |
'isRestoreDisabled' => false, | ||
'isAvatarAvailable' => true, | ||
'isEnabled' => true, | ||
'quota_bytes' => false, | ||
), | ||
Http::STATUS_CREATED | ||
); | ||
|
@@ -1560,6 +1614,7 @@ private function mockUser($userId = 'foo', $displayName = 'M. Foo', | |
'isRestoreDisabled' => false, | ||
'isAvatarAvailable' => true, | ||
'isEnabled' => $enabled, | ||
'quota_bytes' => false, | ||
]; | ||
|
||
return [$user, $result]; | ||
|
@@ -2393,6 +2448,7 @@ public function testCreateSuccessfulWithoutPasswordAndWithEmail() { | |
'lastLogin' => 0, | ||
'displayname' => 'John Doe', | ||
'quota' => null, | ||
'quota_bytes' => false, | ||
'subadmin' => array(), | ||
'email' => '[email protected]', | ||
'isRestoreDisabled' => false, | ||
|