3 require_once 'Sabre/DAVACL/MockPrincipalBackend.php';
4 require_once 'Sabre/CardDAV/AbstractPluginTest.php';
6 class Sabre_CardDAV_PluginTest extends Sabre_CardDAV_AbstractPluginTest {
8 function testConstruct() {
10 $this->assertEquals('card', $this->server->xmlNamespaces[Sabre_CardDAV_Plugin::NS_CARDDAV]);
11 $this->assertEquals('{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook', $this->server->resourceTypeMapping['Sabre_CardDAV_IAddressBook']);
13 $this->assertTrue(in_array('addressbook', $this->plugin->getFeatures()));
17 function testSupportedReportSet() {
19 $this->assertEquals(array(
20 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-multiget',
21 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-query',
22 ), $this->plugin->getSupportedReportSet('addressbooks/user1/book1'));
26 function testSupportedReportSetEmpty() {
28 $this->assertEquals(array(
29 ), $this->plugin->getSupportedReportSet(''));
33 function testAddressBookHomeSet() {
35 $result = $this->server->getProperties('principals/user1', array('{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-home-set'));
37 $this->assertEquals(1, count($result));
38 $this->assertTrue(isset($result['{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-home-set']));
39 $this->assertEquals('addressbooks/user1/', $result['{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-home-set']->getHref());
43 function testMeCardTest() {
45 $result = $this->server->getProperties(
48 '{http://calendarserver.org/ns/}me-card',
54 '{http://calendarserver.org/ns/}me-card' =>
55 new Sabre_DAV_Property_Href('addressbooks/user1/book1/vcard1.vcf')
62 function testDirectoryGateway() {
64 $result = $this->server->getProperties('principals/user1', array('{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}directory-gateway'));
66 $this->assertEquals(1, count($result));
67 $this->assertTrue(isset($result['{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}directory-gateway']));
68 $this->assertEquals(array('directory'), $result['{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}directory-gateway']->getHrefs());
72 function testReportPassThrough() {
74 $this->assertNull($this->plugin->report('{DAV:}foo', new DomDocument()));
78 function testHTMLActionsPanel() {
81 $r = $this->server->broadcastEvent('onHTMLActionsPanel', array($this->server->tree->getNodeForPath('addressbooks/user1'), &$output));
82 $this->assertFalse($r);
84 $this->assertTrue(!!strpos($output,'Display name'));
88 function testBrowserPostAction() {
90 $r = $this->server->broadcastEvent('onBrowserPostAction', array('addressbooks/user1', 'mkaddressbook', array(
91 'name' => 'NEWADDRESSBOOK',
92 '{DAV:}displayname' => 'foo',
94 $this->assertFalse($r);
96 $addressbooks = $this->backend->getAddressBooksforUser('principals/user1');
97 $this->assertEquals(2, count($addressbooks));
99 $newAddressBook = null;
100 foreach($addressbooks as $addressbook) {
101 if ($addressbook['uri'] === 'NEWADDRESSBOOK') {
102 $newAddressBook = $addressbook;
106 if (!$newAddressBook)
107 $this->fail('Could not find newly created addressbook');
111 function testUpdatePropertiesMeCard() {
113 $result = $this->server->updateProperties('addressbooks/user1', array(
114 '{http://calendarserver.org/ns/}me-card' => new Sabre_DAV_Property_Href('/addressbooks/user1/book1/vcard2',true),
119 'href' => 'addressbooks/user1',
121 '{http://calendarserver.org/ns/}me-card' => null,
129 function testUpdatePropertiesMeCardBadValue() {
131 $result = $this->server->updateProperties('addressbooks/user1', array(
132 '{http://calendarserver.org/ns/}me-card' => new Sabre_DAV_Property_HrefList(array()),
137 'href' => 'addressbooks/user1',
139 '{http://calendarserver.org/ns/}me-card' => null,