ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\CardDAV\Backend\AbstractPDOTest Class Reference
+ Inheritance diagram for Sabre\CardDAV\Backend\AbstractPDOTest:
+ Collaboration diagram for Sabre\CardDAV\Backend\AbstractPDOTest:

Public Member Functions

 setUp ()
 
 testGetAddressBooksForUser ()
 
 testUpdateAddressBookInvalidProp ()
 
 testUpdateAddressBookNoProps ()
 
 testUpdateAddressBookSuccess ()
 
 testDeleteAddressBook ()
 
 testCreateAddressBookUnsupportedProp ()
 Sabre More...
 
 testCreateAddressBookSuccess ()
 
 testGetCards ()
 
 testGetCard ()
 
 testCreateCard ()
 testGetCard More...
 
 testGetMultiple ()
 testCreateCard More...
 
 testUpdateCard ()
 testGetCard More...
 
 testDeleteCard ()
 testGetCard More...
 
 testGetChanges ()
 

Protected Attributes

 $backend
 

Detailed Description

Definition at line 8 of file AbstractPDOTest.php.

Member Function Documentation

◆ setUp()

Sabre\CardDAV\Backend\AbstractPDOTest::setUp ( )

Definition at line 17 of file AbstractPDOTest.php.

References $pdo, Sabre\DAV\createSchema(), Sabre\DAV\dropTables(), and Sabre\DAV\getPDO().

17  {
18 
19  $this->dropTables([
20  'addressbooks',
21  'cards',
22  'addressbookchanges',
23  ]);
24  $this->createSchema('addressbooks');
25  $pdo = $this->getPDO();
26 
27  $this->backend = new PDO($pdo);
28  $pdo->exec("INSERT INTO addressbooks (principaluri, displayname, uri, description, synctoken) VALUES ('principals/user1', 'book1', 'book1', 'addressbook 1', 1)");
29  $pdo->exec("INSERT INTO cards (addressbookid, carddata, uri, lastmodified, etag, size) VALUES (1, 'card1', 'card1', 0, '" . md5('card1') . "', 5)");
30 
31  }
getPDO()
Alias for getDb.
dropTables($tableNames)
Drops tables, if they exist.
createSchema($schemaName)
Uses .sql files from the examples directory to initialize the database.
$pdo
Definition: migrateto20.php:62
+ Here is the call graph for this function:

◆ testCreateAddressBookSuccess()

Sabre\CardDAV\Backend\AbstractPDOTest::testCreateAddressBookSuccess ( )

Definition at line 162 of file AbstractPDOTest.php.

References $result, and Sabre\CardDAV\Plugin\NS_CARDDAV.

162  {
163 
164  $this->backend->createAddressBook('principals/user1', 'book2', [
165  '{DAV:}displayname' => 'book2',
166  '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 2',
167  ]);
168 
169  $expected = [
170  [
171  'id' => 1,
172  'uri' => 'book1',
173  'principaluri' => 'principals/user1',
174  '{DAV:}displayname' => 'book1',
175  '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
176  '{http://calendarserver.org/ns/}getctag' => 1,
177  '{http://sabredav.org/ns}sync-token' => 1,
178  ],
179  [
180  'id' => 2,
181  'uri' => 'book2',
182  'principaluri' => 'principals/user1',
183  '{DAV:}displayname' => 'book2',
184  '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 2',
185  '{http://calendarserver.org/ns/}getctag' => 1,
186  '{http://sabredav.org/ns}sync-token' => 1,
187  ]
188  ];
189  $result = $this->backend->getAddressBooksForUser('principals/user1');
190  $this->assertEquals($expected, $result);
191 
192  }
$result
const NS_CARDDAV
xml namespace for CardDAV elements
Definition: Plugin.php:33

◆ testCreateAddressBookUnsupportedProp()

Sabre\CardDAV\Backend\AbstractPDOTest::testCreateAddressBookUnsupportedProp ( )

