]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/CardDAV/AddressBookQueryTest.php
598f653bcab4c74c41d493bba697577dd9159166
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / CardDAV / AddressBookQueryTest.php
1 <?php
2
3 require_once 'Sabre/CardDAV/AbstractPluginTest.php';
4 require_once 'Sabre/HTTP/ResponseMock.php';
5
6 class Sabre_CardDAV_AddressBookQueryTest extends Sabre_CardDAV_AbstractPluginTest {
7
8     function testQuery() {
9
10         $request = new Sabre_HTTP_Request(array(
11             'REQUEST_METHOD' => 'REPORT',
12             'REQUEST_URI' => '/addressbooks/user1/book1',
13             'HTTP_DEPTH' => '1',
14         ));
15
16         $request->setBody(
17 '<?xml version="1.0"?>
18 <c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
19     <d:prop>
20       <d:getetag />
21     </d:prop>
22     <c:filter>
23         <c:prop-filter name="uid" />
24     </c:filter>
25 </c:addressbook-query>'
26             );
27
28         $response = new Sabre_HTTP_ResponseMock();
29
30         $this->server->httpRequest = $request;
31         $this->server->httpResponse = $response;
32
33         $this->server->exec();
34
35         $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body);
36
37         // using the client for parsing
38         $client = new Sabre_DAV_Client(array('baseUri'=>'/'));
39
40         $result = $client->parseMultiStatus($response->body);
41
42         $this->assertEquals(array(
43             '/addressbooks/user1/book1/card1' => array(
44                 200 => array(
45                     '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
46                 ),
47              ),
48             '/addressbooks/user1/book1/card2' => array(
49                 200 => array(
50                     '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:45678\nEND:VCARD") . '"',
51                 ),
52             )
53         ), $result);
54
55
56     }
57
58     function testQueryDepth0() {
59
60         $request = new Sabre_HTTP_Request(array(
61             'REQUEST_METHOD' => 'REPORT',
62             'REQUEST_URI' => '/addressbooks/user1/book1/card1',
63             'HTTP_DEPTH' => '0',
64         ));
65
66         $request->setBody(
67 '<?xml version="1.0"?>
68 <c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
69     <d:prop>
70       <d:getetag />
71     </d:prop>
72     <c:filter>
73         <c:prop-filter name="uid" />
74     </c:filter>
75 </c:addressbook-query>'
76             );
77
78         $response = new Sabre_HTTP_ResponseMock();
79
80         $this->server->httpRequest = $request;
81         $this->server->httpResponse = $response;
82
83         $this->server->exec();
84
85         $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body);
86
87         // using the client for parsing
88         $client = new Sabre_DAV_Client(array('baseUri'=>'/'));
89
90         $result = $client->parseMultiStatus($response->body);
91
92         $this->assertEquals(array(
93             '/addressbooks/user1/book1/card1' => array(
94                 200 => array(
95                     '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
96                 ),
97              ),
98         ), $result);
99
100
101     }
102
103     function testQueryNoMatch() {
104
105         $request = new Sabre_HTTP_Request(array(
106             'REQUEST_METHOD' => 'REPORT',
107             'REQUEST_URI' => '/addressbooks/user1/book1',
108             'HTTP_DEPTH' => '1',
109         ));
110
111         $request->setBody(
112 '<?xml version="1.0"?>
113 <c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
114     <d:prop>
115       <d:getetag />
116     </d:prop>
117     <c:filter>
118         <c:prop-filter name="email" />
119     </c:filter>
120 </c:addressbook-query>'
121             );
122
123         $response = new Sabre_HTTP_ResponseMock();
124
125         $this->server->httpRequest = $request;
126         $this->server->httpResponse = $response;
127
128         $this->server->exec();
129
130         $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body);
131
132         // using the client for parsing
133         $client = new Sabre_DAV_Client(array('baseUri'=>'/'));
134
135         $result = $client->parseMultiStatus($response->body);
136
137         $this->assertEquals(array(), $result);
138
139     }
140
141     function testQueryLimit() {
142
143         $request = new Sabre_HTTP_Request(array(
144             'REQUEST_METHOD' => 'REPORT',
145             'REQUEST_URI' => '/addressbooks/user1/book1',
146             'HTTP_DEPTH' => '1',
147         ));
148
149         $request->setBody(
150 '<?xml version="1.0"?>
151 <c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
152     <d:prop>
153       <d:getetag />
154     </d:prop>
155     <c:filter>
156         <c:prop-filter name="uid" />
157     </c:filter>
158     <c:limit><c:nresults>1</c:nresults></c:limit>
159 </c:addressbook-query>'
160             );
161
162         $response = new Sabre_HTTP_ResponseMock();
163
164         $this->server->httpRequest = $request;
165         $this->server->httpResponse = $response;
166
167         $this->server->exec();
168
169         $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body);
170
171         // using the client for parsing
172         $client = new Sabre_DAV_Client(array('baseUri'=>'/'));
173
174         $result = $client->parseMultiStatus($response->body);
175
176         $this->assertEquals(array(
177             '/addressbooks/user1/book1/card1' => array(
178                 200 => array(
179                     '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"). '"',
180                 ),
181              ),
182         ), $result);
183
184
185     }
186
187 }