]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CardDAV/PluginTest.php
removed community home addon
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CardDAV / PluginTest.php
1 <?php
2
3 require_once 'Sabre/DAVACL/MockPrincipalBackend.php';
4 require_once 'Sabre/CardDAV/AbstractPluginTest.php';
5
6 class Sabre_CardDAV_PluginTest extends Sabre_CardDAV_AbstractPluginTest {
7
8     function testConstruct() {
9
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']);
12
13         $this->assertTrue(in_array('addressbook', $this->plugin->getFeatures()));
14
15     }
16
17     function testSupportedReportSet() {
18
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'));
23
24     }
25
26     function testSupportedReportSetEmpty() {
27
28         $this->assertEquals(array(
29         ), $this->plugin->getSupportedReportSet(''));
30
31     }
32
33     function testAddressBookHomeSet() {
34
35         $result = $this->server->getProperties('principals/user1', array('{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-home-set'));
36
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());
40
41     }
42
43     function testMeCardTest() {
44
45         $result = $this->server->getProperties(
46             'addressbooks/user1',
47             array(
48                 '{http://calendarserver.org/ns/}me-card',
49             )
50         );
51
52         $this->assertEquals(
53             array(
54                 '{http://calendarserver.org/ns/}me-card' =>  
55                     new Sabre_DAV_Property_Href('addressbooks/user1/book1/vcard1.vcf') 
56             ),
57             $result
58         );
59
60     }
61
62     function testDirectoryGateway() {
63
64         $result = $this->server->getProperties('principals/user1', array('{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}directory-gateway'));
65
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());
69
70     }
71
72     function testReportPassThrough() {
73
74         $this->assertNull($this->plugin->report('{DAV:}foo', new DomDocument()));
75
76     }
77
78     function testHTMLActionsPanel() {
79
80         $output = '';
81         $r = $this->server->broadcastEvent('onHTMLActionsPanel', array($this->server->tree->getNodeForPath('addressbooks/user1'), &$output));
82         $this->assertFalse($r);
83
84         $this->assertTrue(!!strpos($output,'Display name'));
85
86     }
87
88     function testBrowserPostAction() {
89
90         $r = $this->server->broadcastEvent('onBrowserPostAction', array('addressbooks/user1', 'mkaddressbook', array(
91             'name' => 'NEWADDRESSBOOK',
92             '{DAV:}displayname' => 'foo',
93         )));
94         $this->assertFalse($r);
95
96         $addressbooks = $this->backend->getAddressBooksforUser('principals/user1');
97         $this->assertEquals(2, count($addressbooks));
98
99         $newAddressBook = null;
100         foreach($addressbooks as $addressbook) {
101            if ($addressbook['uri'] === 'NEWADDRESSBOOK') {
102                 $newAddressBook = $addressbook;
103                 break;
104            }
105         }
106         if (!$newAddressBook)
107             $this->fail('Could not find newly created addressbook');
108
109     }
110
111     function testUpdatePropertiesMeCard() {
112
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),
115         ));
116
117         $this->assertEquals(
118             array(
119                 'href' => 'addressbooks/user1',
120                 200 => array(
121                     '{http://calendarserver.org/ns/}me-card' => null,
122                 ),
123             ),
124             $result
125         );
126
127     }
128
129     function testUpdatePropertiesMeCardBadValue() {
130
131         $result = $this->server->updateProperties('addressbooks/user1', array(
132             '{http://calendarserver.org/ns/}me-card' => new Sabre_DAV_Property_HrefList(array()),
133         ));
134
135         $this->assertEquals(
136             array(
137                 'href' => 'addressbooks/user1',
138                 400 => array(
139                     '{http://calendarserver.org/ns/}me-card' => null,
140                 ),
141             ),
142             $result
143         );
144
145     }
146 }