2013-10-21 22:46:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Sabre\CardDAV;
|
|
|
|
|
|
|
|
use Sabre\HTTP;
|
|
|
|
use Sabre\DAV;
|
|
|
|
|
|
|
|
require_once 'Sabre/CardDAV/AbstractPluginTest.php';
|
|
|
|
require_once 'Sabre/HTTP/ResponseMock.php';
|
|
|
|
|
|
|
|
class AddressBookQueryTest extends AbstractPluginTest {
|
|
|
|
|
|
|
|
function testQuery() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'REPORT',
|
|
|
|
'/addressbooks/user1/book1',
|
|
|
|
['Depth' => '1']
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$request->setBody(
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
|
|
|
<d:prop>
|
|
|
|
<d:getetag />
|
|
|
|
</d:prop>
|
|
|
|
<c:filter>
|
|
|
|
<c:prop-filter name="uid" />
|
|
|
|
</c:filter>
|
|
|
|
</c:addressbook-query>'
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = new HTTP\ResponseMock();
|
|
|
|
|
|
|
|
$this->server->httpRequest = $request;
|
|
|
|
$this->server->httpResponse = $response;
|
|
|
|
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
// using the client for parsing
|
2016-05-28 15:46:24 +00:00
|
|
|
$client = new DAV\Client(['baseUri' => '/']);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$result = $client->parseMultiStatus($response->body);
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'/addressbooks/user1/book1/card1' => [
|
|
|
|
200 => [
|
2013-10-21 22:46:31 +00:00
|
|
|
'{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
|
2016-05-28 15:46:24 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
'/addressbooks/user1/book1/card2' => [
|
|
|
|
404 => [
|
2013-10-21 22:46:31 +00:00
|
|
|
'{DAV:}getetag' => null,
|
2016-05-28 15:46:24 +00:00
|
|
|
],
|
|
|
|
]
|
|
|
|
], $result);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testQueryDepth0() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'REPORT',
|
|
|
|
'/addressbooks/user1/book1/card1',
|
|
|
|
['Depth' => '0']
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$request->setBody(
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
|
|
|
<d:prop>
|
|
|
|
<d:getetag />
|
|
|
|
</d:prop>
|
|
|
|
<c:filter>
|
|
|
|
<c:prop-filter name="uid" />
|
|
|
|
</c:filter>
|
|
|
|
</c:addressbook-query>'
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = new HTTP\ResponseMock();
|
|
|
|
|
|
|
|
$this->server->httpRequest = $request;
|
|
|
|
$this->server->httpResponse = $response;
|
|
|
|
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
// using the client for parsing
|
2016-05-28 15:46:24 +00:00
|
|
|
$client = new DAV\Client(['baseUri' => '/']);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$result = $client->parseMultiStatus($response->body);
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'/addressbooks/user1/book1/card1' => [
|
|
|
|
200 => [
|
2013-10-21 22:46:31 +00:00
|
|
|
'{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
|
2016-05-28 15:46:24 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
], $result);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testQueryNoMatch() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = new HTTP\Request(
|
|
|
|
'REPORT',
|
|
|
|
'/addressbooks/user1/book1',
|
|
|
|
['Depth' => '1']
|
|
|
|
);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$request->setBody(
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
|
|
|
<d:prop>
|
|
|
|
<d:getetag />
|
|
|
|
</d:prop>
|
|
|
|
<c:filter>
|
|
|
|
<c:prop-filter name="email" />
|
|
|
|
</c:filter>
|
|
|
|
</c:addressbook-query>'
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = new HTTP\ResponseMock();
|
|
|
|
|
|
|
|
$this->server->httpRequest = $request;
|
|
|
|
$this->server->httpResponse = $response;
|
|
|
|
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
// using the client for parsing
|
2016-05-28 15:46:24 +00:00
|
|
|
$client = new DAV\Client(['baseUri' => '/']);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$result = $client->parseMultiStatus($response->body);
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([], $result);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testQueryLimit() {
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$request = HTTP\Sapi::createFromServerArray([
|
2013-10-21 22:46:31 +00:00
|
|
|
'REQUEST_METHOD' => 'REPORT',
|
2016-05-28 15:46:24 +00:00
|
|
|
'REQUEST_URI' => '/addressbooks/user1/book1',
|
|
|
|
'HTTP_DEPTH' => '1',
|
|
|
|
]);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$request->setBody(
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
|
|
|
<d:prop>
|
|
|
|
<d:getetag />
|
|
|
|
</d:prop>
|
|
|
|
<c:filter>
|
|
|
|
<c:prop-filter name="uid" />
|
|
|
|
</c:filter>
|
|
|
|
<c:limit><c:nresults>1</c:nresults></c:limit>
|
|
|
|
</c:addressbook-query>'
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = new HTTP\ResponseMock();
|
|
|
|
|
|
|
|
$this->server->httpRequest = $request;
|
|
|
|
$this->server->httpResponse = $response;
|
|
|
|
|
|
|
|
$this->server->exec();
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
// using the client for parsing
|
2016-05-28 15:46:24 +00:00
|
|
|
$client = new DAV\Client(['baseUri' => '/']);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
$result = $client->parseMultiStatus($response->body);
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'/addressbooks/user1/book1/card1' => [
|
|
|
|
200 => [
|
|
|
|
'{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
], $result);
|
2013-10-21 22:46:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-05-11 00:26:44 +00:00
|
|
|
function testJson() {
|
|
|
|
|
|
|
|
$request = new HTTP\Request(
|
|
|
|
'REPORT',
|
|
|
|
'/addressbooks/user1/book1/card1',
|
|
|
|
['Depth' => '0']
|
|
|
|
);
|
|
|
|
|
|
|
|
$request->setBody(
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
|
|
|
<d:prop>
|
|
|
|
<c:address-data content-type="application/vcard+json" />
|
|
|
|
<d:getetag />
|
|
|
|
</d:prop>
|
|
|
|
</c:addressbook-query>'
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = new HTTP\ResponseMock();
|
|
|
|
|
|
|
|
$this->server->httpRequest = $request;
|
|
|
|
$this->server->httpResponse = $response;
|
|
|
|
|
|
|
|
$this->server->exec();
|
|
|
|
|
|
|
|
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
|
|
|
|
|
|
|
// using the client for parsing
|
2016-05-28 15:46:24 +00:00
|
|
|
$client = new DAV\Client(['baseUri' => '/']);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
$result = $client->parseMultiStatus($response->body);
|
|
|
|
|
|
|
|
$vobjVersion = \Sabre\VObject\Version::VERSION;
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'/addressbooks/user1/book1/card1' => [
|
|
|
|
200 => [
|
|
|
|
'{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
|
2016-05-11 00:26:44 +00:00
|
|
|
'{urn:ietf:params:xml:ns:carddav}address-data' => '["vcard",[["version",{},"text","4.0"],["prodid",{},"text","-\/\/Sabre\/\/Sabre VObject ' . $vobjVersion . '\/\/EN"],["uid",{},"text","12345"]]]',
|
2016-05-28 15:46:24 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
], $result);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testVCard4() {
|
|
|
|
|
|
|
|
$request = new HTTP\Request(
|
|
|
|
'REPORT',
|
|
|
|
'/addressbooks/user1/book1/card1',
|
|
|
|
['Depth' => '0']
|
|
|
|
);
|
|
|
|
|
|
|
|
$request->setBody(
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
|
|
|
<d:prop>
|
|
|
|
<c:address-data content-type="text/vcard" version="4.0" />
|
|
|
|
<d:getetag />
|
|
|
|
</d:prop>
|
|
|
|
</c:addressbook-query>'
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = new HTTP\ResponseMock();
|
|
|
|
|
|
|
|
$this->server->httpRequest = $request;
|
|
|
|
$this->server->httpResponse = $response;
|
|
|
|
|
|
|
|
$this->server->exec();
|
|
|
|
|
|
|
|
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
|
|
|
|
|
|
|
// using the client for parsing
|
2016-05-28 15:46:24 +00:00
|
|
|
$client = new DAV\Client(['baseUri' => '/']);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
$result = $client->parseMultiStatus($response->body);
|
|
|
|
|
|
|
|
$vobjVersion = \Sabre\VObject\Version::VERSION;
|
|
|
|
|
2016-05-28 15:46:24 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
'/addressbooks/user1/book1/card1' => [
|
|
|
|
200 => [
|
|
|
|
'{DAV:}getetag' => '"' . md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nEND:VCARD") . '"',
|
2016-05-11 00:26:44 +00:00
|
|
|
'{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",
|
2016-05-28 15:46:24 +00:00
|
|
|
],
|
|
|
|
],
|
|
|
|
], $result);
|
2016-05-11 00:26:44 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function testAddressBookDepth0() {
|
|
|
|
|
|
|
|
$request = new HTTP\Request(
|
|
|
|
'REPORT',
|
|
|
|
'/addressbooks/user1/book1',
|
|
|
|
['Depth' => '0']
|
|
|
|
);
|
|
|
|
|
|
|
|
$request->setBody(
|
|
|
|
'<?xml version="1.0"?>
|
|
|
|
<c:addressbook-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
|
|
|
|
<d:prop>
|
|
|
|
<c:address-data content-type="application/vcard+json" />
|
|
|
|
<d:getetag />
|
|
|
|
</d:prop>
|
|
|
|
</c:addressbook-query>'
|
|
|
|
);
|
|
|
|
|
|
|
|
$response = new HTTP\ResponseMock();
|
|
|
|
|
|
|
|
$this->server->httpRequest = $request;
|
|
|
|
$this->server->httpResponse = $response;
|
|
|
|
|
|
|
|
$this->server->exec();
|
|
|
|
|
|
|
|
$this->assertEquals(415, $response->status, 'Incorrect status code. Full response body:' . $response->body);
|
|
|
|
|
|
|
|
}
|
2013-10-21 22:46:31 +00:00
|
|
|
}
|