diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-05-08 01:10:32 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-05-08 01:20:17 +0200 |
commit | 1e271e9f76a5378d719e699c828a530c95ece336 (patch) | |
tree | ee18684bb102a3899d5b8ac8be1f1a95abf12b5e /apps/provisioning_api/tests | |
parent | 0ac4563ae4cf03b5c28daec82fc4631d1579c13a (diff) | |
download | nextcloud-server-1e271e9f76a5378d719e699c828a530c95ece336.tar.gz nextcloud-server-1e271e9f76a5378d719e699c828a530c95ece336.zip |
provAPI to use only public API of IAccountManager
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/provisioning_api/tests')
-rw-r--r-- | apps/provisioning_api/tests/Controller/GroupsControllerTest.php | 20 | ||||
-rw-r--r-- | apps/provisioning_api/tests/Controller/UsersControllerTest.php | 67 |
2 files changed, 56 insertions, 31 deletions
diff --git a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php index 0624c9e0b75..b32b6e4d89b 100644 --- a/apps/provisioning_api/tests/Controller/GroupsControllerTest.php +++ b/apps/provisioning_api/tests/Controller/GroupsControllerTest.php @@ -30,7 +30,6 @@ namespace OCA\Provisioning_API\Tests\Controller; -use OC\Accounts\AccountManager; use OC\Group\Manager; use OC\SubAdmin; use OC\User\NoUserException; @@ -57,7 +56,7 @@ class GroupsControllerTest extends \Test\TestCase { protected $groupManager; /** @var IUserSession|\PHPUnit\Framework\MockObject\MockObject */ protected $userSession; - /** @var AccountManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IAccountManager|\PHPUnit\Framework\MockObject\MockObject */ protected $accountManager; /** @var LoggerInterface|\PHPUnit\Framework\MockObject\MockObject */ protected $logger; @@ -76,7 +75,7 @@ class GroupsControllerTest extends \Test\TestCase { $this->config = $this->createMock(IConfig::class); $this->groupManager = $this->createMock(Manager::class); $this->userSession = $this->createMock(IUserSession::class); - $this->accountManager = $this->createMock(AccountManager::class); + $this->accountManager = $this->createMock(IAccountManager::class); $this->l10nFactory = $this->createMock(IFactory::class); $this->logger = $this->createMock(LoggerInterface::class); @@ -181,19 +180,6 @@ class GroupsControllerTest extends \Test\TestCase { }); } - private function useAccountManager() { - $this->accountManager->expects($this->any()) - ->method('getUser') - ->willReturnCallback(function (IUser $user) { - return [ - IAccountManager::PROPERTY_PHONE => ['value' => '0800-call-' . $user->getUID()], - IAccountManager::PROPERTY_ADDRESS => ['value' => 'Holzweg 99, 0601 Herrera, Panama'], - IAccountManager::PROPERTY_WEBSITE => ['value' => 'https://' . $user->getUid() . '.pa'], - IAccountManager::PROPERTY_TWITTER => ['value' => '@' . $user->getUID()], - ]; - }); - } - public function dataGetGroups() { return [ [null, 0, 0], @@ -505,7 +491,6 @@ class GroupsControllerTest extends \Test\TestCase { $gid = 'ncg1'; $this->asAdmin(); - $this->useAccountManager(); $users = [ 'ncu1' => $this->createUser('ncu1'), # regular @@ -551,7 +536,6 @@ class GroupsControllerTest extends \Test\TestCase { $gid = 'Department A/B C/D'; $this->asAdmin(); - $this->useAccountManager(); $users = [ 'ncu1' => $this->createUser('ncu1'), # regular diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index 1afe9be4319..ed644f58cd8 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -41,7 +41,6 @@ namespace OCA\Provisioning_API\Tests\Controller; use Exception; -use OC\Accounts\AccountManager; use OC\Authentication\Token\RemoteWipe; use OC\Group\Manager; use OC\KnownUser\KnownUserService; @@ -88,7 +87,7 @@ class UsersControllerTest extends TestCase { protected $logger; /** @var UsersController|MockObject */ protected $api; - /** @var AccountManager|MockObject */ + /** @var IAccountManager|MockObject */ protected $accountManager; /** @var IURLGenerator|MockObject */ protected $urlGenerator; @@ -117,7 +116,7 @@ class UsersControllerTest extends TestCase { $this->userSession = $this->createMock(IUserSession::class); $this->logger = $this->createMock(LoggerInterface::class); $this->request = $this->createMock(IRequest::class); - $this->accountManager = $this->createMock(AccountManager::class); + $this->accountManager = $this->createMock(IAccountManager::class); $this->urlGenerator = $this->createMock(IURLGenerator::class); $this->l10nFactory = $this->createMock(IFactory::class); $this->newUserMailHelper = $this->createMock(NewUserMailHelper::class); @@ -1574,13 +1573,34 @@ class UsersControllerTest extends TestCase { ->method('getBackend') ->willReturn($backend); - $this->accountManager->expects($this->once()) - ->method('getUser') + $propertyMock = $this->createMock(IAccountProperty::class); + $propertyMock->expects($this->any()) + ->method('getName') + ->willReturn($propertyName); + $propertyMock->expects($this->any()) + ->method('getValue') + ->willReturn($oldValue); + $propertyMock->expects($this->once()) + ->method('setValue') + ->with($newValue) + ->willReturnSelf(); + $propertyMock->expects($this->any()) + ->method('getScope') + ->willReturn(IAccountManager::SCOPE_LOCAL); + + $accountMock = $this->createMock(IAccount::class); + $accountMock->expects($this->any()) + ->method('getProperty') + ->with($propertyName) + ->willReturn($propertyMock); + + $this->accountManager->expects($this->atLeastOnce()) + ->method('getAccount') ->with($loggedInUser) - ->willReturn([$propertyName => ['value' => $oldValue, 'scope' => IAccountManager::SCOPE_LOCAL]]); + ->willReturn($accountMock); $this->accountManager->expects($this->once()) - ->method('updateUser') - ->with($loggedInUser, [$propertyName => ['value' => $newValue, 'scope' => IAccountManager::SCOPE_LOCAL]], true); + ->method('updateAccount') + ->with($accountMock); $this->assertEquals([], $this->api->editUser('UserToEdit', $propertyName, $newValue)->getData()); } @@ -1624,13 +1644,34 @@ class UsersControllerTest extends TestCase { ->method('getBackend') ->willReturn($backend); - $this->accountManager->expects($this->once()) - ->method('getUser') + $propertyMock = $this->createMock(IAccountProperty::class); + $propertyMock->expects($this->any()) + ->method('getName') + ->willReturn($propertyName); + $propertyMock->expects($this->any()) + ->method('getValue') + ->willReturn('somevalue'); + $propertyMock->expects($this->any()) + ->method('getScope') + ->willReturn($oldScope); + $propertyMock->expects($this->atLeastOnce()) + ->method('setScope') + ->with($newScope) + ->willReturnSelf(); + + $accountMock = $this->createMock(IAccount::class); + $accountMock->expects($this->any()) + ->method('getProperty') + ->with($propertyName) + ->willReturn($propertyMock); + + $this->accountManager->expects($this->atLeastOnce()) + ->method('getAccount') ->with($loggedInUser) - ->willReturn([$propertyName => ['value' => 'somevalue', 'scope' => $oldScope]]); + ->willReturn($accountMock); $this->accountManager->expects($this->once()) - ->method('updateUser') - ->with($loggedInUser, [$propertyName => ['value' => 'somevalue', 'scope' => $newScope]], true); + ->method('updateAccount') + ->with($accountMock); $this->assertEquals([], $this->api->editUser('UserToEdit', $propertyName . 'Scope', $newScope)->getData()); } |