|
|
|
|
@ -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');
|
|
|
|
|
|