2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 require_once dirname(__FILE__
) . '/../include/test.inc.php';
24 class UserFilterTest
extends PlTestCase
26 private static function checkPlatal()
35 public static function simpleUserProvider()
43 array('SELECT DISTINCT uid
45 WHERE FIND_IN_SET(\'owner\', perms)',
46 new UFC_HasProfile(), -1),
50 array(XDB
::format('SELECT DISTINCT uid
52 WHERE hruid = {?}', 'florent.bruneau.2003'),
53 new UFC_Hruid('florent.bruneau.2003'), 1),
54 array(XDB
::format('SELECT DISTINCT uid
56 WHERE hruid = {?}', 'florent.bruneau.2004'),
57 new UFC_Hruid('florent.bruneau.2004'), 0),
58 array(XDB
::format('SELECT DISTINCT uid
60 WHERE hruid IN {?}', array('florent.bruneau.2003',
61 'stephane.jacob.2004')),
62 new UFC_Hruid('florent.bruneau.2003', 'stephane.jacob.2004'), 2),
63 array(XDB
::format('SELECT DISTINCT uid
65 WHERE hruid IN {?}', array('florent.bruneau.2004',
66 'stephane.jacob.2004')),
67 new UFC_Hruid('florent.bruneau.2004', 'stephane.jacob.2004'), 1),
71 array(XDB
::format('SELECT DISTINCT uid
72 FROM account_profiles AS ap
73 INNER JOIN profiles AS p ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', perms))
74 WHERE hrpid = {?}', 'florent.bruneau.2003'),
75 new UFC_Hrpid('florent.bruneau.2003'), 1),
76 array(XDB
::format('SELECT DISTINCT uid
77 FROM account_profiles AS ap
78 INNER JOIN profiles AS p ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', perms))
79 WHERE hrpid = {?}', 'florent.bruneau.2004'),
80 new UFC_Hrpid('florent.bruneau.2004'), 0),
81 array(XDB
::format('SELECT DISTINCT uid
82 FROM account_profiles AS ap
83 INNER JOIN profiles AS p ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', perms))
84 WHERE hrpid IN {?}', array('florent.bruneau.2003',
85 'stephane.jacob.2004')),
86 new UFC_Hrpid('florent.bruneau.2003', 'stephane.jacob.2004'), 2),
87 array(XDB
::format('SELECT DISTINCT uid
88 FROM account_profiles AS ap
89 INNER JOIN profiles AS p ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', perms))
90 WHERE hrpid IN {?}', array('florent.bruneau.2004',
91 'stephane.jacob.2004')),
92 new UFC_Hrpid('florent.bruneau.2004', 'stephane.jacob.2004'), 1),
96 array(XDB
::format('SELECT DISTINCT a.uid
98 INNER JOIN accounts AS a USING(uid)
99 WHERE ip = {?} OR forward_ip = {?}',
100 ip_to_uint('129.104.247.2'), ip_to_uint('129.104.247.2')),
101 new UFC_Ip('129.104.247.2'), -1),
109 array(XDB
::format('SELECT DISTINCT ap.uid
110 FROM account_profiles AS ap
111 INNER JOIN profile_display AS pd ON (pd.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
112 WHERE pd.promo = {?}', 'X2004'),
113 new UFC_Promo('=', UserFilter
::DISPLAY
, 'X2004'), -1),
114 array(XDB
::format('SELECT DISTINCT ap.uid
115 FROM account_profiles AS ap
116 INNER JOIN profile_display AS pd ON (pd.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
117 WHERE pd.promo < {?}', 'X2004'),
118 new UFC_Promo('<', UserFilter
::DISPLAY
, 'X2004'), -1),
119 array(XDB
::format('SELECT DISTINCT ap.uid
120 FROM account_profiles AS ap
121 INNER JOIN profile_display AS pd ON (pd.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
122 WHERE pd.promo > {?}', 'X2004'),
123 new UFC_Promo('>', UserFilter
::DISPLAY
, 'X2004'), -1),
124 array(XDB
::format('SELECT DISTINCT ap.uid
125 FROM account_profiles AS ap
126 INNER JOIN profile_display AS pd ON (pd.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
127 WHERE pd.promo < {?}', 'X1900'),
128 new UFC_Promo('<', UserFilter
::DISPLAY
, 'X1900'), 0),
130 array(XDB
::format('SELECT DISTINCT ap.uid
131 FROM account_profiles AS ap
132 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
133 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
134 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
135 WHERE pe.entry_year = {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
137 new UFC_Promo('=', UserFilter
::GRADE_ING
, 2004), -1),
138 array(XDB
::format('SELECT DISTINCT ap.uid
139 FROM account_profiles AS ap
140 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
141 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
142 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
143 WHERE pe.entry_year <= {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
145 new UFC_Promo('<=', UserFilter
::GRADE_ING
, 1960), -1),
146 array(XDB
::format('SELECT DISTINCT ap.uid
147 FROM account_profiles AS ap
148 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
149 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
150 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
151 WHERE pe.entry_year > {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
153 new UFC_Promo('>', UserFilter
::GRADE_ING
, 2004), -1),
154 array(XDB
::format('SELECT DISTINCT ap.uid
155 FROM account_profiles AS ap
156 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
157 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
158 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
159 WHERE pe.entry_year < {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
161 new UFC_Promo('<', UserFilter
::GRADE_ING
, 1900), 0),
163 /* XXX : tests disabled until there are Masters and doctors in the DB
164 array(XDB::format('SELECT DISTINCT ap.uid
165 FROM account_profiles AS ap
166 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
167 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
168 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
169 WHERE pe.grad_year = {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
171 new UFC_Promo('=', UserFilter::GRADE_MST, 2009), -1),
172 array(XDB::format('SELECT DISTINCT ap.uid
173 FROM account_profiles AS ap
174 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
175 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
176 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
177 WHERE pe.grad_year <= {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
179 new UFC_Promo('<=', UserFilter::GRADE_MST, 2009), -1),
180 array(XDB::format('SELECT DISTINCT ap.uid
181 FROM account_profiles AS ap
182 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
183 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
184 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
185 WHERE pe.grad_year > {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
187 new UFC_Promo('>', UserFilter::GRADE_MST, 2009), -1),
188 array(XDB::format('SELECT DISTINCT ap.uid
189 FROM account_profiles AS ap
190 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
191 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
192 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
193 WHERE pe.grad_year < {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
195 new UFC_Promo('<', UserFilter::GRADE_MST, 1980), 0),
197 array(XDB::format('SELECT DISTINCT ap.uid
198 FROM account_profiles AS ap
199 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
200 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
201 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
202 WHERE pe.grad_year = {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
204 new UFC_Promo('=', UserFilter::GRADE_PHD, 2009), -1),
205 array(XDB::format('SELECT DISTINCT ap.uid
206 FROM account_profiles AS ap
207 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
208 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
209 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
210 WHERE pe.grad_year <= {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
212 new UFC_Promo('<=', UserFilter::GRADE_PHD, 2009), -1),
213 array(XDB::format('SELECT DISTINCT ap.uid
214 FROM account_profiles AS ap
215 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
216 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
217 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
218 WHERE pe.grad_year > {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
220 new UFC_Promo('>', UserFilter::GRADE_PHD, 2009), -1),
221 array(XDB::format('SELECT DISTINCT ap.uid
222 FROM account_profiles AS ap
223 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
224 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
225 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
226 WHERE pe.grad_year < {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
228 new UFC_Promo('<', UserFilter::GRADE_PHD, 1980), 0),
232 /* TODO: UFC_SchoolId
234 /* UFC_EducationSchool
236 $id_X = XDB
::fetchOneCell('SELECT id
237 FROM profile_education_enum
238 WHERE abbreviation = {?}', 'X');
239 $id_HEC = XDB
::fetchOneCell('SELECT id
240 FROM profile_education_enum
241 WHERE abbreviation = {?}', 'HEC');
243 array(XDB
::format('SELECT DISTINCT ap.uid
244 FROM account_profiles AS ap
245 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
246 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
247 WHERE pee.abbreviation = {?}', 'X'),
248 new UFC_EducationSchool($id_X), -1),
249 array(XDB
::format('SELECT DISTINCT ap.uid
250 FROM account_profiles AS ap
251 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
252 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
253 WHERE pee.abbreviation IN {?}', array('X', 'HEC')),
254 new UFC_EducationSchool($id_X, $id_HEC), -1),
257 /* UFC_EducationDegree
259 $id_DegreeIng = XDB
::fetchOneCell('SELECT id
260 FROM profile_education_degree_enum
261 WHERE abbreviation = {?}', 'Ing.');
262 $id_DegreePhd = XDB
::fetchOneCell('SELECT id
263 FROM profile_education_degree_enum
264 WHERE abbreviation = {?}', 'PhD');
266 array(XDB
::format('SELECT DISTINCT ap.uid
267 FROM account_profiles AS ap
268 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
269 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
270 WHERE pede.abbreviation = {?}', 'Ing.'),
271 new UFC_EducationDegree($id_DegreeIng), -1),
272 array(XDB
::format('SELECT DISTINCT ap.uid
273 FROM account_profiles AS ap
274 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
275 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
276 WHERE pede.abbreviation IN {?}', array('Ing.', 'PhD')),
277 new UFC_EducationDegree($id_DegreeIng, $id_DegreePhd), -1),
279 /* UFC_EducationField
281 $id_FieldInfo = XDB
::fetchOneCell('SELECT id
282 FROM profile_education_field_enum
283 WHERE field = {?}', 'Informatique');
284 $id_FieldDroit = XDB
::fetchOneCell('SELECT id
285 FROM profile_education_field_enum
286 WHERE field = {?}', 'Droit');
287 // FIXME: Replace 0 by -1 in following queries when profile_education will be filled with fieldids
289 array(XDB
::format('SELECT DISTINCT ap.uid
290 FROM account_profiles AS ap
291 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
292 LEFT JOIN profile_education_field_enum AS pefe ON (pe.fieldid = pefe.id)
293 WHERE pefe.field = {?}', 'Informatique'),
294 new UFC_EducationField($id_FieldInfo), 0), // FIXME: should be -1
295 array(XDB
::format('SELECT DISTINCT ap.uid
296 FROM account_profiles AS ap
297 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
298 LEFT JOIN profile_education_field_enum AS pefe ON (pe.fieldid = pefe.id)
299 WHERE pefe.field IN {?}', array('Informatique', 'Droit')),
300 new UFC_EducationField($id_FieldInfo, $id_FieldDroit), 0), // FIXME: should be -1
305 $id_Lastname = DirEnum
::getID(DirEnum
::NAMETYPES
, Profile
::LASTNAME
);
306 $id_Firstname = DirEnum
::getID(DirEnum
::NAMETYPES
, Profile
::FIRSTNAME
);
307 $id_Nickname = DirEnum
::getID(DirEnum
::NAMETYPES
, Profile
::NICKNAME
);
308 $id_Lastname_Marital = DirEnum
::getID(DirEnum
::NAMETYPES
, Profile
::LASTNAME
. '_' . Profile
::VN_MARITAL
);
309 $id_Lastname_Ordinary = DirEnum
::getID(DirEnum
::NAMETYPES
, Profile
::LASTNAME
. '_' . Profile
::VN_ORDINARY
);
313 array(XDB
::format('SELECT DISTINCT ap.uid
314 FROM account_profiles AS ap
315 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
316 WHERE pn.name LIKE {?} AND pn.typeid = {?}', 'BARROIS', $id_Lastname),
317 new UFC_Name(Profile
::LASTNAME
, 'BARROIS', UFC_Name
::EXACT
), -1),
318 array(XDB
::format('SELECT DISTINCT ap.uid
319 FROM account_profiles AS ap
320 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
321 WHERE pn.name LIKE \'BARR%\' AND pn.typeid = {?}', $id_Lastname),
322 new UFC_Name(Profile
::LASTNAME
, 'BARR', UFC_Name
::PREFIX
), -1),
323 array(XDB
::format('SELECT DISTINCT ap.uid
324 FROM account_profiles AS ap
325 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
326 WHERE pn.name LIKE \'%OIS\' AND pn.typeid = {?}', $id_Lastname),
327 new UFC_Name(Profile
::LASTNAME
, 'OIS', UFC_Name
::SUFFIX
), -1),
328 array(XDB
::format('SELECT DISTINCT ap.uid
329 FROM account_profiles AS ap
330 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
331 WHERE pn.name LIKE \'%ARRO%\' AND pn.typeid = {?}', $id_Lastname),
332 new UFC_Name(Profile
::LASTNAME
, 'ARRO', UFC_Name
::CONTAINS
), -1),
333 array(XDB
::format('SELECT DISTINCT ap.uid
334 FROM account_profiles AS ap
335 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
336 WHERE pn.name LIKE \'%ZZZZZZ%\' AND pn.typeid = {?}', $id_Lastname),
337 new UFC_Name(Profile
::LASTNAME
, 'ZZZZZZ', UFC_Name
::CONTAINS
), 0),
340 array(XDB
::format('SELECT DISTINCT ap.uid
341 FROM account_profiles AS ap
342 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
343 WHERE pn.name LIKE {?} AND pn.typeid = {?}', 'Raphaël', $id_Firstname),
344 new UFC_Name(Profile
::FIRSTNAME
, 'Raphaël', UFC_Name
::EXACT
), -1),
345 array(XDB
::format('SELECT DISTINCT ap.uid
346 FROM account_profiles AS ap
347 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
348 WHERE pn.name LIKE \'Raph%\' AND pn.typeid = {?}', $id_Firstname),
349 new UFC_Name(Profile
::FIRSTNAME
, 'Raph', UFC_Name
::PREFIX
), -1),
350 array(XDB
::format('SELECT DISTINCT ap.uid
351 FROM account_profiles AS ap
352 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
353 WHERE pn.name LIKE \'%aël\' AND pn.typeid = {?}', $id_Firstname),
354 new UFC_Name(Profile
::FIRSTNAME
, 'aël', UFC_Name
::SUFFIX
), -1),
355 array(XDB
::format('SELECT DISTINCT ap.uid
356 FROM account_profiles AS ap
357 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
358 WHERE pn.name LIKE \'%apha%\' AND pn.typeid = {?}', $id_Firstname),
359 new UFC_Name(Profile
::FIRSTNAME
, 'apha', UFC_Name
::CONTAINS
), -1),
360 array(XDB
::format('SELECT DISTINCT ap.uid
361 FROM account_profiles AS ap
362 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
363 WHERE pn.name LIKE \'%zzzzzz%\' AND pn.typeid = {?}', $id_Firstname),
364 new UFC_Name(Profile
::FIRSTNAME
, 'zzzzzz', UFC_Name
::CONTAINS
), 0),
367 array(XDB
::format('SELECT DISTINCT ap.uid
368 FROM account_profiles AS ap
369 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
370 WHERE pn.name LIKE {?} AND pn.typeid = {?}', 'Xelnor', $id_Nickname),
371 new UFC_Name(Profile
::NICKNAME
, 'Xelnor', UFC_Name
::EXACT
), -1),
372 array(XDB
::format('SELECT DISTINCT ap.uid
373 FROM account_profiles AS ap
374 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
375 WHERE pn.name LIKE \'Xel%\' AND pn.typeid = {?}', $id_Nickname),
376 new UFC_Name(Profile
::NICKNAME
, 'Xel', UFC_Name
::PREFIX
), -1),
377 array(XDB
::format('SELECT DISTINCT ap.uid
378 FROM account_profiles AS ap
379 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
380 WHERE pn.name LIKE \'%nor\' AND pn.typeid = {?}', $id_Nickname),
381 new UFC_Name(Profile
::NICKNAME
, 'nor', UFC_Name
::SUFFIX
), -1),
382 array(XDB
::format('SELECT DISTINCT ap.uid
383 FROM account_profiles AS ap
384 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
385 WHERE pn.name LIKE \'%lno%\' AND pn.typeid = {?}', $id_Nickname),
386 new UFC_Name(Profile
::NICKNAME
, 'lno', UFC_Name
::CONTAINS
), -1),
387 array(XDB
::format('SELECT DISTINCT ap.uid
388 FROM account_profiles AS ap
389 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
390 WHERE pn.name LIKE \'%zzzzzz%\' AND pn.typeid = {?}', $id_Nickname),
391 new UFC_Name(Profile
::NICKNAME
, 'zzzzzz', UFC_Name
::CONTAINS
), 0),
393 // Lastname + particle
394 array(XDB
::format('SELECT DISTINCT ap.uid
395 FROM account_profiles AS ap
396 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
397 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE {?} AND pn.typeid = {?}', 'DE SINGLY', $id_Lastname),
398 new UFC_Name(Profile
::LASTNAME
, 'DE SINGLY', UFC_Name
::PARTICLE | UFC_Name
::EXACT
), -1),
399 array(XDB
::format('SELECT DISTINCT ap.uid
400 FROM account_profiles AS ap
401 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
402 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE \'DE SI%\' AND pn.typeid = {?}', $id_Lastname),
403 new UFC_Name(Profile
::LASTNAME
, 'DE SI', UFC_Name
::PARTICLE | UFC_Name
::PREFIX
), -1),
404 array(XDB
::format('SELECT DISTINCT ap.uid
405 FROM account_profiles AS ap
406 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
407 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE \'%GLY\' AND pn.typeid = {?}', $id_Lastname),
408 new UFC_Name(Profile
::LASTNAME
, 'GLY', UFC_NAME
::PARTICLE | UFC_Name
::SUFFIX
), -1),
409 array(XDB
::format('SELECT DISTINCT ap.uid
410 FROM account_profiles AS ap
411 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
412 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE \'%E SIN%\' AND pn.typeid = {?}', $id_Lastname),
413 new UFC_Name(Profile
::LASTNAME
, 'E SIN', UFC_Name
::PARTICLE | UFC_Name
::CONTAINS
), -1),
414 array(XDB
::format('SELECT DISTINCT ap.uid
415 FROM account_profiles AS ap
416 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
417 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE \'%ZZZZZZ%\' AND pn.typeid = {?}', $id_Lastname),
418 new UFC_Name(Profile
::LASTNAME
, 'ZZZZZZ', UFC_Name
::PARTICLE | UFC_Name
::CONTAINS
), 0),
421 array(XDB
::format('SELECT DISTINCT ap.uid
422 FROM account_profiles AS ap
423 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
424 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
425 'ALBIZZATI', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
426 new UFC_Name(Profile
::LASTNAME
, 'ALBIZZATI', UFC_Name
::VARIANTS | UFC_Name
::EXACT
), -1),
427 array(XDB
::format('SELECT DISTINCT ap.uid
428 FROM account_profiles AS ap
429 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
430 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
431 'ALBIZ%', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
432 new UFC_Name(Profile
::LASTNAME
, 'ALBIZ', UFC_Name
::VARIANTS | UFC_Name
::PREFIX
), -1),
433 array(XDB
::format('SELECT DISTINCT ap.uid
434 FROM account_profiles AS ap
435 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
436 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
437 '%ZATI', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
438 new UFC_Name(Profile
::LASTNAME
, 'ZATI', UFC_NAME
::VARIANTS | UFC_Name
::SUFFIX
), -1),
439 array(XDB
::format('SELECT DISTINCT ap.uid
440 FROM account_profiles AS ap
441 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
442 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
443 '%BIZZ%', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
444 new UFC_Name(Profile
::LASTNAME
, 'BIZZ', UFC_Name
::VARIANTS | UFC_Name
::CONTAINS
), -1),
445 array(XDB
::format('SELECT DISTINCT ap.uid
446 FROM account_profiles AS ap
447 LEFT JOIN profile_name AS pn ON (ap.pid = pn.pid AND FIND_IN_SET(\'owner\', ap.perms))
448 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
449 '%ZZZZZZ%', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
450 new UFC_Name(Profile
::LASTNAME
, 'ZZZZZZ', UFC_Name
::VARIANTS | UFC_Name
::CONTAINS
), 0),
457 array(XDB
::format('SELECT DISTINCT ap.uid
458 FROM account_profiles AS ap
459 LEFT JOIN search_name AS sn ON (ap.pid = sn.pid AND FIND_IN_SET(\'owner\', ap.perms))
460 WHERE sn.token LIKE \'xelnor%\''),
461 new UFC_NameTokens('xelnor'), 1),
462 array(XDB
::format('SELECT DISTINCT ap.uid
463 FROM account_profiles AS ap
464 LEFT JOIN search_name AS sn ON (ap.pid = sn.pid AND FIND_IN_SET(\'owner\', ap.perms))
465 WHERE sn.token LIKE \'xe%\''),
466 new UFC_NameTokens('xe'), -1),
467 array(XDB
::format('SELECT DISTINCT ap.uid
468 FROM account_profiles AS ap
469 LEFT JOIN search_name AS sn ON (ap.pid = sn.pid AND FIND_IN_SET(\'owner\', ap.perms))
470 WHERE sn.token LIKE \'xe%\' OR sn.token LIKE \'barr%\''),
471 new UFC_NameTokens(array('xe', 'barr')), -1),
472 array(XDB
::format('SELECT DISTINCT ap.uid
473 FROM account_profiles AS ap
474 LEFT JOIN search_name AS sn ON (ap.pid = sn.pid AND FIND_IN_SET(\'owner\', ap.perms))
475 WHERE sn.token LIKE \'zzzzzzzz%\''),
476 new UFC_NameTokens('zzzzzzzz'), 0),
477 array(XDB
::format('SELECT DISTINCT ap.uid
478 FROM account_profiles AS ap
479 LEFT JOIN search_name AS sn ON (ap.pid = sn.pid AND FIND_IN_SET(\'owner\', ap.perms))
480 WHERE sn.token LIKE \'barr%\' AND FIND_IN_SET(\'public\', sn.flags)'),
481 new UFC_NameTokens('barr', UFC_NameTokens
::FLAG_PUBLIC
), -1),
484 array(XDB
::format('SELECT DISTINCT ap.uid
485 FROM account_profiles AS ap
486 LEFT JOIN search_name AS sn ON (ap.pid = sn.pid AND FIND_IN_SET(\'owner\', ap.perms))
487 WHERE sn.token = \'xelnor\''),
488 new UFC_NameTokens('xelnor', array(), false
, true
), 1),
489 array(XDB
::format('SELECT DISTINCT ap.uid
490 FROM account_profiles AS ap
491 LEFT JOIN search_name AS sn ON (ap.pid = sn.pid AND FIND_IN_SET(\'owner\', ap.perms))
492 WHERE sn.token IN (\'xelnor\', \'barrois\')'),
493 new UFC_NameTokens(array('xelnor', 'barrois'), array(), false
, true
), -1),
494 array(XDB
::format('SELECT DISTINCT ap.uid
495 FROM account_profiles AS ap
496 LEFT JOIN search_name AS sn ON (ap.pid = sn.pid AND FIND_IN_SET(\'owner\', ap.perms))
497 WHERE sn.token = \'zzzzzzzz\''),
498 new UFC_NameTokens('zzzzzzzz', array(), false
, true
), 0),
499 array(XDB
::format('SELECT DISTINCT ap.uid
500 FROM account_profiles AS ap
501 LEFT JOIN search_name AS sn ON (ap.pid = sn.pid AND FIND_IN_SET(\'owner\', ap.perms))
502 WHERE sn.token IN (\'zzzzzzzz\', \'yyyyyyyy\')'),
503 new UFC_NameTokens(array('zzzzzzzz', 'yyyyyyyy'), array(), false
, true
), 0),
504 array(XDB
::format('SELECT DISTINCT ap.uid
505 FROM account_profiles AS ap
506 LEFT JOIN search_name AS sn ON (ap.pid = sn.pid AND FIND_IN_SET(\'owner\', ap.perms))
507 WHERE sn.token = \'barrois\' AND FIND_IN_SET(\'public\', sn.flags)'),
508 new UFC_NameTokens('barrois', UFC_NameTokens
::FLAG_PUBLIC
, false
, true
), -1),
511 array(XDB
::format('SELECT DISTINCT ap.uid
512 FROM account_profiles AS ap
513 LEFT JOIN search_name AS sn ON (ap.pid = sn.pid AND FIND_IN_SET(\'owner\', ap.perms))
514 WHERE sn.soundex = \'XLNO\''),
515 new UFC_NameTokens('XLNO', array(), true
), -1),
516 array(XDB
::format('SELECT DISTINCT ap.uid
517 FROM account_profiles AS ap
518 LEFT JOIN search_name AS sn ON (ap.pid = sn.pid AND FIND_IN_SET(\'owner\', ap.perms))
519 WHERE sn.soundex IN (\'XLNO\', \'BROS\')'),
520 new UFC_NameTokens(array('XLNO', 'BROS'), array(), true
), -1),
521 array(XDB
::format('SELECT DISTINCT ap.uid
522 FROM account_profiles AS ap
523 LEFT JOIN search_name AS sn ON (ap.pid = sn.pid AND FIND_IN_SET(\'owner\', ap.perms))
524 WHERE sn.soundex = \'ZZZZZZ\''),
525 new UFC_NameTokens('ZZZZZZ', array(), true
), 0),
526 array(XDB
::format('SELECT DISTINCT ap.uid
527 FROM account_profiles AS ap
528 LEFT JOIN search_name AS sn ON (ap.pid = sn.pid AND FIND_IN_SET(\'owner\', ap.perms))
529 WHERE sn.soundex = \'BROS\' AND FIND_IN_SET(\'public\', sn.flags)'),
530 new UFC_NameTokens('BROS', UFC_NameTokens
::FLAG_PUBLIC
, true
), -1),
533 $testcases = array();
534 foreach ($tests as $t) {
535 $testcases = array_merge($testcases, $t);
541 * @dataProvider simpleUserProvider
543 public function testSimpleUser($query, $cond, $expcount = null
)
546 * @param $query A MySQL query
547 * @param $cond The UFC to test
548 * @param $expcount The expected number of results (-1 if that number is unknown)
553 $query = XDB
::query($query);
554 $count = $query->numRows();
555 if (!is_null($expcount)) {
557 $this->assertNotEquals(0, $count);
559 $this->assertEquals($expcount, $count);
562 $ids = $query->fetchColumn();
563 $this->assertEquals($count, count($ids));
566 $uf = new UserFilter($cond);
567 $this->assertEquals($count, $uf->getTotalUserCount());
568 $got = $uf->getUIDs();
569 $this->assertEquals($count, count($got));
571 $this->assertEquals($ids, $got);
573 $uf = new UserFilter($cond);
574 $got = $uf->getUIDs();
575 $this->assertEquals($count, count($got));
577 $this->assertEquals($ids, $got);
578 $this->assertEquals($count, $uf->getTotalCount());
582 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: