summaryrefslogtreecommitdiffstats
path: root/apps/provisioning_api/tests/Controller/UsersControllerTest.php
diff options
context:
space:
mode:
authorArthur Schiwon <blizzz@arthur-schiwon.de>2021-05-08 01:10:32 +0200
committerArthur Schiwon <blizzz@arthur-schiwon.de>2021-05-08 01:20:17 +0200
commit1e271e9f76a5378d719e699c828a530c95ece336 (patch)
treeee18684bb102a3899d5b8ac8be1f1a95abf12b5e /apps/provisioning_api/tests/Controller/UsersControllerTest.php
parent0ac4563ae4cf03b5c28daec82fc4631d1579c13a (diff)
downloadnextcloud-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/Controller/UsersControllerTest.php')
-rw-r--r--apps/provisioning_api/tests/Controller/UsersControllerTest.php67
1 files changed, 54 insertions, 13 deletions
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());
}