Sabre

Definition at line 154 of file AbstractPDOTest.php.

154  {
155 
156  $this->backend->createAddressBook('principals/user1', 'book2', [
157  '{DAV:}foo' => 'bar',
158  ]);
159 
160  }

◆ testCreateCard()

Sabre\CardDAV\Backend\AbstractPDOTest::testCreateCard ( )

testGetCard

Definition at line 236 of file AbstractPDOTest.php.

References $result.

236  {
237 
238  $result = $this->backend->createCard(1, 'card2', 'data2');
239  $this->assertEquals('"' . md5('data2') . '"', $result);
240  $result = $this->backend->getCard(1, 'card2');
241  $this->assertEquals(2, $result['id']);
242  $this->assertEquals('card2', $result['uri']);
243  if (is_resource($result['carddata'])) {
244  $result['carddata'] = stream_get_contents($result['carddata']);
245  }
246  $this->assertEquals('data2', $result['carddata']);
247 
248  }
$result

◆ testDeleteAddressBook()

Sabre\CardDAV\Backend\AbstractPDOTest::testDeleteAddressBook ( )

Definition at line 143 of file AbstractPDOTest.php.

143  {
144 
145  $this->backend->deleteAddressBook(1);
146 
147  $this->assertEquals([], $this->backend->getAddressBooksForUser('principals/user1'));
148 
149  }

◆ testDeleteCard()

Sabre\CardDAV\Backend\AbstractPDOTest::testDeleteCard ( )

testGetCard

Definition at line 328 of file AbstractPDOTest.php.

References $result.

328  {
329 
330  $this->backend->deleteCard(1, 'card1');
331  $result = $this->backend->getCard(1, 'card1');
332  $this->assertFalse($result);
333 
334  }
$result

◆ testGetAddressBooksForUser()

Sabre\CardDAV\Backend\AbstractPDOTest::testGetAddressBooksForUser ( )

Definition at line 33 of file AbstractPDOTest.php.

References $result, and Sabre\CardDAV\Plugin\NS_CARDDAV.

33  {
34 
35  $result = $this->backend->getAddressBooksForUser('principals/user1');
36 
37  $expected = [
38  [
39  'id' => 1,
40  'uri' => 'book1',
41  'principaluri' => 'principals/user1',
42  '{DAV:}displayname' => 'book1',
43  '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
44  '{http://calendarserver.org/ns/}getctag' => 1,
45  '{http://sabredav.org/ns}sync-token' => 1
46  ]
47  ];
48 
49  $this->assertEquals($expected, $result);
50 
51  }
$result
const NS_CARDDAV
xml namespace for CardDAV elements
Definition: Plugin.php:33

◆ testGetCard()

Sabre\CardDAV\Backend\AbstractPDOTest::testGetCard ( )

Definition at line 212 of file AbstractPDOTest.php.

References $result.

212  {
213 
214  $result = $this->backend->getCard(1, 'card1');
215 
216  $expected = [
217  'id' => 1,
218  'uri' => 'card1',
219  'carddata' => 'card1',
220  'lastmodified' => 0,
221  'etag' => '"' . md5('card1') . '"',
222  'size' => 5
223  ];
224 
225  if (is_resource($result['carddata'])) {
226  $result['carddata'] = stream_get_contents($result['carddata']);
227  }
228 
229  $this->assertEquals($expected, $result);
230 
231  }
$result

◆ testGetCards()

Sabre\CardDAV\Backend\AbstractPDOTest::testGetCards ( )

Definition at line 194 of file AbstractPDOTest.php.

References $result.

194  {
195 
196  $result = $this->backend->getCards(1);
197 
198  $expected = [
199  [
200  'id' => 1,
201  'uri' => 'card1',
202  'lastmodified' => 0,
203  'etag' => '"' . md5('card1') . '"',
204  'size' => 5
205  ]
206  ];
207 
208  $this->assertEquals($expected, $result);
209 
210  }
$result

