diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2018-04-19 00:12:06 +0200 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2018-07-31 13:33:55 +0200 |
commit | 36326e38a08a4269416b6defe460e2a65609ad9a (patch) | |
tree | a02d67c5a218b988b9220033b0c382bf0401061c /apps/provisioning_api/tests | |
parent | c39bc1638b812ef9660cfdb0ab6ca58d70ad68d8 (diff) | |
download | nextcloud-server-36326e38a08a4269416b6defe460e2a65609ad9a.tar.gz nextcloud-server-36326e38a08a4269416b6defe460e2a65609ad9a.zip |
Add optional "displayName" parameter to add user endpoint
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'apps/provisioning_api/tests')
-rw-r--r-- | apps/provisioning_api/tests/Controller/UsersControllerTest.php | 71 |
1 files changed, 64 insertions, 7 deletions
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index af4d5958b53..adbdb9d8685 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -247,7 +247,7 @@ class UsersControllerTest extends TestCase { ->with('adminUser') ->willReturn(true); - $this->api->addUser('AlreadyExistingUser', 'password', '', []); + $this->api->addUser('AlreadyExistingUser', 'password', '', '', []); } /** @@ -283,7 +283,7 @@ class UsersControllerTest extends TestCase { ->with('NonExistingGroup') ->willReturn(false); - $this->api->addUser('NewUser', 'pass', '', ['NonExistingGroup']); + $this->api->addUser('NewUser', 'pass', '', '', ['NonExistingGroup']); } /** @@ -325,7 +325,7 @@ class UsersControllerTest extends TestCase { ['NonExistingGroup', false] ])); - $this->api->addUser('NewUser', 'pass', '', ['ExistingGroup', 'NonExistingGroup']); + $this->api->addUser('NewUser', 'pass', '', '', ['ExistingGroup', 'NonExistingGroup']); } public function testAddUserSuccessful() { @@ -362,6 +362,63 @@ class UsersControllerTest extends TestCase { $this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser')->getData()); } + public function testAddUserSuccessfulWithDisplayName() { + $api = $this->getMockBuilder('OCA\Provisioning_API\Controller\UsersController') + ->setConstructorArgs([ + 'provisioning_api', + $this->request, + $this->userManager, + $this->config, + $this->appManager, + $this->groupManager, + $this->userSession, + $this->accountManager, + $this->logger, + $this->l10nFactory, + $this->newUserMailHelper, + $this->federatedFileSharingFactory, + $this->secureRandom + ]) + ->setMethods(['editUser']) + ->getMock(); + + $this->userManager + ->expects($this->once()) + ->method('userExists') + ->with('NewUser') + ->will($this->returnValue(false)); + $this->userManager + ->expects($this->once()) + ->method('createUser') + ->with('NewUser', 'PasswordOfTheNewUser'); + $this->logger + ->expects($this->once()) + ->method('info') + ->with('Successful addUser call with userid: NewUser', ['app' => 'ocs_api']); + $loggedInUser = $this->getMockBuilder(IUser::class) + ->disableOriginalConstructor() + ->getMock(); + $loggedInUser + ->expects($this->any()) + ->method('getUID') + ->will($this->returnValue('adminUser')); + $this->userSession + ->expects($this->any()) + ->method('getUser') + ->will($this->returnValue($loggedInUser)); + $this->groupManager + ->expects($this->once()) + ->method('isAdmin') + ->with('adminUser') + ->willReturn(true); + $api + ->expects($this->once()) + ->method('editUser') + ->with('NewUser', 'display', 'DisplayNameOfTheNewUser'); + + $this->assertEquals([], $api->addUser('NewUser', 'PasswordOfTheNewUser', 'DisplayNameOfTheNewUser')->getData()); + } + public function testAddUserExistingGroup() { $this->userManager ->expects($this->once()) @@ -417,7 +474,7 @@ class UsersControllerTest extends TestCase { ['Added userid NewUser to group ExistingGroup', ['app' => 'ocs_api']] ); - $this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', ['ExistingGroup'])->getData()); + $this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData()); } /** @@ -495,7 +552,7 @@ class UsersControllerTest extends TestCase { ->with() ->willReturn($subAdminManager); - $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', []); + $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', []); } /** @@ -544,7 +601,7 @@ class UsersControllerTest extends TestCase { ->with('ExistingGroup') ->willReturn(true); - $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', ['ExistingGroup'])->getData(); + $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup'])->getData(); } public function testAddUserAsSubAdminExistingGroups() { @@ -635,7 +692,7 @@ class UsersControllerTest extends TestCase { ) ->willReturn(true); - $this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', ['ExistingGroup1', 'ExistingGroup2'])->getData()); + $this->assertEquals([], $this->api->addUser('NewUser', 'PasswordOfTheNewUser', '', '', ['ExistingGroup1', 'ExistingGroup2'])->getData()); } /** |