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/HTTP/ResponseMock.php'; 9*a1a3b679SAndreas Boehler 10*a1a3b679SAndreas Boehlerclass MultiGetTest extends AbstractPluginTest { 11*a1a3b679SAndreas Boehler 12*a1a3b679SAndreas Boehler function testMultiGet() { 13*a1a3b679SAndreas Boehler 14*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray(array( 15*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 16*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/addressbooks/user1/book1', 17*a1a3b679SAndreas Boehler )); 18*a1a3b679SAndreas Boehler 19*a1a3b679SAndreas Boehler $request->setBody( 20*a1a3b679SAndreas Boehler'<?xml version="1.0"?> 21*a1a3b679SAndreas Boehler<c:addressbook-multiget xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav"> 22*a1a3b679SAndreas Boehler <d:prop> 23*a1a3b679SAndreas Boehler <d:getetag /> 24*a1a3b679SAndreas Boehler <c:address-data /> 25*a1a3b679SAndreas Boehler </d:prop> 26*a1a3b679SAndreas Boehler <d:href>/addressbooks/user1/book1/card1</d:href> 27*a1a3b679SAndreas Boehler</c:addressbook-multiget>' 28*a1a3b679SAndreas Boehler ); 29*a1a3b679SAndreas Boehler 30*a1a3b679SAndreas Boehler $response = new HTTP\ResponseMock(); 31*a1a3b679SAndreas Boehler 32*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 33*a1a3b679SAndreas Boehler $this->server->httpResponse = $response; 34*a1a3b679SAndreas Boehler 35*a1a3b679SAndreas Boehler $this->server->exec(); 36*a1a3b679SAndreas Boehler 37*a1a3b679SAndreas Boehler $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); 38*a1a3b679SAndreas Boehler 39*a1a3b679SAndreas Boehler // using the client for parsing 40*a1a3b679SAndreas Boehler $client = new DAV\Client(array('baseUri'=>'/')); 41*a1a3b679SAndreas Boehler 42*a1a3b679SAndreas Boehler $result = $client->parseMultiStatus($response->body); 43*a1a3b679SAndreas Boehler 44*a1a3b679SAndreas Boehler $this->assertEquals(array( 45*a1a3b679SAndreas Boehler '/addressbooks/user1/book1/card1' => array( 46*a1a3b679SAndreas Boehler 200 => array( 47*a1a3b679SAndreas Boehler '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', 48*a1a3b679SAndreas Boehler '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:3.0\r\nUID:12345\r\nEND:VCARD\r\n", 49*a1a3b679SAndreas Boehler ) 50*a1a3b679SAndreas Boehler ) 51*a1a3b679SAndreas Boehler ), $result); 52*a1a3b679SAndreas Boehler 53*a1a3b679SAndreas Boehler } 54*a1a3b679SAndreas Boehler 55*a1a3b679SAndreas Boehler function testMultiGetVCard4() { 56*a1a3b679SAndreas Boehler 57*a1a3b679SAndreas Boehler $request = HTTP\Sapi::createFromServerArray(array( 58*a1a3b679SAndreas Boehler 'REQUEST_METHOD' => 'REPORT', 59*a1a3b679SAndreas Boehler 'REQUEST_URI' => '/addressbooks/user1/book1', 60*a1a3b679SAndreas Boehler )); 61*a1a3b679SAndreas Boehler 62*a1a3b679SAndreas Boehler $request->setBody( 63*a1a3b679SAndreas Boehler'<?xml version="1.0"?> 64*a1a3b679SAndreas Boehler<c:addressbook-multiget xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav"> 65*a1a3b679SAndreas Boehler <d:prop> 66*a1a3b679SAndreas Boehler <d:getetag /> 67*a1a3b679SAndreas Boehler <c:address-data content-type="text/vcard" version="4.0" /> 68*a1a3b679SAndreas Boehler </d:prop> 69*a1a3b679SAndreas Boehler <d:href>/addressbooks/user1/book1/card1</d:href> 70*a1a3b679SAndreas Boehler</c:addressbook-multiget>' 71*a1a3b679SAndreas Boehler ); 72*a1a3b679SAndreas Boehler 73*a1a3b679SAndreas Boehler $response = new HTTP\ResponseMock(); 74*a1a3b679SAndreas Boehler 75*a1a3b679SAndreas Boehler $this->server->httpRequest = $request; 76*a1a3b679SAndreas Boehler $this->server->httpResponse = $response; 77*a1a3b679SAndreas Boehler 78*a1a3b679SAndreas Boehler $this->server->exec(); 79*a1a3b679SAndreas Boehler 80*a1a3b679SAndreas Boehler $this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body); 81*a1a3b679SAndreas Boehler 82*a1a3b679SAndreas Boehler // using the client for parsing 83*a1a3b679SAndreas Boehler $client = new DAV\Client(array('baseUri'=>'/')); 84*a1a3b679SAndreas Boehler 85*a1a3b679SAndreas Boehler $result = $client->parseMultiStatus($response->body); 86*a1a3b679SAndreas Boehler 87*a1a3b679SAndreas Boehler $prodId = "PRODID:-//Sabre//Sabre VObject " . \Sabre\VObject\Version::VERSION . "//EN"; 88*a1a3b679SAndreas Boehler 89*a1a3b679SAndreas Boehler $this->assertEquals(array( 90*a1a3b679SAndreas Boehler '/addressbooks/user1/book1/card1' => array( 91*a1a3b679SAndreas Boehler 200 => array( 92*a1a3b679SAndreas Boehler '{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"', 93*a1a3b679SAndreas Boehler '{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:4.0\r\n$prodId\r\nUID:12345\r\nEND:VCARD\r\n", 94*a1a3b679SAndreas Boehler ) 95*a1a3b679SAndreas Boehler ) 96*a1a3b679SAndreas Boehler ), $result); 97*a1a3b679SAndreas Boehler 98*a1a3b679SAndreas Boehler } 99*a1a3b679SAndreas Boehler} 100