Skip to content

Commit

Permalink
Testing the share request parser, and fixing a few bugs.
Browse files Browse the repository at this point in the history
Fixes #662
  • Loading branch information
evert committed May 20, 2015
1 parent 9c795c2 commit 8176aca
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 47 deletions.
5 changes: 3 additions & 2 deletions lib/CalDAV/Xml/Request/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ static function xmlDeserialize(Reader $reader) {
$sharee = $elem['value'];

$sumElem = '{' . Plugin::NS_CALENDARSERVER . '}summary';
$commonName = '{' . Plugin::NS_CALENDARSERVER . '}common-name';

$set[] = [
'href' => $sharee['{DAV:}href'],
'commonName' => $sharee['{' . Plugin::NS_CALENDARSERVER . '}common-name'],
'commonName' => isset($sharee[$commonName]) ? $sharee[$commonName] : null,
'summary' => isset($sharee[$sumElem]) ? $sharee[$sumElem] : null,
'readOnly' => isset($sharee['{' . Plugin::NS_CALENDARSERVER . '}readOnly']),
'readOnly' => !array_key_exists('{' . Plugin::NS_CALENDARSERVER . '}read-write', $sharee),
];
break;

Expand Down
90 changes: 45 additions & 45 deletions tests/Sabre/CalDAV/Xml/Request/CalendarQueryReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ function testDeserialize() {
'{DAV:}getetag',
];
$calendarQueryReport->filters = [
'name' => 'VCALENDAR',
'name' => 'VCALENDAR',
'is-not-defined' => false,
'comp-filters' => [],
'prop-filters' => [],
'time-range' => false,
'comp-filters' => [],
'prop-filters' => [],
'time-range' => false,
];

$this->assertEquals(
Expand Down Expand Up @@ -115,96 +115,96 @@ function testDeserializeComplex() {
];
$calendarQueryReport->expand = [
'start' => new \DateTime('2015-01-01 00:00:00', new \DateTimeZone('UTC')),
'end' => new \DateTime('2016-01-01 00:00:00', new \DateTimeZone('UTC')),
'end' => new \DateTime('2016-01-01 00:00:00', new \DateTimeZone('UTC')),
];
$calendarQueryReport->filters = [
'name' => 'VCALENDAR',
'name' => 'VCALENDAR',
'is-not-defined' => false,
'comp-filters' => [
'comp-filters' => [
[
'name' => 'VEVENT',
'name' => 'VEVENT',
'is-not-defined' => false,
'comp-filters' => [
'comp-filters' => [
[
'name' => 'VALARM',
'name' => 'VALARM',
'is-not-defined' => true,
'comp-filters' => [],
'prop-filters' => [],
'time-range' => false,
'comp-filters' => [],
'prop-filters' => [],
'time-range' => false,
],
],
'prop-filters' => [
[
'name' => 'UID',
'name' => 'UID',
'is-not-defined' => false,
'time-range' => false,
'text-match' => null,
'param-filters' => [],
'time-range' => false,
'text-match' => null,
'param-filters' => [],
],
[
'name' => 'X-PROP',
'name' => 'X-PROP',
'is-not-defined' => false,
'time-range' => false,
'text-match' => null,
'param-filters' => [
'time-range' => false,
'text-match' => null,
'param-filters' => [
[
'name' => 'X-PARAM',
'name' => 'X-PARAM',
'is-not-defined' => false,
'text-match' => null,
'text-match' => null,
],
[
'name' => 'X-PARAM2',
'name' => 'X-PARAM2',
'is-not-defined' => true,
'text-match' => null,
'text-match' => null,
],
[
'name' => 'X-PARAM3',
'name' => 'X-PARAM3',
'is-not-defined' => false,
'text-match' => [
'text-match' => [
'negate-condition' => true,
'collation' => 'i;ascii-casemap',
'value' => 'hi',
'collation' => 'i;ascii-casemap',
'value' => 'hi',
],
],
],
],
[
'name' => 'X-PROP2',
'name' => 'X-PROP2',
'is-not-defined' => true,
'time-range' => false,
'text-match' => null,
'param-filters' => [],
'time-range' => false,
'text-match' => null,
'param-filters' => [],
],
[
'name' => 'X-PROP3',
'name' => 'X-PROP3',
'is-not-defined' => false,
'time-range' => [
'time-range' => [
'start' => new \DateTime('2015-01-01 00:00:00', new \DateTimeZone('UTC')),
'end' => new \DateTime('2016-01-01 00:00:00', new \DateTimeZone('UTC')),
],
'text-match' => null,
'end' => new \DateTime('2016-01-01 00:00:00', new \DateTimeZone('UTC')),
],
'text-match' => null,
'param-filters' => [],
],
[
'name' => 'X-PROP4',
'name' => 'X-PROP4',
'is-not-defined' => false,
'time-range' => false,
'text-match' => [
'time-range' => false,
'text-match' => [
'negate-condition' => false,
'collation' => 'i;ascii-casemap',
'value' => 'Hello',
'collation' => 'i;ascii-casemap',
'value' => 'Hello',
],
'param-filters' => [],
],
],
'time-range' => [
'start' => new \DateTime('2015-01-01 00:00:00', new \DateTimeZone('UTC')),
'end' => new \DateTime('2016-01-01 00:00:00', new \DateTimeZone('UTC')),
'end' => new \DateTime('2016-01-01 00:00:00', new \DateTimeZone('UTC')),
]
],
],
'prop-filters' => [],
'time-range' => false,
'time-range' => false,
];

$this->assertEquals(
Expand Down
86 changes: 86 additions & 0 deletions tests/Sabre/CalDAV/Xml/Request/ShareTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

namespace Sabre\CalDAV\Xml\Request;

use Sabre\DAV\Xml\XmlTest;

class ShareTest extends XmlTest {

protected $elementMap = [
'{http://calendarserver.org/ns/}share' => 'Sabre\\CalDAV\\Xml\\Request\\Share',
];

function testDeserialize() {

$xml = <<<XML
<?xml version="1.0" encoding="utf-8" ?>
<CS:share xmlns:D="DAV:"
xmlns:CS="http://calendarserver.org/ns/">
<CS:set>
<D:href>mailto:eric@example.com</D:href>
<CS:common-name>Eric York</CS:common-name>
<CS:summary>Shared workspace</CS:summary>
<CS:read-write />
</CS:set>
<CS:remove>
<D:href>mailto:foo@bar</D:href>
</CS:remove>
</CS:share>
XML;

$result = $this->parse($xml);
$share = new Share(
[
[
'href' => 'mailto:eric@example.com',
'commonName' => 'Eric York',
'summary' => 'Shared workspace',
'readOnly' => false,
]
],
[
'mailto:foo@bar',
]
);

$this->assertEquals(
$share,
$result['value']
);

}

function testDeserializeMininal() {

$xml = <<<XML
<?xml version="1.0" encoding="utf-8" ?>
<CS:share xmlns:D="DAV:"
xmlns:CS="http://calendarserver.org/ns/">
<CS:set>
<D:href>mailto:eric@example.com</D:href>
<CS:read />
</CS:set>
</CS:share>
XML;

$result = $this->parse($xml);
$share = new Share(
[
[
'href' => 'mailto:eric@example.com',
'commonName' => null,
'summary' => null,
'readOnly' => true,
]
],
[]
);

$this->assertEquals(
$share,
$result['value']
);

}

}

0 comments on commit 8176aca

Please sign in to comment.