diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-06-15 20:32:39 +0300 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-06-30 01:41:11 +0300 |
commit | 638c04d6e08a9a1d859398a219771c08e0dcabf3 (patch) | |
tree | 668bbcc9ccfcefd9bb93ceb00aa1792cb22c7ebd /tests | |
parent | d109d4f58198b2ac35d590e59a45f948da23ca8e (diff) |
accounts event handler to use eventdispatcher, DI and Accounts API
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/lib/Accounts/HooksTest.php | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/tests/lib/Accounts/HooksTest.php b/tests/lib/Accounts/HooksTest.php index 8af9e209034..d5c7cd60b1b 100644 --- a/tests/lib/Accounts/HooksTest.php +++ b/tests/lib/Accounts/HooksTest.php @@ -23,7 +23,9 @@ namespace Test\Accounts; use OC\Accounts\AccountManager; use OC\Accounts\Hooks; +use OCP\Accounts\IAccount; use OCP\Accounts\IAccountManager; +use OCP\Accounts\IAccountProperty; use OCP\IUser; use PHPUnit\Framework\MockObject\MockObject; use Psr\Log\LoggerInterface; @@ -43,7 +45,7 @@ class HooksTest extends TestCase { /** @var AccountManager|MockObject */ private $accountManager; - /** @var Hooks|MockObject */ + /** @var Hooks */ private $hooks; protected function setUp(): void { @@ -53,12 +55,7 @@ class HooksTest extends TestCase { $this->accountManager = $this->getMockBuilder(AccountManager::class) ->disableOriginalConstructor()->getMock(); - $this->hooks = $this->getMockBuilder(Hooks::class) - ->setConstructorArgs([$this->logger]) - ->setMethods(['getAccountManager']) - ->getMock(); - - $this->hooks->method('getAccountManager')->willReturn($this->accountManager); + $this->hooks = new Hooks($this->logger, $this->accountManager); } /** @@ -72,48 +69,57 @@ class HooksTest extends TestCase { */ public function testChangeUserHook($params, $data, $setEmail, $setDisplayName, $error) { if ($error) { - $this->accountManager->expects($this->never())->method('getUser'); - $this->accountManager->expects($this->never())->method('updateUser'); + $this->accountManager->expects($this->never())->method('updateAccount'); } else { - $this->accountManager->expects($this->once())->method('getUser')->willReturn($data); - $newData = $data; + $account = $this->createMock(IAccount::class); + $this->accountManager->expects($this->atLeastOnce())->method('getAccount')->willReturn($account); if ($setEmail) { - $newData[IAccountManager::PROPERTY_EMAIL]['value'] = $params['value']; - $this->accountManager->expects($this->once())->method('updateUser') - ->with($params['user'], $newData); + $property = $this->createMock(IAccountProperty::class); + $property->expects($this->atLeastOnce()) + ->method('getValue') + ->willReturn($data[IAccountManager::PROPERTY_EMAIL]['value']); + $property->expects($this->atLeastOnce()) + ->method('setValue') + ->with($params['value']); + + $account->expects($this->atLeastOnce()) + ->method('getProperty') + ->with(IAccountManager::PROPERTY_EMAIL) + ->willReturn($property); + + $this->accountManager->expects($this->once()) + ->method('updateAccount') + ->with($account); } elseif ($setDisplayName) { - $newData[IAccountManager::PROPERTY_DISPLAYNAME]['value'] = $params['value']; - $this->accountManager->expects($this->once())->method('updateUser') - ->with($params['user'], $newData); + $property = $this->createMock(IAccountProperty::class); + $property->expects($this->atLeastOnce()) + ->method('getValue') + ->willReturn($data[IAccountManager::PROPERTY_DISPLAYNAME]['value']); + $property->expects($this->atLeastOnce()) + ->method('setValue') + ->with($params['value']); + + $account->expects($this->atLeastOnce()) + ->method('getProperty') + ->with(IAccountManager::PROPERTY_DISPLAYNAME) + ->willReturn($property); + + $this->accountManager->expects($this->once()) + ->method('updateAccount') + ->with($account); } else { - $this->accountManager->expects($this->never())->method('updateUser'); + $this->accountManager->expects($this->never())->method('updateAccount'); } } - $this->hooks->changeUserHook($params); + $this->hooks->changeUserHook($params['user'], $params['feature'], $params['value']); } public function dataTestChangeUserHook() { $user = $this->createMock(IUser::class); return [ [ - ['feature' => '', 'value' => ''], - [ - IAccountManager::PROPERTY_EMAIL => ['value' => ''], - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => ''] - ], - false, false, true - ], - [ - ['user' => $user, 'value' => ''], - [ - IAccountManager::PROPERTY_EMAIL => ['value' => ''], - IAccountManager::PROPERTY_DISPLAYNAME => ['value' => ''] - ], - false, false, true - ], - [ - ['user' => $user, 'feature' => ''], + ['user' => $user, 'feature' => '', 'value' => ''], [ IAccountManager::PROPERTY_EMAIL => ['value' => ''], IAccountManager::PROPERTY_DISPLAYNAME => ['value' => ''] @@ -146,10 +152,4 @@ class HooksTest extends TestCase { ], ]; } - - public function testGetAccountManager() { - $hooks = new Hooks($this->logger); - $result = $this->invokePrivate($hooks, 'getAccountManager'); - $this->assertInstanceOf(AccountManager::class, $result); - } } |