1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\CardDAV; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse Sabre\HTTP; 6*a1a3b679SAndreas Boehleruse Sabre\DAV; 7*a1a3b679SAndreas Boehler 8*a1a3b679SAndreas Boehlerrequire_once 'Sabre/CardDAV/AbstractPluginTest.php'; 9*a1a3b679SAndreas Boehlerrequire_once 'Sabre/HTTP/ResponseMock.php'; 10*a1a3b679SAndreas Boehler 11*a1a3b679SAndreas Boehlerclass AddressBookQueryTest extends AbstractPluginTest { 12*a1a3b679SAndreas Boehler 13*a1a3b679SAndreas Boehler function testQuery() { 14*a1a3b679SAndreas Boehler 15*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray(array( 16*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 17*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/addressbooks/user1/book1', 18*a1a3b679SAndreas Boehler 'HTTP_DEPTH' => '1', 19*a1a3b679SAndreas Boehler )); 20*a1a3b679SAndreas Boehler 21*a1a3b679SAndreas Boehler $request->setBody( 22*a1a3b679SAndreas Boehler'<?xml version="1.0"?> 23*a1a3b679SAndreas Boehler<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav"> 24*a1a3b679SAndreas Boehler <d:prop> 25*a1a3b679SAndreas Boehler <d:getetag /> 26*a1a3b679SAndreas Boehler </d:prop> 27*a1a3b679SAndreas Boehler <c:filter> 28*a1a3b679SAndreas Boehler <c:prop-filter name="uid" /> 29*a1a3b679SAndreas Boehler </c:filter> 30*a1a3b679SAndreas Boehler</c:addressbook-query>' 31*a1a3b679SAndreas Boehler ); 32*a1a3b679SAndreas Boehler 33*a1a3b679SAndreas Boehler $response = new HTTP\ResponseMock(); 34*a1a3b679SAndreas Boehler 35*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 36*a1a3b679SAndreas Boehler $this->server->httpResponse = $response; 37*a1a3b679SAndreas Boehler 38*a1a3b679SAndreas Boehler $this->server->exec(); 39*a1a3b679SAndreas Boehler 40*a1a3b679SAndreas Boehler $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); 41*a1a3b679SAndreas Boehler 42*a1a3b679SAndreas Boehler // using the client for parsing 43*a1a3b679SAndreas Boehler $client = new DAV\Client(array('baseUri'=>'/')); 44*a1a3b679SAndreas Boehler 45*a1a3b679SAndreas Boehler $result = $client->parseMultiStatus($response->body); 46*a1a3b679SAndreas Boehler 47*a1a3b679SAndreas Boehler $this->assertEquals(array( 48*a1a3b679SAndreas Boehler '/addressbooks/user1/book1/card1' => array( 49*a1a3b679SAndreas Boehler 200 => array( 50*a1a3b679SAndreas Boehler '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', 51*a1a3b679SAndreas Boehler ), 52*a1a3b679SAndreas Boehler ), 53*a1a3b679SAndreas Boehler '/addressbooks/user1/book1/card2' => array( 54*a1a3b679SAndreas Boehler 404 => array( 55*a1a3b679SAndreas Boehler '{DAV:}getetag' => null, 56*a1a3b679SAndreas Boehler ), 57*a1a3b679SAndreas Boehler ) 58*a1a3b679SAndreas Boehler ), $result); 59*a1a3b679SAndreas Boehler 60*a1a3b679SAndreas Boehler 61*a1a3b679SAndreas Boehler } 62*a1a3b679SAndreas Boehler 63*a1a3b679SAndreas Boehler function testQueryDepth0() { 64*a1a3b679SAndreas Boehler 65*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray(array( 66*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 67*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/addressbooks/user1/book1/card1', 68*a1a3b679SAndreas Boehler 'HTTP_DEPTH' => '0', 69*a1a3b679SAndreas Boehler )); 70*a1a3b679SAndreas Boehler 71*a1a3b679SAndreas Boehler $request->setBody( 72*a1a3b679SAndreas Boehler'<?xml version="1.0"?> 73*a1a3b679SAndreas Boehler<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav"> 74*a1a3b679SAndreas Boehler <d:prop> 75*a1a3b679SAndreas Boehler <d:getetag /> 76*a1a3b679SAndreas Boehler </d:prop> 77*a1a3b679SAndreas Boehler <c:filter> 78*a1a3b679SAndreas Boehler <c:prop-filter name="uid" /> 79*a1a3b679SAndreas Boehler </c:filter> 80*a1a3b679SAndreas Boehler</c:addressbook-query>' 81*a1a3b679SAndreas Boehler ); 82*a1a3b679SAndreas Boehler 83*a1a3b679SAndreas Boehler $response = new HTTP\ResponseMock(); 84*a1a3b679SAndreas Boehler 85*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 86*a1a3b679SAndreas Boehler $this->server->httpResponse = $response; 87*a1a3b679SAndreas Boehler 88*a1a3b679SAndreas Boehler $this->server->exec(); 89*a1a3b679SAndreas Boehler 90*a1a3b679SAndreas Boehler $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); 91*a1a3b679SAndreas Boehler 92*a1a3b679SAndreas Boehler // using the client for parsing 93*a1a3b679SAndreas Boehler $client = new DAV\Client(array('baseUri'=>'/')); 94*a1a3b679SAndreas Boehler 95*a1a3b679SAndreas Boehler $result = $client->parseMultiStatus($response->body); 96*a1a3b679SAndreas Boehler 97*a1a3b679SAndreas Boehler $this->assertEquals(array( 98*a1a3b679SAndreas Boehler '/addressbooks/user1/book1/card1' => array( 99*a1a3b679SAndreas Boehler 200 => array( 100*a1a3b679SAndreas Boehler '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', 101*a1a3b679SAndreas Boehler ), 102*a1a3b679SAndreas Boehler ), 103*a1a3b679SAndreas Boehler ), $result); 104*a1a3b679SAndreas Boehler 105*a1a3b679SAndreas Boehler 106*a1a3b679SAndreas Boehler } 107*a1a3b679SAndreas Boehler 108*a1a3b679SAndreas Boehler function testQueryNoMatch() { 109*a1a3b679SAndreas Boehler 110*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray(array( 111*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 112*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/addressbooks/user1/book1', 113*a1a3b679SAndreas Boehler 'HTTP_DEPTH' => '1', 114*a1a3b679SAndreas Boehler )); 115*a1a3b679SAndreas Boehler 116*a1a3b679SAndreas Boehler $request->setBody( 117*a1a3b679SAndreas Boehler'<?xml version="1.0"?> 118*a1a3b679SAndreas Boehler<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav"> 119*a1a3b679SAndreas Boehler <d:prop> 120*a1a3b679SAndreas Boehler <d:getetag /> 121*a1a3b679SAndreas Boehler </d:prop> 122*a1a3b679SAndreas Boehler <c:filter> 123*a1a3b679SAndreas Boehler <c:prop-filter name="email" /> 124*a1a3b679SAndreas Boehler </c:filter> 125*a1a3b679SAndreas Boehler</c:addressbook-query>' 126*a1a3b679SAndreas Boehler ); 127*a1a3b679SAndreas Boehler 128*a1a3b679SAndreas Boehler $response = new HTTP\ResponseMock(); 129*a1a3b679SAndreas Boehler 130*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 131*a1a3b679SAndreas Boehler $this->server->httpResponse = $response; 132*a1a3b679SAndreas Boehler 133*a1a3b679SAndreas Boehler $this->server->exec(); 134*a1a3b679SAndreas Boehler 135*a1a3b679SAndreas Boehler $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); 136*a1a3b679SAndreas Boehler 137*a1a3b679SAndreas Boehler // using the client for parsing 138*a1a3b679SAndreas Boehler $client = new DAV\Client(array('baseUri'=>'/')); 139*a1a3b679SAndreas Boehler 140*a1a3b679SAndreas Boehler $result = $client->parseMultiStatus($response->body); 141*a1a3b679SAndreas Boehler 142*a1a3b679SAndreas Boehler $this->assertEquals(array(), $result); 143*a1a3b679SAndreas Boehler 144*a1a3b679SAndreas Boehler } 145*a1a3b679SAndreas Boehler 146*a1a3b679SAndreas Boehler function testQueryLimit() { 147*a1a3b679SAndreas Boehler 148*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray(array( 149*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 150*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/addressbooks/user1/book1', 151*a1a3b679SAndreas Boehler 'HTTP_DEPTH' => '1', 152*a1a3b679SAndreas Boehler )); 153*a1a3b679SAndreas Boehler 154*a1a3b679SAndreas Boehler $request->setBody( 155*a1a3b679SAndreas Boehler'<?xml version="1.0"?> 156*a1a3b679SAndreas Boehler<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav"> 157*a1a3b679SAndreas Boehler <d:prop> 158*a1a3b679SAndreas Boehler <d:getetag /> 159*a1a3b679SAndreas Boehler </d:prop> 160*a1a3b679SAndreas Boehler <c:filter> 161*a1a3b679SAndreas Boehler <c:prop-filter name="uid" /> 162*a1a3b679SAndreas Boehler </c:filter> 163*a1a3b679SAndreas Boehler <c:limit><c:nresults>1</c:nresults></c:limit> 164*a1a3b679SAndreas Boehler</c:addressbook-query>' 165*a1a3b679SAndreas Boehler ); 166*a1a3b679SAndreas Boehler 167*a1a3b679SAndreas Boehler $response = new HTTP\ResponseMock(); 168*a1a3b679SAndreas Boehler 169*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 170*a1a3b679SAndreas Boehler $this->server->httpResponse = $response; 171*a1a3b679SAndreas Boehler 172*a1a3b679SAndreas Boehler $this->server->exec(); 173*a1a3b679SAndreas Boehler 174*a1a3b679SAndreas Boehler $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); 175*a1a3b679SAndreas Boehler 176*a1a3b679SAndreas Boehler // using the client for parsing 177*a1a3b679SAndreas Boehler $client = new DAV\Client(array('baseUri'=>'/')); 178*a1a3b679SAndreas Boehler 179*a1a3b679SAndreas Boehler $result = $client->parseMultiStatus($response->body); 180*a1a3b679SAndreas Boehler 181*a1a3b679SAndreas Boehler $this->assertEquals(array( 182*a1a3b679SAndreas Boehler '/addressbooks/user1/book1/card1' => array( 183*a1a3b679SAndreas Boehler 200 => array( 184*a1a3b679SAndreas Boehler '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"). '"', 185*a1a3b679SAndreas Boehler ), 186*a1a3b679SAndreas Boehler ), 187*a1a3b679SAndreas Boehler ), $result); 188*a1a3b679SAndreas Boehler 189*a1a3b679SAndreas Boehler 190*a1a3b679SAndreas Boehler } 191*a1a3b679SAndreas Boehler 192*a1a3b679SAndreas Boehler function testJson() { 193*a1a3b679SAndreas Boehler 194*a1a3b679SAndreas Boehler $request = new HTTP\Request( 195*a1a3b679SAndreas Boehler 'REPORT', 196*a1a3b679SAndreas Boehler '/addressbooks/user1/book1/card1', 197*a1a3b679SAndreas Boehler ['Depth' => '0'] 198*a1a3b679SAndreas Boehler ); 199*a1a3b679SAndreas Boehler 200*a1a3b679SAndreas Boehler $request->setBody( 201*a1a3b679SAndreas Boehler'<?xml version="1.0"?> 202*a1a3b679SAndreas Boehler<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav"> 203*a1a3b679SAndreas Boehler <d:prop> 204*a1a3b679SAndreas Boehler <c:address-data content-type="application/vcard+json" /> 205*a1a3b679SAndreas Boehler <d:getetag /> 206*a1a3b679SAndreas Boehler </d:prop> 207*a1a3b679SAndreas Boehler</c:addressbook-query>' 208*a1a3b679SAndreas Boehler ); 209*a1a3b679SAndreas Boehler 210*a1a3b679SAndreas Boehler $response = new HTTP\ResponseMock(); 211*a1a3b679SAndreas Boehler 212*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 213*a1a3b679SAndreas Boehler $this->server->httpResponse = $response; 214*a1a3b679SAndreas Boehler 215*a1a3b679SAndreas Boehler $this->server->exec(); 216*a1a3b679SAndreas Boehler 217*a1a3b679SAndreas Boehler $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); 218*a1a3b679SAndreas Boehler 219*a1a3b679SAndreas Boehler // using the client for parsing 220*a1a3b679SAndreas Boehler $client = new DAV\Client(array('baseUri'=>'/')); 221*a1a3b679SAndreas Boehler 222*a1a3b679SAndreas Boehler $result = $client->parseMultiStatus($response->body); 223*a1a3b679SAndreas Boehler 224*a1a3b679SAndreas Boehler $vobjVersion = \Sabre\VObject\Version::VERSION; 225*a1a3b679SAndreas Boehler 226*a1a3b679SAndreas Boehler $this->assertEquals(array( 227*a1a3b679SAndreas Boehler '/addressbooks/user1/book1/card1' => array( 228*a1a3b679SAndreas Boehler 200 => array( 229*a1a3b679SAndreas Boehler '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"). '"', 230*a1a3b679SAndreas Boehler '{urn:ietf:params:xml:ns:carddav}address-data' => '["vcard",[["version",{},"text","4.0"],["prodid",{},"text","-\/\/Sabre\/\/Sabre VObject ' . $vobjVersion . '\/\/EN"],["uid",{},"text","12345"]]]', 231*a1a3b679SAndreas Boehler ), 232*a1a3b679SAndreas Boehler ), 233*a1a3b679SAndreas Boehler ), $result); 234*a1a3b679SAndreas Boehler 235*a1a3b679SAndreas Boehler } 236*a1a3b679SAndreas Boehler 237*a1a3b679SAndreas Boehler function testVCard4() { 238*a1a3b679SAndreas Boehler 239*a1a3b679SAndreas Boehler $request = new HTTP\Request( 240*a1a3b679SAndreas Boehler 'REPORT', 241*a1a3b679SAndreas Boehler '/addressbooks/user1/book1/card1', 242*a1a3b679SAndreas Boehler ['Depth' => '0'] 243*a1a3b679SAndreas Boehler ); 244*a1a3b679SAndreas Boehler 245*a1a3b679SAndreas Boehler $request->setBody( 246*a1a3b679SAndreas Boehler'<?xml version="1.0"?> 247*a1a3b679SAndreas Boehler<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav"> 248*a1a3b679SAndreas Boehler <d:prop> 249*a1a3b679SAndreas Boehler <c:address-data content-type="text/vcard" version="4.0" /> 250*a1a3b679SAndreas Boehler <d:getetag /> 251*a1a3b679SAndreas Boehler </d:prop> 252*a1a3b679SAndreas Boehler</c:addressbook-query>' 253*a1a3b679SAndreas Boehler ); 254*a1a3b679SAndreas Boehler 255*a1a3b679SAndreas Boehler $response = new HTTP\ResponseMock(); 256*a1a3b679SAndreas Boehler 257*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 258*a1a3b679SAndreas Boehler $this->server->httpResponse = $response; 259*a1a3b679SAndreas Boehler 260*a1a3b679SAndreas Boehler $this->server->exec(); 261*a1a3b679SAndreas Boehler 262*a1a3b679SAndreas Boehler $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); 263*a1a3b679SAndreas Boehler 264*a1a3b679SAndreas Boehler // using the client for parsing 265*a1a3b679SAndreas Boehler $client = new DAV\Client(array('baseUri'=>'/')); 266*a1a3b679SAndreas Boehler 267*a1a3b679SAndreas Boehler $result = $client->parseMultiStatus($response->body); 268*a1a3b679SAndreas Boehler 269*a1a3b679SAndreas Boehler $vobjVersion = \Sabre\VObject\Version::VERSION; 270*a1a3b679SAndreas Boehler 271*a1a3b679SAndreas Boehler $this->assertEquals(array( 272*a1a3b679SAndreas Boehler '/addressbooks/user1/book1/card1' => array( 273*a1a3b679SAndreas Boehler 200 => array( 274*a1a3b679SAndreas Boehler '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD"). '"', 275*a1a3b679SAndreas Boehler '{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*a1a3b679SAndreas Boehler ), 277*a1a3b679SAndreas Boehler ), 278*a1a3b679SAndreas Boehler ), $result); 279*a1a3b679SAndreas Boehler 280*a1a3b679SAndreas Boehler } 281*a1a3b679SAndreas Boehler 282*a1a3b679SAndreas Boehler function testAddressBookDepth0() { 283*a1a3b679SAndreas Boehler 284*a1a3b679SAndreas Boehler $request = new HTTP\Request( 285*a1a3b679SAndreas Boehler 'REPORT', 286*a1a3b679SAndreas Boehler '/addressbooks/user1/book1', 287*a1a3b679SAndreas Boehler ['Depth' => '0'] 288*a1a3b679SAndreas Boehler ); 289*a1a3b679SAndreas Boehler 290*a1a3b679SAndreas Boehler $request->setBody( 291*a1a3b679SAndreas Boehler'<?xml version="1.0"?> 292*a1a3b679SAndreas Boehler<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav"> 293*a1a3b679SAndreas Boehler <d:prop> 294*a1a3b679SAndreas Boehler <c:address-data content-type="application/vcard+json" /> 295*a1a3b679SAndreas Boehler <d:getetag /> 296*a1a3b679SAndreas Boehler </d:prop> 297*a1a3b679SAndreas Boehler</c:addressbook-query>' 298*a1a3b679SAndreas Boehler ); 299*a1a3b679SAndreas Boehler 300*a1a3b679SAndreas Boehler $response = new HTTP\ResponseMock(); 301*a1a3b679SAndreas Boehler 302*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 303*a1a3b679SAndreas Boehler $this->server->httpResponse = $response; 304*a1a3b679SAndreas Boehler 305*a1a3b679SAndreas Boehler $this->server->exec(); 306*a1a3b679SAndreas Boehler 307*a1a3b679SAndreas Boehler $this->assertEquals(415, $response->status, 'Incorrect status code. Full response body:' . $response->body); 308*a1a3b679SAndreas Boehler 309*a1a3b679SAndreas Boehler } 310*a1a3b679SAndreas Boehler} 311