ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
AddressBookQueryTest.php
Go to the documentation of this file.
1<?php
2
3namespace Sabre\CardDAV;
4
5use Sabre\DAV;
6use Sabre\HTTP;
7
8require_once 'Sabre/CardDAV/AbstractPluginTest.php';
9require_once 'Sabre/HTTP/ResponseMock.php';
10
12
13 function testQuery() {
14
15 $request = new HTTP\Request(
16 'REPORT',
17 '/addressbooks/user1/book1',
18 ['Depth' => '1']
19 );
20
21 $request->setBody(
22'<?xml version="1.0"?>
23<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
24 <d:prop>
25 <d:getetag />
26 </d:prop>
27 <c:filter>
28 <c:prop-filter name="uid" />
29 </c:filter>
30</c:addressbook-query>'
31 );
32
33 $response = new HTTP\ResponseMock();
34
35 $this->server->httpRequest = $request;
36 $this->server->httpResponse = $response;
37
38 $this->server->exec();
39
40 $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
41
42 // using the client for parsing
43 $client = new DAV\Client(['baseUri' => '/']);
44
45 $result = $client->parseMultiStatus($response->body);
46
47 $this->assertEquals([
48 '/addressbooks/user1/book1/card1' => [
49 200 => [
50 '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
51 ],
52 ],
53 '/addressbooks/user1/book1/card2' => [
54 404 => [
55 '{DAV:}getetag' => null,
56 ],
57 ]
58 ], $result);
59
60
61 }
62
63 function testQueryDepth0() {
64
65 $request = new HTTP\Request(
66 'REPORT',
67 '/addressbooks/user1/book1/card1',
68 ['Depth' => '0']
69 );
70
71 $request->setBody(
72'<?xml version="1.0"?>
73<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
74 <d:prop>
75 <d:getetag />
76 </d:prop>
77 <c:filter>
78 <c:prop-filter name="uid" />
79 </c:filter>
80</c:addressbook-query>'
81 );
82
83 $response = new HTTP\ResponseMock();
84
85 $this->server->httpRequest = $request;
86 $this->server->httpResponse = $response;
87
88 $this->server->exec();
89
90 $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
91
92 // using the client for parsing
93 $client = new DAV\Client(['baseUri' => '/']);
94
95 $result = $client->parseMultiStatus($response->body);
96
97 $this->assertEquals([
98 '/addressbooks/user1/book1/card1' => [
99 200 => [
100 '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
101 ],
102 ],
103 ], $result);
104
105
106 }
107
108 function testQueryNoMatch() {
109
110 $request = new HTTP\Request(
111 'REPORT',
112 '/addressbooks/user1/book1',
113 ['Depth' => '1']
114 );
115
116 $request->setBody(
117'<?xml version="1.0"?>
118<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
119 <d:prop>
120 <d:getetag />
121 </d:prop>
122 <c:filter>
123 <c:prop-filter name="email" />
124 </c:filter>
125</c:addressbook-query>'
126 );
127
128 $response = new HTTP\ResponseMock();
129
130 $this->server->httpRequest = $request;
131 $this->server->httpResponse = $response;
132
133 $this->server->exec();
134
135 $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
136
137 // using the client for parsing
138 $client = new DAV\Client(['baseUri' => '/']);
139
140 $result = $client->parseMultiStatus($response->body);
141
142 $this->assertEquals([], $result);
143
144 }
145
146 function testQueryLimit() {
147
149 'REQUEST_METHOD' => 'REPORT',
150 'REQUEST_URI' => '/addressbooks/user1/book1',
151 'HTTP_DEPTH' => '1',
152 ]);
153
154 $request->setBody(
155'<?xml version="1.0"?>
156<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
157 <d:prop>
158 <d:getetag />
159 </d:prop>
160 <c:filter>
161 <c:prop-filter name="uid" />
162 </c:filter>
163 <c:limit><c:nresults>1</c:nresults></c:limit>
164</c:addressbook-query>'
165 );
166
167 $response = new HTTP\ResponseMock();
168
169 $this->server->httpRequest = $request;
170 $this->server->httpResponse = $response;
171
172 $this->server->exec();
173
174 $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
175
176 // using the client for parsing
177 $client = new DAV\Client(['baseUri' => '/']);
178
179 $result = $client->parseMultiStatus($response->body);
180
181 $this->assertEquals([
182 '/addressbooks/user1/book1/card1' => [
183 200 => [
184 '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
185 ],
186 ],
187 ], $result);
188
189
190 }
191
192 function testJson() {
193
194 $request = new HTTP\Request(
195 'REPORT',
196 '/addressbooks/user1/book1/card1',
197 ['Depth' => '0']
198 );
199
200 $request->setBody(
201'<?xml version="1.0"?>
202<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
203 <d:prop>
204 <c:address-data content-type="application/vcard+json" />
205 <d:getetag />
206 </d:prop>
207</c:addressbook-query>'
208 );
209
210 $response = new HTTP\ResponseMock();
211
212 $this->server->httpRequest = $request;
213 $this->server->httpResponse = $response;
214
215 $this->server->exec();
216
217 $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
218
219 // using the client for parsing
220 $client = new DAV\Client(['baseUri' => '/']);
221
222 $result = $client->parseMultiStatus($response->body);
223
224 $vobjVersion = \Sabre\VObject\Version::VERSION;
225
226 $this->assertEquals([
227 '/addressbooks/user1/book1/card1' => [
228 200 => [
229 '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
230 '{urn:ietf:params:xml:ns:carddav}address-data' => '["vcard",[["version",{},"text","4.0"],["prodid",{},"text","-\/\/Sabre\/\/Sabre VObject ' . $vobjVersion . '\/\/EN"],["uid",{},"text","12345"]]]',
231 ],
232 ],
233 ], $result);
234
235 }
236
237 function testVCard4() {
238
239 $request = new HTTP\Request(
240 'REPORT',
241 '/addressbooks/user1/book1/card1',
242 ['Depth' => '0']
243 );
244
245 $request->setBody(
246'<?xml version="1.0"?>
247<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
248 <d:prop>
249 <c:address-data content-type="text/vcard" version="4.0" />
250 <d:getetag />
251 </d:prop>
252</c:addressbook-query>'
253 );
254
255 $response = new HTTP\ResponseMock();
256
257 $this->server->httpRequest = $request;
258 $this->server->httpResponse = $response;
259
260 $this->server->exec();
261
262 $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
263
264 // using the client for parsing
265 $client = new DAV\Client(['baseUri' => '/']);
266
267 $result = $client->parseMultiStatus($response->body);
268
269 $vobjVersion = \Sabre\VObject\Version::VERSION;
270
271 $this->assertEquals([
272 '/addressbooks/user1/book1/card1' => [
273 200 => [
274 '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
275 '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:4.0\r\nPRODID:-//Sabre//Sabre VObject $vobjVersion//EN\r\nUID:12345\r\nEND:VCARD\r\n",
276 ],
277 ],
278 ], $result);
279
280 }
281
283
284 $request = new HTTP\Request(
285 'REPORT',
286 '/addressbooks/user1/book1',
287 ['Depth' => '0']
288 );
289
290 $request->setBody(
291 '<?xml version="1.0"?>
292<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
293 <d:prop>
294 <c:address-data content-type="application/vcard+json" />
295 <d:getetag />
296 </d:prop>
297</c:addressbook-query>'
298 );
299
300 $response = new HTTP\ResponseMock();
301
302 $this->server->httpRequest = $request;
303 $this->server->httpResponse = $response;
304
305 $this->server->exec();
306
307 $this->assertEquals(415, $response->status, 'Incorrect status code. Full response body:' . $response->body);
308 }
309
311
312 $request = new HTTP\Request(
313 'REPORT',
314 '/addressbooks/user1/book3',
315 ['Depth' => '1']
316 );
317
318 $request->setBody(
319 '<?xml version="1.0"?>
320<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
321 <d:prop>
322 <c:address-data>
323 <c:prop name="FN"/>
324 <c:prop name="BDAY"/>
325 </c:address-data>
326 <d:getetag />
327 </d:prop>
328</c:addressbook-query>'
329 );
330
331 $response = new HTTP\ResponseMock();
332
333 $this->server->httpRequest = $request;
334 $this->server->httpResponse = $response;
335
336 $this->server->exec();
337
338 $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
339
340 // using the client for parsing
341 $client = new DAV\Client(['baseUri' => '/']);
342
343 $result = $client->parseMultiStatus($response->body);
344
345 $this->assertEquals([
346 '/addressbooks/user1/book3/card3' => [
347 200 => [
348 '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nFN:Test-Card\nEMAIL;TYPE=home:bar@example.org\nEND:VCARD") . '"',
349 '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:3.0\r\nUID:12345\r\nFN:Test-Card\r\nEND:VCARD\r\n",
350 ],
351 ],
352 ], $result);
353
354 }
355}
$result
foreach($paths as $path) $request
Definition: asyncclient.php:32
An exception for terminatinating execution or to throw for unit testing.
SabreDAV DAV client.
Definition: Client.php:20
static createFromServerArray(array $serverArray)
This static method will create a new Request object, based on a PHP $_SERVER array.
Definition: Sapi.php:107
const VERSION
Full version number.
Definition: Version.php:17
if($_SERVER['argc']< 4) $client
Definition: cron.php:12
$response