diff options
author | Roeland Jago Douma <rullzer@owncloud.com> | 2015-10-20 13:34:41 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-10-21 11:41:25 +0200 |
commit | 02af4269f27d4d7b4a3a053e23a614738293be2b (patch) | |
tree | f8fd2684b6a26c5c61acd688894950aead824aa2 /tests/settings | |
parent | c515628ebe23d78170c699a63d9a2ca1100e5412 (diff) | |
download | nextcloud-server-02af4269f27d4d7b4a3a053e23a614738293be2b.tar.gz nextcloud-server-02af4269f27d4d7b4a3a053e23a614738293be2b.zip |
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
Diffstat (limited to 'tests/settings')
-rw-r--r-- | tests/settings/controller/userscontrollertest.php | 108 |
1 files changed, 93 insertions, 15 deletions
diff --git a/tests/settings/controller/userscontrollertest.php b/tests/settings/controller/userscontrollertest.php index 6fab43d6a16..408ddc45589 100644 --- a/tests/settings/controller/userscontrollertest.php +++ b/tests/settings/controller/userscontrollertest.php @@ -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); } |