Add UTs for UFC_SchoolId
[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
f5aea068 221 /* UFC_SchoolId
d836f8db 222 */
f5aea068
RB
223 $tests[] = array(
224 array(self::buildProfileQuery('WHERE p.xorg_id = {?}', 20060076),
225 new UFC_SchoolId(UFC_SchoolId::Xorg, 20060076), 1),
226 array(self::buildProfileQuery('WHERE p.ax_id = {?}', 20060062),
227 new UFC_SchoolId(UFC_SchoolId::AX, 20060062), 1),
228 array(self::buildProfileQuery('WHERE p.xorg_id = {?}', 007),
229 new UFC_SchoolId(UFC_SchoolId::Xorg, 007), 0),
230 array(self::buildProfileQuery('WHERE p.ax_id = {?}', 007),
231 new UFC_SchoolId(UFC_SchoolId::AX, 007), 0),
232 /* FIXME: disabled until we have some examples of school_id
233 array(self::buildProfileQuery('WHERE p.school_id = {?}', 12345678),
234 new UFC_SchoolId(UFC_SchoolId::School, 12345678), 1),
235 array(self::buildProfileQuery('WHERE p.school_id = {?}', 007),
236 new UFC_SchoolId(UFC_SchoolId::School, 007), 0),
237 */
238 );
d836f8db
RB
239 /* UFC_EducationSchool
240 */
ed4d85c3
RB
241 $id_X = XDB::fetchOneCell('SELECT id
242 FROM profile_education_enum
243 WHERE abbreviation = {?}', 'X');
244 $id_HEC = XDB::fetchOneCell('SELECT id
245 FROM profile_education_enum
246 WHERE abbreviation = {?}', 'HEC');
247 $tests[] = array(
5b3f6e44
FB
248 array(self::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
249 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
250 WHERE pee.abbreviation = {?}', 'X'),
ed4d85c3 251 new UFC_EducationSchool($id_X), -1),
5b3f6e44
FB
252 array(self::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
253 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
254 WHERE pee.abbreviation IN {?}', array('X', 'HEC')),
61d1fd8b 255 new UFC_EducationSchool($id_X, $id_HEC), -1),
aaf70eb8 256 );
ed4d85c3 257
4894915d
RB
258 /* UFC_EducationDegree
259 */
260 $id_DegreeIng = XDB::fetchOneCell('SELECT id
261 FROM profile_education_degree_enum
262 WHERE abbreviation = {?}', 'Ing.');
263 $id_DegreePhd = XDB::fetchOneCell('SELECT id
264 FROM profile_education_degree_enum
265 WHERE abbreviation = {?}', 'PhD');
266 $tests[] = array(
5b3f6e44
FB
267 array(self::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
268 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
269 WHERE pede.abbreviation = {?}', 'Ing.'),
4894915d 270 new UFC_EducationDegree($id_DegreeIng), -1),
5b3f6e44
FB
271 array(self::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
272 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
273 WHERE pede.abbreviation IN {?}', array('Ing.', 'PhD')),
61d1fd8b 274 new UFC_EducationDegree($id_DegreeIng, $id_DegreePhd), -1),
4894915d 275 );
01df65b5
RB
276 /* UFC_EducationField
277 */
278 $id_FieldInfo = XDB::fetchOneCell('SELECT id
279 FROM profile_education_field_enum
280 WHERE field = {?}', 'Informatique');
281 $id_FieldDroit = XDB::fetchOneCell('SELECT id
282 FROM profile_education_field_enum
283 WHERE field = {?}', 'Droit');
b5a9f12a 284 // FIXME: Replace 0 by -1 in following queries when profile_education will be filled with fieldids
01df65b5 285 $tests[] = array(
5b3f6e44
FB
286 array(self::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
287 LEFT JOIN profile_education_field_enum AS pefe ON (pe.fieldid = pefe.id)
288 WHERE pefe.field = {?}', 'Informatique'),
01df65b5 289 new UFC_EducationField($id_FieldInfo), 0), // FIXME: should be -1
5b3f6e44
FB
290 array(self::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
291 LEFT JOIN profile_education_field_enum AS pefe ON (pe.fieldid = pefe.id)
292 WHERE pefe.field IN {?}', array('Informatique', 'Droit')),
61d1fd8b 293 new UFC_EducationField($id_FieldInfo, $id_FieldDroit), 0), // FIXME: should be -1
01df65b5 294 );
4894915d 295
b5a9f12a
RB
296 /* UFC_Name
297 */
298 $id_Lastname = DirEnum::getID(DirEnum::NAMETYPES, Profile::LASTNAME);
299 $id_Firstname = DirEnum::getID(DirEnum::NAMETYPES, Profile::FIRSTNAME);
cf183020
RB
300 $id_Nickname = DirEnum::getID(DirEnum::NAMETYPES, Profile::NICKNAME);
301 $id_Lastname_Marital = DirEnum::getID(DirEnum::NAMETYPES, Profile::LASTNAME . '_' . Profile::VN_MARITAL);
302 $id_Lastname_Ordinary = DirEnum::getID(DirEnum::NAMETYPES, Profile::LASTNAME . '_' . Profile::VN_ORDINARY);
303
b5a9f12a 304 $tests[] = array(
cf183020 305 // Lastname
5b3f6e44
FB
306 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (pn.pid = p.pid)
307 WHERE pn.name LIKE {?} AND pn.typeid = {?}', 'BARROIS', $id_Lastname),
b5a9f12a 308 new UFC_Name(Profile::LASTNAME, 'BARROIS', UFC_Name::EXACT), -1),
5b3f6e44
FB
309 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (pn.pid = p.pid)
310 WHERE pn.name LIKE \'BARR%\' AND pn.typeid = {?}', $id_Lastname),
b5a9f12a 311 new UFC_Name(Profile::LASTNAME, 'BARR', UFC_Name::PREFIX), -1),
5b3f6e44
FB
312 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (pn.pid = p.pid)
313 WHERE pn.name LIKE \'%OIS\' AND pn.typeid = {?}', $id_Lastname),
b5a9f12a 314 new UFC_Name(Profile::LASTNAME, 'OIS', UFC_Name::SUFFIX), -1),
5b3f6e44
FB
315 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
316 WHERE pn.name LIKE \'%ARRO%\' AND pn.typeid = {?}', $id_Lastname),
b5a9f12a 317 new UFC_Name(Profile::LASTNAME, 'ARRO', UFC_Name::CONTAINS), -1),
5b3f6e44
FB
318 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
319 WHERE pn.name LIKE \'%ZZZZZZ%\' AND pn.typeid = {?}', $id_Lastname),
b5a9f12a
RB
320 new UFC_Name(Profile::LASTNAME, 'ZZZZZZ', UFC_Name::CONTAINS), 0),
321
cf183020 322 // Firstname
5b3f6e44
FB
323 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
324 WHERE pn.name LIKE {?} AND pn.typeid = {?}', 'Raphaël', $id_Firstname),
b5a9f12a 325 new UFC_Name(Profile::FIRSTNAME, 'Raphaël', UFC_Name::EXACT), -1),
5b3f6e44
FB
326 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
327 WHERE pn.name LIKE \'Raph%\' AND pn.typeid = {?}', $id_Firstname),
b5a9f12a 328 new UFC_Name(Profile::FIRSTNAME, 'Raph', UFC_Name::PREFIX), -1),
5b3f6e44
FB
329 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
330 WHERE pn.name LIKE \'%aël\' AND pn.typeid = {?}', $id_Firstname),
b5a9f12a 331 new UFC_Name(Profile::FIRSTNAME, 'aël', UFC_Name::SUFFIX), -1),
5b3f6e44
FB
332 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
333 WHERE pn.name LIKE \'%apha%\' AND pn.typeid = {?}', $id_Firstname),
b5a9f12a 334 new UFC_Name(Profile::FIRSTNAME, 'apha', UFC_Name::CONTAINS), -1),
5b3f6e44
FB
335 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
336 WHERE pn.name LIKE \'%zzzzzz%\' AND pn.typeid = {?}', $id_Firstname),
b5a9f12a 337 new UFC_Name(Profile::FIRSTNAME, 'zzzzzz', UFC_Name::CONTAINS), 0),
cf183020
RB
338
339 // Nickname
5b3f6e44
FB
340 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
341 WHERE pn.name LIKE {?} AND pn.typeid = {?}', 'Xelnor', $id_Nickname),
cf183020 342 new UFC_Name(Profile::NICKNAME, 'Xelnor', UFC_Name::EXACT), -1),
5b3f6e44
FB
343 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
344 WHERE pn.name LIKE \'Xel%\' AND pn.typeid = {?}', $id_Nickname),
cf183020 345 new UFC_Name(Profile::NICKNAME, 'Xel', UFC_Name::PREFIX), -1),
5b3f6e44
FB
346 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
347 WHERE pn.name LIKE \'%nor\' AND pn.typeid = {?}', $id_Nickname),
cf183020 348 new UFC_Name(Profile::NICKNAME, 'nor', UFC_Name::SUFFIX), -1),
5b3f6e44
FB
349 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
350 WHERE pn.name LIKE \'%lno%\' AND pn.typeid = {?}', $id_Nickname),
cf183020 351 new UFC_Name(Profile::NICKNAME, 'lno', UFC_Name::CONTAINS), -1),
5b3f6e44
FB
352 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
353 WHERE pn.name LIKE \'%zzzzzz%\' AND pn.typeid = {?}', $id_Nickname),
cf183020
RB
354 new UFC_Name(Profile::NICKNAME, 'zzzzzz', UFC_Name::CONTAINS), 0),
355
356 // Lastname + particle
5b3f6e44
FB
357 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
358 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE {?} AND pn.typeid = {?}', 'DE SINGLY', $id_Lastname),
cf183020 359 new UFC_Name(Profile::LASTNAME, 'DE SINGLY', UFC_Name::PARTICLE | UFC_Name::EXACT), -1),
5b3f6e44
FB
360 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
361 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE \'DE SI%\' AND pn.typeid = {?}', $id_Lastname),
cf183020 362 new UFC_Name(Profile::LASTNAME, 'DE SI', UFC_Name::PARTICLE | UFC_Name::PREFIX), -1),
5b3f6e44
FB
363 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
364 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE \'%GLY\' AND pn.typeid = {?}', $id_Lastname),
cf183020 365 new UFC_Name(Profile::LASTNAME, 'GLY', UFC_NAME::PARTICLE | UFC_Name::SUFFIX), -1),
5b3f6e44
FB
366 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
367 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE \'%E SIN%\' AND pn.typeid = {?}', $id_Lastname),
cf183020 368 new UFC_Name(Profile::LASTNAME, 'E SIN', UFC_Name::PARTICLE | UFC_Name::CONTAINS), -1),
5b3f6e44
FB
369 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
370 WHERE CONCAT(pn.particle, \' \', pn.name) LIKE \'%ZZZZZZ%\' AND pn.typeid = {?}', $id_Lastname),
cf183020
RB
371 new UFC_Name(Profile::LASTNAME, 'ZZZZZZ', UFC_Name::PARTICLE | UFC_Name::CONTAINS), 0),
372
373 // Lastname_ordinary
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 'ALBIZZATI', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
377 new UFC_Name(Profile::LASTNAME, 'ALBIZZATI', UFC_Name::VARIANTS | UFC_Name::EXACT), -1),
5b3f6e44
FB
378 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
379 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
cf183020
RB
380 'ALBIZ%', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
381 new UFC_Name(Profile::LASTNAME, 'ALBIZ', UFC_Name::VARIANTS | UFC_Name::PREFIX), -1),
5b3f6e44
FB
382 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
383 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
cf183020
RB
384 '%ZATI', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
385 new UFC_Name(Profile::LASTNAME, 'ZATI', UFC_NAME::VARIANTS | UFC_Name::SUFFIX), -1),
5b3f6e44
FB
386 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
387 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
cf183020
RB
388 '%BIZZ%', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
389 new UFC_Name(Profile::LASTNAME, 'BIZZ', UFC_Name::VARIANTS | UFC_Name::CONTAINS), -1),
5b3f6e44
FB
390 array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (p.pid = pn.pid)
391 WHERE pn.name LIKE {?} AND pn.typeid IN {?}',
cf183020
RB
392 '%ZZZZZZ%', array($id_Lastname, $id_Lastname_Marital, $id_Lastname_Ordinary)),
393 new UFC_Name(Profile::LASTNAME, 'ZZZZZZ', UFC_Name::VARIANTS | UFC_Name::CONTAINS), 0),
b5a9f12a
RB
394 );
395
6a47d09f
RB
396 /* UFC_NameTokens
397 */
398 $tests[] = array(
399 // !soundex, !exact
5b3f6e44
FB
400 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
401 WHERE sn.token LIKE \'xelnor%\''),
6a47d09f 402 new UFC_NameTokens('xelnor'), 1),
5b3f6e44
FB
403 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
404 WHERE sn.token LIKE \'xe%\''),
6a47d09f 405 new UFC_NameTokens('xe'), -1),
5b3f6e44
FB
406 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
407 WHERE sn.token LIKE \'xe%\' OR sn.token LIKE \'barr%\''),
6a47d09f 408 new UFC_NameTokens(array('xe', 'barr')), -1),
5b3f6e44
FB
409 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
410 WHERE sn.token LIKE \'zzzzzzzz%\''),
6a47d09f 411 new UFC_NameTokens('zzzzzzzz'), 0),
5b3f6e44
FB
412 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
413 WHERE sn.token LIKE \'barr%\' AND FIND_IN_SET(\'public\', sn.flags)'),
6a47d09f
RB
414 new UFC_NameTokens('barr', UFC_NameTokens::FLAG_PUBLIC), -1),
415
416 // !soundex, exact
5b3f6e44
FB
417 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
418 WHERE sn.token = \'xelnor\''),
6a47d09f 419 new UFC_NameTokens('xelnor', array(), false, true), 1),
5b3f6e44
FB
420 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
421 WHERE sn.token IN (\'xelnor\', \'barrois\')'),
6a47d09f 422 new UFC_NameTokens(array('xelnor', 'barrois'), array(), false, true), -1),
5b3f6e44
FB
423 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
424 WHERE sn.token = \'zzzzzzzz\''),
6a47d09f 425 new UFC_NameTokens('zzzzzzzz', array(), false, true), 0),
5b3f6e44
FB
426 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
427 WHERE sn.token IN (\'zzzzzzzz\', \'yyyyyyyy\')'),
6a47d09f 428 new UFC_NameTokens(array('zzzzzzzz', 'yyyyyyyy'), array(), false, true), 0),
5b3f6e44
FB
429 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
430 WHERE sn.token = \'barrois\' AND FIND_IN_SET(\'public\', sn.flags)'),
6a47d09f
RB
431 new UFC_NameTokens('barrois', UFC_NameTokens::FLAG_PUBLIC, false, true), -1),
432
433 // soundex, !exact
5b3f6e44
FB
434 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
435 WHERE sn.soundex = \'XLNO\''),
6a47d09f 436 new UFC_NameTokens('XLNO', array(), true), -1),
5b3f6e44
FB
437 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
438 WHERE sn.soundex IN (\'XLNO\', \'BROS\')'),
6a47d09f 439 new UFC_NameTokens(array('XLNO', 'BROS'), array(), true), -1),
5b3f6e44
FB
440 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
441 WHERE sn.soundex = \'ZZZZZZ\''),
6a47d09f 442 new UFC_NameTokens('ZZZZZZ', array(), true), 0),
5b3f6e44
FB
443 array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
444 WHERE sn.soundex = \'BROS\' AND FIND_IN_SET(\'public\', sn.flags)'),
6a47d09f
RB
445 new UFC_NameTokens('BROS', UFC_NameTokens::FLAG_PUBLIC, true), -1),
446 );
447
ed4d85c3
RB
448 $testcases = array();
449 foreach ($tests as $t) {
450 $testcases = array_merge($testcases, $t);
451 }
452 return $testcases;
aaf70eb8
FB
453 }
454
455 /**
456 * @dataProvider simpleUserProvider
457 */
458 public function testSimpleUser($query, $cond, $expcount = null)
459 {
d836f8db 460 /*
5b3f6e44 461 * @param $query A pair MySQL query (one for user selector, one for profile selector)
d836f8db
RB
462 * @param $cond The UFC to test
463 * @param $expcount The expected number of results (-1 if that number is unknown)
464 */
465
5b3f6e44
FB
466 $query = $query[0];
467
d836f8db 468 self::checkPlatal();
aaf70eb8
FB
469
470 $query = XDB::query($query);
471 $count = $query->numRows();
472 if (!is_null($expcount)) {
473 if ($expcount < 0) {
474 $this->assertNotEquals(0, $count);
475 } else {
476 $this->assertEquals($expcount, $count);
477 }
478 }
479 $ids = $query->fetchColumn();
480 $this->assertEquals($count, count($ids));
481 sort($ids);
482
483 $uf = new UserFilter($cond);
af746402 484 $this->assertEquals($count, $uf->getTotalUserCount());
aaf70eb8
FB
485 $got = $uf->getUIDs();
486 $this->assertEquals($count, count($got));
487 sort($got);
488 $this->assertEquals($ids, $got);
489
490 $uf = new UserFilter($cond);
491 $got = $uf->getUIDs();
492 $this->assertEquals($count, count($got));
493 sort($got);
494 $this->assertEquals($ids, $got);
5b3f6e44
FB
495 $this->assertEquals($count, $uf->getTotalUserCount());
496 }
497
498 /**
499 * @dataProvider simpleUserProvider
500 */
501 public function testSimpleProfile($query, $cond, $expcount = null)
502 {
503 /*
504 * @param $query A pair MySQL query (one for user selector, one for profile selector)
505 * @param $cond The UFC to test
506 * @param $expcount The expected number of results (-1 if that number is unknown)
507 */
508
509 $query = $query[1];
510
511 self::checkPlatal();
512
513 $query = XDB::query($query);
514 $count = $query->numRows();
515 if (!is_null($expcount)) {
516 if ($expcount < 0) {
517 $this->assertNotEquals(0, $count);
518 } else {
519 $this->assertEquals($expcount, $count);
520 }
521 }
522 $ids = $query->fetchColumn();
523 $this->assertEquals($count, count($ids));
524 sort($ids);
525
526 $uf = new UserFilter($cond);
527 $this->assertEquals($count, $uf->getTotalProfileCount());
528 $got = $uf->getPIDs();
529 $this->assertEquals($count, count($got));
530 sort($got);
531 $this->assertEquals($ids, $got);
532
533 $uf = new UserFilter($cond);
534 $got = $uf->getPIDs();
535 $this->assertEquals($count, count($got));
536 sort($got);
537 $this->assertEquals($ids, $got);
538 $this->assertEquals($count, $uf->getTotalProfileCount());
aaf70eb8 539 }
5b3f6e44 540
aaf70eb8
FB
541}
542
543// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
544?>