diff options
Diffstat (limited to 'apps/provisioning_api/tests/Controller/UsersControllerTest.php')
-rw-r--r-- | apps/provisioning_api/tests/Controller/UsersControllerTest.php | 135 |
1 files changed, 83 insertions, 52 deletions
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index 2eb3853d333..57e1d2eac66 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -70,12 +70,6 @@ class UsersControllerTest extends TestCase { protected $accountManager; /** @var IRequest|PHPUnit_Framework_MockObject_MockObject */ protected $request; - /** @var IURLGenerator|PHPUnit_Framework_MockObject_MockObject */ - private $urlGenerator; - /** @var IMailer|PHPUnit_Framework_MockObject_MockObject */ - private $mailer; - /** @var Defaults|PHPUnit_Framework_MockObject_MockObject */ - private $defaults; /** @var IFactory|PHPUnit_Framework_MockObject_MockObject */ private $l10nFactory; /** @var NewUserMailHelper|PHPUnit_Framework_MockObject_MockObject */ @@ -91,9 +85,6 @@ class UsersControllerTest extends TestCase { $this->logger = $this->createMock(ILogger::class); $this->request = $this->createMock(IRequest::class); $this->accountManager = $this->createMock(AccountManager::class); - $this->urlGenerator = $this->createMock(IURLGenerator::class); - $this->mailer = $this->createMock(IMailer::class); - $this->defaults = $this->createMock(Defaults::class); $this->l10nFactory = $this->createMock(IFactory::class); $this->newUserMailHelper = $this->createMock(NewUserMailHelper::class); @@ -107,10 +98,6 @@ class UsersControllerTest extends TestCase { $this->userSession, $this->accountManager, $this->logger, - 'test@example.org', - $this->urlGenerator, - $this->mailer, - $this->defaults, $this->l10nFactory, $this->newUserMailHelper ]) @@ -705,19 +692,19 @@ class UsersControllerTest extends TestCase { $this->config ->expects($this->at(0)) ->method('getUserValue') - ->with('UserToGet', 'core', 'enabled', 'true') + ->with('UID', 'core', 'enabled', 'true') ->will($this->returnValue('true')); $this->api ->expects($this->once()) ->method('fillStorageInfo') - ->with('UserToGet') + ->with('UID') ->will($this->returnValue(['DummyValue'])); $targetUser ->expects($this->once()) ->method('getDisplayName') ->will($this->returnValue('Demo User')); $targetUser - ->expects($this->once()) + ->expects($this->exactly(3)) ->method('getUID') ->will($this->returnValue('UID')); @@ -784,19 +771,19 @@ class UsersControllerTest extends TestCase { $this->config ->expects($this->at(0)) ->method('getUserValue') - ->with('UserToGet', 'core', 'enabled', 'true') + ->with('UID', 'core', 'enabled', 'true') ->will($this->returnValue('true')); $this->api ->expects($this->once()) ->method('fillStorageInfo') - ->with('UserToGet') + ->with('UID') ->will($this->returnValue(['DummyValue'])); $targetUser ->expects($this->once()) ->method('getDisplayName') ->will($this->returnValue('Demo User')); $targetUser - ->expects($this->once()) + ->expects($this->exactly(3)) ->method('getUID') ->will($this->returnValue('UID')); $this->accountManager->expects($this->any())->method('getUser') @@ -878,7 +865,7 @@ class UsersControllerTest extends TestCase { $loggedInUser ->expects($this->exactly(2)) ->method('getUID') - ->will($this->returnValue('subadmin')); + ->will($this->returnValue('UID')); $targetUser = $this->getMockBuilder(IUser::class) ->disableOriginalConstructor() ->getMock(); @@ -894,7 +881,7 @@ class UsersControllerTest extends TestCase { $this->groupManager ->expects($this->once()) ->method('isAdmin') - ->with('subadmin') + ->with('UID') ->will($this->returnValue(false)); $subAdminManager = $this->getMockBuilder('OC\SubAdmin') ->disableOriginalConstructor() @@ -915,7 +902,7 @@ class UsersControllerTest extends TestCase { $this->api ->expects($this->once()) ->method('fillStorageInfo') - ->with('subadmin') + ->with('UID') ->will($this->returnValue(['DummyValue'])); $targetUser ->expects($this->once()) @@ -926,7 +913,7 @@ class UsersControllerTest extends TestCase { ->method('getEMailAddress') ->will($this->returnValue('subadmin@owncloud.org')); $targetUser - ->expects($this->once()) + ->expects($this->exactly(3)) ->method('getUID') ->will($this->returnValue('UID')); $this->accountManager->expects($this->any())->method('getUser') @@ -961,7 +948,7 @@ class UsersControllerTest extends TestCase { $loggedInUser ->expects($this->any()) ->method('getUID') - ->will($this->returnValue('UserToEdit')); + ->will($this->returnValue('UID')); $targetUser = $this->getMockBuilder(IUser::class) ->disableOriginalConstructor() ->getMock(); @@ -978,6 +965,10 @@ class UsersControllerTest extends TestCase { ->expects($this->once()) ->method('setDisplayName') ->with('NewDisplayName'); + $targetUser + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('UID')); $this->assertEquals([], $this->api->editUser('UserToEdit', 'display', 'NewDisplayName')->getData()); } @@ -989,7 +980,7 @@ class UsersControllerTest extends TestCase { $loggedInUser ->expects($this->any()) ->method('getUID') - ->will($this->returnValue('UserToEdit')); + ->will($this->returnValue('UID')); $targetUser = $this->getMockBuilder(IUser::class) ->disableOriginalConstructor() ->getMock(); @@ -1006,6 +997,10 @@ class UsersControllerTest extends TestCase { ->expects($this->once()) ->method('setEMailAddress') ->with('demo@owncloud.org'); + $targetUser + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('UID')); $this->assertEquals([], $this->api->editUser('UserToEdit', 'email', 'demo@owncloud.org')->getData()); } @@ -1022,7 +1017,7 @@ class UsersControllerTest extends TestCase { $loggedInUser ->expects($this->any()) ->method('getUID') - ->will($this->returnValue('UserToEdit')); + ->will($this->returnValue('UID')); $targetUser = $this->getMockBuilder(IUser::class) ->disableOriginalConstructor() ->getMock(); @@ -1035,6 +1030,10 @@ class UsersControllerTest extends TestCase { ->method('get') ->with('UserToEdit') ->will($this->returnValue($targetUser)); + $targetUser + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('UID')); $this->api->editUser('UserToEdit', 'email', 'demo.org'); } @@ -1046,7 +1045,7 @@ class UsersControllerTest extends TestCase { $loggedInUser ->expects($this->any()) ->method('getUID') - ->will($this->returnValue('UserToEdit')); + ->will($this->returnValue('UID')); $targetUser = $this->getMockBuilder(IUser::class) ->disableOriginalConstructor() ->getMock(); @@ -1063,6 +1062,10 @@ class UsersControllerTest extends TestCase { ->expects($this->once()) ->method('setPassword') ->with('NewPassword'); + $targetUser + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('UID')); $this->assertEquals([], $this->api->editUser('UserToEdit', 'password', 'NewPassword')->getData()); } @@ -1079,7 +1082,7 @@ class UsersControllerTest extends TestCase { $loggedInUser ->expects($this->any()) ->method('getUID') - ->will($this->returnValue('UserToEdit')); + ->will($this->returnValue('UID')); $targetUser = $this->getMockBuilder(IUser::class) ->disableOriginalConstructor() ->getMock(); @@ -1092,6 +1095,10 @@ class UsersControllerTest extends TestCase { ->method('get') ->with('UserToEdit') ->will($this->returnValue($targetUser)); + $targetUser + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('UID')); $this->api->editUser('UserToEdit', 'quota', 'NewQuota'); } @@ -1101,7 +1108,7 @@ class UsersControllerTest extends TestCase { $loggedInUser ->expects($this->any()) ->method('getUID') - ->will($this->returnValue('UserToEdit')); + ->will($this->returnValue('UID')); $targetUser = $this->getMockBuilder('\OCP\IUser')->disableOriginalConstructor()->getMock(); $targetUser->expects($this->once()) ->method('setQuota') @@ -1118,8 +1125,12 @@ class UsersControllerTest extends TestCase { $this->groupManager ->expects($this->once()) ->method('isAdmin') - ->with('UserToEdit') + ->with('UID') ->will($this->returnValue(true)); + $targetUser + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('UID')); $this->assertEquals([], $this->api->editUser('UserToEdit', 'quota', '3042824')->getData()); } @@ -1135,7 +1146,7 @@ class UsersControllerTest extends TestCase { $loggedInUser ->expects($this->any()) ->method('getUID') - ->will($this->returnValue('UserToEdit')); + ->will($this->returnValue('UID')); $targetUser = $this->getMockBuilder('\OCP\IUser')->disableOriginalConstructor()->getMock(); $this->userSession ->expects($this->once()) @@ -1149,8 +1160,12 @@ class UsersControllerTest extends TestCase { $this->groupManager ->expects($this->once()) ->method('isAdmin') - ->with('UserToEdit') + ->with('UID') ->will($this->returnValue(true)); + $targetUser + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('UID')); $this->api->editUser('UserToEdit', 'quota', 'ABC'); } @@ -1186,6 +1201,10 @@ class UsersControllerTest extends TestCase { ->expects($this->once()) ->method('getSubAdmin') ->will($this->returnValue($subAdminManager)); + $targetUser + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('UID')); $this->assertEquals([], $this->api->editUser('UserToEdit', 'quota', '3042824')->getData()); } @@ -1221,6 +1240,10 @@ class UsersControllerTest extends TestCase { ->expects($this->once()) ->method('getSubAdmin') ->will($this->returnValue($subAdminManager)); + $targetUser + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('UID')); $this->assertEquals([], $this->api->editUser('UserToEdit', 'quota', '3042824')->getData()); } @@ -1257,6 +1280,10 @@ class UsersControllerTest extends TestCase { ->expects($this->once()) ->method('getSubAdmin') ->will($this->returnValue($subAdminManager)); + $targetUser + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('UID')); $this->api->editUser('UserToEdit', 'quota', 'value'); } @@ -1293,12 +1320,12 @@ class UsersControllerTest extends TestCase { $loggedInUser ->expects($this->any()) ->method('getUID') - ->will($this->returnValue('UserToDelete')); + ->will($this->returnValue('UID')); $targetUser = $this->getMockBuilder('\OCP\IUser')->disableOriginalConstructor()->getMock(); $targetUser ->expects($this->once()) ->method('getUID') - ->will($this->returnValue('UserToDelete')); + ->will($this->returnValue('UID')); $this->userSession ->expects($this->once()) ->method('getUser') @@ -1322,7 +1349,7 @@ class UsersControllerTest extends TestCase { $targetUser ->expects($this->once()) ->method('getUID') - ->will($this->returnValue('UserToDelete')); + ->will($this->returnValue('UID')); $this->userSession ->expects($this->once()) ->method('getUser') @@ -1359,7 +1386,7 @@ class UsersControllerTest extends TestCase { $targetUser ->expects($this->once()) ->method('getUID') - ->will($this->returnValue('UserToDelete')); + ->will($this->returnValue('UID')); $this->userSession ->expects($this->once()) ->method('getUser') @@ -1392,7 +1419,7 @@ class UsersControllerTest extends TestCase { $targetUser ->expects($this->once()) ->method('getUID') - ->will($this->returnValue('UserToDelete')); + ->will($this->returnValue('UID')); $this->userSession ->expects($this->once()) ->method('getUser') @@ -1440,7 +1467,7 @@ class UsersControllerTest extends TestCase { $targetUser ->expects($this->once()) ->method('getUID') - ->will($this->returnValue('UserToDelete')); + ->will($this->returnValue('UID')); $this->userSession ->expects($this->once()) ->method('getUser') @@ -1488,7 +1515,7 @@ class UsersControllerTest extends TestCase { $targetUser ->expects($this->once()) ->method('getUID') - ->will($this->returnValue('UserToDelete')); + ->will($this->returnValue('UID')); $this->userSession ->expects($this->once()) ->method('getUser') @@ -1984,6 +2011,10 @@ class UsersControllerTest extends TestCase { ->method('getUID') ->will($this->returnValue('admin')); $targetUser = $this->getMockBuilder('\OCP\IUser')->disableOriginalConstructor()->getMock(); + $targetUser + ->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('admin')); $targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock(); $targetGroup ->expects($this->once()) @@ -2001,7 +2032,7 @@ class UsersControllerTest extends TestCase { $this->userManager ->expects($this->once()) ->method('get') - ->with('admin') + ->with('Admin') ->will($this->returnValue($targetUser)); $subAdminManager = $this->getMockBuilder('OC\SubAdmin') ->disableOriginalConstructor()->getMock(); @@ -2015,7 +2046,7 @@ class UsersControllerTest extends TestCase { ->with('admin') ->will($this->returnValue(true)); - $this->api->removeFromGroup('admin', 'admin'); + $this->api->removeFromGroup('Admin', 'admin'); } /** @@ -2030,6 +2061,10 @@ class UsersControllerTest extends TestCase { ->method('getUID') ->will($this->returnValue('subadmin')); $targetUser = $this->getMockBuilder('\OCP\IUser')->disableOriginalConstructor()->getMock(); + $targetUser + ->expects($this->once()) + ->method('getUID') + ->will($this->returnValue('subadmin')); $targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock(); $targetGroup ->expects($this->any()) @@ -2047,7 +2082,7 @@ class UsersControllerTest extends TestCase { $this->userManager ->expects($this->once()) ->method('get') - ->with('subadmin') + ->with('SubAdmin') ->will($this->returnValue($targetUser)); $subAdminManager = $this->getMockBuilder('OC\SubAdmin') ->disableOriginalConstructor()->getMock(); @@ -2066,7 +2101,7 @@ class UsersControllerTest extends TestCase { ->with('subadmin') ->will($this->returnValue(false)); - $this->api->removeFromGroup('subadmin', 'subadmin'); + $this->api->removeFromGroup('SubAdmin', 'subadmin'); } /** @@ -2190,7 +2225,7 @@ class UsersControllerTest extends TestCase { /** * @expectedException \OCP\AppFramework\OCS\OCSException * @expectedExceptionCode 102 - * @expectedExceptionMessage Group:NotExistingGroup does not exist + * @expectedExceptionMessage Group does not exist */ public function testAddSubAdminWithNotExistingTargetGroup() { @@ -2217,6 +2252,10 @@ class UsersControllerTest extends TestCase { public function testAddSubAdminToAdminGroup() { $targetUser = $this->getMockBuilder('\OCP\IUser')->disableOriginalConstructor()->getMock(); $targetGroup = $this->getMockBuilder('\OCP\IGroup')->disableOriginalConstructor()->getMock(); + $targetGroup + ->expects($this->once()) + ->method('getGID') + ->will($this->returnValue('admin')); $this->userManager ->expects($this->once()) ->method('get') @@ -2612,10 +2651,6 @@ class UsersControllerTest extends TestCase { $this->userSession, $this->accountManager, $this->logger, - '', - $this->urlGenerator, - $this->mailer, - $this->defaults, $this->l10nFactory, $this->newUserMailHelper ]) @@ -2676,10 +2711,6 @@ class UsersControllerTest extends TestCase { $this->userSession, $this->accountManager, $this->logger, - '', - $this->urlGenerator, - $this->mailer, - $this->defaults, $this->l10nFactory, $this->newUserMailHelper ]) |