3 require_once 'Sabre/CardDAV/AbstractPluginTest.php';
4 require_once 'Sabre/HTTP/ResponseMock.php';
6 class Sabre_CardDAV_AddressBookQueryTest extends Sabre_CardDAV_AbstractPluginTest {
10 $request = new Sabre_HTTP_Request(array(
11 'REQUEST_METHOD' => 'REPORT',
12 'REQUEST_URI' => '/addressbooks/user1/book1',
17 '<?xml version="1.0"?>
18 <c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
23 <c:prop-filter name="uid" />
25 </c:addressbook-query>'
28 $response = new Sabre_HTTP_ResponseMock();
30 $this->server->httpRequest = $request;
31 $this->server->httpResponse = $response;
33 $this->server->exec();
35 $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body);
37 // using the client for parsing
38 $client = new Sabre_DAV_Client(array('baseUri'=>'/'));
40 $result = $client->parseMultiStatus($response->body);
42 $this->assertEquals(array(
43 '/addressbooks/user1/book1/card1' => array(
45 '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
48 '/addressbooks/user1/book1/card2' => array(
50 '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:45678\nEND:VCARD") . '"',
58 function testQueryDepth0() {
60 $request = new Sabre_HTTP_Request(array(
61 'REQUEST_METHOD' => 'REPORT',
62 'REQUEST_URI' => '/addressbooks/user1/book1/card1',
67 '<?xml version="1.0"?>
68 <c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
73 <c:prop-filter name="uid" />
75 </c:addressbook-query>'
78 $response = new Sabre_HTTP_ResponseMock();
80 $this->server->httpRequest = $request;
81 $this->server->httpResponse = $response;
83 $this->server->exec();
85 $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body);
87 // using the client for parsing
88 $client = new Sabre_DAV_Client(array('baseUri'=>'/'));
90 $result = $client->parseMultiStatus($response->body);
92 $this->assertEquals(array(
93 '/addressbooks/user1/book1/card1' => array(
95 '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
103 function testQueryNoMatch() {
105 $request = new Sabre_HTTP_Request(array(
106 'REQUEST_METHOD' => 'REPORT',
107 'REQUEST_URI' => '/addressbooks/user1/book1',
112 '<?xml version="1.0"?>
113 <c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
118 <c:prop-filter name="email" />
120 </c:addressbook-query>'
123 $response = new Sabre_HTTP_ResponseMock();
125 $this->server->httpRequest = $request;
126 $this->server->httpResponse = $response;
128 $this->server->exec();
130 $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body);
132 // using the client for parsing
133 $client = new Sabre_DAV_Client(array('baseUri'=>'/'));
135 $result = $client->parseMultiStatus($response->body);
137 $this->assertEquals(array(), $result);
141 function testQueryLimit() {
143 $request = new Sabre_HTTP_Request(array(
144 'REQUEST_METHOD' => 'REPORT',
145 'REQUEST_URI' => '/addressbooks/user1/book1',
150 '<?xml version="1.0"?>
151 <c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
156 <c:prop-filter name="uid" />
158 <c:limit><c:nresults>1</c:nresults></c:limit>
159 </c:addressbook-query>'
162 $response = new Sabre_HTTP_ResponseMock();
164 $this->server->httpRequest = $request;
165 $this->server->httpResponse = $response;
167 $this->server->exec();
169 $this->assertEquals('HTTP/1.1 207 Multi-Status', $response->status, 'Incorrect status code. Full response body:' . $response->body);
171 // using the client for parsing
172 $client = new Sabre_DAV_Client(array('baseUri'=>'/'));
174 $result = $client->parseMultiStatus($response->body);
176 $this->assertEquals(array(
177 '/addressbooks/user1/book1/card1' => array(
179 '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"). '"',