2015-10-30 15:05:25 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 14:49:16 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2016-07-21 14:49:16 +00:00
|
|
|
* @author Bjoern Schiessle <bjoern@schiessle.org>
|
2016-05-26 17:56:05 +00:00
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
2017-11-06 19:15:27 +00:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2016-07-21 14:49:16 +00:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2016-01-12 14:02:16 +00:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2015-10-30 15:05:25 +00:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2016-05-25 14:04:15 +00:00
|
|
|
|
|
|
|
namespace OCA\DAV\Tests\unit\CardDAV;
|
2015-10-30 15:05:25 +00:00
|
|
|
|
2015-12-14 10:48:31 +00:00
|
|
|
use InvalidArgumentException;
|
2016-01-11 15:10:09 +00:00
|
|
|
use OCA\DAV\CardDAV\AddressBook;
|
2015-10-30 15:05:25 +00:00
|
|
|
use OCA\DAV\CardDAV\CardDavBackend;
|
2015-11-25 14:24:50 +00:00
|
|
|
use OCA\DAV\Connector\Sabre\Principal;
|
2016-02-29 08:44:40 +00:00
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
2018-06-01 11:24:04 +00:00
|
|
|
use OCP\IConfig;
|
2015-11-25 14:24:50 +00:00
|
|
|
use OCP\IDBConnection;
|
2017-10-05 10:32:46 +00:00
|
|
|
use OCP\IGroupManager;
|
2016-09-20 16:59:14 +00:00
|
|
|
use OCP\IL10N;
|
2017-05-02 12:32:26 +00:00
|
|
|
use OCP\IUserManager;
|
2018-04-23 12:29:46 +00:00
|
|
|
use OCP\IUserSession;
|
|
|
|
use OCP\Share\IManager as ShareManager;
|
2018-11-03 18:33:59 +00:00
|
|
|
use Sabre\DAV\Exception\BadRequest;
|
2015-10-30 15:05:25 +00:00
|
|
|
use Sabre\DAV\PropPatch;
|
2015-11-25 14:24:50 +00:00
|
|
|
use Sabre\VObject\Component\VCard;
|
|
|
|
use Sabre\VObject\Property\Text;
|
2017-05-02 12:32:26 +00:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
|
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
2015-10-30 15:05:25 +00:00
|
|
|
use Test\TestCase;
|
|
|
|
|
2015-11-05 15:46:37 +00:00
|
|
|
/**
|
|
|
|
* Class CardDavBackendTest
|
|
|
|
*
|
|
|
|
* @group DB
|
|
|
|
*
|
2016-05-25 14:04:15 +00:00
|
|
|
* @package OCA\DAV\Tests\unit\CardDAV
|
2015-11-05 15:46:37 +00:00
|
|
|
*/
|
2015-10-30 15:05:25 +00:00
|
|
|
class CardDavBackendTest extends TestCase {
|
|
|
|
|
|
|
|
/** @var CardDavBackend */
|
|
|
|
private $backend;
|
|
|
|
|
2016-02-15 13:13:04 +00:00
|
|
|
/** @var Principal | \PHPUnit_Framework_MockObject_MockObject */
|
2015-11-25 14:24:50 +00:00
|
|
|
private $principal;
|
|
|
|
|
2017-05-02 12:32:26 +00:00
|
|
|
/** @var IUserManager|\PHPUnit_Framework_MockObject_MockObject */
|
2016-08-18 13:14:04 +00:00
|
|
|
private $userManager;
|
|
|
|
|
2017-10-05 10:32:46 +00:00
|
|
|
/** @var IGroupManager|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $groupManager;
|
|
|
|
|
2017-05-02 12:32:26 +00:00
|
|
|
/** @var EventDispatcherInterface|\PHPUnit_Framework_MockObject_MockObject */
|
|
|
|
private $dispatcher;
|
|
|
|
|
2015-11-25 14:24:50 +00:00
|
|
|
/** @var IDBConnection */
|
|
|
|
private $db;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $dbCardsTable = 'cards';
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $dbCardsPropertiesTable = 'cards_properties';
|
|
|
|
|
2016-01-28 16:40:59 +00:00
|
|
|
const UNIT_TEST_USER = 'principals/users/carddav-unit-test';
|
|
|
|
const UNIT_TEST_USER1 = 'principals/users/carddav-unit-test1';
|
|
|
|
const UNIT_TEST_GROUP = 'principals/groups/carddav-unit-test-group';
|
2015-10-30 15:05:25 +00:00
|
|
|
|
2018-11-03 18:33:59 +00:00
|
|
|
private $vcardTest0 = 'BEGIN:VCARD'.PHP_EOL.
|
2018-11-02 13:20:53 +00:00
|
|
|
'VERSION:3.0'.PHP_EOL.
|
|
|
|
'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL.
|
|
|
|
'UID:Test'.PHP_EOL.
|
|
|
|
'FN:Test'.PHP_EOL.
|
|
|
|
'N:Test;;;;'.PHP_EOL.
|
|
|
|
'END:VCARD';
|
|
|
|
|
2018-11-03 18:33:59 +00:00
|
|
|
private $vcardTest1 = 'BEGIN:VCARD'.PHP_EOL.
|
|
|
|
'VERSION:3.0'.PHP_EOL.
|
|
|
|
'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL.
|
|
|
|
'UID:Test2'.PHP_EOL.
|
|
|
|
'FN:Test2'.PHP_EOL.
|
|
|
|
'N:Test2;;;;'.PHP_EOL.
|
|
|
|
'END:VCARD';
|
|
|
|
|
|
|
|
private $vcardTest2 = 'BEGIN:VCARD'.PHP_EOL.
|
|
|
|
'VERSION:3.0'.PHP_EOL.
|
|
|
|
'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL.
|
|
|
|
'UID:Test3'.PHP_EOL.
|
|
|
|
'FN:Test3'.PHP_EOL.
|
|
|
|
'N:Test3;;;;'.PHP_EOL.
|
|
|
|
'END:VCARD';
|
|
|
|
|
|
|
|
private $vcardTestNoUID = 'BEGIN:VCARD'.PHP_EOL.
|
|
|
|
'VERSION:3.0'.PHP_EOL.
|
|
|
|
'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL.
|
|
|
|
'FN:TestNoUID'.PHP_EOL.
|
|
|
|
'N:TestNoUID;;;;'.PHP_EOL.
|
|
|
|
'END:VCARD';
|
|
|
|
|
2015-10-30 15:05:25 +00:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
|
2017-05-02 12:32:26 +00:00
|
|
|
$this->userManager = $this->createMock(IUserManager::class);
|
2017-10-05 10:32:46 +00:00
|
|
|
$this->groupManager = $this->createMock(IGroupManager::class);
|
2017-10-24 13:26:53 +00:00
|
|
|
$this->principal = $this->getMockBuilder(Principal::class)
|
2018-04-23 12:29:46 +00:00
|
|
|
->setConstructorArgs([
|
|
|
|
$this->userManager,
|
|
|
|
$this->groupManager,
|
|
|
|
$this->createMock(ShareManager::class),
|
|
|
|
$this->createMock(IUserSession::class),
|
2018-06-01 11:24:04 +00:00
|
|
|
$this->createMock(IConfig::class),
|
2018-04-23 12:29:46 +00:00
|
|
|
])
|
2016-01-28 16:40:59 +00:00
|
|
|
->setMethods(['getPrincipalByPath', 'getGroupMembership'])
|
2015-11-05 15:46:37 +00:00
|
|
|
->getMock();
|
2015-11-25 14:24:50 +00:00
|
|
|
$this->principal->method('getPrincipalByPath')
|
2015-11-05 15:46:37 +00:00
|
|
|
->willReturn([
|
2017-04-19 14:18:44 +00:00
|
|
|
'uri' => 'principals/best-friend',
|
|
|
|
'{DAV:}displayname' => 'User\'s displayname',
|
2015-11-05 15:46:37 +00:00
|
|
|
]);
|
2016-01-28 16:40:59 +00:00
|
|
|
$this->principal->method('getGroupMembership')
|
|
|
|
->withAnyParameters()
|
|
|
|
->willReturn([self::UNIT_TEST_GROUP]);
|
2017-05-02 12:32:26 +00:00
|
|
|
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
|
2015-11-25 14:24:50 +00:00
|
|
|
|
|
|
|
$this->db = \OC::$server->getDatabaseConnection();
|
|
|
|
|
2017-10-05 10:32:46 +00:00
|
|
|
$this->backend = new CardDavBackend($this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher);
|
2015-11-25 14:24:50 +00:00
|
|
|
// start every test with a empty cards_properties and cards table
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
$query->delete('cards_properties')->execute();
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
$query->delete('cards')->execute();
|
2015-11-05 15:46:37 +00:00
|
|
|
|
2015-10-30 15:05:25 +00:00
|
|
|
$this->tearDown();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tearDown() {
|
|
|
|
parent::tearDown();
|
|
|
|
|
|
|
|
if (is_null($this->backend)) {
|
|
|
|
return;
|
|
|
|
}
|
2017-06-08 07:08:24 +00:00
|
|
|
|
|
|
|
$this->principal->method('getGroupMembership')
|
|
|
|
->withAnyParameters()
|
|
|
|
->willReturn([self::UNIT_TEST_GROUP]);
|
2015-10-30 15:05:25 +00:00
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
|
|
|
|
foreach ($books as $book) {
|
|
|
|
$this->backend->deleteAddressBook($book['id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testAddressBookOperations() {
|
|
|
|
|
|
|
|
// create a new address book
|
|
|
|
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
|
|
|
|
2016-08-30 13:11:33 +00:00
|
|
|
$this->assertEquals(1, $this->backend->getAddressBooksForUserCount(self::UNIT_TEST_USER));
|
2015-10-30 15:05:25 +00:00
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
|
|
|
|
$this->assertEquals(1, count($books));
|
2015-11-10 10:37:07 +00:00
|
|
|
$this->assertEquals('Example', $books[0]['{DAV:}displayname']);
|
2017-04-19 14:18:44 +00:00
|
|
|
$this->assertEquals('User\'s displayname', $books[0]['{http://nextcloud.com/ns}owner-displayname']);
|
2015-10-30 15:05:25 +00:00
|
|
|
|
|
|
|
// update it's display name
|
|
|
|
$patch = new PropPatch([
|
|
|
|
'{DAV:}displayname' => 'Unit test',
|
|
|
|
'{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'Addressbook used for unit testing'
|
|
|
|
]);
|
|
|
|
$this->backend->updateAddressBook($books[0]['id'], $patch);
|
|
|
|
$patch->commit();
|
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
|
|
|
|
$this->assertEquals(1, count($books));
|
|
|
|
$this->assertEquals('Unit test', $books[0]['{DAV:}displayname']);
|
|
|
|
$this->assertEquals('Addressbook used for unit testing', $books[0]['{urn:ietf:params:xml:ns:carddav}addressbook-description']);
|
|
|
|
|
|
|
|
// delete the address book
|
|
|
|
$this->backend->deleteAddressBook($books[0]['id']);
|
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
|
|
|
|
$this->assertEquals(0, count($books));
|
|
|
|
}
|
|
|
|
|
2016-01-28 16:40:59 +00:00
|
|
|
public function testAddressBookSharing() {
|
|
|
|
|
2017-10-05 10:32:46 +00:00
|
|
|
$this->userManager->expects($this->any())
|
|
|
|
->method('userExists')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$this->groupManager->expects($this->any())
|
|
|
|
->method('groupExists')
|
|
|
|
->willReturn(true);
|
|
|
|
|
2016-01-28 16:40:59 +00:00
|
|
|
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
|
|
|
|
$this->assertEquals(1, count($books));
|
2016-09-20 16:59:14 +00:00
|
|
|
$l = $this->createMock(IL10N::class);
|
|
|
|
$addressBook = new AddressBook($this->backend, $books[0], $l);
|
2016-01-28 16:40:59 +00:00
|
|
|
$this->backend->updateShares($addressBook, [
|
|
|
|
[
|
|
|
|
'href' => 'principal:' . self::UNIT_TEST_USER1,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'href' => 'principal:' . self::UNIT_TEST_GROUP,
|
|
|
|
]
|
|
|
|
], []);
|
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER1);
|
|
|
|
$this->assertEquals(1, count($books));
|
|
|
|
|
|
|
|
// delete the address book
|
|
|
|
$this->backend->deleteAddressBook($books[0]['id']);
|
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
|
|
|
|
$this->assertEquals(0, count($books));
|
|
|
|
}
|
|
|
|
|
2015-10-30 15:05:25 +00:00
|
|
|
public function testCardOperations() {
|
2015-11-25 14:24:50 +00:00
|
|
|
|
2015-12-14 10:48:31 +00:00
|
|
|
/** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $backend */
|
2016-10-13 10:15:10 +00:00
|
|
|
$backend = $this->getMockBuilder(CardDavBackend::class)
|
2017-10-05 10:32:46 +00:00
|
|
|
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
|
2015-11-25 14:24:50 +00:00
|
|
|
->setMethods(['updateProperties', 'purgeProperties'])->getMock();
|
|
|
|
|
2015-10-30 15:05:25 +00:00
|
|
|
// create a new address book
|
2015-11-25 14:24:50 +00:00
|
|
|
$backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
|
|
|
$books = $backend->getAddressBooksForUser(self::UNIT_TEST_USER);
|
2015-10-30 15:05:25 +00:00
|
|
|
$this->assertEquals(1, count($books));
|
|
|
|
$bookId = $books[0]['id'];
|
|
|
|
|
|
|
|
$uri = $this->getUniqueID('card');
|
2015-11-25 14:24:50 +00:00
|
|
|
// updateProperties is expected twice, once for createCard and once for updateCard
|
2018-11-03 18:33:59 +00:00
|
|
|
$backend->expects($this->at(0))->method('updateProperties')->with($bookId, $uri, $this->vcardTest0);
|
|
|
|
$backend->expects($this->at(1))->method('updateProperties')->with($bookId, $uri, $this->vcardTest0);
|
2017-05-02 12:32:26 +00:00
|
|
|
|
|
|
|
// Expect event
|
|
|
|
$this->dispatcher->expects($this->at(0))
|
|
|
|
->method('dispatch')
|
|
|
|
->with('\OCA\DAV\CardDAV\CardDavBackend::createCard', $this->callback(function(GenericEvent $e) use ($bookId, $uri) {
|
|
|
|
return $e->getArgument('addressBookId') === $bookId &&
|
|
|
|
$e->getArgument('cardUri') === $uri &&
|
2018-11-03 18:33:59 +00:00
|
|
|
$e->getArgument('cardData') === $this->vcardTest0;
|
2017-05-02 12:32:26 +00:00
|
|
|
}));
|
|
|
|
|
2015-11-25 14:24:50 +00:00
|
|
|
// create a card
|
2018-11-03 18:33:59 +00:00
|
|
|
$backend->createCard($bookId, $uri, $this->vcardTest0);
|
2015-10-30 15:05:25 +00:00
|
|
|
|
|
|
|
// get all the cards
|
2015-11-25 14:24:50 +00:00
|
|
|
$cards = $backend->getCards($bookId);
|
2015-10-30 15:05:25 +00:00
|
|
|
$this->assertEquals(1, count($cards));
|
2018-11-03 18:33:59 +00:00
|
|
|
$this->assertEquals($this->vcardTest0, $cards[0]['carddata']);
|
2015-10-30 15:05:25 +00:00
|
|
|
|
|
|
|
// get the cards
|
2015-11-25 14:24:50 +00:00
|
|
|
$card = $backend->getCard($bookId, $uri);
|
2015-10-30 15:05:25 +00:00
|
|
|
$this->assertNotNull($card);
|
|
|
|
$this->assertArrayHasKey('id', $card);
|
|
|
|
$this->assertArrayHasKey('uri', $card);
|
|
|
|
$this->assertArrayHasKey('lastmodified', $card);
|
|
|
|
$this->assertArrayHasKey('etag', $card);
|
|
|
|
$this->assertArrayHasKey('size', $card);
|
2018-11-03 18:33:59 +00:00
|
|
|
$this->assertEquals($this->vcardTest0, $card['carddata']);
|
2015-10-30 15:05:25 +00:00
|
|
|
|
2017-05-02 12:32:26 +00:00
|
|
|
// Expect event
|
|
|
|
$this->dispatcher->expects($this->at(0))
|
|
|
|
->method('dispatch')
|
|
|
|
->with('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $this->callback(function(GenericEvent $e) use ($bookId, $uri) {
|
|
|
|
return $e->getArgument('addressBookId') === $bookId &&
|
|
|
|
$e->getArgument('cardUri') === $uri &&
|
2018-11-03 18:33:59 +00:00
|
|
|
$e->getArgument('cardData') === $this->vcardTest0;
|
2017-05-02 12:32:26 +00:00
|
|
|
}));
|
|
|
|
|
2015-10-30 15:05:25 +00:00
|
|
|
// update the card
|
2018-11-03 18:33:59 +00:00
|
|
|
$backend->updateCard($bookId, $uri, $this->vcardTest0);
|
2015-11-25 14:24:50 +00:00
|
|
|
$card = $backend->getCard($bookId, $uri);
|
2018-11-03 18:33:59 +00:00
|
|
|
$this->assertEquals($this->vcardTest0, $card['carddata']);
|
2015-10-30 15:05:25 +00:00
|
|
|
|
2017-05-02 12:32:26 +00:00
|
|
|
// Expect event
|
|
|
|
$this->dispatcher->expects($this->at(0))
|
|
|
|
->method('dispatch')
|
|
|
|
->with('\OCA\DAV\CardDAV\CardDavBackend::deleteCard', $this->callback(function(GenericEvent $e) use ($bookId, $uri) {
|
|
|
|
return $e->getArgument('addressBookId') === $bookId &&
|
|
|
|
$e->getArgument('cardUri') === $uri;
|
|
|
|
}));
|
|
|
|
|
2015-10-30 15:05:25 +00:00
|
|
|
// delete the card
|
2015-11-25 14:24:50 +00:00
|
|
|
$backend->expects($this->once())->method('purgeProperties')->with($bookId, $card['id']);
|
|
|
|
$backend->deleteCard($bookId, $uri);
|
|
|
|
$cards = $backend->getCards($bookId);
|
2015-10-30 15:05:25 +00:00
|
|
|
$this->assertEquals(0, count($cards));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMultiCard() {
|
2016-10-13 10:15:10 +00:00
|
|
|
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
2017-10-05 10:32:46 +00:00
|
|
|
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
|
2015-11-25 14:24:50 +00:00
|
|
|
->setMethods(['updateProperties'])->getMock();
|
|
|
|
|
2015-10-30 15:05:25 +00:00
|
|
|
// create a new address book
|
|
|
|
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
|
|
|
|
$this->assertEquals(1, count($books));
|
|
|
|
$bookId = $books[0]['id'];
|
|
|
|
|
|
|
|
// create a card
|
2018-11-03 18:33:59 +00:00
|
|
|
$uri0 = self::getUniqueID('card');
|
|
|
|
$this->backend->createCard($bookId, $uri0, $this->vcardTest0);
|
|
|
|
$uri1 = self::getUniqueID('card');
|
|
|
|
$this->backend->createCard($bookId, $uri1, $this->vcardTest1);
|
|
|
|
$uri2 = self::getUniqueID('card');
|
|
|
|
$this->backend->createCard($bookId, $uri2, $this->vcardTest2);
|
2015-10-30 15:05:25 +00:00
|
|
|
|
|
|
|
// get all the cards
|
|
|
|
$cards = $this->backend->getCards($bookId);
|
|
|
|
$this->assertEquals(3, count($cards));
|
2018-11-03 18:33:59 +00:00
|
|
|
usort($cards, function ($a, $b) { return $a['id'] < $b['id'] ? -1 : 1; });
|
2015-10-30 15:05:25 +00:00
|
|
|
|
2018-11-03 18:33:59 +00:00
|
|
|
$this->assertEquals($this->vcardTest0, $cards[0]['carddata']);
|
|
|
|
$this->assertEquals($this->vcardTest1, $cards[1]['carddata']);
|
|
|
|
$this->assertEquals($this->vcardTest2, $cards[2]['carddata']);
|
|
|
|
|
|
|
|
// get the cards 1 & 2 (not 0)
|
2015-10-30 15:05:25 +00:00
|
|
|
$cards = $this->backend->getMultipleCards($bookId, [$uri1, $uri2]);
|
|
|
|
$this->assertEquals(2, count($cards));
|
2018-11-03 18:33:59 +00:00
|
|
|
usort($cards, function ($a, $b) { return $a['id'] < $b['id'] ? -1 : 1; });
|
|
|
|
foreach($cards as $index => $card) {
|
2015-10-30 15:05:25 +00:00
|
|
|
$this->assertArrayHasKey('id', $card);
|
|
|
|
$this->assertArrayHasKey('uri', $card);
|
|
|
|
$this->assertArrayHasKey('lastmodified', $card);
|
|
|
|
$this->assertArrayHasKey('etag', $card);
|
|
|
|
$this->assertArrayHasKey('size', $card);
|
2018-11-03 18:33:59 +00:00
|
|
|
$this->assertEquals($this->{ 'vcardTest'.($index+1) }, $card['carddata']);
|
2015-10-30 15:05:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// delete the card
|
|
|
|
$this->backend->deleteCard($bookId, $uri0);
|
|
|
|
$this->backend->deleteCard($bookId, $uri1);
|
|
|
|
$this->backend->deleteCard($bookId, $uri2);
|
|
|
|
$cards = $this->backend->getCards($bookId);
|
|
|
|
$this->assertEquals(0, count($cards));
|
|
|
|
}
|
|
|
|
|
2018-11-03 18:33:59 +00:00
|
|
|
public function testMultipleUIDOnDifferentAddressbooks() {
|
|
|
|
|
|
|
|
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
|
|
|
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
|
|
|
|
->setMethods(['updateProperties'])->getMock();
|
|
|
|
|
|
|
|
// create 2 new address books
|
|
|
|
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
|
|
|
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example2', []);
|
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
|
|
|
|
$this->assertEquals(2, count($books));
|
|
|
|
$bookId0 = $books[0]['id'];
|
|
|
|
$bookId1 = $books[1]['id'];
|
|
|
|
|
|
|
|
// create a card
|
|
|
|
$uri0 = $this->getUniqueID('card');
|
|
|
|
$this->backend->createCard($bookId0, $uri0, $this->vcardTest0);
|
|
|
|
|
|
|
|
// create another card with same uid but in second address book
|
|
|
|
$uri1 = $this->getUniqueID('card');
|
|
|
|
$this->backend->createCard($bookId1, $uri1, $this->vcardTest0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMultipleUIDDenied() {
|
|
|
|
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
|
|
|
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
|
|
|
|
->setMethods(['updateProperties'])->getMock();
|
|
|
|
|
|
|
|
// create a new address book
|
|
|
|
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
|
|
|
|
$this->assertEquals(1, count($books));
|
|
|
|
$bookId = $books[0]['id'];
|
|
|
|
|
|
|
|
// create a card
|
|
|
|
$uri0 = $this->getUniqueID('card');
|
|
|
|
$this->backend->createCard($bookId, $uri0, $this->vcardTest0);
|
|
|
|
|
|
|
|
// create another card with same uid
|
|
|
|
$uri1 = $this->getUniqueID('card');
|
|
|
|
$this->expectException(BadRequest::class);
|
|
|
|
$test = $this->backend->createCard($bookId, $uri1, $this->vcardTest0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoValidUID() {
|
|
|
|
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
|
|
|
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
|
|
|
|
->setMethods(['updateProperties'])->getMock();
|
|
|
|
|
|
|
|
// create a new address book
|
|
|
|
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
|
|
|
|
$this->assertEquals(1, count($books));
|
|
|
|
$bookId = $books[0]['id'];
|
|
|
|
|
|
|
|
// create a card without uid
|
|
|
|
$uri1 = $this->getUniqueID('card');
|
|
|
|
$this->expectException(BadRequest::class);
|
|
|
|
$test = $this->backend->createCard($bookId, $uri1, $this->vcardTestNoUID);
|
|
|
|
}
|
|
|
|
|
2016-01-21 11:19:28 +00:00
|
|
|
public function testDeleteWithoutCard() {
|
2016-10-13 10:15:10 +00:00
|
|
|
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
2017-10-05 10:32:46 +00:00
|
|
|
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
|
2016-01-21 11:19:28 +00:00
|
|
|
->setMethods([
|
|
|
|
'getCardId',
|
|
|
|
'addChange',
|
|
|
|
'purgeProperties',
|
|
|
|
'updateProperties',
|
|
|
|
])
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
// create a new address book
|
|
|
|
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
2017-02-14 08:33:04 +00:00
|
|
|
$books = $this->backend->getUsersOwnAddressBooks(self::UNIT_TEST_USER);
|
2016-01-21 11:19:28 +00:00
|
|
|
$this->assertEquals(1, count($books));
|
|
|
|
|
|
|
|
$bookId = $books[0]['id'];
|
|
|
|
$uri = $this->getUniqueID('card');
|
|
|
|
|
|
|
|
// create a new address book
|
|
|
|
$this->backend->expects($this->once())
|
|
|
|
->method('getCardId')
|
2016-02-15 13:13:04 +00:00
|
|
|
->with($bookId, $uri)
|
2016-01-21 11:19:28 +00:00
|
|
|
->willThrowException(new \InvalidArgumentException());
|
|
|
|
$this->backend->expects($this->exactly(2))
|
|
|
|
->method('addChange')
|
|
|
|
->withConsecutive(
|
|
|
|
[$bookId, $uri, 1],
|
|
|
|
[$bookId, $uri, 3]
|
|
|
|
);
|
|
|
|
$this->backend->expects($this->never())
|
|
|
|
->method('purgeProperties');
|
|
|
|
|
|
|
|
// create a card
|
2018-11-03 18:33:59 +00:00
|
|
|
$this->backend->createCard($bookId, $uri, $this->vcardTest0);
|
2016-01-21 11:19:28 +00:00
|
|
|
|
|
|
|
// delete the card
|
|
|
|
$this->assertTrue($this->backend->deleteCard($bookId, $uri));
|
|
|
|
}
|
|
|
|
|
2015-10-30 15:05:25 +00:00
|
|
|
public function testSyncSupport() {
|
2016-10-13 10:15:10 +00:00
|
|
|
$this->backend = $this->getMockBuilder(CardDavBackend::class)
|
2017-10-05 10:32:46 +00:00
|
|
|
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
|
2015-11-25 14:24:50 +00:00
|
|
|
->setMethods(['updateProperties'])->getMock();
|
|
|
|
|
2015-10-30 15:05:25 +00:00
|
|
|
// create a new address book
|
|
|
|
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
|
|
|
|
$this->assertEquals(1, count($books));
|
|
|
|
$bookId = $books[0]['id'];
|
|
|
|
|
|
|
|
// fist call without synctoken
|
|
|
|
$changes = $this->backend->getChangesForAddressBook($bookId, '', 1);
|
|
|
|
$syncToken = $changes['syncToken'];
|
|
|
|
|
|
|
|
// add a change
|
|
|
|
$uri0 = $this->getUniqueID('card');
|
2018-11-03 18:33:59 +00:00
|
|
|
$this->backend->createCard($bookId, $uri0, $this->vcardTest0);
|
2015-10-30 15:05:25 +00:00
|
|
|
|
|
|
|
// look for changes
|
|
|
|
$changes = $this->backend->getChangesForAddressBook($bookId, $syncToken, 1);
|
|
|
|
$this->assertEquals($uri0, $changes['added'][0]);
|
|
|
|
}
|
2015-11-05 15:46:37 +00:00
|
|
|
|
|
|
|
public function testSharing() {
|
2017-10-05 10:32:46 +00:00
|
|
|
|
|
|
|
$this->userManager->expects($this->any())
|
|
|
|
->method('userExists')
|
|
|
|
->willReturn(true);
|
|
|
|
|
|
|
|
$this->groupManager->expects($this->any())
|
|
|
|
->method('groupExists')
|
|
|
|
->willReturn(true);
|
|
|
|
|
2015-11-05 15:46:37 +00:00
|
|
|
$this->backend->createAddressBook(self::UNIT_TEST_USER, 'Example', []);
|
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER);
|
|
|
|
$this->assertEquals(1, count($books));
|
|
|
|
|
2016-09-20 16:59:14 +00:00
|
|
|
$l = $this->createMock(IL10N::class);
|
|
|
|
$exampleBook = new AddressBook($this->backend, $books[0], $l);
|
2017-10-05 10:32:46 +00:00
|
|
|
$this->backend->updateShares($exampleBook, [['href' => 'principal:' . self::UNIT_TEST_USER1]], []);
|
2015-11-05 15:46:37 +00:00
|
|
|
|
2016-01-25 21:49:26 +00:00
|
|
|
$shares = $this->backend->getShares($exampleBook->getResourceId());
|
2015-11-05 15:46:37 +00:00
|
|
|
$this->assertEquals(1, count($shares));
|
|
|
|
|
2015-11-18 14:04:53 +00:00
|
|
|
// adding the same sharee again has no effect
|
2017-10-05 10:32:46 +00:00
|
|
|
$this->backend->updateShares($exampleBook, [['href' => 'principal:' . self::UNIT_TEST_USER1]], []);
|
2015-11-18 14:04:53 +00:00
|
|
|
|
2016-01-25 21:49:26 +00:00
|
|
|
$shares = $this->backend->getShares($exampleBook->getResourceId());
|
2015-11-18 14:04:53 +00:00
|
|
|
$this->assertEquals(1, count($shares));
|
|
|
|
|
2017-10-05 10:32:46 +00:00
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER1);
|
2015-11-05 15:46:37 +00:00
|
|
|
$this->assertEquals(1, count($books));
|
|
|
|
|
2017-10-05 10:32:46 +00:00
|
|
|
$this->backend->updateShares($exampleBook, [], ['principal:' . self::UNIT_TEST_USER1]);
|
2015-11-05 15:46:37 +00:00
|
|
|
|
2016-01-25 21:49:26 +00:00
|
|
|
$shares = $this->backend->getShares($exampleBook->getResourceId());
|
2015-11-05 15:46:37 +00:00
|
|
|
$this->assertEquals(0, count($shares));
|
|
|
|
|
2017-10-05 10:32:46 +00:00
|
|
|
$books = $this->backend->getAddressBooksForUser(self::UNIT_TEST_USER1);
|
2015-11-05 15:46:37 +00:00
|
|
|
$this->assertEquals(0, count($books));
|
|
|
|
}
|
2015-11-25 14:24:50 +00:00
|
|
|
|
|
|
|
public function testUpdateProperties() {
|
|
|
|
|
|
|
|
$bookId = 42;
|
|
|
|
$cardUri = 'card-uri';
|
|
|
|
$cardId = 2;
|
|
|
|
|
2016-10-13 10:15:10 +00:00
|
|
|
$backend = $this->getMockBuilder(CardDavBackend::class)
|
2017-10-05 10:32:46 +00:00
|
|
|
->setConstructorArgs([$this->db, $this->principal, $this->userManager, $this->groupManager, $this->dispatcher])
|
2015-11-25 14:24:50 +00:00
|
|
|
->setMethods(['getCardId'])->getMock();
|
|
|
|
|
|
|
|
$backend->expects($this->any())->method('getCardId')->willReturn($cardId);
|
|
|
|
|
|
|
|
// add properties for new vCard
|
|
|
|
$vCard = new VCard();
|
2016-10-13 10:15:10 +00:00
|
|
|
$vCard->UID = $cardUri;
|
|
|
|
$vCard->FN = 'John Doe';
|
2015-11-25 14:24:50 +00:00
|
|
|
$this->invokePrivate($backend, 'updateProperties', [$bookId, $cardUri, $vCard->serialize()]);
|
|
|
|
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
$result = $query->select('*')->from('cards_properties')->execute()->fetchAll();
|
|
|
|
|
|
|
|
$this->assertSame(2, count($result));
|
|
|
|
|
|
|
|
$this->assertSame('UID', $result[0]['name']);
|
|
|
|
$this->assertSame($cardUri, $result[0]['value']);
|
|
|
|
$this->assertSame($bookId, (int)$result[0]['addressbookid']);
|
|
|
|
$this->assertSame($cardId, (int)$result[0]['cardid']);
|
|
|
|
|
|
|
|
$this->assertSame('FN', $result[1]['name']);
|
|
|
|
$this->assertSame('John Doe', $result[1]['value']);
|
|
|
|
$this->assertSame($bookId, (int)$result[1]['addressbookid']);
|
|
|
|
$this->assertSame($cardId, (int)$result[1]['cardid']);
|
|
|
|
|
|
|
|
// update properties for existing vCard
|
|
|
|
$vCard = new VCard();
|
2016-10-13 10:15:10 +00:00
|
|
|
$vCard->UID = $cardUri;
|
2015-11-25 14:24:50 +00:00
|
|
|
$this->invokePrivate($backend, 'updateProperties', [$bookId, $cardUri, $vCard->serialize()]);
|
|
|
|
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
$result = $query->select('*')->from('cards_properties')->execute()->fetchAll();
|
|
|
|
|
|
|
|
$this->assertSame(1, count($result));
|
|
|
|
|
2016-10-13 10:15:10 +00:00
|
|
|
$this->assertSame('UID', $result[0]['name']);
|
|
|
|
$this->assertSame($cardUri, $result[0]['value']);
|
2015-11-25 14:24:50 +00:00
|
|
|
$this->assertSame($bookId, (int)$result[0]['addressbookid']);
|
|
|
|
$this->assertSame($cardId, (int)$result[0]['cardid']);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPurgeProperties() {
|
|
|
|
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
$query->insert('cards_properties')
|
|
|
|
->values(
|
|
|
|
[
|
|
|
|
'addressbookid' => $query->createNamedParameter(1),
|
|
|
|
'cardid' => $query->createNamedParameter(1),
|
|
|
|
'name' => $query->createNamedParameter('name1'),
|
|
|
|
'value' => $query->createNamedParameter('value1'),
|
|
|
|
'preferred' => $query->createNamedParameter(0)
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$query->execute();
|
|
|
|
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
$query->insert('cards_properties')
|
|
|
|
->values(
|
|
|
|
[
|
|
|
|
'addressbookid' => $query->createNamedParameter(1),
|
|
|
|
'cardid' => $query->createNamedParameter(2),
|
|
|
|
'name' => $query->createNamedParameter('name2'),
|
|
|
|
'value' => $query->createNamedParameter('value2'),
|
|
|
|
'preferred' => $query->createNamedParameter(0)
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$query->execute();
|
|
|
|
|
|
|
|
$this->invokePrivate($this->backend, 'purgeProperties', [1, 1]);
|
|
|
|
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
$result = $query->select('*')->from('cards_properties')->execute()->fetchAll();
|
|
|
|
$this->assertSame(1, count($result));
|
|
|
|
$this->assertSame(1 ,(int)$result[0]['addressbookid']);
|
|
|
|
$this->assertSame(2 ,(int)$result[0]['cardid']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetCardId() {
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
|
|
|
|
$query->insert('cards')
|
|
|
|
->values(
|
|
|
|
[
|
|
|
|
'addressbookid' => $query->createNamedParameter(1),
|
|
|
|
'carddata' => $query->createNamedParameter(''),
|
|
|
|
'uri' => $query->createNamedParameter('uri'),
|
|
|
|
'lastmodified' => $query->createNamedParameter(4738743),
|
|
|
|
'etag' => $query->createNamedParameter('etag'),
|
|
|
|
'size' => $query->createNamedParameter(120)
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$query->execute();
|
|
|
|
$id = $query->getLastInsertId();
|
|
|
|
|
|
|
|
$this->assertSame($id,
|
2016-02-15 13:13:04 +00:00
|
|
|
$this->invokePrivate($this->backend, 'getCardId', [1, 'uri']));
|
2015-11-25 14:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testGetCardIdFailed() {
|
2016-02-15 13:13:04 +00:00
|
|
|
$this->invokePrivate($this->backend, 'getCardId', [1, 'uri']);
|
2015-11-25 14:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataTestSearch
|
|
|
|
*
|
|
|
|
* @param string $pattern
|
2016-01-25 21:49:26 +00:00
|
|
|
* @param array $properties
|
2015-11-25 14:24:50 +00:00
|
|
|
* @param array $expected
|
|
|
|
*/
|
2015-12-14 12:51:12 +00:00
|
|
|
public function testSearch($pattern, $properties, $expected) {
|
2015-12-14 10:48:31 +00:00
|
|
|
/** @var VCard $vCards */
|
2015-11-25 14:24:50 +00:00
|
|
|
$vCards = [];
|
|
|
|
$vCards[0] = new VCard();
|
|
|
|
$vCards[0]->add(new Text($vCards[0], 'UID', 'uid'));
|
|
|
|
$vCards[0]->add(new Text($vCards[0], 'FN', 'John Doe'));
|
2015-12-14 12:51:12 +00:00
|
|
|
$vCards[0]->add(new Text($vCards[0], 'CLOUD', 'john@owncloud.org'));
|
2015-11-25 14:24:50 +00:00
|
|
|
$vCards[1] = new VCard();
|
|
|
|
$vCards[1]->add(new Text($vCards[1], 'UID', 'uid'));
|
|
|
|
$vCards[1]->add(new Text($vCards[1], 'FN', 'John M. Doe'));
|
|
|
|
|
|
|
|
$vCardIds = [];
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
for($i=0; $i<2; $i++) {
|
|
|
|
$query->insert($this->dbCardsTable)
|
|
|
|
->values(
|
|
|
|
[
|
|
|
|
'addressbookid' => $query->createNamedParameter(0),
|
2016-02-29 08:44:40 +00:00
|
|
|
'carddata' => $query->createNamedParameter($vCards[$i]->serialize(), IQueryBuilder::PARAM_LOB),
|
2015-11-25 14:24:50 +00:00
|
|
|
'uri' => $query->createNamedParameter('uri' . $i),
|
2015-12-14 10:48:31 +00:00
|
|
|
'lastmodified' => $query->createNamedParameter(time()),
|
2015-11-25 14:24:50 +00:00
|
|
|
'etag' => $query->createNamedParameter('etag' . $i),
|
|
|
|
'size' => $query->createNamedParameter(120),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$query->execute();
|
|
|
|
$vCardIds[] = $query->getLastInsertId();
|
|
|
|
}
|
|
|
|
|
|
|
|
$query->insert($this->dbCardsPropertiesTable)
|
|
|
|
->values(
|
|
|
|
[
|
|
|
|
'addressbookid' => $query->createNamedParameter(0),
|
|
|
|
'cardid' => $query->createNamedParameter($vCardIds[0]),
|
|
|
|
'name' => $query->createNamedParameter('FN'),
|
|
|
|
'value' => $query->createNamedParameter('John Doe'),
|
|
|
|
'preferred' => $query->createNamedParameter(0)
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$query->execute();
|
2015-12-14 12:51:12 +00:00
|
|
|
$query->insert($this->dbCardsPropertiesTable)
|
|
|
|
->values(
|
|
|
|
[
|
|
|
|
'addressbookid' => $query->createNamedParameter(0),
|
|
|
|
'cardid' => $query->createNamedParameter($vCardIds[0]),
|
|
|
|
'name' => $query->createNamedParameter('CLOUD'),
|
|
|
|
'value' => $query->createNamedParameter('John@owncloud.org'),
|
|
|
|
'preferred' => $query->createNamedParameter(0)
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$query->execute();
|
2015-11-25 14:24:50 +00:00
|
|
|
$query->insert($this->dbCardsPropertiesTable)
|
|
|
|
->values(
|
|
|
|
[
|
|
|
|
'addressbookid' => $query->createNamedParameter(0),
|
|
|
|
'cardid' => $query->createNamedParameter($vCardIds[1]),
|
|
|
|
'name' => $query->createNamedParameter('FN'),
|
|
|
|
'value' => $query->createNamedParameter('John M. Doe'),
|
|
|
|
'preferred' => $query->createNamedParameter(0)
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$query->execute();
|
|
|
|
|
2015-12-14 12:51:12 +00:00
|
|
|
$result = $this->backend->search(0, $pattern, $properties);
|
2015-11-25 14:24:50 +00:00
|
|
|
|
|
|
|
// check result
|
|
|
|
$this->assertSame(count($expected), count($result));
|
|
|
|
$found = [];
|
|
|
|
foreach ($result as $r) {
|
|
|
|
foreach ($expected as $exp) {
|
2016-06-21 13:25:44 +00:00
|
|
|
if ($r['uri'] === $exp[0] && strpos($r['carddata'], $exp[1]) > 0) {
|
|
|
|
$found[$exp[1]] = true;
|
2015-11-25 14:24:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertSame(count($expected), count($found));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function dataTestSearch() {
|
|
|
|
return [
|
2016-06-21 13:25:44 +00:00
|
|
|
['John', ['FN'], [['uri0', 'John Doe'], ['uri1', 'John M. Doe']]],
|
|
|
|
['M. Doe', ['FN'], [['uri1', 'John M. Doe']]],
|
|
|
|
['Do', ['FN'], [['uri0', 'John Doe'], ['uri1', 'John M. Doe']]],
|
|
|
|
'check if duplicates are handled correctly' => ['John', ['FN', 'CLOUD'], [['uri0', 'John Doe'], ['uri1', 'John M. Doe']]],
|
|
|
|
'case insensitive' => ['john', ['FN'], [['uri0', 'John Doe'], ['uri1', 'John M. Doe']]]
|
2015-11-25 14:24:50 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetCardUri() {
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
$query->insert($this->dbCardsTable)
|
|
|
|
->values(
|
|
|
|
[
|
|
|
|
'addressbookid' => $query->createNamedParameter(1),
|
2016-02-29 08:44:40 +00:00
|
|
|
'carddata' => $query->createNamedParameter('carddata', IQueryBuilder::PARAM_LOB),
|
2015-11-25 14:24:50 +00:00
|
|
|
'uri' => $query->createNamedParameter('uri'),
|
|
|
|
'lastmodified' => $query->createNamedParameter(5489543),
|
|
|
|
'etag' => $query->createNamedParameter('etag'),
|
|
|
|
'size' => $query->createNamedParameter(120),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$query->execute();
|
|
|
|
|
|
|
|
$id = $query->getLastInsertId();
|
|
|
|
|
|
|
|
$this->assertSame('uri', $this->backend->getCardUri($id));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testGetCardUriFailed() {
|
|
|
|
$this->backend->getCardUri(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetContact() {
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
for($i=0; $i<2; $i++) {
|
|
|
|
$query->insert($this->dbCardsTable)
|
|
|
|
->values(
|
|
|
|
[
|
|
|
|
'addressbookid' => $query->createNamedParameter($i),
|
2016-02-29 08:44:40 +00:00
|
|
|
'carddata' => $query->createNamedParameter('carddata' . $i, IQueryBuilder::PARAM_LOB),
|
2015-11-25 14:24:50 +00:00
|
|
|
'uri' => $query->createNamedParameter('uri' . $i),
|
|
|
|
'lastmodified' => $query->createNamedParameter(5489543),
|
|
|
|
'etag' => $query->createNamedParameter('etag' . $i),
|
|
|
|
'size' => $query->createNamedParameter(120),
|
|
|
|
]
|
|
|
|
);
|
|
|
|
$query->execute();
|
|
|
|
}
|
|
|
|
|
2016-02-15 13:13:04 +00:00
|
|
|
$result = $this->backend->getContact(0, 'uri0');
|
2018-11-02 13:20:53 +00:00
|
|
|
$this->assertSame(8, count($result));
|
2015-11-25 14:24:50 +00:00
|
|
|
$this->assertSame(0, (int)$result['addressbookid']);
|
|
|
|
$this->assertSame('uri0', $result['uri']);
|
|
|
|
$this->assertSame(5489543, (int)$result['lastmodified']);
|
|
|
|
$this->assertSame('etag0', $result['etag']);
|
|
|
|
$this->assertSame(120, (int)$result['size']);
|
2016-06-28 14:11:06 +00:00
|
|
|
|
|
|
|
// this shouldn't return any result because 'uri1' is in address book 1
|
|
|
|
// see https://github.com/nextcloud/server/issues/229
|
|
|
|
$result = $this->backend->getContact(0, 'uri1');
|
|
|
|
$this->assertEmpty($result);
|
2015-11-25 14:24:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetContactFail() {
|
2016-02-15 13:13:04 +00:00
|
|
|
$this->assertEmpty($this->backend->getContact(0, 'uri'));
|
2015-11-25 14:24:50 +00:00
|
|
|
}
|
|
|
|
|
2016-02-10 16:06:13 +00:00
|
|
|
public function testCollectCardProperties() {
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
$query->insert($this->dbCardsPropertiesTable)
|
|
|
|
->values(
|
|
|
|
[
|
|
|
|
'addressbookid' => $query->createNamedParameter(666),
|
|
|
|
'cardid' => $query->createNamedParameter(777),
|
|
|
|
'name' => $query->createNamedParameter('FN'),
|
|
|
|
'value' => $query->createNamedParameter('John Doe'),
|
|
|
|
'preferred' => $query->createNamedParameter(0)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
$result = $this->backend->collectCardProperties(666, 'FN');
|
|
|
|
$this->assertEquals(['John Doe'], $result);
|
|
|
|
}
|
2015-10-30 15:05:25 +00:00
|
|
|
}
|