Add testSimpleProfile.
[platal.git] / ut / userfiltertest.php
CommitLineData
aaf70eb8
FB
1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
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. *
10 * *
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. *
15 * *
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 *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22require_once dirname(__FILE__) . '/../include/test.inc.php';
23
24class UserFilterTest extends PlTestCase
25{
d836f8db
RB
26 private static function checkPlatal()
27 {
28 global $platal;
29 if($platal == null)
30 {
31 $platal = new Xorg();
32 }
33 }
34
5b3f6e44
FB
35 private static function buildAccountQuery()
36 {
37 $args = func_get_args();
38 $joinsAndWhere = XDB::_prepare($args);
39 return array('SELECT DISTINCT a.uid
40 FROM accounts AS a
41 ' . $joinsAndWhere,
42 'SELECT DISTINCT p.pid
43 FROM profiles AS p
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)
46 ' . $joinsAndWhere);
47 }
48
49 private static function buildProfileQuery()
50 {
51 $args = func_get_args();
52 $joinsAndWhere = XDB::_prepare($args);
53 return array('SELECT DISTINCT a.uid
54 FROM accounts AS a
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)
57 ' . $joinsAndWhere,
58 'SELECT DISTINCT p.pid
59 FROM profiles AS p
60 ' . $joinsAndWhere);
61 }
62
aaf70eb8
FB
63 public static function simpleUserProvider()
64 {
d836f8db 65 self::checkPlatal();
ed4d85c3
RB
66 $tests = array();
67
68 $tests[] = array(
aaf70eb8
FB
69 /* UFC_Hrpid
70 */
5b3f6e44
FB
71 array(self::buildAccountQuery('INNER JOIN account_profiles AS ap2 ON (ap2.uid = a.uid)
72 WHERE FIND_IN_SET(\'owner\', ap2.perms)'),
aaf70eb8
FB
73 new UFC_HasProfile(), -1),
74
75 /* UFC_Hruid
76 */
5b3f6e44 77 array(self::buildAccountQuery('WHERE a.hruid = {?}', 'florent.bruneau.2003'),
aaf70eb8 78 new UFC_Hruid('florent.bruneau.2003'), 1),
5b3f6e44 79 array(self::buildAccountQuery('WHERE a.hruid = {?}', 'florent.bruneau.2004'),
aaf70eb8 80 new UFC_Hruid('florent.bruneau.2004'), 0),
5b3f6e44
FB
81 array(self::buildAccountQuery('WHERE a.hruid IN {?}', array('florent.bruneau.2003',
82 'stephane.jacob.2004')),
61d1fd8b 83 new UFC_Hruid('florent.bruneau.2003', 'stephane.jacob.2004'), 2),
5b3f6e44
FB
84 array(self::buildAccountQuery('WHERE a.hruid IN {?}', array('florent.bruneau.2004',
85 'stephane.jacob.2004')),
61d1fd8b 86 new UFC_Hruid('florent.bruneau.2004', 'stephane.jacob.2004'), 1),
aaf70eb8
FB
87
88 /* UFC_Hrpid
89 */
5b3f6e44 90 array(self::buildProfileQuery('WHERE p.hrpid = {?}', 'florent.bruneau.2003'),
aaf70eb8 91 new UFC_Hrpid('florent.bruneau.2003'), 1),
5b3f6e44 92 array(self::buildProfileQuery('WHERE p.hrpid = {?}', 'florent.bruneau.2004'),
aaf70eb8 93 new UFC_Hrpid('florent.bruneau.2004'), 0),
5b3f6e44
FB
94 array(self::buildProfileQuery('WHERE p.hrpid IN {?}', array('florent.bruneau.2003',
95 'stephane.jacob.2004')),
61d1fd8b 96 new UFC_Hrpid('florent.bruneau.2003', 'stephane.jacob.2004'), 2),
5b3f6e44
FB
97 array(self::buildProfileQuery('WHERE p.hrpid IN {?}', array('florent.bruneau.2004',
98 'stephane.jacob.2004')),
61d1fd8b 99 new UFC_Hrpid('florent.bruneau.2004', 'stephane.jacob.2004'), 1),
aaf70eb8
FB
100
101 /* UFC_IP
102 */
5b3f6e44
FB
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')),
aaf70eb8 106 new UFC_Ip('129.104.247.2'), -1),
ed4d85c3 107 );
3867f628
RB
108 /* TODO: UFC_Comment
109 */
ed4d85c3 110
3867f628
RB
111 /* UFC_Promo
112 */
ed4d85c3 113 $tests[] = array(
5b3f6e44
FB
114 array(self::buildProfileQuery('INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
115 WHERE pd.promo = {?}', 'X2004'),
3867f628 116 new UFC_Promo('=', UserFilter::DISPLAY, 'X2004'), -1),
5b3f6e44
FB
117 array(self::buildProfileQuery('INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
118 WHERE pd.promo < {?}', 'X2004'),
3867f628 119 new UFC_Promo('<', UserFilter::DISPLAY, 'X2004'), -1),
5b3f6e44
FB
120 array(self::buildProfileQuery('INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
121 WHERE pd.promo > {?}', 'X2004'),
3867f628 122 new UFC_Promo('>', UserFilter::DISPLAY, 'X2004'), -1),
5b3f6e44
FB
123 array(self::buildProfileQuery('INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
124 WHERE pd.promo < {?}', 'X1900'),
3867f628 125 new UFC_Promo('<', UserFilter::DISPLAY, 'X1900'), 0),
3867f628 126
5b3f6e44
FB
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 = {?}',
131 '2004', 'Ing.'),
3867f628 132 new UFC_Promo('=', UserFilter::GRADE_ING, 2004), -1),
5b3f6e44
FB
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 = {?}',
137 '1960', 'Ing.'),
3867f628 138 new UFC_Promo('<=', UserFilter::GRADE_ING, 1960), -1),
5b3f6e44
FB
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 = {?}',
143 '2004', 'Ing.'),
3867f628 144 new UFC_Promo('>', UserFilter::GRADE_ING, 2004), -1),
5b3f6e44
FB
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 = {?}',
149 '1900', 'Ing.'),
3867f628
RB
150 new UFC_Promo('<', UserFilter::GRADE_ING, 1900), 0),
151
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 = {?}',
159 '2009', 'MSc'),
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 = {?}',
167 '2009', 'MSc'),
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 = {?}',
175 '2009', 'MSc'),
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 = {?}',
183 '1980', 'MSc'),
184 new UFC_Promo('<', UserFilter::GRADE_MST, 1980), 0),
185
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 = {?}',
192 '2009', 'PhD'),
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 = {?}',
200 '2009', 'PhD'),
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 = {?}',
208 '2009', 'PhD'),
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 = {?}',
216 '1980', 'PhD'),
217 new UFC_Promo('<', UserFilter::GRADE_PHD, 1980), 0),
ed4d85c3
RB
218 */
219 );
220
d836f8db
RB
221 /* TODO: UFC_SchoolId
222 */
223 /* UFC_EducationSchool
224 */
ed4d85c3
RB
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');
231 $tests[] = array(
5b3f6e44
FB
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'),
ed4d85c3 235 new UFC_EducationSchool($id_X), -1),
5b3f6e44
FB
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')),
61d1fd8b 239 new UFC_EducationSchool($id_X, $id_HEC), -1),
aaf70eb8 240 );
ed4d85c3 241
4894915d
RB
242 /* UFC_EducationDegree
243 */
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');
250 $tests[] = array(
5b3f6e44
FB
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.'),
4894915d 254 new UFC_EducationDegree($id_DegreeIng), -1),
5b3f6e44
FB
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')),
61d1fd8b 258 new UFC_EducationDegree($id_DegreeIng, $id_DegreePhd), -1),
4894915d 259 );
01df65b5
RB
260 /* UFC_EducationField
261 */
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');
b5a9f12a 268 // FIXME: Replace 0 by -1 in following queries when profile_education will be filled with fieldids
01df65b5 269 $tests[] = array(
5b3f6e44
FB
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'),
01df65b5 273 new UFC_EducationField($id_FieldInfo), 0), // FIXME: should be -1
5b3f6e44
FB
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')),
61d1fd8b 277 new UFC_EducationField($id_FieldInfo, $id_FieldDroit), 0), // FIXME: should be -1
01df65b5 278 );
4894915d 279
b5a9f12a
RB
280 /* UFC_Name
281 */
282 $id_Lastname = DirEnum::getID(DirEnum::NAMETYPES, Profile::LASTNAME);
283 $id_Firstname = DirEnum::getID(DirEnum::NAMETYPES, Profile::FIRSTNAME);
cf183020
RB
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);
287
b5a9f12a 288 $tests[] = array(
cf183020 289 // Lastname
5b3f6e44
FB
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),
b5a9f12a 292 new UFC_Name(Profile::LASTNAME, 'BARROIS', UFC_Name::EXACT), -1),
5b3f6e44
FB
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),
b5a9f12a 295 new UFC_Name(Profile::LASTNAME, 'BARR', UFC_Name::PREFIX), -1),
5b3f6e44
FB
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),
b5a9f12a 298 new UFC_Name(Profile::LASTNAME, 'OIS', UFC_Name::SUFFIX), -1),
5b3f6e44
FB
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),
b5a9f12a 301 new UFC_Name(Profile::LASTNAME, 'ARRO', UFC_Name::CONTAINS), -1),
5b3f6e44
FB
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),
b5a9f12a
RB
304 new UFC_Name(Profile::LASTNAME, 'ZZZZZZ', UFC_Name::CONTAINS), 0),
305
cf183020 306 // Firstname
5b3f6e44
FB
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),
b5a9f12a 309 new UFC_Name(Profile::FIRSTNAME, 'Raphaël', UFC_Name::EXACT), -1),
5b3f6e44
FB
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),
b5a9f12a 312 new UFC_Name(Profile::FIRSTNAME, 'Raph', UFC_Name::PREFIX), -1),
5b3f6e44
FB
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),
b5a9f12a 315 new UFC_Name(Profile::FIRSTNAME, 'aël', UFC_Name::SUFFIX), -1),
5b3f6e44
FB
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),
b5a9f12a 318 new UFC_Name(Profile::FIRSTNAME, 'apha', UFC_Name::CONTAINS), -1),
5b3f6e44
FB
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),
b5a9f12a 321 new UFC_Name(Profile::FIRSTNAME, 'zzzzzz', UFC_Name::CONTAINS), 0),
cf183020
RB
322
323 // Nickname
5b3f6e44
FB
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),
cf183020 326 new UFC_Name(Profile::NICKNAME, 'Xelnor', UFC_Name::EXACT), -1),
5b3f6e44
FB
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),
cf183020 329 new UFC_Name(Profile::NICKNAME, 'Xel', UFC_Name::PREFIX), -1),
5b3f6e44
FB
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),
cf183020 332 new UFC_Name(Profile::NICKNAME, 'nor', UFC_Name::SUFFIX), -1),
5b3f6e44
FB
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),
cf183020 335 new UFC_Name(Profile::NICKNAME, 'lno', UFC_Name::CONTAINS), -1),
5b3f6e44
FB
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),
cf183020
RB
338 new UFC_Name(Profile::NICKNAME, 'zzzzzz', UFC_Name::CONTAINS), 0),
339
340 // Lastname + particle
5b3f6e44
FB
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),
cf183020 343 new UFC_Name(Profile::LASTNAME, 'DE SINGLY', UFC_Name::PARTICLE | UFC_Name::EXACT), -1),
5b3f6e44
FB
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),
cf183020 346 new UFC_Name(Profile::LASTNAME, 'DE SI', UFC_Name::PARTICLE | UFC_Name::PREFIX), -1),
5b3f6e44
FB
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),
cf183020 349 new UFC_Name(Profile::LASTNAME, 'GLY', UFC_NAME::PARTICLE | UFC_Name::SUFFIX), -1),
5b3f6e44
FB
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),
cf183020 352 new UFC_Name(Profile::LASTNAME, 'E SIN', UFC_Name::PARTICLE | UFC_Name::CONTAINS), -1),
5b3f6e44
FB
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),
cf183020
RB
355 new UFC_Name(Profile::LASTNAME, 'ZZZZZZ', UFC_Name::PARTICLE | UFC_Name::CONTAINS), 0),
356
357 // Lastname_ordinary
5b3f6e44
FB
358 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
359 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
cf183020
RB
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),
5b3f6e44
FB
362 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
363 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
cf183020
RB
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),
5b3f6e44
FB
366 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
367 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
cf183020
RB
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),
5b3f6e44
FB
370 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
371 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
cf183020
RB
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),
5b3f6e44
FB
374 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
375 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
cf183020
RB
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),
b5a9f12a
RB
378 );
379
6a47d09f
RB
380 /* UFC_NameTokens
381 */
382 $tests[] = array(
383 // !soundex, !exact
5b3f6e44
FB
384 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
385 WHERE sn.token LIKE \'xelnor%\''),
6a47d09f 386 new UFC_NameTokens('xelnor'), 1),
5b3f6e44
FB
387 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
388 WHERE sn.token LIKE \'xe%\''),
6a47d09f 389 new UFC_NameTokens('xe'), -1),
5b3f6e44
FB
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%\''),
6a47d09f 392 new UFC_NameTokens(array('xe', 'barr')), -1),
5b3f6e44
FB
393 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
394 WHERE sn.token LIKE \'zzzzzzzz%\''),
6a47d09f 395 new UFC_NameTokens('zzzzzzzz'), 0),
5b3f6e44
FB
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)'),
6a47d09f
RB
398 new UFC_NameTokens('barr', UFC_NameTokens::FLAG_PUBLIC), -1),
399
400 // !soundex, exact
5b3f6e44
FB
401 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
402 WHERE sn.token = \'xelnor\''),
6a47d09f 403 new UFC_NameTokens('xelnor', array(), false, true), 1),
5b3f6e44
FB
404 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
405 WHERE sn.token IN (\'xelnor\', \'barrois\')'),
6a47d09f 406 new UFC_NameTokens(array('xelnor', 'barrois'), array(), false, true), -1),
5b3f6e44
FB
407 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
408 WHERE sn.token = \'zzzzzzzz\''),
6a47d09f 409 new UFC_NameTokens('zzzzzzzz', array(), false, true), 0),
5b3f6e44
FB
410 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
411 WHERE sn.token IN (\'zzzzzzzz\', \'yyyyyyyy\')'),
6a47d09f 412 new UFC_NameTokens(array('zzzzzzzz', 'yyyyyyyy'), array(), false, true), 0),
5b3f6e44
FB
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)'),
6a47d09f
RB
415 new UFC_NameTokens('barrois', UFC_NameTokens::FLAG_PUBLIC, false, true), -1),
416
417 // soundex, !exact
5b3f6e44
FB
418 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
419 WHERE sn.soundex = \'XLNO\''),
6a47d09f 420 new UFC_NameTokens('XLNO', array(), true), -1),
5b3f6e44
FB
421 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
422 WHERE sn.soundex IN (\'XLNO\', \'BROS\')'),
6a47d09f 423 new UFC_NameTokens(array('XLNO', 'BROS'), array(), true), -1),
5b3f6e44
FB
424 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
425 WHERE sn.soundex = \'ZZZZZZ\''),
6a47d09f 426 new UFC_NameTokens('ZZZZZZ', array(), true), 0),
5b3f6e44
FB
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)'),
6a47d09f
RB
429 new UFC_NameTokens('BROS', UFC_NameTokens::FLAG_PUBLIC, true), -1),
430 );
431
ed4d85c3
RB
432 $testcases = array();
433 foreach ($tests as $t) {
434 $testcases = array_merge($testcases, $t);
435 }
436 return $testcases;
aaf70eb8
FB
437 }
438
439 /**
440 * @dataProvider simpleUserProvider
441 */
442 public function testSimpleUser($query, $cond, $expcount = null)
443 {
d836f8db 444 /*
5b3f6e44 445 * @param $query A pair MySQL query (one for user selector, one for profile selector)
d836f8db
RB
446 * @param $cond The UFC to test
447 * @param $expcount The expected number of results (-1 if that number is unknown)
448 */
449
5b3f6e44
FB
450 $query = $query[0];
451
d836f8db 452 self::checkPlatal();
aaf70eb8
FB
453
454 $query = XDB::query($query);
455 $count = $query->numRows();
456 if (!is_null($expcount)) {
457 if ($expcount < 0) {
458 $this->assertNotEquals(0, $count);
459 } else {
460 $this->assertEquals($expcount, $count);
461 }
462 }
463 $ids = $query->fetchColumn();
464 $this->assertEquals($count, count($ids));
465 sort($ids);
466
467 $uf = new UserFilter($cond);
af746402 468 $this->assertEquals($count, $uf->getTotalUserCount());
aaf70eb8
FB
469 $got = $uf->getUIDs();
470 $this->assertEquals($count, count($got));
471 sort($got);
472 $this->assertEquals($ids, $got);
473
474 $uf = new UserFilter($cond);
475 $got = $uf->getUIDs();
476 $this->assertEquals($count, count($got));
477 sort($got);
478 $this->assertEquals($ids, $got);
5b3f6e44
FB
479 $this->assertEquals($count, $uf->getTotalUserCount());
480 }
481
482 /**
483 * @dataProvider simpleUserProvider
484 */
485 public function testSimpleProfile($query, $cond, $expcount = null)
486 {
487 /*
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)
491 */
492
493 $query = $query[1];
494
495 self::checkPlatal();
496
497 $query = XDB::query($query);
498 $count = $query->numRows();
499 if (!is_null($expcount)) {
500 if ($expcount < 0) {
501 $this->assertNotEquals(0, $count);
502 } else {
503 $this->assertEquals($expcount, $count);
504 }
505 }
506 $ids = $query->fetchColumn();
507 $this->assertEquals($count, count($ids));
508 sort($ids);
509
510 $uf = new UserFilter($cond);
511 $this->assertEquals($count, $uf->getTotalProfileCount());
512 $got = $uf->getPIDs();
513 $this->assertEquals($count, count($got));
514 sort($got);
515 $this->assertEquals($ids, $got);
516
517 $uf = new UserFilter($cond);
518 $got = $uf->getPIDs();
519 $this->assertEquals($count, count($got));
520 sort($got);
521 $this->assertEquals($ids, $got);
522 $this->assertEquals($count, $uf->getTotalProfileCount());
aaf70eb8 523 }
5b3f6e44 524
aaf70eb8
FB
525}
526
527// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
528?>