3 require_once 'Sabre/CardDAV/Backend/Mock.php';
5 class Sabre_CardDAV_AddressBookTest extends PHPUnit_Framework_TestCase {
8 * @var Sabre_CardDAV_AddressBook
15 $this->backend = new Sabre_CardDAV_Backend_Mock();
16 $this->ab = new Sabre_CardDAV_AddressBook(
21 '{DAV:}displayname' => 'd-name',
22 'principaluri' => 'principals/user1',
28 function testGetName() {
30 $this->assertEquals('book1', $this->ab->getName());
34 function testGetChild() {
36 $card = $this->ab->getChild('card1');
37 $this->assertInstanceOf('Sabre_CardDAV_Card', $card);
38 $this->assertEquals('card1', $card->getName());
43 * @expectedException Sabre_DAV_Exception_NotFound
45 function testGetChildNotFound() {
47 $card = $this->ab->getChild('card3');
51 function testGetChildren() {
53 $cards = $this->ab->getChildren();
54 $this->assertEquals(2, count($cards));
56 $this->assertEquals('card1', $cards[0]->getName());
57 $this->assertEquals('card2', $cards[1]->getName());
62 * @expectedException Sabre_DAV_Exception_MethodNotAllowed
64 function testCreateDirectory() {
66 $this->ab->createDirectory('name');
70 function testCreateFile() {
72 $file = fopen('php://memory','r+');
75 $this->ab->createFile('card2',$file);
77 $this->assertEquals('foo', $this->backend->cards['foo']['card2']);
81 function testDelete() {
84 $this->assertEquals(array(), $this->backend->addressBooks);
89 * @expectedException Sabre_DAV_Exception_MethodNotAllowed
91 function testSetName() {
93 $this->ab->setName('foo');
97 function testGetLastModified() {
99 $this->assertNull($this->ab->getLastModified());
103 function testUpdateProperties() {
106 $this->ab->updateProperties(array('{DAV:}displayname' => 'barrr'))
109 $this->assertEquals('barrr', $this->backend->addressBooks[0]['{DAV:}displayname']);
113 function testGetProperties() {
115 $props = $this->ab->getProperties(array('{DAV:}displayname'));
116 $this->assertEquals(array(
117 '{DAV:}displayname' => 'd-name',
122 function testACLMethods() {
124 $this->assertEquals('principals/user1', $this->ab->getOwner());
125 $this->assertNull($this->ab->getGroup());
126 $this->assertEquals(array(
128 'privilege' => '{DAV:}read',
129 'principal' => 'principals/user1',
133 'privilege' => '{DAV:}write',
134 'principal' => 'principals/user1',
137 ), $this->ab->getACL());
142 * @expectedException Sabre_DAV_Exception_MethodNotAllowed
144 function testSetACL() {
146 $this->ab->setACL(array());
150 function testGetSupportedPrivilegeSet() {
153 $this->ab->getSupportedPrivilegeSet()