6b4db76149e5e47d04b592f67afde07ae1753604
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(array('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(array('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(array('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(array('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(array($id_X, $id_HEC)), -1),
257 $testcases = array();
258 foreach ($tests as $t) {
259 $testcases = array_merge($testcases, $t);
265 * @dataProvider simpleUserProvider
267 public function testSimpleUser($query, $cond, $expcount = null
)
270 * @param $query A MySQL query
271 * @param $cond The UFC to test
272 * @param $expcount The expected number of results (-1 if that number is unknown)
277 $query = XDB
::query($query);
278 $count = $query->numRows();
279 if (!is_null($expcount)) {
281 $this->assertNotEquals(0, $count);
283 $this->assertEquals($expcount, $count);
286 $ids = $query->fetchColumn();
287 $this->assertEquals($count, count($ids));
290 $uf = new UserFilter($cond);
291 $this->assertEquals($count, $uf->getTotalUserCount());
292 $got = $uf->getUIDs();
293 $this->assertEquals($count, count($got));
295 $this->assertEquals($ids, $got);
297 $uf = new UserFilter($cond);
298 $got = $uf->getUIDs();
299 $this->assertEquals($count, count($got));
301 $this->assertEquals($ids, $got);
302 $this->assertEquals($count, $uf->getTotalCount());
306 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: