From c7abad65eaed44f0075c679d97934a9810666d45 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20M=C3=BCller?= Date: Tue, 26 Jan 2016 18:19:14 +0100 Subject: [PATCH] Fix sql to get shared addressbooks including unit tests --- apps/dav/lib/migration/addressbookadapter.php | 2 +- .../unit/migration/addressbookadaptertest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/dav/lib/migration/addressbookadapter.php b/apps/dav/lib/migration/addressbookadapter.php index a86790d1f2a..ef7b00188fb 100644 --- a/apps/dav/lib/migration/addressbookadapter.php +++ b/apps/dav/lib/migration/addressbookadapter.php @@ -75,7 +75,7 @@ class AddressBookAdapter { */ public function getShares($addressBookId) { $query = $this->dbConnection->getQueryBuilder(); - $shares = $query->select()->from('share') + $shares = $query->select('*')->from('share') ->where($query->expr()->eq('item_source', $query->createNamedParameter($addressBookId))) ->andWhere($query->expr()->eq('item_type', $query->expr()->literal('addressbook'))) ->andWhere($query->expr()->in('share_type', [ $query->expr()->literal(0), $query->expr()->literal(1)])) diff --git a/apps/dav/tests/unit/migration/addressbookadaptertest.php b/apps/dav/tests/unit/migration/addressbookadaptertest.php index c011fcd13ff..e6e57049a93 100644 --- a/apps/dav/tests/unit/migration/addressbookadaptertest.php +++ b/apps/dav/tests/unit/migration/addressbookadaptertest.php @@ -91,6 +91,17 @@ class AddressbookAdapterTest extends TestCase { 'lastmodified' => $builder->createNamedParameter('112233'), ]) ->execute(); + $builder = $this->db->getQueryBuilder(); + $builder->insert('share') + ->values([ + 'share_type' => $builder->createNamedParameter(1), + 'share_with' => $builder->createNamedParameter('user01'), + 'uid_owner' => $builder->createNamedParameter('user02'), + 'item_type' => $builder->createNamedParameter('addressbook'), + 'item_source' => $builder->createNamedParameter(6666), + 'item_target' => $builder->createNamedParameter('Contacts (user02)'), + ]) + ->execute(); // test the adapter $this->adapter->foreachBook('test-user-666', function($row) { @@ -108,6 +119,11 @@ class AddressbookAdapterTest extends TestCase { }); $this->assertArrayHasKey('id', $this->cards[0]); $this->assertEquals(6666, $this->cards[0]['addressbookid']); + + // test getShares + $shares = $this->adapter->getShares(6666); + $this->assertEquals(1, count($shares)); + } } -- 2.39.5