' . implode("\n", $xml) . '
';
$dom = DAV\XMLUtil::loadDOMDocument($xml);
$q = new CalendarQueryParser($dom);
$q->parse();
return $q->filters;
}
/**
* @expectedException Sabre\DAV\Exception\BadRequest
*/
function testNoFilter() {
$xml = array();
$this->parse($xml);
}
/**
* @expectedException Sabre\DAV\Exception\BadRequest
*/
function testTwoCompFilter() {
$xml = array(
'',
' ',
' ',
''
);
$this->parse($xml);
}
function testBasicFilter() {
$xml = array(
'',
' ',
''
);
$result = $this->parse($xml);
$expected = array(
'name' => 'VCALENDAR',
'comp-filters' => array(),
'prop-filters' => array(),
'is-not-defined' => false,
'time-range' => false
);
$this->assertEquals(
$expected,
$result
);
}
function testCompIsNotDefined() {
$xml = array(
'',
' ',
' ',
' ',
' ',
' ',
''
);
$result = $this->parse($xml);
$expected = array(
'name' => 'VCALENDAR',
'comp-filters' => array(
array(
'name' => 'VEVENT',
'comp-filters' => array(),
'prop-filters' => array(),
'is-not-defined' => true,
'time-range' => false
),
),
'prop-filters' => array(),
'is-not-defined' => false,
'time-range' => false
);
$this->assertEquals(
$expected,
$result
);
}
/**
* @expectedException Sabre\DAV\Exception\BadRequest
*/
function testCompTimeRangeOnVCALENDAR() {
$xml = array(
'',
' ',
' ',
' ',
''
);
$result = $this->parse($xml);
}
function testCompTimeRange() {
$xml = array(
'',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
''
);
$result = $this->parse($xml);
$expected = array(
'name' => 'VCALENDAR',
'comp-filters' => array(
array(
'name' => 'VEVENT',
'comp-filters' => array(),
'prop-filters' => array(),
'is-not-defined' => false,
'time-range' => array(
'start' => new \DateTime('2011-01-01 00:00:00', new \DateTimeZone('GMT')),
'end' => new \DateTime('2011-12-31 23:59:59', new \DateTimeZone('GMT')),
),
),
array(
'name' => 'VTODO',
'comp-filters' => array(),
'prop-filters' => array(),
'is-not-defined' => false,
'time-range' => array(
'start' => new \DateTime('2011-01-01 00:00:00', new \DateTimeZone('GMT')),
'end' => null,
),
),
array(
'name' => 'VJOURNAL',
'comp-filters' => array(),
'prop-filters' => array(),
'is-not-defined' => false,
'time-range' => array(
'start' => null,
'end' => new \DateTime('2011-12-31 23:59:59', new \DateTimeZone('GMT')),
),
),
),
'prop-filters' => array(),
'is-not-defined' => false,
'time-range' => false
);
$this->assertEquals(
$expected,
$result
);
}
/**
* @expectedException Sabre\DAV\Exception\BadRequest
*/
function testCompTimeRangeBadRange() {
$xml = array(
'',
' ',
' ',
' ',
' ',
' ',
''
);
$this->parse($xml);
}
function testProp() {
$xml = array(
'',
' ',
' ',
' ',
' vacation',
' ',
' ',
' ',
''
);
$result = $this->parse($xml);
$expected = array(
'name' => 'VCALENDAR',
'comp-filters' => array(
array(
'name' => 'VEVENT',
'is-not-defined' => false,
'comp-filters' => array(),
'prop-filters' => array(
array(
'name' => 'SUMMARY',
'is-not-defined' => false,
'param-filters' => array(),
'text-match' => array(
'negate-condition' => false,
'collation' => 'i;ascii-casemap',
'value' => 'vacation',
),
'time-range' => null,
),
),
'time-range' => null,
),
),
'prop-filters' => array(),
'is-not-defined' => false,
'time-range' => false
);
$this->assertEquals(
$expected,
$result
);
}
function testComplex() {
$xml = array(
'',
' ',
' ',
' ',
' vacation',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' DATE',
' ',
' ',
' ',
' ',
''
);
$result = $this->parse($xml);
$expected = array(
'name' => 'VCALENDAR',
'comp-filters' => array(
array(
'name' => 'VEVENT',
'is-not-defined' => false,
'comp-filters' => array(),
'prop-filters' => array(
array(
'name' => 'SUMMARY',
'is-not-defined' => false,
'param-filters' => array(),
'text-match' => array(
'negate-condition' => false,
'collation' => 'i;unicode-casemap',
'value' => 'vacation',
),
'time-range' => null,
),
array(
'name' => 'DTSTAMP',
'is-not-defined' => false,
'param-filters' => array(),
'text-match' => null,
'time-range' => array(
'start' => new \DateTime('2011-07-04 00:00:00', new \DateTimeZone('GMT')),
'end' => null,
),
),
array(
'name' => 'ORGANIZER',
'is-not-defined' => true,
'param-filters' => array(),
'text-match' => null,
'time-range' => null,
),
array(
'name' => 'DTSTART',
'is-not-defined' => false,
'param-filters' => array(
array(
'name' => 'VALUE',
'is-not-defined' => false,
'text-match' => array(
'negate-condition' => true,
'value' => 'DATE',
'collation' => 'i;ascii-casemap',
),
),
),
'text-match' => null,
'time-range' => null,
),
),
'time-range' => null,
),
),
'prop-filters' => array(),
'is-not-defined' => false,
'time-range' => false
);
$this->assertEquals(
$expected,
$result
);
}
function testOther1() {
// This body was exactly sent to us from the sabredav mailing list. Checking if this parses correctly.
$body = <<
BLA;
$dom = DAV\XMLUtil::loadDOMDocument($body);
$q = new CalendarQueryParser($dom);
$q->parse();
$this->assertEquals(array(
'{urn:ietf:params:xml:ns:caldav}calendar-data',
'{DAV:}getetag',
), $q->requestedProperties);
$expectedFilters = array(
'name' => 'VCALENDAR',
'comp-filters' => array(
array(
'name' => 'VEVENT',
'comp-filters' => array(),
'prop-filters' => array(),
'time-range' => array(
'start' => new \DateTime('2009-01-01 00:00:00', new \DateTimeZone('UTC')),
'end' => new \DateTime('2012-12-02 00:00:00', new \DateTimeZone('UTC')),
),
'is-not-defined' => false,
),
),
'prop-filters' => array(),
'time-range' => null,
'is-not-defined' => false,
);
$this->assertEquals($expectedFilters, $q->filters);
}
function testExpand() {
$xml = array(
'',
' ',
' ',
' ',
'',
'',
' ',
''
);
$xml =
'
' . implode("\n", $xml) . '
';
$dom = DAV\XMLUtil::loadDOMDocument($xml);
$q = new CalendarQueryParser($dom);
$q->parse();
$expected = array(
'name' => 'VCALENDAR',
'comp-filters' => array(),
'prop-filters' => array(),
'is-not-defined' => false,
'time-range' => false
);
$this->assertEquals(
$expected,
$q->filters
);
$this->assertEquals(array(
'{urn:ietf:params:xml:ns:caldav}calendar-data',
), $q->requestedProperties);
$this->assertEquals(
array(
'start' => new \DateTime('2011-01-01 00:00:00', new \DateTimeZone('UTC')),
'end' => new \DateTime('2012-01-01 00:00:00', new \DateTimeZone('UTC')),
),
$q->expand
);
}
/**
* @expectedException Sabre\DAV\Exception\BadRequest
*/
function testExpandNoStart() {
$xml = array(
'',
' ',
' ',
' ',
'',
'',
' ',
''
);
$xml =
'
' . implode("\n", $xml) . '
';
$dom = DAV\XMLUtil::loadDOMDocument($xml);
$q = new CalendarQueryParser($dom);
$q->parse();
}
/**
* @expectedException Sabre\DAV\Exception\BadRequest
*/
function testExpandNoEnd() {
$xml = array(
'',
' ',
' ',
' ',
'',
'',
' ',
''
);
$xml =
'
' . implode("\n", $xml) . '
';
$dom = DAV\XMLUtil::loadDOMDocument($xml);
$q = new CalendarQueryParser($dom);
$q->parse();
}
/**
* @expectedException Sabre\DAV\Exception\BadRequest
*/
function testExpandBadTimes() {
$xml = array(
'',
' ',
' ',
' ',
'',
'',
' ',
''
);
$xml =
'
' . implode("\n", $xml) . '
';
$dom = DAV\XMLUtil::loadDOMDocument($xml);
$q = new CalendarQueryParser($dom);
$q->parse();
}
}