Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Morris Jobke <[email protected]>
  • Loading branch information
MorrisJobke committed Jul 5, 2017
1 parent 96e1dab commit 01da4b6
Showing 1 changed file with 68 additions and 12 deletions.
80 changes: 68 additions & 12 deletions tests/Settings/Controller/UsersControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -149,7 +153,8 @@ protected function getController($isAdmin = false, $mockedMethods = []) {
$this->timeFactory,
$this->crypto,
$this->securityManager,
$this->jobList
$this->jobList,
$this->userMountCache

);
} else {
Expand All @@ -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();
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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,
),
)
);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 => [
Expand All @@ -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,
],
]
);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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,
),
)
);
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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,
)
)
);
Expand All @@ -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);
Expand Down Expand Up @@ -915,6 +966,7 @@ public function testCreateSuccessfulWithoutGroupAdmin() {
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
'isEnabled' => true,
'quota_bytes' => false,
),
Http::STATUS_CREATED
);
Expand Down Expand Up @@ -1001,6 +1053,7 @@ public function testCreateSuccessfulWithGroupAdmin() {
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
'isEnabled' => true,
'quota_bytes' => false,
),
Http::STATUS_CREATED
);
Expand Down Expand Up @@ -1093,6 +1146,7 @@ public function testCreateSuccessfulWithGroupSubAdmin() {
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
'isEnabled' => true,
'quota_bytes' => false,
),
Http::STATUS_CREATED
);
Expand Down Expand Up @@ -1560,6 +1614,7 @@ private function mockUser($userId = 'foo', $displayName = 'M. Foo',
'isRestoreDisabled' => false,
'isAvatarAvailable' => true,
'isEnabled' => $enabled,
'quota_bytes' => false,
];

return [$user, $result];
Expand Down Expand Up @@ -2393,6 +2448,7 @@ public function testCreateSuccessfulWithoutPasswordAndWithEmail() {
'lastLogin' => 0,
'displayname' => 'John Doe',
'quota' => null,
'quota_bytes' => false,
'subadmin' => array(),
'email' => '[email protected]',
'isRestoreDisabled' => false,
Expand Down

0 comments on commit 01da4b6

Please sign in to comment.