From ca25055cc8331c65606d5cb7b27a0a0d1c5ac01f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20M=C3=BCller?= Date: Thu, 28 Jan 2016 15:02:01 +0100 Subject: [PATCH] Register all system address books to the contacts manager --- apps/dav/lib/carddav/contactsmanager.php | 14 ++++++++++++-- apps/dav/tests/unit/appinfo/applicationtest.php | 17 ++++++++++++++--- .../tests/unit/carddav/contactsmanagertest.php | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/apps/dav/lib/carddav/contactsmanager.php b/apps/dav/lib/carddav/contactsmanager.php index 3fe4de4a15e..7900c6ccae0 100644 --- a/apps/dav/lib/carddav/contactsmanager.php +++ b/apps/dav/lib/carddav/contactsmanager.php @@ -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( diff --git a/apps/dav/tests/unit/appinfo/applicationtest.php b/apps/dav/tests/unit/appinfo/applicationtest.php index 36a75212ff5..7f533a185df 100644 --- a/apps/dav/tests/unit/appinfo/applicationtest.php +++ b/apps/dav/tests/unit/appinfo/applicationtest.php @@ -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); } } diff --git a/apps/dav/tests/unit/carddav/contactsmanagertest.php b/apps/dav/tests/unit/carddav/contactsmanagertest.php index c4ec4c29e39..5a384550df5 100644 --- a/apps/dav/tests/unit/carddav/contactsmanagertest.php +++ b/apps/dav/tests/unit/carddav/contactsmanagertest.php @@ -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([ -- 2.39.5