2017-04-25 14:37:13 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2017 Georg Ehrke <oc.list@georgehrke.com>
|
2017-11-06 14:56:42 +00:00
|
|
|
*
|
2017-11-06 19:15:27 +00:00
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
2017-11-06 14:56:42 +00:00
|
|
|
*
|
2017-04-25 14:37:13 +00:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
2017-11-06 14:56:42 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
2017-04-25 14:37:13 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-11-06 14:56:42 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-04-25 14:37:13 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
2017-11-06 14:56:42 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-04-25 14:37:13 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\DAV\Tests\unit\CalDAV\Search\Xml\Request;
|
|
|
|
|
|
|
|
use OCA\DAV\CalDAV\Search\Xml\Request\CalendarSearchReport;
|
|
|
|
use Sabre\Xml\Reader;
|
|
|
|
use Test\TestCase;
|
|
|
|
|
|
|
|
class CalendarSearchReportTest extends TestCase {
|
|
|
|
|
|
|
|
private $elementMap = [
|
|
|
|
'{http://nextcloud.com/ns}calendar-search' =>
|
|
|
|
'OCA\\DAV\\CalDAV\\Search\\Xml\\Request\\CalendarSearchReport',
|
|
|
|
];
|
|
|
|
|
|
|
|
public function testFoo() {
|
|
|
|
$xml = <<<XML
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
|
|
|
|
<d:prop>
|
|
|
|
<d:getetag />
|
|
|
|
<c:calendar-data />
|
|
|
|
</d:prop>
|
|
|
|
<nc:filter>
|
|
|
|
<nc:comp-filter name="VEVENT" />
|
|
|
|
<nc:comp-filter name="VTODO" />
|
|
|
|
<nc:prop-filter name="SUMMARY" />
|
|
|
|
<nc:prop-filter name="LOCATION" />
|
|
|
|
<nc:prop-filter name="ATTENDEE" />
|
|
|
|
<nc:param-filter property="ATTENDEE" name="CN" />
|
|
|
|
<nc:search-term>foo</nc:search-term>
|
|
|
|
</nc:filter>
|
|
|
|
<nc:limit>10</nc:limit>
|
|
|
|
<nc:offset>5</nc:offset>
|
|
|
|
</nc:calendar-search>
|
|
|
|
XML;
|
|
|
|
|
|
|
|
$result = $this->parse($xml);
|
|
|
|
|
|
|
|
$calendarSearchReport = new CalendarSearchReport();
|
|
|
|
$calendarSearchReport->properties = [
|
|
|
|
'{DAV:}getetag',
|
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-data',
|
|
|
|
];
|
|
|
|
$calendarSearchReport->filters = [
|
|
|
|
'comps' => [
|
|
|
|
'VEVENT',
|
|
|
|
'VTODO'
|
|
|
|
],
|
|
|
|
'props' => [
|
|
|
|
'SUMMARY',
|
|
|
|
'LOCATION',
|
|
|
|
'ATTENDEE'
|
|
|
|
],
|
|
|
|
'params' => [
|
|
|
|
[
|
|
|
|
'property' => 'ATTENDEE',
|
|
|
|
'parameter' => 'CN'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'search-term' => 'foo'
|
|
|
|
];
|
|
|
|
$calendarSearchReport->limit = 10;
|
|
|
|
$calendarSearchReport->offset = 5;
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$calendarSearchReport,
|
|
|
|
$result['value']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoLimitOffset() {
|
|
|
|
$xml = <<<XML
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
|
|
|
|
<d:prop>
|
|
|
|
<d:getetag />
|
|
|
|
<c:calendar-data />
|
|
|
|
</d:prop>
|
|
|
|
<nc:filter>
|
|
|
|
<nc:comp-filter name="VEVENT" />
|
|
|
|
<nc:prop-filter name="SUMMARY" />
|
|
|
|
<nc:search-term>foo</nc:search-term>
|
|
|
|
</nc:filter>
|
|
|
|
</nc:calendar-search>
|
|
|
|
XML;
|
|
|
|
|
|
|
|
$result = $this->parse($xml);
|
|
|
|
|
|
|
|
$calendarSearchReport = new CalendarSearchReport();
|
|
|
|
$calendarSearchReport->properties = [
|
|
|
|
'{DAV:}getetag',
|
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-data',
|
|
|
|
];
|
|
|
|
$calendarSearchReport->filters = [
|
|
|
|
'comps' => [
|
|
|
|
'VEVENT',
|
|
|
|
],
|
|
|
|
'props' => [
|
|
|
|
'SUMMARY',
|
|
|
|
],
|
|
|
|
'search-term' => 'foo'
|
|
|
|
];
|
|
|
|
$calendarSearchReport->limit = null;
|
|
|
|
$calendarSearchReport->offset = null;
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$calendarSearchReport,
|
|
|
|
$result['value']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Sabre\DAV\Exception\BadRequest
|
|
|
|
* @expectedExceptionMessage {http://nextcloud.com/ns}prop-filter or {http://nextcloud.com/ns}param-filter given without any {http://nextcloud.com/ns}comp-filter
|
|
|
|
*/
|
|
|
|
public function testRequiresCompFilter() {
|
|
|
|
$xml = <<<XML
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
|
|
|
|
<d:prop>
|
|
|
|
<d:getetag />
|
|
|
|
<c:calendar-data />
|
|
|
|
</d:prop>
|
|
|
|
<nc:filter>
|
|
|
|
<nc:prop-filter name="SUMMARY" />
|
|
|
|
<nc:prop-filter name="LOCATION" />
|
|
|
|
<nc:prop-filter name="ATTENDEE" />
|
|
|
|
<nc:param-filter property="ATTENDEE" name="CN" />
|
|
|
|
<nc:search-term>foo</nc:search-term>
|
|
|
|
</nc:filter>
|
|
|
|
<nc:limit>10</nc:limit>
|
|
|
|
<nc:offset>5</nc:offset>
|
|
|
|
</nc:calendar-search>
|
|
|
|
XML;
|
|
|
|
|
|
|
|
$this->parse($xml);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Sabre\DAV\Exception\BadRequest
|
|
|
|
* @expectedExceptionMessage The {http://nextcloud.com/ns}filter element is required for this request
|
|
|
|
*/
|
|
|
|
public function testRequiresFilter() {
|
|
|
|
$xml = <<<XML
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
|
|
|
|
<d:prop>
|
|
|
|
<d:getetag />
|
|
|
|
<c:calendar-data />
|
|
|
|
</d:prop>
|
|
|
|
</nc:calendar-search>
|
|
|
|
XML;
|
|
|
|
|
|
|
|
$this->parse($xml);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Sabre\DAV\Exception\BadRequest
|
|
|
|
* @expectedExceptionMessage {http://nextcloud.com/ns}search-term is required for this request
|
|
|
|
*/
|
|
|
|
public function testNoSearchTerm() {
|
|
|
|
$xml = <<<XML
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
|
|
|
|
<d:prop>
|
|
|
|
<d:getetag />
|
|
|
|
<c:calendar-data />
|
|
|
|
</d:prop>
|
|
|
|
<nc:filter>
|
|
|
|
<nc:comp-filter name="VEVENT" />
|
|
|
|
<nc:comp-filter name="VTODO" />
|
|
|
|
<nc:prop-filter name="SUMMARY" />
|
|
|
|
<nc:prop-filter name="LOCATION" />
|
|
|
|
<nc:prop-filter name="ATTENDEE" />
|
|
|
|
<nc:param-filter property="ATTENDEE" name="CN" />
|
|
|
|
</nc:filter>
|
|
|
|
<nc:limit>10</nc:limit>
|
|
|
|
<nc:offset>5</nc:offset>
|
|
|
|
</nc:calendar-search>
|
|
|
|
XML;
|
|
|
|
|
2017-11-06 08:43:45 +00:00
|
|
|
$this->parse($xml);
|
2017-04-25 14:37:13 +00:00
|
|
|
}
|
|
|
|
|
2017-04-25 16:20:32 +00:00
|
|
|
/**
|
|
|
|
* @expectedException \Sabre\DAV\Exception\BadRequest
|
|
|
|
* @expectedExceptionMessage At least one{http://nextcloud.com/ns}prop-filter or {http://nextcloud.com/ns}param-filter is required for this request
|
|
|
|
*/
|
2017-04-25 14:37:13 +00:00
|
|
|
public function testCompOnly() {
|
|
|
|
$xml = <<<XML
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
|
|
|
|
<d:prop>
|
|
|
|
<d:getetag />
|
|
|
|
<c:calendar-data />
|
|
|
|
</d:prop>
|
|
|
|
<nc:filter>
|
|
|
|
<nc:comp-filter name="VEVENT" />
|
|
|
|
<nc:comp-filter name="VTODO" />
|
|
|
|
<nc:search-term>foo</nc:search-term>
|
|
|
|
</nc:filter>
|
|
|
|
</nc:calendar-search>
|
|
|
|
XML;
|
|
|
|
|
|
|
|
$result = $this->parse($xml);
|
|
|
|
|
|
|
|
$calendarSearchReport = new CalendarSearchReport();
|
|
|
|
$calendarSearchReport->properties = [
|
|
|
|
'{DAV:}getetag',
|
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-data',
|
|
|
|
];
|
|
|
|
$calendarSearchReport->filters = [
|
|
|
|
'comps' => [
|
|
|
|
'VEVENT',
|
|
|
|
'VTODO'
|
|
|
|
],
|
|
|
|
'search-term' => 'foo'
|
|
|
|
];
|
|
|
|
$calendarSearchReport->limit = null;
|
|
|
|
$calendarSearchReport->offset = null;
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$calendarSearchReport,
|
|
|
|
$result['value']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testPropOnly() {
|
|
|
|
$xml = <<<XML
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
|
|
|
|
<d:prop>
|
|
|
|
<d:getetag />
|
|
|
|
<c:calendar-data />
|
|
|
|
</d:prop>
|
|
|
|
<nc:filter>
|
|
|
|
<nc:comp-filter name="VEVENT" />
|
|
|
|
<nc:prop-filter name="SUMMARY" />
|
|
|
|
<nc:search-term>foo</nc:search-term>
|
|
|
|
</nc:filter>
|
|
|
|
</nc:calendar-search>
|
|
|
|
XML;
|
|
|
|
|
|
|
|
$result = $this->parse($xml);
|
|
|
|
|
|
|
|
$calendarSearchReport = new CalendarSearchReport();
|
|
|
|
$calendarSearchReport->properties = [
|
|
|
|
'{DAV:}getetag',
|
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-data',
|
|
|
|
];
|
|
|
|
$calendarSearchReport->filters = [
|
|
|
|
'comps' => [
|
|
|
|
'VEVENT',
|
|
|
|
],
|
|
|
|
'props' => [
|
|
|
|
'SUMMARY',
|
|
|
|
],
|
|
|
|
'search-term' => 'foo'
|
|
|
|
];
|
|
|
|
$calendarSearchReport->limit = null;
|
|
|
|
$calendarSearchReport->offset = null;
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$calendarSearchReport,
|
|
|
|
$result['value']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testParamOnly() {
|
|
|
|
$xml = <<<XML
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<nc:calendar-search xmlns:nc="http://nextcloud.com/ns" xmlns:c="urn:ietf:params:xml:ns:caldav" xmlns:d="DAV:">
|
|
|
|
<d:prop>
|
|
|
|
<d:getetag />
|
|
|
|
<c:calendar-data />
|
|
|
|
</d:prop>
|
|
|
|
<nc:filter>
|
|
|
|
<nc:comp-filter name="VEVENT" />
|
|
|
|
<nc:param-filter property="ATTENDEE" name="CN" />
|
|
|
|
<nc:search-term>foo</nc:search-term>
|
|
|
|
</nc:filter>
|
|
|
|
</nc:calendar-search>
|
|
|
|
XML;
|
|
|
|
|
|
|
|
$result = $this->parse($xml);
|
|
|
|
|
|
|
|
$calendarSearchReport = new CalendarSearchReport();
|
|
|
|
$calendarSearchReport->properties = [
|
|
|
|
'{DAV:}getetag',
|
|
|
|
'{urn:ietf:params:xml:ns:caldav}calendar-data',
|
|
|
|
];
|
|
|
|
$calendarSearchReport->filters = [
|
|
|
|
'comps' => [
|
|
|
|
'VEVENT',
|
|
|
|
],
|
|
|
|
'params' => [
|
|
|
|
[
|
|
|
|
'property' => 'ATTENDEE',
|
|
|
|
'parameter' => 'CN'
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'search-term' => 'foo'
|
|
|
|
];
|
|
|
|
$calendarSearchReport->limit = null;
|
|
|
|
$calendarSearchReport->offset = null;
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
$calendarSearchReport,
|
|
|
|
$result['value']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function parse($xml, array $elementMap = []) {
|
|
|
|
$reader = new Reader();
|
|
|
|
$reader->elementMap = array_merge($this->elementMap, $elementMap);
|
|
|
|
$reader->xml($xml);
|
|
|
|
return $reader->parse();
|
|
|
|
}
|
|
|
|
}
|