* @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(
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);
}
}
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([