]> source.dussan.org Git - nextcloud-server.git/commitdiff
Register all system address books to the contacts manager
authorThomas Müller <thomas.mueller@tmit.eu>
Thu, 28 Jan 2016 14:02:01 +0000 (15:02 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 2 Feb 2016 09:56:33 +0000 (10:56 +0100)
apps/dav/lib/carddav/contactsmanager.php
apps/dav/tests/unit/appinfo/applicationtest.php
apps/dav/tests/unit/carddav/contactsmanagertest.php

index 3fe4de4a15e63c7613535f4956239ffa010756ef..7900c6ccae0ac5d4da7be8606dc05077cfaa20aa 100644 (file)
@@ -39,8 +39,18 @@ class ContactsManager {
         * @param string $userId
         */
        public function setupContactsProvider(IManager $cm, $userId) {
-               $addressBooks = $this->backend->getAddressBooksForUser("principals/$userId");
-               foreach ($addressBooks as $addressBookInfo)  {
+               $addressBooks = $this->backend->getAddressBooksForUser("principals/users/$userId");
+               $this->register($cm, $addressBooks);
+               $addressBooks = $this->backend->getAddressBooksForUser("principals/system/system");
+               $this->register($cm, $addressBooks);
+       }
+
+       /**
+        * @param IManager $cm
+        * @param $addressBooks
+        */
+       private function register(IManager $cm, $addressBooks) {
+               foreach ($addressBooks as $addressBookInfo) {
                        $addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo);
                        $cm->registerAddressBook(
                                new AddressBookImpl(
index 36a75212ff556dd351c90af0b10f24cc84a985ec..7f533a185dfc237f0e7ac69c7ca0df66fefde832 100644 (file)
@@ -35,17 +35,28 @@ use Test\TestCase;
 class ApplicationTest extends TestCase {
        public function test() {
                $app = new Application();
+               $c = $app->getContainer();
 
                // assert service instances in the container are properly setup
-               $s = $app->getContainer()->query('ContactsManager');
+               $s = $c->query('ContactsManager');
                $this->assertInstanceOf('OCA\DAV\CardDAV\ContactsManager', $s);
-               $s = $app->getContainer()->query('CardDavBackend');
+               $s = $c->query('CardDavBackend');
                $this->assertInstanceOf('OCA\DAV\CardDAV\CardDavBackend', $s);
+       }
+
+       public function testContactsManagerSetup() {
+               $app = new Application();
+               $c = $app->getContainer();
+               $c->registerService('CardDavBackend', function($c) {
+                       $service = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')->disableOriginalConstructor()->getMock();
+                       $service->method('getAddressBooksForUser')->willReturn([]);
+                       return $service;
+               });
 
                // assert setupContactsProvider() is proper
                /** @var IManager | \PHPUnit_Framework_MockObject_MockObject $cm */
                $cm = $this->getMockBuilder('OCP\Contacts\IManager')->disableOriginalConstructor()->getMock();
-               $app->setupContactsProvider($cm, 'user01');
+               $app->setupContactsProvider($cm, 'xxx');
                $this->assertTrue(true);
        }
 }
index c4ec4c29e39bfc6b16957d000fb0d66aec1144e3..5a384550df570eb4b7839cbb54bb730c67da3e23 100644 (file)
@@ -30,7 +30,7 @@ class ContactsManagerTest extends TestCase {
        public function test() {
                /** @var IManager | \PHPUnit_Framework_MockObject_MockObject $cm */
                $cm = $this->getMockBuilder('OCP\Contacts\IManager')->disableOriginalConstructor()->getMock();
-               $cm->expects($this->once())->method('registerAddressBook');
+               $cm->expects($this->exactly(2))->method('registerAddressBook');
                /** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $backEnd */
                $backEnd = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')->disableOriginalConstructor()->getMock();
                $backEnd->method('getAddressBooksForUser')->willReturn([