]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CardDAV/Backend/AbstractPDOTest.php
Merge remote branch 'upstream/master'
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CardDAV / Backend / AbstractPDOTest.php
1 <?php
2
3 abstract class Sabre_CardDAV_Backend_AbstractPDOTest extends PHPUnit_Framework_TestCase {
4
5     /**
6      * @var Sabre_CardDAV_Backend_PDO
7      */
8     protected $backend;
9
10     /**
11      * @abstract
12      * @return PDO
13      */
14     abstract function getPDO();
15
16     public function setUp() {
17
18         $this->backend = new Sabre_CardDAV_Backend_PDO($this->getPDO());
19
20     }
21
22     public function testGetAddressBooksForUser() {
23
24         $result = $this->backend->getAddressBooksForUser('principals/user1');
25
26         $expected = array(
27             array(
28                 'id' => 1,
29                 'uri' => 'book1',
30                 'principaluri' => 'principals/user1',
31                 '{DAV:}displayname' => 'book1',
32                 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
33                 '{http://calendarserver.org/ns/}getctag' => 1,
34                 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
35             )
36         );
37
38         $this->assertEquals($expected, $result);
39
40     }
41
42     public function testUpdateAddressBookInvalidProp() {
43
44         $result = $this->backend->updateAddressBook(1, array(
45             '{DAV:}displayname' => 'updated',
46             '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
47             '{DAV:}foo' => 'bar',
48         ));
49
50         $this->assertFalse($result);
51
52         $result = $this->backend->getAddressBooksForUser('principals/user1');
53
54         $expected = array(
55             array(
56                 'id' => 1,
57                 'uri' => 'book1',
58                 'principaluri' => 'principals/user1',
59                 '{DAV:}displayname' => 'book1',
60                 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
61                 '{http://calendarserver.org/ns/}getctag' => 1,
62                 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
63             )
64         );
65
66         $this->assertEquals($expected, $result);
67
68     }
69
70     public function testUpdateAddressBookNoProps() {
71
72         $result = $this->backend->updateAddressBook(1, array());
73
74         $this->assertFalse($result);
75
76         $result = $this->backend->getAddressBooksForUser('principals/user1');
77
78         $expected = array(
79             array(
80                 'id' => 1,
81                 'uri' => 'book1',
82                 'principaluri' => 'principals/user1',
83                 '{DAV:}displayname' => 'book1',
84                 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
85                 '{http://calendarserver.org/ns/}getctag' => 1,
86                 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
87             )
88         );
89
90         $this->assertEquals($expected, $result);
91
92
93     }
94
95     public function testUpdateAddressBookSuccess() {
96
97         $result = $this->backend->updateAddressBook(1, array(
98             '{DAV:}displayname' => 'updated',
99             '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
100         ));
101
102         $this->assertTrue($result);
103
104         $result = $this->backend->getAddressBooksForUser('principals/user1');
105
106         $expected = array(
107             array(
108                 'id' => 1,
109                 'uri' => 'book1',
110                 'principaluri' => 'principals/user1',
111                 '{DAV:}displayname' => 'updated',
112                 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
113                 '{http://calendarserver.org/ns/}getctag' => 2,
114                 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
115             )
116         );
117
118         $this->assertEquals($expected, $result);
119
120
121     }
122
123     public function testDeleteAddressBook() {
124
125         $this->backend->deleteAddressBook(1);
126
127         $this->assertEquals(array(), $this->backend->getAddressBooksForUser('principals/user1'));
128
129     }
130
131     /**
132      * @expectedException Sabre_DAV_Exception_BadRequest
133      */
134     public function testCreateAddressBookUnsupportedProp() {
135
136         $this->backend->createAddressBook('principals/user1','book2', array(
137             '{DAV:}foo' => 'bar',
138         ));
139
140     }
141
142     public function testCreateAddressBookSuccess() {
143
144         $this->backend->createAddressBook('principals/user1','book2', array(
145             '{DAV:}displayname' => 'book2',
146             '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 2',
147         ));
148
149         $expected = array(
150             array(
151                 'id' => 1,
152                 'uri' => 'book1',
153                 'principaluri' => 'principals/user1',
154                 '{DAV:}displayname' => 'book1',
155                 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
156                 '{http://calendarserver.org/ns/}getctag' => 1,
157                 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
158             ),
159             array(
160                 'id' => 2,
161                 'uri' => 'book2',
162                 'principaluri' => 'principals/user1',
163                 '{DAV:}displayname' => 'book2',
164                 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 2',
165                 '{http://calendarserver.org/ns/}getctag' => 1,
166                 '{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}supported-address-data' => new Sabre_CardDAV_Property_SupportedAddressData(),
167             )
168         );
169         $result = $this->backend->getAddressBooksForUser('principals/user1');
170         $this->assertEquals($expected, $result);
171
172     }
173
174     public function testGetCards() {
175
176         $result = $this->backend->getCards(1);
177
178         $expected = array(
179             array(
180                 'id' => 1,
181                 'uri' => 'card1',
182                 'carddata' => 'card1',
183                 'lastmodified' => 0,
184             )
185         );
186
187         $this->assertEquals($expected, $result);
188
189     }
190
191     public function testGetCard() {
192
193         $result = $this->backend->getCard(1,'card1');
194
195         $expected = array(
196             'id' => 1,
197             'uri' => 'card1',
198             'carddata' => 'card1',
199             'lastmodified' => 0,
200         );
201
202         $this->assertEquals($expected, $result);
203
204     }
205
206     /**
207      * @depends testGetCard
208      */
209     public function testCreateCard() {
210
211         $result = $this->backend->createCard(1, 'card2', 'data2');
212         $this->assertEquals('"' . md5('data2') . '"', $result);
213         $result = $this->backend->getCard(1,'card2');
214         $this->assertEquals(2, $result['id']);
215         $this->assertEquals('card2', $result['uri']);
216         $this->assertEquals('data2', $result['carddata']);
217
218     }
219
220     /**
221      * @depends testGetCard
222      */
223     public function testUpdateCard() {
224
225         $result = $this->backend->updateCard(1, 'card1', 'newdata');
226         $this->assertEquals('"' . md5('newdata') . '"', $result);
227
228         $result = $this->backend->getCard(1,'card1');
229         $this->assertEquals(1, $result['id']);
230         $this->assertEquals('newdata', $result['carddata']);
231
232     }
233
234     /**
235      * @depends testGetCard
236      */
237     public function testDeleteCard() {
238
239         $this->backend->deleteCard(1, 'card1');
240         $result = $this->backend->getCard(1,'card1');
241         $this->assertFalse($result);
242
243     }
244 }
245