3 require_once 'Sabre/CardDAV/AbstractPluginTest.php';
5 class Sabre_CardDAV_ValidateFilterTest extends Sabre_CardDAV_AbstractPluginTest {
10 function testFilter($input, $filters, $test, $result, $message = null) {
13 $this->assertTrue($this->plugin->validateFilters($input, $filters, $test), $message);
15 $this->assertFalse($this->plugin->validateFilters($input, $filters, $test), $message);
27 TEL;TYPE=IPHONE;TYPE=pref:(222) 22 22 22
28 TEL;TYPE=HOME:(33) 333 66 66
29 TEL;TYPE=WORK:(444) 44 44 44
30 TEL;TYPE=MAIN:(55) 555 55 55
31 ITEM4.TEL:(111) 11 11 11
32 ITEM5.TEL:(6) 66 66 66 66
33 ITEM6.TEL:(77) 777 77 77
34 UID:3151DE6A-BC35-4612-B340-B53A034A2B27
35 ITEM1.EMAIL:1111@111.com
36 ITEM2.EMAIL:bbbbb@bbbb.com
37 ITEM3.EMAIL:ccccc@ccccc.com
39 N:Last;First;Middle;Dr
41 ADR;TYPE=HOME:;;Street;City;;3556;Montenegro
42 ADR;TYPE=WORK:;;Street\\nStreet2;Harkema;;35444;Australia
47 // Check if TITLE is defined
49 array('name' => 'title', 'is-not-defined' => false, 'param-filters' => array(), 'text-matches' => array());
51 // Check if FOO is defined
53 array('name' => 'foo', 'is-not-defined' => false, 'param-filters' => array(), 'text-matches' => array());
55 // Check if TITLE is not defined
57 array('name' => 'title', 'is-not-defined' => true, 'param-filters' => array(), 'text-matches' => array());
59 // Check if FOO is not defined
61 array('name' => 'foo', 'is-not-defined' => true, 'param-filters' => array(), 'text-matches' => array());
63 // Check if TEL[TYPE] is defined
67 'is-not-defined' => false,
69 'param-filters' => array(
72 'is-not-defined' => false,
76 'text-matches' => array(),
79 // Check if TEL[FOO] is defined
81 $filter6['param-filters'][0]['name'] = 'FOO';
83 // Check if TEL[TYPE] is not defined
85 $filter7['param-filters'][0]['is-not-defined'] = true;
87 // Check if TEL[FOO] is not defined
89 $filter8['param-filters'][0]['name'] = 'FOO';
90 $filter8['param-filters'][0]['is-not-defined'] = true;
92 // Combining property filters
94 $filter9['param-filters'][] = $filter6['param-filters'][0];
97 $filter10['param-filters'][] = $filter6['param-filters'][0];
98 $filter10['test'] = 'allof';
100 // Check if URL contains 'google'
104 'is-not-defined' => false,
106 'param-filters' => array(),
107 'text-matches' => array(
109 'match-type' => 'contains',
111 'negate-condition' => false,
112 'collation' => 'i;octet',
117 // Check if URL contains 'bing'
118 $filter12 = $filter11;
119 $filter12['text-matches'][0]['value'] = 'bing';
121 // Check if URL does not contain 'google'
122 $filter13 = $filter11;
123 $filter13['text-matches'][0]['negate-condition'] = true;
125 // Check if URL does not contain 'bing'
126 $filter14 = $filter11;
127 $filter14['text-matches'][0]['value'] = 'bing';
128 $filter14['text-matches'][0]['negate-condition'] = true;
130 // Param filter with text
131 $filter15 = $filter5;
132 $filter15['param-filters'][0]['text-match'] = array(
133 'match-type' => 'contains',
135 'collation' => 'i;octet',
136 'negate-condition' => false,
138 $filter16 = $filter15;
139 $filter16['param-filters'][0]['text-match']['negate-condition'] = true;
142 // Param filter + text filter
143 $filter17 = $filter5;
144 $filter17['test'] = 'anyof';
145 $filter17['text-matches'][] = array(
146 'match-type' => 'contains',
148 'collation' => 'i;octet',
149 'negate-condition' => false,
152 $filter18 = $filter17;
153 $filter18['text-matches'][0]['negate-condition'] = true;
155 $filter18['test'] = 'allof';
160 array($body1, array($filter1), 'anyof',true),
161 array($body1, array($filter2), 'anyof',false),
162 array($body1, array($filter3), 'anyof',false),
163 array($body1, array($filter4), 'anyof',true),
166 array($body1, array($filter1, $filter2), 'anyof',true),
167 array($body1, array($filter1, $filter2), 'allof',false),
168 array($body1, array($filter1, $filter4), 'anyof',true),
169 array($body1, array($filter1, $filter4), 'allof',true),
170 array($body1, array($filter2, $filter3), 'anyof',false),
171 array($body1, array($filter2, $filter3), 'allof',false),
174 array($body1, array($filter5), 'anyof', true, 'TEL;TYPE is defined, so this should return true'),
175 array($body1, array($filter6), 'anyof', false, 'TEL;FOO is not defined, so this should return false'),
177 array($body1, array($filter7), 'anyof', false, 'TEL;TYPE is defined, so this should return false'),
178 array($body1, array($filter8), 'anyof', true, 'TEL;TYPE is not defined, so this should return true'),
180 // Combined parameters
181 array($body1, array($filter9), 'anyof', true),
182 array($body1, array($filter10), 'anyof', false),
185 array($body1, array($filter11), 'anyof', true),
186 array($body1, array($filter12), 'anyof', false),
187 array($body1, array($filter13), 'anyof', false),
188 array($body1, array($filter14), 'anyof', true),
190 // Param filter with text-match
191 array($body1, array($filter15), 'anyof', true),
192 array($body1, array($filter16), 'anyof', false),
194 // Param filter + text filter
195 array($body1, array($filter17), 'anyof', true),
196 array($body1, array($filter18), 'anyof', false),
197 array($body1, array($filter18), 'anyof', false),