diff options
author | Joas Schilling <coding@schilljs.com> | 2021-04-08 13:28:13 +0200 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2021-04-28 18:29:18 +0000 |
commit | a1d746fe05048b3e23998254953eafe02e777b47 (patch) | |
tree | 4ad9274da8518fc761e316083fcc05d5b0b88583 /apps/provisioning_api/tests | |
parent | 97b9e8f0bcaa024cc373cce11ba1d44253737726 (diff) | |
download | nextcloud-server-a1d746fe05048b3e23998254953eafe02e777b47.tar.gz nextcloud-server-a1d746fe05048b3e23998254953eafe02e777b47.zip |
Only return display name as editable when the user backend allows it
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/provisioning_api/tests')
-rw-r--r-- | apps/provisioning_api/tests/Controller/UsersControllerTest.php | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index 2b4ca780625..c9b848f3014 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -67,6 +67,8 @@ use OCP\L10N\IFactory; use OCP\Mail\IEMailTemplate; use OCP\Security\Events\GenerateSecurePasswordEvent; use OCP\Security\ISecureRandom; +use OCP\User\Backend\IGetDisplayNameBackend; +use OCP\User\Backend\ISetDisplayNameBackend; use OCP\UserInterface; use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; @@ -1445,6 +1447,10 @@ class UsersControllerTest extends TestCase { ->willReturn($targetUser); $targetUser ->expects($this->once()) + ->method('getBackend') + ->willReturn($this->createMock(ISetDisplayNameBackend::class)); + $targetUser + ->expects($this->once()) ->method('setDisplayName') ->with('NewDisplayName'); $targetUser @@ -3716,20 +3722,27 @@ class UsersControllerTest extends TestCase { public function dataGetEditableFields() { return [ - [false, [ + [false, ISetDisplayNameBackend::class, [ IAccountManager::PROPERTY_PHONE, IAccountManager::PROPERTY_ADDRESS, IAccountManager::PROPERTY_WEBSITE, IAccountManager::PROPERTY_TWITTER, ]], - [ true, [ + [true, ISetDisplayNameBackend::class, [ IAccountManager::PROPERTY_DISPLAYNAME, IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_PHONE, IAccountManager::PROPERTY_ADDRESS, IAccountManager::PROPERTY_WEBSITE, IAccountManager::PROPERTY_TWITTER, - ]] + ]], + [true, IGetDisplayNameBackend::class, [ + IAccountManager::PROPERTY_EMAIL, + IAccountManager::PROPERTY_PHONE, + IAccountManager::PROPERTY_ADDRESS, + IAccountManager::PROPERTY_WEBSITE, + IAccountManager::PROPERTY_TWITTER, + ]], ]; } @@ -3737,9 +3750,10 @@ class UsersControllerTest extends TestCase { * @dataProvider dataGetEditableFields * * @param bool $allowedToChangeDisplayName + * @param string $userBackend * @param array $expected */ - public function testGetEditableFields(bool $allowedToChangeDisplayName, array $expected) { + public function testGetEditableFields(bool $allowedToChangeDisplayName, string $userBackend, array $expected) { $this->config ->method('getSystemValue') ->with( @@ -3747,8 +3761,19 @@ class UsersControllerTest extends TestCase { $this->anything() )->willReturn($allowedToChangeDisplayName); + $user = $this->createMock(IUser::class); + $this->userSession->method('getUser') + ->willReturn($user); + + $backend = $this->createMock($userBackend); + + $user->method('getUID') + ->willReturn('userId'); + $user->method('getBackend') + ->willReturn($backend); + $expectedResp = new DataResponse($expected); - $this->assertEquals($expectedResp, $this->api->getEditableFields()); + $this->assertEquals($expectedResp, $this->api->getEditableFields('userId')); } private function mockAccount($targetUser, $accountProperties) { |