Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiget addressdata filter #1310

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/CardDAV/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ public function addressbookMultiGetReport($report)
if (isset($props['200']['{'.self::NS_CARDDAV.'}address-data'])) {
$props['200']['{'.self::NS_CARDDAV.'}address-data'] = $this->convertVCard(
$props[200]['{'.self::NS_CARDDAV.'}address-data'],
$vcardType
$vcardType,
$report->addressDataProperties
);
}
$propertyList[] = $props;
Expand Down
5 changes: 3 additions & 2 deletions lib/DAV/Xml/Element/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,14 @@ public function getResponseProperties()
*/
public function xmlSerialize(Writer $writer)
{
$empty = true;

if ($status = $this->getHTTPStatus()) {
$empty = false;
$writer->writeElement('{DAV:}status', 'HTTP/1.1 '.$status.' '.\Sabre\HTTP\Response::$statusCodes[$status]);
}
$writer->writeElement('{DAV:}href', $writer->contextUri.\Sabre\HTTP\encodePath($this->getHref()));

$empty = true;

foreach ($this->getResponseProperties() as $status => $properties) {
// Skipping empty lists
if (!$properties || (!ctype_digit($status) && !is_int($status))) {
Expand Down
46 changes: 46 additions & 0 deletions tests/Sabre/CardDAV/MultiGetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,50 @@ public function testMultiGetVCard4()
],
], $result);
}

public function testMultiGetAddressObjectProperties()
{
$request = HTTP\Sapi::createFromServerArray([
'REQUEST_METHOD' => 'REPORT',
'REQUEST_URI' => '/addressbooks/user1/book3',
]);

$request->setBody(
'<?xml version="1.0"?>
<c:addressbook-multiget xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:carddav">
<d:prop>
<d:getetag />
<c:address-data>
<c:prop name="FN"/>
<c:prop name="BDAY"/>
</c:address-data>
</d:prop>
<d:href>/addressbooks/user1/book3/card3</d:href>
</c:addressbook-multiget>'
);

$response = new HTTP\ResponseMock();

$this->server->httpRequest = $request;
$this->server->httpResponse = $response;

$this->server->exec();

$bodyAsString = $response->getBodyAsString();
$this->assertEquals(207, $response->status, 'Incorrect status code. Full response body:'.$bodyAsString);

// using the client for parsing
$client = new DAV\Client(['baseUri' => '/']);

$result = $client->parseMultiStatus($bodyAsString);

$this->assertEquals([
'/addressbooks/user1/book3/card3' => [
200 => [
'{DAV:}getetag' => '"'.md5("BEGIN:VCARD\nVERSION:3.0\nUID:12345\nFN:Test-Card\nEMAIL;TYPE=home:bar@example.org\nEND:VCARD").'"',
'{urn:ietf:params:xml:ns:carddav}address-data' => "BEGIN:VCARD\r\nVERSION:3.0\r\nUID:12345\r\nFN:Test-Card\r\nEND:VCARD\r\n",
],
],
], $result);
}
}
4 changes: 0 additions & 4 deletions tests/Sabre/DAVACL/PrincipalMatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ public function testPrincipalMatch()
<d:multistatus xmlns:d="DAV:" xmlns:s="http://sabredav.org/ns">
<d:status>HTTP/1.1 200 OK</d:status>
<d:href>/principals/user1</d:href>
<d:propstat>
<d:prop/>
<d:status>HTTP/1.1 418 I'm a teapot</d:status>
</d:propstat>
</d:multistatus>
XML;

Expand Down