diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-05-07 23:15:11 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2021-05-08 00:18:17 +0200 |
commit | 04edd067f4382f5d3824929f3f21b415e115155a (patch) | |
tree | 134acf252f1e4fd3d0da324de7c5f4f0faaf3c59 /apps/dav/tests/unit/CardDAV/ConverterTest.php | |
parent | 0ac4563ae4cf03b5c28daec82fc4631d1579c13a (diff) | |
download | nextcloud-server-04edd067f4382f5d3824929f3f21b415e115155a.tar.gz nextcloud-server-04edd067f4382f5d3824929f3f21b415e115155a.zip |
dav: do not use private AccountManager
- also updates data structure in test
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
Diffstat (limited to 'apps/dav/tests/unit/CardDAV/ConverterTest.php')
-rw-r--r-- | apps/dav/tests/unit/CardDAV/ConverterTest.php | 89 |
1 files changed, 45 insertions, 44 deletions
diff --git a/apps/dav/tests/unit/CardDAV/ConverterTest.php b/apps/dav/tests/unit/CardDAV/ConverterTest.php index 43344451437..ef46845a5ae 100644 --- a/apps/dav/tests/unit/CardDAV/ConverterTest.php +++ b/apps/dav/tests/unit/CardDAV/ConverterTest.php @@ -27,65 +27,66 @@ namespace OCA\DAV\Tests\unit\CardDAV; -use OC\Accounts\AccountManager; use OCA\DAV\CardDAV\Converter; +use OCP\Accounts\IAccount; use OCP\Accounts\IAccountManager; +use OCP\Accounts\IAccountProperty; use OCP\IImage; use OCP\IUser; +use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; class ConverterTest extends TestCase { - /** @var AccountManager|\PHPUnit\Framework\MockObject\MockObject */ + /** @var IAccountManager|\PHPUnit\Framework\MockObject\MockObject */ private $accountManager; protected function setUp(): void { parent::setUp(); - $this->accountManager = $this->createMock(AccountManager::class); + $this->accountManager = $this->createMock(IAccountManager::class); + } + + /** + * @return IAccountProperty|MockObject + */ + protected function getAccountPropertyMock(string $name, ?string $value, string $scope) { + $property = $this->createMock(IAccountProperty::class); + $property->expects($this->any()) + ->method('getName') + ->willReturn($name); + $property->expects($this->any()) + ->method('getValue') + ->willReturn((string)$value); + $property->expects($this->any()) + ->method('getScope') + ->willReturn($scope); + $property->expects($this->any()) + ->method('getVerified') + ->willReturn(IAccountManager::NOT_VERIFIED); + return $property; } public function getAccountManager(IUser $user) { - $accountManager = $this->getMockBuilder(AccountManager::class) + $account = $this->createMock(IAccount::class); + $account->expects($this->any()) + ->method('getProperties') + ->willReturnCallback(function () use ($user) { + return [ + $this->getAccountPropertyMock(IAccountManager::PROPERTY_DISPLAYNAME, $user->getDisplayName(), IAccountManager::SCOPE_FEDERATED), + $this->getAccountPropertyMock(IAccountManager::PROPERTY_ADDRESS, '', IAccountManager::SCOPE_LOCAL), + $this->getAccountPropertyMock(IAccountManager::PROPERTY_WEBSITE, '', IAccountManager::SCOPE_LOCAL), + $this->getAccountPropertyMock(IAccountManager::PROPERTY_EMAIL, $user->getEMailAddress(), IAccountManager::SCOPE_FEDERATED), + $this->getAccountPropertyMock(IAccountManager::PROPERTY_AVATAR, $user->getAvatarImage(-1)->data(), IAccountManager::SCOPE_FEDERATED), + $this->getAccountPropertyMock(IAccountManager::PROPERTY_PHONE, '', IAccountManager::SCOPE_LOCAL), + $this->getAccountPropertyMock(IAccountManager::PROPERTY_TWITTER, '', IAccountManager::SCOPE_LOCAL), + ]; + }); + + $accountManager = $this->getMockBuilder(IAccountManager::class) ->disableOriginalConstructor()->getMock(); - $accountManager->expects($this->any())->method('getUser')->willReturn( - [ - IAccountManager::PROPERTY_DISPLAYNAME => - [ - 'value' => $user->getDisplayName(), - 'scope' => AccountManager::SCOPE_FEDERATED, - ], - IAccountManager::PROPERTY_ADDRESS => - [ - 'value' => '', - 'scope' => AccountManager::SCOPE_LOCAL, - ], - IAccountManager::PROPERTY_WEBSITE => - [ - 'value' => '', - 'scope' => AccountManager::SCOPE_LOCAL, - ], - IAccountManager::PROPERTY_EMAIL => - [ - 'value' => $user->getEMailAddress(), - 'scope' => AccountManager::SCOPE_FEDERATED, - ], - IAccountManager::PROPERTY_AVATAR => - [ - 'scope' => AccountManager::SCOPE_FEDERATED - ], - IAccountManager::PROPERTY_PHONE => - [ - 'value' => '', - 'scope' => AccountManager::SCOPE_LOCAL, - ], - IAccountManager::PROPERTY_TWITTER => - [ - 'value' => '', - 'scope' => AccountManager::SCOPE_LOCAL, - ], - ] - ); + + $accountManager->expects($this->any())->method('getAccount')->willReturn($account); return $accountManager; } @@ -94,7 +95,7 @@ class ConverterTest extends TestCase { * @dataProvider providesNewUsers */ public function testCreation($expectedVCard, $displayName = null, $eMailAddress = null, $cloudId = null) { - $user = $this->getUserMock($displayName, $eMailAddress, $cloudId); + $user = $this->getUserMock((string)$displayName, $eMailAddress, $cloudId); $accountManager = $this->getAccountManager($user); $converter = new Converter($accountManager); @@ -203,7 +204,7 @@ class ConverterTest extends TestCase { * @param $cloudId * @return IUser | \PHPUnit\Framework\MockObject\MockObject */ - protected function getUserMock($displayName, $eMailAddress, $cloudId) { + protected function getUserMock(string $displayName, ?string $eMailAddress, ?string $cloudId) { $image0 = $this->getMockBuilder(IImage::class)->disableOriginalConstructor()->getMock(); $image0->method('mimeType')->willReturn('image/jpeg'); $image0->method('data')->willReturn('123456789'); |