summaryrefslogtreecommitdiffstats
path: root/apps/dav/tests
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/tests')
-rw-r--r--apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php2
-rw-r--r--apps/dav/tests/unit/CardDAV/CardDavBackendTest.php2
-rw-r--r--apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php49
3 files changed, 53 insertions, 0 deletions
diff --git a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
index ec966248e01..0a234fc5c8d 100644
--- a/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
+++ b/apps/dav/tests/unit/CalDAV/AbstractCalDavBackend.php
@@ -30,6 +30,7 @@ use OC\KnownUser\KnownUserService;
use OCA\DAV\CalDAV\CalDavBackend;
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCA\DAV\Connector\Sabre\Principal;
+use OCP\Accounts\IAccountManager;
use OCP\App\IAppManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
@@ -89,6 +90,7 @@ abstract class AbstractCalDavBackend extends TestCase {
->setConstructorArgs([
$this->userManager,
$this->groupManager,
+ $this->createMock(IAccountManager::class),
$this->createMock(ShareManager::class),
$this->createMock(IUserSession::class),
$this->createMock(IAppManager::class),
diff --git a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
index 7eda691d199..136751628d0 100644
--- a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
+++ b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php
@@ -37,6 +37,7 @@ use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCA\DAV\CardDAV\AddressBook;
use OCA\DAV\CardDAV\CardDavBackend;
use OCA\DAV\Connector\Sabre\Principal;
+use OCP\Accounts\IAccountManager;
use OCP\App\IAppManager;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\EventDispatcher\IEventDispatcher;
@@ -136,6 +137,7 @@ class CardDavBackendTest extends TestCase {
->setConstructorArgs([
$this->userManager,
$this->groupManager,
+ $this->createMock(IAccountManager::class),
$this->createMock(ShareManager::class),
$this->createMock(IUserSession::class),
$this->createMock(IAppManager::class),
diff --git a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
index 86413e4a366..444c267b509 100644
--- a/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/PrincipalTest.php
@@ -34,6 +34,10 @@ use OC\User\User;
use OCA\DAV\CalDAV\Proxy\Proxy;
use OCA\DAV\CalDAV\Proxy\ProxyMapper;
use OCA\DAV\Connector\Sabre\Principal;
+use OCP\Accounts\IAccount;
+use OCP\Accounts\IAccountManager;
+use OCP\Accounts\IAccountProperty;
+use OCP\Accounts\IAccountPropertyCollection;
use OCP\App\IAppManager;
use OCP\IConfig;
use OCP\IGroup;
@@ -59,6 +63,9 @@ class PrincipalTest extends TestCase {
/** @var IGroupManager | MockObject */
private $groupManager;
+ /** @var IAccountManager|MockObject */
+ private $accountManager;
+
/** @var IManager | MockObject */
private $shareManager;
@@ -81,6 +88,7 @@ class PrincipalTest extends TestCase {
protected function setUp(): void {
$this->userManager = $this->createMock(IUserManager::class);
$this->groupManager = $this->createMock(IGroupManager::class);
+ $this->accountManager = $this->createMock(IAccountManager::class);
$this->shareManager = $this->createMock(IManager::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->appManager = $this->createMock(IAppManager::class);
@@ -92,6 +100,7 @@ class PrincipalTest extends TestCase {
$this->connector = new Principal(
$this->userManager,
$this->groupManager,
+ $this->accountManager,
$this->shareManager,
$this->userSession,
$this->appManager,
@@ -143,6 +152,45 @@ class PrincipalTest extends TestCase {
->withConsecutive([$fooUser], [$barUser])
->willReturnOnConsecutiveCalls('de', 'en');
+ $fooAccountPropertyCollection = $this->createMock(IAccountPropertyCollection::class);
+ $fooAccountPropertyCollection->expects($this->once())
+ ->method('getProperties')
+ ->with()
+ ->willReturn([]);
+ $fooAccount = $this->createMock(IAccount::class);
+ $fooAccount->expects($this->once())
+ ->method('getPropertyCollection')
+ ->with(IAccountManager::COLLECTION_EMAIL)
+ ->willReturn($fooAccountPropertyCollection);
+
+ $emailPropertyOne = $this->createMock(IAccountProperty::class);
+ $emailPropertyOne->expects($this->once())
+ ->method('getValue')
+ ->with()
+ ->willReturn('alias@nextcloud.com');
+ $emailPropertyTwo = $this->createMock(IAccountProperty::class);
+ $emailPropertyTwo->expects($this->once())
+ ->method('getValue')
+ ->with()
+ ->willReturn('alias2@nextcloud.com');
+
+ $barAccountPropertyCollection = $this->createMock(IAccountPropertyCollection::class);
+ $barAccountPropertyCollection->expects($this->once())
+ ->method('getProperties')
+ ->with()
+ ->willReturn([$emailPropertyOne, $emailPropertyTwo]);
+ $barAccount = $this->createMock(IAccount::class);
+ $barAccount->expects($this->once())
+ ->method('getPropertyCollection')
+ ->with(IAccountManager::COLLECTION_EMAIL)
+ ->willReturn($barAccountPropertyCollection);
+
+ $this->accountManager
+ ->expects($this->exactly(2))
+ ->method('getAccount')
+ ->withConsecutive([$fooUser], [$barUser])
+ ->willReturnOnConsecutiveCalls($fooAccount, $barAccount);
+
$expectedResponse = [
0 => [
'uri' => 'principals/users/foo',
@@ -156,6 +204,7 @@ class PrincipalTest extends TestCase {
'{urn:ietf:params:xml:ns:caldav}calendar-user-type' => 'INDIVIDUAL',
'{http://nextcloud.com/ns}language' => 'en',
'{http://sabredav.org/ns}email-address' => 'bar@nextcloud.com',
+ '{DAV:}alternate-URI-set' => ['mailto:alias@nextcloud.com', 'mailto:alias2@nextcloud.com']
]
];
$response = $this->connector->getPrincipalsByPrefix('principals/users');