|
|
|
|
@ -27,7 +27,6 @@ use InvalidArgumentException;
|
|
|
|
|
use OCA\DAV\CardDAV\AddressBook;
|
|
|
|
|
use OCA\DAV\CardDAV\CardDavBackend;
|
|
|
|
|
use OCA\DAV\Connector\Sabre\Principal;
|
|
|
|
|
use OCA\DAV\DAV\GroupPrincipalBackend;
|
|
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
use Sabre\DAV\PropPatch;
|
|
|
|
|
@ -59,9 +58,6 @@ class CardDavBackendTest extends TestCase {
|
|
|
|
|
/** @var string */
|
|
|
|
|
private $dbCardsPropertiesTable = 'cards_properties';
|
|
|
|
|
|
|
|
|
|
/** @var GroupPrincipalBackend */
|
|
|
|
|
private $groupPrincipal;
|
|
|
|
|
|
|
|
|
|
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';
|
|
|
|
|
@ -73,21 +69,17 @@ class CardDavBackendTest extends TestCase {
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->setMethods(['getPrincipalByPath', 'getGroupMembership'])
|
|
|
|
|
->getMock();
|
|
|
|
|
$this->principal->expects($this->any())->method('getPrincipalByPath')
|
|
|
|
|
$this->principal->method('getPrincipalByPath')
|
|
|
|
|
->willReturn([
|
|
|
|
|
'uri' => 'principals/best-friend'
|
|
|
|
|
]);
|
|
|
|
|
$this->principal->expects($this->any())->method('getGroupMembership')
|
|
|
|
|
$this->principal->method('getGroupMembership')
|
|
|
|
|
->withAnyParameters()
|
|
|
|
|
->willReturn([self::UNIT_TEST_GROUP]);
|
|
|
|
|
$this->groupPrincipal = $this->getMockBuilder('OCA\DAV\DAV\GroupPrincipalBackend')
|
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
|
->setMethods(['getPrincipalByPath', 'getGroupMembership'])
|
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
|
|
$this->db = \OC::$server->getDatabaseConnection();
|
|
|
|
|
|
|
|
|
|
$this->backend = new CardDavBackend($this->db, $this->principal, $this->groupPrincipal, null);
|
|
|
|
|
$this->backend = new CardDavBackend($this->db, $this->principal, null);
|
|
|
|
|
|
|
|
|
|
// start every test with a empty cards_properties and cards table
|
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
|
@ -165,7 +157,7 @@ class CardDavBackendTest extends TestCase {
|
|
|
|
|
|
|
|
|
|
/** @var CardDavBackend | \PHPUnit_Framework_MockObject_MockObject $backend */
|
|
|
|
|
$backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')
|
|
|
|
|
->setConstructorArgs([$this->db, $this->principal, $this->groupPrincipal, null])
|
|
|
|
|
->setConstructorArgs([$this->db, $this->principal, null])
|
|
|
|
|
->setMethods(['updateProperties', 'purgeProperties'])->getMock();
|
|
|
|
|
|
|
|
|
|
// create a new address book
|
|
|
|
|
@ -211,7 +203,7 @@ class CardDavBackendTest extends TestCase {
|
|
|
|
|
public function testMultiCard() {
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')
|
|
|
|
|
->setConstructorArgs([$this->db, $this->principal, $this->groupPrincipal, null])
|
|
|
|
|
->setConstructorArgs([$this->db, $this->principal, null])
|
|
|
|
|
->setMethods(['updateProperties'])->getMock();
|
|
|
|
|
|
|
|
|
|
// create a new address book
|
|
|
|
|
@ -256,8 +248,9 @@ class CardDavBackendTest extends TestCase {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testDeleteWithoutCard() {
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')
|
|
|
|
|
->setConstructorArgs([$this->db, $this->principal, $this->groupPrincipal, null])
|
|
|
|
|
->setConstructorArgs([$this->db, $this->principal, null])
|
|
|
|
|
->setMethods([
|
|
|
|
|
'getCardId',
|
|
|
|
|
'addChange',
|
|
|
|
|
@ -296,8 +289,9 @@ class CardDavBackendTest extends TestCase {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testSyncSupport() {
|
|
|
|
|
|
|
|
|
|
$this->backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')
|
|
|
|
|
->setConstructorArgs([$this->db, $this->principal, $this->groupPrincipal, null])
|
|
|
|
|
->setConstructorArgs([$this->db, $this->principal, null])
|
|
|
|
|
->setMethods(['updateProperties'])->getMock();
|
|
|
|
|
|
|
|
|
|
// create a new address book
|
|
|
|
|
@ -327,13 +321,13 @@ class CardDavBackendTest extends TestCase {
|
|
|
|
|
$exampleBook = new AddressBook($this->backend, $books[0]);
|
|
|
|
|
$this->backend->updateShares($exampleBook, [['href' => 'principal:principals/best-friend']], []);
|
|
|
|
|
|
|
|
|
|
$shares = $this->backend->getShares($exampleBook->getResourceId(), null);
|
|
|
|
|
$shares = $this->backend->getShares($exampleBook->getResourceId());
|
|
|
|
|
$this->assertEquals(1, count($shares));
|
|
|
|
|
|
|
|
|
|
// adding the same sharee again has no effect
|
|
|
|
|
$this->backend->updateShares($exampleBook, [['href' => 'principal:principals/best-friend']], []);
|
|
|
|
|
|
|
|
|
|
$shares = $this->backend->getShares($exampleBook->getResourceId(), null);
|
|
|
|
|
$shares = $this->backend->getShares($exampleBook->getResourceId());
|
|
|
|
|
$this->assertEquals(1, count($shares));
|
|
|
|
|
|
|
|
|
|
$books = $this->backend->getAddressBooksForUser('principals/best-friend');
|
|
|
|
|
@ -341,7 +335,7 @@ class CardDavBackendTest extends TestCase {
|
|
|
|
|
|
|
|
|
|
$this->backend->updateShares($exampleBook, [], ['principal:principals/best-friend']);
|
|
|
|
|
|
|
|
|
|
$shares = $this->backend->getShares($exampleBook->getResourceId(), null);
|
|
|
|
|
$shares = $this->backend->getShares($exampleBook->getResourceId());
|
|
|
|
|
$this->assertEquals(0, count($shares));
|
|
|
|
|
|
|
|
|
|
$books = $this->backend->getAddressBooksForUser('principals/best-friend');
|
|
|
|
|
@ -355,7 +349,7 @@ class CardDavBackendTest extends TestCase {
|
|
|
|
|
$cardId = 2;
|
|
|
|
|
|
|
|
|
|
$backend = $this->getMockBuilder('OCA\DAV\CardDAV\CardDavBackend')
|
|
|
|
|
->setConstructorArgs([$this->db, $this->principal, $this->groupPrincipal, null])
|
|
|
|
|
->setConstructorArgs([$this->db, $this->principal, null])
|
|
|
|
|
->setMethods(['getCardId'])->getMock();
|
|
|
|
|
|
|
|
|
|
$backend->expects($this->any())->method('getCardId')->willReturn($cardId);
|
|
|
|
|
|