◆ testGetChanges()

Sabre\CardDAV\Backend\AbstractPDOTest::testGetChanges ( )

Definition at line 336 of file AbstractPDOTest.php.

References Sabre\CardDAV\Backend\AbstractPDOTest\$backend, $id, and $result.

336  {
337 
339  $id = $backend->createAddressBook(
340  'principals/user1',
341  'bla',
342  []
343  );
344  $result = $backend->getChangesForAddressBook($id, null, 1);
345 
346  $this->assertEquals([
347  'syncToken' => 1,
348  "added" => [],
349  'modified' => [],
350  'deleted' => [],
351  ], $result);
352 
353  $currentToken = $result['syncToken'];
354 
355  $dummyCard = "BEGIN:VCARD\r\nEND:VCARD\r\n";
356 
357  $backend->createCard($id, "card1.ics", $dummyCard);
358  $backend->createCard($id, "card2.ics", $dummyCard);
359  $backend->createCard($id, "card3.ics", $dummyCard);
360  $backend->updateCard($id, "card1.ics", $dummyCard);
361  $backend->deleteCard($id, "card2.ics");
362 
363  $result = $backend->getChangesForAddressBook($id, $currentToken, 1);
364 
365  $this->assertEquals([
366  'syncToken' => 6,
367  'modified' => ["card1.ics"],
368  'deleted' => ["card2.ics"],
369  "added" => ["card3.ics"],
370  ], $result);
371 
372  }
$result
if(!array_key_exists('StateId', $_REQUEST)) $id

◆ testGetMultiple()

Sabre\CardDAV\Backend\AbstractPDOTest::testGetMultiple ( )

testCreateCard

Definition at line 253 of file AbstractPDOTest.php.

References $index, and $result.

253  {
254 
255  $result = $this->backend->createCard(1, 'card2', 'data2');
256  $result = $this->backend->createCard(1, 'card3', 'data3');
257  $check = [
258  [
259  'id' => 1,
260  'uri' => 'card1',
261  'carddata' => 'card1',
262  'lastmodified' => 0,
263  ],
264  [
265  'id' => 2,
266  'uri' => 'card2',
267  'carddata' => 'data2',
268  'lastmodified' => time(),
269  ],
270  [
271  'id' => 3,
272  'uri' => 'card3',
273  'carddata' => 'data3',
274  'lastmodified' => time(),
275  ],
276  ];
277 
278  $result = $this->backend->getMultipleCards(1, ['card1', 'card2', 'card3']);
279 
280  foreach ($check as $index => $node) {
281 
282  foreach ($node as $k => $v) {
283 
284  $expected = $v;
285  $actual = $result[$index][$k];
286 
287  switch ($k) {
288  case 'lastmodified' :
289  $this->assertInternalType('int', $actual);
290  break;
291  case 'carddata' :
292  if (is_resource($actual)) {
293  $actual = stream_get_contents($actual);
294  }
295  // No break intended.
296  default :
297  $this->assertEquals($expected, $actual);
298  break;
299  }
300 
301  }
302 
303  }
304 
305 
306  }
$result
$index
Definition: metadata.php:60

◆ testUpdateAddressBookInvalidProp()

Sabre\CardDAV\Backend\AbstractPDOTest::testUpdateAddressBookInvalidProp ( )

Definition at line 53 of file AbstractPDOTest.php.

References $result, and Sabre\CardDAV\Plugin\NS_CARDDAV.

53  {
54 
55  $propPatch = new PropPatch([
56  '{DAV:}displayname' => 'updated',
57  '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
58  '{DAV:}foo' => 'bar',
59  ]);
60 
61  $this->backend->updateAddressBook(1, $propPatch);
62  $result = $propPatch->commit();
63 
64  $this->assertFalse($result);
65 
66  $result = $this->backend->getAddressBooksForUser('principals/user1');
67 
68  $expected = [
69  [
70  'id' => 1,
71  'uri' => 'book1',
72  'principaluri' => 'principals/user1',
73  '{DAV:}displayname' => 'book1',
74  '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
75  '{http://calendarserver.org/ns/}getctag' => 1,
76  '{http://sabredav.org/ns}sync-token' => 1
77  ]
78  ];
79 
80  $this->assertEquals($expected, $result);
81 
82  }
$result
const NS_CARDDAV
xml namespace for CardDAV elements
Definition: Plugin.php:33

◆ testUpdateAddressBookNoProps()

Sabre\CardDAV\Backend\AbstractPDOTest::testUpdateAddressBookNoProps ( )

Definition at line 84 of file AbstractPDOTest.php.

References $result, and Sabre\CardDAV\Plugin\NS_CARDDAV.

84  {
85 
86  $propPatch = new PropPatch([
87  ]);
88 
89  $this->backend->updateAddressBook(1, $propPatch);
90  $result = $propPatch->commit();
91  $this->assertTrue($result);
92 
93  $result = $this->backend->getAddressBooksForUser('principals/user1');
94 
95  $expected = [
96  [
97  'id' => 1,
98  'uri' => 'book1',
99  'principaluri' => 'principals/user1',
100  '{DAV:}displayname' => 'book1',
101  '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'addressbook 1',
102  '{http://calendarserver.org/ns/}getctag' => 1,
103  '{http://sabredav.org/ns}sync-token' => 1
104  ]
105  ];
106 
107  $this->assertEquals($expected, $result);
108 
109 
110  }
$result
const NS_CARDDAV
xml namespace for CardDAV elements
Definition: Plugin.php:33

◆ testUpdateAddressBookSuccess()

Sabre\CardDAV\Backend\AbstractPDOTest::testUpdateAddressBookSuccess ( )

Definition at line 112 of file AbstractPDOTest.php.

References $result, and Sabre\CardDAV\Plugin\NS_CARDDAV.

112  {
113 
114  $propPatch = new PropPatch([
115  '{DAV:}displayname' => 'updated',
116  '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
117  ]);
118 
119  $this->backend->updateAddressBook(1, $propPatch);
120  $result = $propPatch->commit();
121 
122  $this->assertTrue($result);
123 
124  $result = $this->backend->getAddressBooksForUser('principals/user1');
125 
126  $expected = [
127  [
128  'id' => 1,
129  'uri' => 'book1',
130  'principaluri' => 'principals/user1',
131  '{DAV:}displayname' => 'updated',
132  '{' . CardDAV\Plugin::NS_CARDDAV . '}addressbook-description' => 'updated',
133  '{http://calendarserver.org/ns/}getctag' => 2,
134  '{http://sabredav.org/ns}sync-token' => 2
135  ]
136  ];
137 
138  $this->assertEquals($expected, $result);
139 
140 
141  }
$result
const NS_CARDDAV
xml namespace for CardDAV elements
Definition: Plugin.php:33

◆ testUpdateCard()

Sabre\CardDAV\Backend\AbstractPDOTest::testUpdateCard ( )

testGetCard

Definition at line 311 of file AbstractPDOTest.php.

References $result.

311  {
312 
313  $result = $this->backend->updateCard(1, 'card1', 'newdata');
314  $this->assertEquals('"' . md5('newdata') . '"', $result);
315 
316  $result = $this->backend->getCard(1, 'card1');
317  $this->assertEquals(1, $result['id']);
318  if (is_resource($result['carddata'])) {
319  $result['carddata'] = stream_get_contents($result['carddata']);
320  }
321  $this->assertEquals('newdata', $result['carddata']);
322 
323  }
$result

Field Documentation

◆ $backend

Sabre\CardDAV\Backend\AbstractPDOTest::$backend
protected

The documentation for this class was generated from the following file: