Fix unit test

Now that OC_SubAdmin is just a wrapper around OC\SubAdmin some unit
tests had to be fixed because they expected different behaviour.

Eventually they should move to properly mocked instances of OC\SubAdmin
of course
This commit is contained in:
Roeland Jago Douma 2015-10-20 13:34:41 +02:00 committed by Thomas Müller
parent c515628ebe
commit 02af4269f2
2 changed files with 94 additions and 16 deletions

View File

@ -167,7 +167,7 @@ class UsersController extends Controller {
'name' => $user->getUID(),
'displayname' => $user->getDisplayName(),
'groups' => (empty($userGroups)) ? $this->groupManager->getUserGroupIds($user) : $userGroups,
'subadmin' => \OC_SubAdmin::getSubAdminsGroups($user->getUID()),
'subadmin' => $this->subAdminFactory->getSubAdminsOfGroups($user->getUID()),
'quota' => $this->config->getUserValue($user->getUID(), 'files', 'quota', 'default'),
'storageLocation' => $user->getHome(),
'lastLogin' => $user->getLastLogin() * 1000,

View File

@ -153,6 +153,22 @@ class UsersControllerTest extends \Test\TestCase {
404, 'admin@bar.com',
2323, 'bar@dummy.com'));
$this->container['SubAdminFactory']
->expects($this->at(0))
->method('getSubAdminsOfGroups')
->with('foo')
->will($this->returnValue([]));
$this->container['SubAdminFactory']
->expects($this->at(1))
->method('getSubAdminsOfGroups')
->with('admin')
->will($this->returnValue([]));
$this->container['SubAdminFactory']
->expects($this->at(2))
->method('getSubAdminsOfGroups')
->with('bar')
->will($this->returnValue([]));
$expectedResponse = new DataResponse(
array(
0 => array(
@ -199,11 +215,6 @@ class UsersControllerTest extends \Test\TestCase {
public function testIndexSubAdmin() {
$this->container['IsAdmin'] = false;
$this->container['SubAdminFactory']
->expects($this->once())
->method('getSubAdminsOfGroups')
->with('username')
->will($this->returnValue(['SubGroup1', 'SubGroup2']));
$user = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
@ -321,6 +332,15 @@ class UsersControllerTest extends \Test\TestCase {
2323, 'bar@dummy.com'
));
$this->container['SubAdminFactory']
->method('getSubAdminsOfGroups')
->will($this->returnValueMap([
['username' , ['SubGroup1', 'SubGroup2']],
['foo', []],
['admin', []],
['bar', []],
]));
$expectedResponse = new DataResponse(
[
0 => [
@ -452,6 +472,23 @@ class UsersControllerTest extends \Test\TestCase {
404, 'admin@bar.com',
2323, 'bar@dummy.com'));
$this->container['SubAdminFactory']
->expects($this->at(0))
->method('getSubAdminsOfGroups')
->with('foo')
->will($this->returnValue([]));
$this->container['SubAdminFactory']
->expects($this->at(1))
->method('getSubAdminsOfGroups')
->with('admin')
->will($this->returnValue([]));
$this->container['SubAdminFactory']
->expects($this->at(2))
->method('getSubAdminsOfGroups')
->with('bar')
->will($this->returnValue([]));
$expectedResponse = new DataResponse(
array(
0 => array(
@ -532,6 +569,12 @@ class UsersControllerTest extends \Test\TestCase {
->with('')
->will($this->returnValue([$user]));
$this->container['SubAdminFactory']
->expects($this->once())
->method('getSubAdminsOfGroups')
->with('foo')
->will($this->returnValue([]));
$expectedResponse = new DataResponse(
array(
0 => array(
@ -591,6 +634,11 @@ class UsersControllerTest extends \Test\TestCase {
->method('createUser')
->will($this->onConsecutiveCalls($user));
$this->container['SubAdminFactory']
->expects($this->once())
->method('getSubAdminsOfGroups')
->with('foo')
->will($this->returnValue([]));
$expectedResponse = new DataResponse(
array(
@ -613,11 +661,6 @@ class UsersControllerTest extends \Test\TestCase {
public function testCreateSuccessfulWithoutGroupSubAdmin() {
$this->container['IsAdmin'] = false;
$this->container['SubAdminFactory']
->expects($this->once())
->method('getSubAdminsOfGroups')
->with('username')
->will($this->returnValue(['SubGroup1', 'SubGroup2']));
$user = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$user
@ -671,6 +714,13 @@ class UsersControllerTest extends \Test\TestCase {
->with($user)
->will($this->onConsecutiveCalls(['SubGroup1', 'SubGroup2']));
$this->container['SubAdminFactory']
->method('getSubAdminsOfGroups')
->will($this->returnValueMap([
['username', ['SubGroup1', 'SubGroup2']],
['foo', []],
]));
$expectedResponse = new DataResponse(
array(
'name' => 'foo',
@ -740,6 +790,12 @@ class UsersControllerTest extends \Test\TestCase {
->with($user)
->will($this->onConsecutiveCalls(array('NewGroup', 'ExistingGroup')));
$this->container['SubAdminFactory']
->expects($this->once())
->method('getSubAdminsOfGroups')
->with('foo')
->will($this->returnValue([]));
$expectedResponse = new DataResponse(
array(
'name' => 'foo',
@ -761,11 +817,6 @@ class UsersControllerTest extends \Test\TestCase {
public function testCreateSuccessfulWithGroupSubAdmin() {
$this->container['IsAdmin'] = false;
$this->container['SubAdminFactory']
->expects($this->once())
->method('getSubAdminsOfGroups')
->with('username')
->will($this->returnValue(['SubGroup1', 'SubGroup2']));
$user = $this->getMockBuilder('\OC\User\User')
->disableOriginalConstructor()->getMock();
$user
@ -819,6 +870,13 @@ class UsersControllerTest extends \Test\TestCase {
->with($user)
->will($this->onConsecutiveCalls(['SubGroup1']));
$this->container['SubAdminFactory']
->method('getSubAdminsOfGroups')
->will($this->returnValueMap([
['username', ['SubGroup1', 'SubGroup2']],
['foo', []],
]));
$expectedResponse = new DataResponse(
array(
'name' => 'foo',
@ -1286,6 +1344,11 @@ class UsersControllerTest extends \Test\TestCase {
list($user, $expectedResult) = $this->mockUser();
$this->container['SubAdminFactory']
->method('getSubAdminsOfGroups')
->with($user->getUID())
->will($this->returnValue([]));
$result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]);
$this->assertEquals($expectedResult, $result);
}
@ -1323,6 +1386,11 @@ class UsersControllerTest extends \Test\TestCase {
)
->will($this->returnValue('1'));
$this->container['SubAdminFactory']
->method('getSubAdminsOfGroups')
->with($user->getUID())
->will($this->returnValue([]));
$result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]);
$this->assertEquals($expectedResult, $result);
}
@ -1341,6 +1409,11 @@ class UsersControllerTest extends \Test\TestCase {
$expectedResult['isRestoreDisabled'] = true;
$this->container['SubAdminFactory']
->method('getSubAdminsOfGroups')
->with($user->getUID())
->will($this->returnValue([]));
$result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]);
$this->assertEquals($expectedResult, $result);
}
@ -1380,6 +1453,11 @@ class UsersControllerTest extends \Test\TestCase {
$expectedResult['isRestoreDisabled'] = true;
$this->container['SubAdminFactory']
->method('getSubAdminsOfGroups')
->with($user->getUID())
->will($this->returnValue([]));
$result = self::invokePrivate($this->container['UsersController'], 'formatUserForIndex', [$user]);
$this->assertEquals($expectedResult, $result);
}