3 class Sabre_CardDAV_AddressBookQueryParserTest extends PHPUnit_Framework_TestCase {
7 $xml = implode("\n", $xml);
8 $dom = Sabre_DAV_XMLUtil::loadDOMDocument($xml);
10 $q = new Sabre_CardDAV_AddressBookQueryParser($dom);
16 function testFilterBasic() {
19 '<?xml version="1.0"?>',
20 '<c:addressbook-query xmlns:c="urn:ietf:params:xml:ns:carddav" xmlns:d="DAV:">',
25 ' <c:prop-filter name="NICKNAME" />',
27 '</c:addressbook-query>'
30 $q = $this->parse($xml);
34 $q->requestedProperties
42 'is-not-defined' => false,
43 'param-filters' => array(),
44 'text-matches' => array(),
50 $this->assertNull($q->limit);
51 $this->assertEquals('anyof', $q->test);
55 function testNoFilter() {
57 // This is non-standard, but helps working around a KDE bug
59 '<?xml version="1.0"?>',
60 '<c:addressbook-query xmlns:c="urn:ietf:params:xml:ns:carddav" xmlns:d="DAV:">',
64 '</c:addressbook-query>'
67 $q = $this->parse($xml);
71 $q->requestedProperties
79 $this->assertNull($q->limit);
80 $this->assertEquals('anyof', $q->test);
85 * @expectedException Sabre_DAV_Exception_BadRequest
87 function testFilterDoubleFilter() {
90 '<?xml version="1.0"?>',
91 '<c:addressbook-query xmlns:c="urn:ietf:params:xml:ns:carddav" xmlns:d="DAV:">',
96 ' <c:prop-filter name="NICKNAME" />',
99 ' <c:prop-filter name="NICKNAME" />',
101 '</c:addressbook-query>'
104 $q = $this->parse($xml);
108 * @expectedException Sabre_DAV_Exception_BadRequest
110 function testFilterCorruptTest() {
113 '<?xml version="1.0"?>',
114 '<c:addressbook-query xmlns:c="urn:ietf:params:xml:ns:carddav" xmlns:d="DAV:">',
118 ' <c:filter test="foo">',
119 ' <c:prop-filter name="NICKNAME" />',
121 '</c:addressbook-query>'
124 $q = $this->parse($xml);
128 function testPropFilter() {
131 '<?xml version="1.0"?>',
132 '<c:addressbook-query xmlns:c="urn:ietf:params:xml:ns:carddav" xmlns:d="DAV:">',
136 ' <c:filter test="allof">',
137 ' <c:prop-filter name="NICKNAME" />',
138 ' <c:prop-filter name="EMAIL" test="allof" />',
139 ' <c:prop-filter name="FN">',
140 ' <c:is-not-defined />',
143 ' <c:limit><c:nresults>4</c:nresults></c:limit>',
144 '</c:addressbook-query>'
147 $q = $this->parse($xml);
152 'name' => 'NICKNAME',
154 'is-not-defined' => false,
155 'param-filters' => array(),
156 'text-matches' => array(),
161 'is-not-defined' => false,
162 'param-filters' => array(),
163 'text-matches' => array(),
168 'is-not-defined' => true,
169 'param-filters' => array(),
170 'text-matches' => array(),
176 $this->assertEquals(4,$q->limit);
177 $this->assertEquals('allof', $q->test);
181 function testParamFilter() {
184 '<?xml version="1.0"?>',
185 '<c:addressbook-query xmlns:c="urn:ietf:params:xml:ns:carddav" xmlns:d="DAV:">',
190 ' <c:prop-filter name="NICKNAME">',
191 ' <c:param-filter name="BLA" />',
192 ' <c:param-filter name="BLA2">',
193 ' <c:is-not-defined />',
194 ' </c:param-filter>',
197 '</c:addressbook-query>'
200 $q = $this->parse($xml);
205 'name' => 'NICKNAME',
207 'is-not-defined' => false,
208 'param-filters' => array(
211 'is-not-defined' => false,
216 'is-not-defined' => true,
220 'text-matches' => array(),
228 function testTextMatch() {
231 '<?xml version="1.0"?>',
232 '<c:addressbook-query xmlns:c="urn:ietf:params:xml:ns:carddav" xmlns:d="DAV:">',
237 ' <c:prop-filter name="NICKNAME">',
238 ' <c:text-match>evert</c:text-match>',
239 ' <c:text-match collation="i;octet">evert</c:text-match>',
240 ' <c:text-match negate-condition="yes">rene</c:text-match>',
241 ' <c:text-match match-type="starts-with">e</c:text-match>',
242 ' <c:param-filter name="BLA">',
243 ' <c:text-match>foo</c:text-match>',
244 ' </c:param-filter>',
247 '</c:addressbook-query>'
250 $q = $this->parse($xml);
255 'name' => 'NICKNAME',
257 'is-not-defined' => false,
258 'param-filters' => array(
261 'is-not-defined' => false,
262 'text-match' => array(
263 'negate-condition' => false,
264 'collation' => 'i;unicode-casemap',
265 'match-type' => 'contains',
270 'text-matches' => array(
272 'negate-condition' => false,
273 'collation' => 'i;unicode-casemap',
274 'match-type' => 'contains',
278 'negate-condition' => false,
279 'collation' => 'i;octet',
280 'match-type' => 'contains',
284 'negate-condition' => true,
285 'collation' => 'i;unicode-casemap',
286 'match-type' => 'contains',
290 'negate-condition' => false,
291 'collation' => 'i;unicode-casemap',
292 'match-type' => 'starts-with',
304 * @expectedException Sabre_DAV_Exception_BadRequest
306 function testBadTextMatch() {
309 '<?xml version="1.0"?>',
310 '<c:addressbook-query xmlns:c="urn:ietf:params:xml:ns:carddav" xmlns:d="DAV:">',
315 ' <c:prop-filter name="NICKNAME">',
316 ' <c:text-match match-type="foo">evert</c:text-match>',
319 '</c:addressbook-query>'
322 $q = $this->parse($xml);