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 private static function buildAccountQuery()
37 $args = func_get_args();
38 $joinsAndWhere = XDB
::_prepare($args);
39 return array('SELECT DISTINCT a.uid
42 'SELECT DISTINCT p.pid
44 INNER JOIN account_profiles AS ap ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', perms))
45 INNER JOIN accounts AS a ON (a.uid = ap.uid)
49 private static function buildProfileQuery()
51 $args = func_get_args();
52 $joinsAndWhere = XDB
::_prepare($args);
53 return array('SELECT DISTINCT a.uid
55 INNER JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET(\'owner\', perms))
56 INNER JOIN profiles AS p ON (p.pid = ap.pid)
58 'SELECT DISTINCT p.pid
63 public static function simpleUserProvider()
71 array(self
::buildAccountQuery('INNER JOIN account_profiles AS ap2 ON (ap2.uid = a.uid)
72 WHERE FIND_IN_SET(\'owner\', ap2.perms)'),
73 new UFC_HasProfile(), -1),
77 array(self
::buildAccountQuery('WHERE a.hruid = {?}', 'florent.bruneau.2003'),
78 new UFC_Hruid('florent.bruneau.2003'), 1),
79 array(self
::buildAccountQuery('WHERE a.hruid = {?}', 'florent.bruneau.2004'),
80 new UFC_Hruid('florent.bruneau.2004'), 0),
81 array(self
::buildAccountQuery('WHERE a.hruid IN {?}', array('florent.bruneau.2003',
82 'stephane.jacob.2004')),
83 new UFC_Hruid('florent.bruneau.2003', 'stephane.jacob.2004'), 2),
84 array(self
::buildAccountQuery('WHERE a.hruid IN {?}', array('florent.bruneau.2004',
85 'stephane.jacob.2004')),
86 new UFC_Hruid('florent.bruneau.2004', 'stephane.jacob.2004'), 1),
90 array(self
::buildProfileQuery('WHERE p.hrpid = {?}', 'florent.bruneau.2003'),
91 new UFC_Hrpid('florent.bruneau.2003'), 1),
92 array(self
::buildProfileQuery('WHERE p.hrpid = {?}', 'florent.bruneau.2004'),
93 new UFC_Hrpid('florent.bruneau.2004'), 0),
94 array(self
::buildProfileQuery('WHERE p.hrpid IN {?}', array('florent.bruneau.2003',
95 'stephane.jacob.2004')),
96 new UFC_Hrpid('florent.bruneau.2003', 'stephane.jacob.2004'), 2),
97 array(self
::buildProfileQuery('WHERE p.hrpid IN {?}', array('florent.bruneau.2004',
98 'stephane.jacob.2004')),
99 new UFC_Hrpid('florent.bruneau.2004', 'stephane.jacob.2004'), 1),
103 array(self
::buildAccountQuery('INNER JOIN log_sessions AS s ON (s.uid = a.uid)
104 WHERE s.ip = {?} OR s.forward_ip = {?}',
105 ip_to_uint('129.104.247.2'), ip_to_uint('129.104.247.2')),
106 new UFC_Ip('129.104.247.2'), -1),
114 array(self
::buildProfileQuery('INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
115 WHERE pd.promo = {?}', 'X2004'),
116 new UFC_Promo('=', UserFilter
::DISPLAY
, 'X2004'), -1),
117 array(self
::buildProfileQuery('INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
118 WHERE pd.promo < {?}', 'X2004'),
119 new UFC_Promo('<', UserFilter
::DISPLAY
, 'X2004'), -1),
120 array(self
::buildProfileQuery('INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
121 WHERE pd.promo > {?}', 'X2004'),
122 new UFC_Promo('>', UserFilter
::DISPLAY
, 'X2004'), -1),
123 array(self
::buildProfileQuery('INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
124 WHERE pd.promo < {?}', 'X1900'),
125 new UFC_Promo('<', UserFilter
::DISPLAY
, 'X1900'), 0),
127 array(self
::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
128 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
129 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
130 WHERE pe.entry_year = {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
132 new UFC_Promo('=', UserFilter
::GRADE_ING
, 2004), -1),
133 array(self
::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
134 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
135 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
136 WHERE pe.entry_year <= {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
138 new UFC_Promo('<=', UserFilter
::GRADE_ING
, 1960), -1),
139 array(self
::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
140 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
141 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
142 WHERE pe.entry_year > {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
144 new UFC_Promo('>', UserFilter
::GRADE_ING
, 2004), -1),
145 array(self
::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
146 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
147 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
148 WHERE pe.entry_year < {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
150 new UFC_Promo('<', UserFilter
::GRADE_ING
, 1900), 0),
152 /* XXX : tests disabled until there are Masters and doctors in the DB
153 array(XDB::format('SELECT DISTINCT ap.uid
154 FROM account_profiles AS ap
155 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
156 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
157 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
158 WHERE pe.grad_year = {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
160 new UFC_Promo('=', UserFilter::GRADE_MST, 2009), -1),
161 array(XDB::format('SELECT DISTINCT ap.uid
162 FROM account_profiles AS ap
163 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
164 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
165 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
166 WHERE pe.grad_year <= {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
168 new UFC_Promo('<=', UserFilter::GRADE_MST, 2009), -1),
169 array(XDB::format('SELECT DISTINCT ap.uid
170 FROM account_profiles AS ap
171 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
172 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
173 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
174 WHERE pe.grad_year > {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
176 new UFC_Promo('>', UserFilter::GRADE_MST, 2009), -1),
177 array(XDB::format('SELECT DISTINCT ap.uid
178 FROM account_profiles AS ap
179 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
180 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
181 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
182 WHERE pe.grad_year < {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
184 new UFC_Promo('<', UserFilter::GRADE_MST, 1980), 0),
186 array(XDB::format('SELECT DISTINCT ap.uid
187 FROM account_profiles AS ap
188 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
189 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
190 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
191 WHERE pe.grad_year = {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
193 new UFC_Promo('=', UserFilter::GRADE_PHD, 2009), -1),
194 array(XDB::format('SELECT DISTINCT ap.uid
195 FROM account_profiles AS ap
196 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
197 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
198 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
199 WHERE pe.grad_year <= {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
201 new UFC_Promo('<=', UserFilter::GRADE_PHD, 2009), -1),
202 array(XDB::format('SELECT DISTINCT ap.uid
203 FROM account_profiles AS ap
204 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
205 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
206 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
207 WHERE pe.grad_year > {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
209 new UFC_Promo('>', UserFilter::GRADE_PHD, 2009), -1),
210 array(XDB::format('SELECT DISTINCT ap.uid
211 FROM account_profiles AS ap
212 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
213 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
214 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
215 WHERE pe.grad_year < {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
217 new UFC_Promo('<', UserFilter::GRADE_PHD, 1980), 0),
221 /* TODO: UFC_SchoolId
223 /* UFC_EducationSchool
225 $id_X = XDB
::fetchOneCell('SELECT id
226 FROM profile_education_enum
227 WHERE abbreviation = {?}', 'X');
228 $id_HEC = XDB
::fetchOneCell('SELECT id
229 FROM profile_education_enum
230 WHERE abbreviation = {?}', 'HEC');
232 array(self
::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
233 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
234 WHERE pee.abbreviation = {?}', 'X'),
235 new UFC_EducationSchool($id_X), -1),
236 array(self
::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
237 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
238 WHERE pee.abbreviation IN {?}', array('X', 'HEC')),
239 new UFC_EducationSchool($id_X, $id_HEC), -1),
242 /* UFC_EducationDegree
244 $id_DegreeIng = XDB
::fetchOneCell('SELECT id
245 FROM profile_education_degree_enum
246 WHERE abbreviation = {?}', 'Ing.');
247 $id_DegreePhd = XDB
::fetchOneCell('SELECT id
248 FROM profile_education_degree_enum
249 WHERE abbreviation = {?}', 'PhD');
251 array(self
::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
252 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
253 WHERE pede.abbreviation = {?}', 'Ing.'),
254 new UFC_EducationDegree($id_DegreeIng), -1),
255 array(self
::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
256 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
257 WHERE pede.abbreviation IN {?}', array('Ing.', 'PhD')),
258 new UFC_EducationDegree($id_DegreeIng, $id_DegreePhd), -1),
260 /* UFC_EducationField
262 $id_FieldInfo = XDB
::fetchOneCell('SELECT id
263 FROM profile_education_field_enum
264 WHERE field = {?}', 'Informatique');
265 $id_FieldDroit = XDB
::fetchOneCell('SELECT id
266 FROM profile_education_field_enum
267 WHERE field = {?}', 'Droit');
268 // FIXME: Replace 0 by -1 in following queries when profile_education will be filled with fieldids
270 array(self
::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
271 LEFT JOIN profile_education_field_enum AS pefe ON (pe.fieldid = pefe.id)
272 WHERE pefe.field = {?}', 'Informatique'),
273 new UFC_EducationField($id_FieldInfo), 0), // FIXME: should be -1
274 array(self
::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
275 LEFT JOIN profile_education_field_enum AS pefe ON (pe.fieldid = pefe.id)
276 WHERE pefe.field IN {?}', array('Informatique', 'Droit')),
277 new UFC_EducationField($id_FieldInfo, $id_FieldDroit), 0), // FIXME: should be -1
282 $id_Lastname = DirEnum
::getID(DirEnum
::NAMETYPES
, Profile
::LASTNAME
);
283 $id_Firstname = DirEnum
::getID(DirEnum
::NAMETYPES
, Profile
::FIRSTNAME
);
284 $id_Nickname = DirEnum
::getID(DirEnum
::NAMETYPES
, Profile
::NICKNAME
);
285 $id_Lastname_Marital = DirEnum
::getID(DirEnum
::NAMETYPES
, Profile
::LASTNAME
. '_' . Profile
::VN_MARITAL
);
286 $id_Lastname_Ordinary = DirEnum
::getID(DirEnum
::NAMETYPES
, Profile
::LASTNAME
. '_' . Profile
::VN_ORDINARY
);
290 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (pn.pid = p.pid)
291 WHERE pn.name LIKE {?} AND pn.typeid = {?}', 'BARROIS', $id_Lastname),
292 new UFC_Name(Profile
::LASTNAME
, 'BARROIS', UFC_Name
::EXACT
), -1),
293 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (pn.pid = p.pid)
294 WHERE pn.name LIKE \'BARR%\' AND pn.typeid = {?}', $id_Lastname),
295 new UFC_Name(Profile
::LASTNAME
, 'BARR', UFC_Name
::PREFIX
), -1),
296 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (pn.pid = p.pid)
297 WHERE pn.name LIKE \'%OIS\' AND pn.typeid = {?}', $id_Lastname),
298 new UFC_Name(Profile
::LASTNAME
, 'OIS', UFC_Name
::SUFFIX
), -1),
299 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
300 WHERE pn.name LIKE \'%ARRO%\' AND pn.typeid = {?}', $id_Lastname),
301 new UFC_Name(Profile
::LASTNAME
, 'ARRO', UFC_Name
::CONTAINS
), -1),
302 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
303 WHERE pn.name LIKE \'%ZZZZZZ%\' AND pn.typeid = {?}', $id_Lastname),
304 new UFC_Name(Profile
::LASTNAME
, 'ZZZZZZ', UFC_Name
::CONTAINS
), 0),
307 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
308 WHERE pn.name LIKE {?} AND pn.typeid = {?}', 'Raphaël', $id_Firstname),
309 new UFC_Name(Profile
::FIRSTNAME
, 'Raphaël', UFC_Name
::EXACT
), -1),
310 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
311 WHERE pn.name LIKE \'Raph%\' AND pn.typeid = {?}', $id_Firstname),
312 new UFC_Name(Profile
::FIRSTNAME
, 'Raph', UFC_Name
::PREFIX
), -1),
313 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
314 WHERE pn.name LIKE \'%aël\' AND pn.typeid = {?}', $id_Firstname),
315 new UFC_Name(Profile
::FIRSTNAME
, 'aël', UFC_Name
::SUFFIX
), -1),
316 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
317 WHERE pn.name LIKE \'%apha%\' AND pn.typeid = {?}', $id_Firstname),
318 new UFC_Name(Profile
::FIRSTNAME
, 'apha', UFC_Name
::CONTAINS
), -1),
319 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
320 WHERE pn.name LIKE \'%zzzzzz%\' AND pn.typeid = {?}', $id_Firstname),
321 new UFC_Name(Profile
::FIRSTNAME
, 'zzzzzz', UFC_Name
::CONTAINS
), 0),
324 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
325 WHERE pn.name LIKE {?} AND pn.typeid = {?}', 'Xelnor', $id_Nickname),
326 new UFC_Name(Profile
::NICKNAME
, 'Xelnor', UFC_Name
::EXACT
), -1),
327 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
328 WHERE pn.name LIKE \'Xel%\' AND pn.typeid = {?}', $id_Nickname),
329 new UFC_Name(Profile
::NICKNAME
, 'Xel', UFC_Name
::PREFIX
), -1),
330 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
331 WHERE pn.name LIKE \'%nor\' AND pn.typeid = {?}', $id_Nickname),
332 new UFC_Name(Profile
::NICKNAME
, 'nor', UFC_Name
::SUFFIX
), -1),
333 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
334 WHERE pn.name LIKE \'%lno%\' AND pn.typeid = {?}', $id_Nickname),
335 new UFC_Name(Profile
::NICKNAME
, 'lno', UFC_Name
::CONTAINS
), -1),
336 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
337 WHERE pn.name LIKE \'%zzzzzz%\' AND pn.typeid = {?}', $id_Nickname),
338 new UFC_Name(Profile
::NICKNAME
, 'zzzzzz', UFC_Name
::CONTAINS
), 0),
340 // Lastname + particle
341 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
342 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE {?} AND pn.typeid = {?}', 'DE SINGLY', $id_Lastname),
343 new UFC_Name(Profile
::LASTNAME
, 'DE SINGLY', UFC_Name
::PARTICLE | UFC_Name
::EXACT
), -1),
344 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
345 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE \'DE SI%\' AND pn.typeid = {?}', $id_Lastname),
346 new UFC_Name(Profile
::LASTNAME
, 'DE SI', UFC_Name
::PARTICLE | UFC_Name
::PREFIX
), -1),
347 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
348 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE \'%GLY\' AND pn.typeid = {?}', $id_Lastname),
349 new UFC_Name(Profile
::LASTNAME
, 'GLY', UFC_NAME
::PARTICLE | UFC_Name
::SUFFIX
), -1),
350 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
351 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE \'%E SIN%\' AND pn.typeid = {?}', $id_Lastname),
352 new UFC_Name(Profile
::LASTNAME
, 'E SIN', UFC_Name
::PARTICLE | UFC_Name
::CONTAINS
), -1),
353 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
354 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE \'%ZZZZZZ%\' AND pn.typeid = {?}', $id_Lastname),
355 new UFC_Name(Profile
::LASTNAME
, 'ZZZZZZ', UFC_Name
::PARTICLE | UFC_Name
::CONTAINS
), 0),
358 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
359 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
360 'ALBIZZATI', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
361 new UFC_Name(Profile
::LASTNAME
, 'ALBIZZATI', UFC_Name
::VARIANTS | UFC_Name
::EXACT
), -1),
362 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
363 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
364 'ALBIZ%', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
365 new UFC_Name(Profile
::LASTNAME
, 'ALBIZ', UFC_Name
::VARIANTS | UFC_Name
::PREFIX
), -1),
366 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
367 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
368 '%ZATI', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
369 new UFC_Name(Profile
::LASTNAME
, 'ZATI', UFC_NAME
::VARIANTS | UFC_Name
::SUFFIX
), -1),
370 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
371 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
372 '%BIZZ%', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
373 new UFC_Name(Profile
::LASTNAME
, 'BIZZ', UFC_Name
::VARIANTS | UFC_Name
::CONTAINS
), -1),
374 array(self
::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
375 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
376 '%ZZZZZZ%', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
377 new UFC_Name(Profile
::LASTNAME
, 'ZZZZZZ', UFC_Name
::VARIANTS | UFC_Name
::CONTAINS
), 0),
384 array(self
::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
385 WHERE sn.token LIKE \'xelnor%\''),
386 new UFC_NameTokens('xelnor'), 1),
387 array(self
::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
388 WHERE sn.token LIKE \'xe%\''),
389 new UFC_NameTokens('xe'), -1),
390 array(self
::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
391 WHERE sn.token LIKE \'xe%\' OR sn.token LIKE \'barr%\''),
392 new UFC_NameTokens(array('xe', 'barr')), -1),
393 array(self
::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
394 WHERE sn.token LIKE \'zzzzzzzz%\''),
395 new UFC_NameTokens('zzzzzzzz'), 0),
396 array(self
::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
397 WHERE sn.token LIKE \'barr%\' AND FIND_IN_SET(\'public\', sn.flags)'),
398 new UFC_NameTokens('barr', UFC_NameTokens
::FLAG_PUBLIC
), -1),
401 array(self
::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
402 WHERE sn.token = \'xelnor\''),
403 new UFC_NameTokens('xelnor', array(), false
, true
), 1),
404 array(self
::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
405 WHERE sn.token IN (\'xelnor\', \'barrois\')'),
406 new UFC_NameTokens(array('xelnor', 'barrois'), array(), false
, true
), -1),
407 array(self
::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
408 WHERE sn.token = \'zzzzzzzz\''),
409 new UFC_NameTokens('zzzzzzzz', array(), false
, true
), 0),
410 array(self
::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
411 WHERE sn.token IN (\'zzzzzzzz\', \'yyyyyyyy\')'),
412 new UFC_NameTokens(array('zzzzzzzz', 'yyyyyyyy'), array(), false
, true
), 0),
413 array(self
::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
414 WHERE sn.token = \'barrois\' AND FIND_IN_SET(\'public\', sn.flags)'),
415 new UFC_NameTokens('barrois', UFC_NameTokens
::FLAG_PUBLIC
, false
, true
), -1),
418 array(self
::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
419 WHERE sn.soundex = \'XLNO\''),
420 new UFC_NameTokens('XLNO', array(), true
), -1),
421 array(self
::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
422 WHERE sn.soundex IN (\'XLNO\', \'BROS\')'),
423 new UFC_NameTokens(array('XLNO', 'BROS'), array(), true
), -1),
424 array(self
::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
425 WHERE sn.soundex = \'ZZZZZZ\''),
426 new UFC_NameTokens('ZZZZZZ', array(), true
), 0),
427 array(self
::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
428 WHERE sn.soundex = \'BROS\' AND FIND_IN_SET(\'public\', sn.flags)'),
429 new UFC_NameTokens('BROS', UFC_NameTokens
::FLAG_PUBLIC
, true
), -1),
432 $testcases = array();
433 foreach ($tests as $t) {
434 $testcases = array_merge($testcases, $t);
440 * @dataProvider simpleUserProvider
442 public function testSimpleUser($query, $cond, $expcount = null
)
445 * @param $query A pair MySQL query (one for user selector, one for profile selector)
446 * @param $cond The UFC to test
447 * @param $expcount The expected number of results (-1 if that number is unknown)
454 $query = XDB
::query($query);
455 $count = $query->numRows();
456 if (!is_null($expcount)) {
458 $this->assertNotEquals(0, $count);
460 $this->assertEquals($expcount, $count);
463 $ids = $query->fetchColumn();
464 $this->assertEquals($count, count($ids));
467 $uf = new UserFilter($cond);
468 $this->assertEquals($count, $uf->getTotalUserCount());
469 $got = $uf->getUIDs();
470 $this->assertEquals($count, count($got));
472 $this->assertEquals($ids, $got);
474 $uf = new UserFilter($cond);
475 $got = $uf->getUIDs();
476 $this->assertEquals($count, count($got));
478 $this->assertEquals($ids, $got);
479 $this->assertEquals($count, $uf->getTotalUserCount());
483 * @dataProvider simpleUserProvider
485 public function testSimpleProfile($query, $cond, $expcount = null
)
488 * @param $query A pair MySQL query (one for user selector, one for profile selector)
489 * @param $cond The UFC to test
490 * @param $expcount The expected number of results (-1 if that number is unknown)
497 $query = XDB
::query($query);
498 $count = $query->numRows();
499 if (!is_null($expcount)) {
501 $this->assertNotEquals(0, $count);
503 $this->assertEquals($expcount, $count);
506 $ids = $query->fetchColumn();
507 $this->assertEquals($count, count($ids));
510 $uf = new UserFilter($cond);
511 $this->assertEquals($count, $uf->getTotalProfileCount());
512 $got = $uf->getPIDs();
513 $this->assertEquals($count, count($got));
515 $this->assertEquals($ids, $got);
517 $uf = new UserFilter($cond);
518 $got = $uf->getPIDs();
519 $this->assertEquals($count, count($got));
521 $this->assertEquals($ids, $got);
522 $this->assertEquals($count, $uf->getTotalProfileCount());
527 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: