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