[Pkg-owncloud-commits] [php-sabredav] 95/148: More CalDAV tests.
David Prévot
taffit at moszumanska.debian.org
Wed Apr 15 01:37:22 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabredav.
commit 1b160a23b23bbbedf5665619c75f56a129f72037
Author: Evert Pot <me at evertpot.com>
Date: Fri Mar 27 17:10:40 2015 -0700
More CalDAV tests.
---
lib/CalDAV/Xml/Filter/ParamFilter.php | 2 +-
lib/CalDAV/Xml/Filter/PropFilter.php | 3 -
.../Xml/Property/ScheduleCalendarTranspTest.php | 118 +++++++
.../CalDAV/Xml/Request/CalendarQueryReportTest.php | 367 +++++++++++++++++++++
4 files changed, 486 insertions(+), 4 deletions(-)
diff --git a/lib/CalDAV/Xml/Filter/ParamFilter.php b/lib/CalDAV/Xml/Filter/ParamFilter.php
index 79dbfa0..57d6674 100644
--- a/lib/CalDAV/Xml/Filter/ParamFilter.php
+++ b/lib/CalDAV/Xml/Filter/ParamFilter.php
@@ -44,7 +44,7 @@ class ParamFilter implements XmlDeserializable {
* @param Reader $reader
* @return mixed
*/
- static function deserializeXml(Reader $reader) {
+ static function xmlDeserialize(Reader $reader) {
$result = [
'name' => null,
diff --git a/lib/CalDAV/Xml/Filter/PropFilter.php b/lib/CalDAV/Xml/Filter/PropFilter.php
index 411e5c9..3dddcbe 100644
--- a/lib/CalDAV/Xml/Filter/PropFilter.php
+++ b/lib/CalDAV/Xml/Filter/PropFilter.php
@@ -71,9 +71,6 @@ class PropFilter implements XmlDeserializable {
$result['is-not-defined'] = true;
break;
case '{' . Plugin::NS_CALDAV . '}time-range' :
- if ($result['name'] === 'VCALENDAR') {
- throw new BadRequest('You cannot add time-range filters on the VCALENDAR component');
- }
$result['time-range'] = [
'start' => isset($elem['attributes']['start'])?DateTimeParser::parseDateTime($elem['attributes']['start']):null,
'end' => isset($elem['attributes']['end'])?DateTimeParser::parseDateTime($elem['attributes']['end']):null,
diff --git a/tests/Sabre/CalDAV/Xml/Property/ScheduleCalendarTranspTest.php b/tests/Sabre/CalDAV/Xml/Property/ScheduleCalendarTranspTest.php
new file mode 100644
index 0000000..729db45
--- /dev/null
+++ b/tests/Sabre/CalDAV/Xml/Property/ScheduleCalendarTranspTest.php
@@ -0,0 +1,118 @@
+<?php
+
+namespace Sabre\CalDAV\Xml\Property;
+
+use Sabre\CalDAV;
+use Sabre\DAV;
+
+class ScheduleCalendarTranspTest extends DAV\Xml\XmlTest {
+
+ function setUp() {
+
+ $this->namespaceMap[CalDAV\Plugin::NS_CALDAV] = 'cal';
+ $this->namespaceMap[CalDAV\Plugin::NS_CALENDARSERVER] = 'cs';
+
+
+ }
+
+ function testSimple() {
+
+ $prop = new ScheduleCalendarTransp(ScheduleCalendarTransp::OPAQUE);
+ $this->assertEquals(
+ ScheduleCalendarTransp::OPAQUE,
+ $prop->getValue()
+ );
+
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ */
+ function testBadValue() {
+
+ new ScheduleCalendarTransp('ahhh');
+
+ }
+
+ /**
+ * @depends testSimple
+ */
+ function testSerializeOpaque() {
+
+ $property = new ScheduleCalendarTransp(ScheduleCalendarTransp::OPAQUE);
+ $xml = $this->write(['{DAV:}root' => $property]);
+
+ $this->assertXmlStringEqualsXmlString(
+'<?xml version="1.0"?>
+<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '" xmlns:cs="' . CalDAV\Plugin::NS_CALENDARSERVER . '">
+ <cal:opaque />
+</d:root>
+', $xml);
+
+ }
+
+ /**
+ * @depends testSimple
+ */
+ function testSerializeTransparent() {
+
+ $property = new ScheduleCalendarTransp(ScheduleCalendarTransp::TRANSPARENT);
+ $xml = $this->write(['{DAV:}root' => $property]);
+
+ $this->assertXmlStringEqualsXmlString(
+'<?xml version="1.0"?>
+<d:root xmlns:d="DAV:" xmlns:cal="' . CalDAV\Plugin::NS_CALDAV . '" xmlns:cs="' . CalDAV\Plugin::NS_CALENDARSERVER . '">
+ <cal:transparent />
+</d:root>
+', $xml);
+
+ }
+
+ function testUnserializeTransparent() {
+
+ $cal = CalDAV\Plugin::NS_CALDAV;
+ $cs = CalDAV\Plugin::NS_CALENDARSERVER;
+
+$xml = <<<XML
+<?xml version="1.0"?>
+<d:root xmlns:d="DAV:" xmlns:cal="$cal" xmlns:cs="$cs">
+ <cal:transparent />
+</d:root>
+XML;
+
+ $result = $this->parse(
+ $xml,
+ ['{DAV:}root' => 'Sabre\\CalDAV\\Xml\\Property\\ScheduleCalendarTransp']
+ );
+
+ $this->assertEquals(
+ new ScheduleCalendarTransp(ScheduleCalendarTransp::TRANSPARENT),
+ $result['value']
+ );
+
+ }
+
+ function testUnserializeOpaque() {
+
+ $cal = CalDAV\Plugin::NS_CALDAV;
+ $cs = CalDAV\Plugin::NS_CALENDARSERVER;
+
+$xml = <<<XML
+<?xml version="1.0"?>
+<d:root xmlns:d="DAV:" xmlns:cal="$cal" xmlns:cs="$cs">
+ <cal:opaque />
+</d:root>
+XML;
+
+ $result = $this->parse(
+ $xml,
+ ['{DAV:}root' => 'Sabre\\CalDAV\\Xml\\Property\\ScheduleCalendarTransp']
+ );
+
+ $this->assertEquals(
+ new ScheduleCalendarTransp(ScheduleCalendarTransp::OPAQUE),
+ $result['value']
+ );
+
+ }
+}
diff --git a/tests/Sabre/CalDAV/Xml/Request/CalendarQueryReportTest.php b/tests/Sabre/CalDAV/Xml/Request/CalendarQueryReportTest.php
new file mode 100644
index 0000000..b7ca01f
--- /dev/null
+++ b/tests/Sabre/CalDAV/Xml/Request/CalendarQueryReportTest.php
@@ -0,0 +1,367 @@
+<?php
+
+namespace Sabre\CalDAV\Xml\Request;
+
+use Sabre\DAV\Xml\XmlTest;
+
+class CalendarQueryReportTest extends XmlTest {
+
+ protected $elementMap = [
+ '{urn:ietf:params:xml:ns:caldav}calendar-query' => 'Sabre\\CalDAV\\Xml\\Request\CalendarQueryReport',
+ ];
+
+ function testDeserialize() {
+
+ $xml = <<<XML
+<?xml version="1.0"?>
+<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
+ <d:prop>
+ <d:getetag />
+ </d:prop>
+ <c:filter>
+ <c:comp-filter name="VCALENDAR" />
+ </c:filter>
+</c:calendar-query>
+XML;
+
+ $result = $this->parse($xml);
+ $calendarQueryReport = new CalendarQueryReport();
+ $calendarQueryReport->properties = [
+ '{DAV:}getetag',
+ ];
+ $calendarQueryReport->filters = [
+ 'name' => 'VCALENDAR',
+ 'is-not-defined' => false,
+ 'comp-filters' => [],
+ 'prop-filters' => [],
+ 'time-range' => false,
+ ];
+
+ $this->assertEquals(
+ $calendarQueryReport,
+ $result['value']
+ );
+
+ }
+
+ /**
+ * @expectedException Sabre\DAV\Exception\BadRequest
+ */
+ function testDeserializeNoFilter() {
+
+ $xml = <<<XML
+<?xml version="1.0"?>
+<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
+ <d:prop>
+ <d:getetag />
+ </d:prop>
+</c:calendar-query>
+XML;
+
+ $this->parse($xml);
+
+ }
+
+ function testDeserializeComplex() {
+
+ $xml = <<<XML
+<?xml version="1.0"?>
+<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
+ <d:prop>
+ <d:getetag />
+ <c:calendar-data content-type="application/json+calendar" version="2.0">
+ <c:expand start="20150101T000000Z" end="20160101T000000Z" />
+ </c:calendar-data>
+ </d:prop>
+ <c:filter>
+ <c:comp-filter name="VCALENDAR">
+ <c:comp-filter name="VEVENT">
+ <c:time-range start="20150101T000000Z" end="20160101T000000Z" />
+ <c:prop-filter name="UID" />
+ <c:comp-filter name="VALARM">
+ <c:is-not-defined />
+ </c:comp-filter>
+ <c:prop-filter name="X-PROP">
+ <c:param-filter name="X-PARAM" />
+ <c:param-filter name="X-PARAM2">
+ <c:is-not-defined />
+ </c:param-filter>
+ <c:param-filter name="X-PARAM3">
+ <c:text-match negate-condition="yes">hi</c:text-match>
+ </c:param-filter>
+ </c:prop-filter>
+ <c:prop-filter name="X-PROP2">
+ <c:is-not-defined />
+ </c:prop-filter>
+ <c:prop-filter name="X-PROP3">
+ <c:time-range start="20150101T000000Z" end="20160101T000000Z" />
+ </c:prop-filter>
+ <c:prop-filter name="X-PROP4">
+ <c:text-match>Hello</c:text-match>
+ </c:prop-filter>
+ </c:comp-filter>
+ </c:comp-filter>
+ </c:filter>
+</c:calendar-query>
+XML;
+
+ $result = $this->parse($xml);
+ $calendarQueryReport = new CalendarQueryReport();
+ $calendarQueryReport->version = '2.0';
+ $calendarQueryReport->contentType = 'application/json+calendar';
+ $calendarQueryReport->properties = [
+ '{DAV:}getetag',
+ '{urn:ietf:params:xml:ns:caldav}calendar-data',
+ ];
+ $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')),
+ ];
+ $calendarQueryReport->filters = [
+ 'name' => 'VCALENDAR',
+ 'is-not-defined' => false,
+ 'comp-filters' => [
+ [
+ 'name' => 'VEVENT',
+ 'is-not-defined' => false,
+ 'comp-filters' => [
+ [
+ 'name' => 'VALARM',
+ 'is-not-defined' => true,
+ 'comp-filters' => [],
+ 'prop-filters' => [],
+ 'time-range' => false,
+ ],
+ ],
+ 'prop-filters' => [
+ [
+ 'name' => 'UID',
+ 'is-not-defined' => false,
+ 'time-range' => false,
+ 'text-match' => null,
+ 'param-filters' => [],
+ ],
+ [
+ 'name' => 'X-PROP',
+ 'is-not-defined' => false,
+ 'time-range' => false,
+ 'text-match' => null,
+ 'param-filters' => [
+ [
+ 'name' => 'X-PARAM',
+ 'is-not-defined' => false,
+ 'text-match' => null,
+ ],
+ [
+ 'name' => 'X-PARAM2',
+ 'is-not-defined' => true,
+ 'text-match' => null,
+ ],
+ [
+ 'name' => 'X-PARAM3',
+ 'is-not-defined' => false,
+ 'text-match' => [
+ 'negate-condition' => true,
+ 'collation' => 'i;ascii-casemap',
+ 'value' => 'hi',
+ ],
+ ],
+ ],
+ ],
+ [
+ 'name' => 'X-PROP2',
+ 'is-not-defined' => true,
+ 'time-range' => false,
+ 'text-match' => null,
+ 'param-filters' => [],
+ ],
+ [
+ 'name' => 'X-PROP3',
+ 'is-not-defined' => false,
+ '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,
+ 'param-filters' => [],
+ ],
+ [
+ 'name' => 'X-PROP4',
+ 'is-not-defined' => false,
+ 'time-range' => false,
+ 'text-match' => [
+ 'negate-condition' => false,
+ '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')),
+ ]
+ ],
+ ],
+ 'prop-filters' => [],
+ 'time-range' => false,
+ ];
+
+ $this->assertEquals(
+ $calendarQueryReport,
+ $result['value']
+ );
+
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\BadRequest
+ */
+ function testDeserializeDoubleTopCompFilter() {
+
+ $xml = <<<XML
+<?xml version="1.0"?>
+<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
+ <d:prop>
+ <d:getetag />
+ <c:calendar-data content-type="application/json+calendar" version="2.0">
+ <c:expand start="20150101T000000Z" end="20160101T000000Z" />
+ </c:calendar-data>
+ </d:prop>
+ <c:filter>
+ <c:comp-filter name="VCALENDAR" />
+ <c:comp-filter name="VCALENDAR" />
+ </c:filter>
+</c:calendar-query>
+XML;
+
+ $this->parse($xml);
+
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\BadRequest
+ */
+ function testDeserializeMissingExpandEnd() {
+
+ $xml = <<<XML
+<?xml version="1.0"?>
+<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
+ <d:prop>
+ <d:getetag />
+ <c:calendar-data content-type="application/json+calendar" version="2.0">
+ <c:expand start="20150101T000000Z" />
+ </c:calendar-data>
+ </d:prop>
+ <c:filter>
+ <c:comp-filter name="VCALENDAR" />
+ </c:filter>
+</c:calendar-query>
+XML;
+
+ $this->parse($xml);
+
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\BadRequest
+ */
+ function testDeserializeExpandEndBeforeStart() {
+
+ $xml = <<<XML
+<?xml version="1.0"?>
+<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
+ <d:prop>
+ <d:getetag />
+ <c:calendar-data content-type="application/json+calendar" version="2.0">
+ <c:expand start="20150101T000000Z" end="20140101T000000Z" />
+ </c:calendar-data>
+ </d:prop>
+ <c:filter>
+ <c:comp-filter name="VCALENDAR" />
+ </c:filter>
+</c:calendar-query>
+XML;
+
+ $this->parse($xml);
+
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\BadRequest
+ */
+ function testDeserializeTimeRangeOnVCALENDAR() {
+
+ $xml = <<<XML
+<?xml version="1.0"?>
+<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
+ <d:prop>
+ <d:getetag />
+ <c:calendar-data />
+ </d:prop>
+ <c:filter>
+ <c:comp-filter name="VCALENDAR">
+ <c:time-range start="20150101T000000Z" end="20160101T000000Z" />
+ </c:comp-filter>
+ </c:filter>
+</c:calendar-query>
+XML;
+
+ $this->parse($xml);
+
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\BadRequest
+ */
+ function testDeserializeTimeRangeEndBeforeStart() {
+
+ $xml = <<<XML
+<?xml version="1.0"?>
+<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
+ <d:prop>
+ <d:getetag />
+ <c:calendar-data />
+ </d:prop>
+ <c:filter>
+ <c:comp-filter name="VCALENDAR">
+ <c:comp-filter name="VEVENT">
+ <c:time-range start="20150101T000000Z" end="20140101T000000Z" />
+ </c:comp-filter>
+ </c:comp-filter>
+ </c:filter>
+</c:calendar-query>
+XML;
+
+ $this->parse($xml);
+
+ }
+
+ /**
+ * @expectedException \Sabre\DAV\Exception\BadRequest
+ */
+ function testDeserializeTimeRangePropEndBeforeStart() {
+
+ $xml = <<<XML
+<?xml version="1.0"?>
+<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
+ <d:prop>
+ <d:getetag />
+ <c:calendar-data />
+ </d:prop>
+ <c:filter>
+ <c:comp-filter name="VCALENDAR">
+ <c:comp-filter name="VEVENT">
+ <c:prop-filter name="DTSTART">
+ <c:time-range start="20150101T000000Z" end="20140101T000000Z" />
+ </c:prop-filter>
+ </c:comp-filter>
+ </c:comp-filter>
+ </c:filter>
+</c:calendar-query>
+XML;
+
+ $this->parse($xml);
+
+ }
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabredav.git
More information about the Pkg-owncloud-commits
mailing list