2013-10-21 22:46:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Sabre\CardDAV;
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
use Sabre\DAV\PropPatch;
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
class AddressBookTest extends \PHPUnit_Framework_TestCase {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
use \Sabre\DAV\DbTestHelperTrait;
|
|
|
|
|
2013-10-21 22:46:31 +00:00
|
|
|
/**
|
|
|
|
* @var Sabre\CardDAV\AddressBook
|
|
|
|
*/
|
|
|
|
protected $ab;
|
|
|
|
protected $backend;
|
|
|
|
|
|
|
|
function setUp() {
|
|
|
|
|
|
|
|
$this->backend = new Backend\Mock();
|
|
|
|
$this->ab = new AddressBook(
|
|
|
|
$this->backend,
|
2016-05-28 15:46:24 +00:00
|
|
|
[
|
|
|
|
'uri' => 'book1',
|
|
|
|
'id' => 'foo',
|
2013-10-21 22:46:31 +00:00
|
|
|
'{DAV:}displayname' => 'd-name',
|
2016-05-28 15:46:24 +00:00
|
|
|
'principaluri' => 'principals/user1',
|
|
|
|
]
|
2013-10-21 22:46:31 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetName() {
|
|
|
|
|
|
|
|
$this->assertEquals('book1', $this->ab->getName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetChild() {
|
|
|
|
|
|
|
|
$card = $this->ab->getChild('card1');
|
|
|
|
$this->assertInstanceOf('Sabre\\CardDAV\\Card', $card);
|
|
|
|
$this->assertEquals('card1', $card->getName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception\NotFound
|
|
|
|
*/
|
|
|
|
function testGetChildNotFound() {
|
|
|
|
|
|
|
|
$card = $this->ab->getChild('card3');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetChildren() {
|
|
|
|
|
|
|
|
$cards = $this->ab->getChildren();
|
|
|
|
$this->assertEquals(2, count($cards));
|
|
|
|
|
|
|
|
$this->assertEquals('card1', $cards[0]->getName());
|
|
|
|
$this->assertEquals('card2', $cards[1]->getName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
|
|
|
|
*/
|
|
|
|
function testCreateDirectory() {
|
|
|
|
|
|
|
|
$this->ab->createDirectory('name');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testCreateFile() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$file = fopen('php://memory', 'r+');
|
|
|
|
fwrite($file, 'foo');
|
2013-10-21 22:46:31 +00:00
|
|
|
rewind($file);
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->ab->createFile('card2', $file);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$this->assertEquals('foo', $this->backend->cards['foo']['card2']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testDelete() {
|
|
|
|
|
|
|
|
$this->ab->delete();
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([], $this->backend->addressBooks);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Sabre\DAV\Exception\MethodNotAllowed
|
|
|
|
*/
|
|
|
|
function testSetName() {
|
|
|
|
|
|
|
|
$this->ab->setName('foo');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetLastModified() {
|
|
|
|
|
|
|
|
$this->assertNull($this->ab->getLastModified());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testUpdateProperties() {
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$propPatch = new PropPatch([
|
|
|
|
'{DAV:}displayname' => 'barrr',
|
|
|
|
]);
|
|
|
|
$this->ab->propPatch($propPatch);
|
|
|
|
$this->assertTrue($propPatch->commit());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$this->assertEquals('barrr', $this->backend->addressBooks[0]['{DAV:}displayname']);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetProperties() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$props = $this->ab->getProperties(['{DAV:}displayname']);
|
|
|
|
$this->assertEquals([
|
2013-10-21 22:46:31 +00:00
|
|
|
'{DAV:}displayname' => 'd-name',
|
2016-05-28 15:46:24 +00:00
|
|
|
], $props);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testACLMethods() {
|
|
|
|
|
|
|
|
$this->assertEquals('principals/user1', $this->ab->getOwner());
|
|
|
|
$this->assertNull($this->ab->getGroup());
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
[
|
|
|
|
'privilege' => '{DAV:}all',
|
|
|
|
'principal' => '{DAV:}owner',
|
2013-10-21 22:46:31 +00:00
|
|
|
'protected' => true,
|
2016-05-28 15:46:24 +00:00
|
|
|
],
|
|
|
|
], $this->ab->getACL());
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-28 15:46:24 +00:00
|
|
|
* @expectedException Sabre\DAV\Exception\Forbidden
|
2013-10-21 22:46:31 +00:00
|
|
|
*/
|
|
|
|
function testSetACL() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->ab->setACL([]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetSupportedPrivilegeSet() {
|
|
|
|
|
|
|
|
$this->assertNull(
|
|
|
|
$this->ab->getSupportedPrivilegeSet()
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
function testGetSyncTokenNoSyncSupport() {
|
|
|
|
|
|
|
|
$this->assertNull($this->ab->getSyncToken());
|
|
|
|
|
|
|
|
}
|
|
|
|
function testGetChangesNoSyncSupport() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertNull($this->ab->getChanges(1, null));
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetSyncToken() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->driver = 'sqlite';
|
|
|
|
$this->dropTables(['addressbooks', 'cards', 'addressbookchanges']);
|
|
|
|
$this->createSchema('addressbooks');
|
|
|
|
$backend = new Backend\PDO(
|
|
|
|
$this->getPDO()
|
|
|
|
);
|
|
|
|
$ab = new AddressBook($backend, [ 'id' => 1, '{DAV:}sync-token' => 2]);
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(2, $ab->getSyncToken());
|
|
|
|
}
|
|
|
|
|
|
|
|
function testGetSyncToken2() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->driver = 'sqlite';
|
|
|
|
$this->dropTables(['addressbooks', 'cards', 'addressbookchanges']);
|
|
|
|
$this->createSchema('addressbooks');
|
|
|
|
$backend = new Backend\PDO(
|
|
|
|
$this->getPDO()
|
|
|
|
);
|
|
|
|
$ab = new AddressBook($backend, [ 'id' => 1, '{http://sabredav.org/ns}sync-token' => 2]);
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(2, $ab->getSyncToken());
|
|
|
|
}
|
|
|
|
|
2013-10-21 22:46:31 +00:00
|
|
|
}
|