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 public static function simpleUserProvider()
31 array('SELECT DISTINCT uid
33 WHERE FIND_IN_SET(\'owner\', perms)',
34 new UFC_HasProfile(), -1),
38 array(XDB
::format('SELECT DISTINCT uid
40 WHERE hruid = {?}', 'florent.bruneau.2003'),
41 new UFC_Hruid('florent.bruneau.2003'), 1),
42 array(XDB
::format('SELECT DISTINCT uid
44 WHERE hruid = {?}', 'florent.bruneau.2004'),
45 new UFC_Hruid('florent.bruneau.2004'), 0),
46 array(XDB
::format('SELECT DISTINCT uid
48 WHERE hruid IN {?}', array('florent.bruneau.2003',
49 'stephane.jacob.2004')),
50 new UFC_Hruid(array('florent.bruneau.2003', 'stephane.jacob.2004')), 2),
51 array(XDB
::format('SELECT DISTINCT uid
53 WHERE hruid IN {?}', array('florent.bruneau.2004',
54 'stephane.jacob.2004')),
55 new UFC_Hruid(array('florent.bruneau.2004', 'stephane.jacob.2004')), 1),
59 array(XDB
::format('SELECT DISTINCT uid
60 FROM account_profiles AS ap
61 INNER JOIN profiles AS p ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', perms))
62 WHERE hrpid = {?}', 'florent.bruneau.2003'),
63 new UFC_Hrpid('florent.bruneau.2003'), 1),
64 array(XDB
::format('SELECT DISTINCT uid
65 FROM account_profiles AS ap
66 INNER JOIN profiles AS p ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', perms))
67 WHERE hrpid = {?}', 'florent.bruneau.2004'),
68 new UFC_Hrpid('florent.bruneau.2004'), 0),
69 array(XDB
::format('SELECT DISTINCT uid
70 FROM account_profiles AS ap
71 INNER JOIN profiles AS p ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', perms))
72 WHERE hrpid IN {?}', array('florent.bruneau.2003',
73 'stephane.jacob.2004')),
74 new UFC_Hrpid(array('florent.bruneau.2003', 'stephane.jacob.2004')), 2),
75 array(XDB
::format('SELECT DISTINCT uid
76 FROM account_profiles AS ap
77 INNER JOIN profiles AS p ON (ap.pid = p.pid AND FIND_IN_SET(\'owner\', perms))
78 WHERE hrpid IN {?}', array('florent.bruneau.2004',
79 'stephane.jacob.2004')),
80 new UFC_Hrpid(array('florent.bruneau.2004', 'stephane.jacob.2004')), 1),
84 array(XDB
::format('SELECT DISTINCT a.uid
86 INNER JOIN accounts AS a USING(uid)
87 WHERE ip = {?} OR forward_ip = {?}',
88 ip_to_uint('129.104.247.2'), ip_to_uint('129.104.247.2')),
89 new UFC_Ip('129.104.247.2'), -1),
94 array(XDB
::format('SELECT DISTINCT ap.uid
95 FROM account_profiles AS ap
96 INNER JOIN profile_display AS pd ON (pd.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
97 WHERE pd.promo = {?}', 'X2004'),
98 new UFC_Promo('=', UserFilter
::DISPLAY
, 'X2004'), -1),
99 array(XDB
::format('SELECT DISTINCT ap.uid
100 FROM account_profiles AS ap
101 INNER JOIN profile_display AS pd ON (pd.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
102 WHERE pd.promo < {?}', 'X2004'),
103 new UFC_Promo('<', UserFilter
::DISPLAY
, 'X2004'), -1),
104 array(XDB
::format('SELECT DISTINCT ap.uid
105 FROM account_profiles AS ap
106 INNER JOIN profile_display AS pd ON (pd.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
107 WHERE pd.promo > {?}', 'X2004'),
108 new UFC_Promo('>', UserFilter
::DISPLAY
, 'X2004'), -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 < {?}', 'X1900'),
113 new UFC_Promo('<', UserFilter
::DISPLAY
, 'X1900'), 0),
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 < {?}', 'X1900'),
118 new UFC_Promo('<', UserFilter
::DISPLAY
, 'X1900'), 0),
120 array(XDB
::format('SELECT DISTINCT ap.uid
121 FROM account_profiles AS ap
122 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
123 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
124 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
125 WHERE pe.entry_year = {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
127 new UFC_Promo('=', UserFilter
::GRADE_ING
, 2004), -1),
128 array(XDB
::format('SELECT DISTINCT ap.uid
129 FROM account_profiles AS ap
130 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
131 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
132 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
133 WHERE pe.entry_year <= {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
135 new UFC_Promo('<=', UserFilter
::GRADE_ING
, 1960), -1),
136 array(XDB
::format('SELECT DISTINCT ap.uid
137 FROM account_profiles AS ap
138 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
139 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
140 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
141 WHERE pe.entry_year > {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
143 new UFC_Promo('>', UserFilter
::GRADE_ING
, 2004), -1),
144 array(XDB
::format('SELECT DISTINCT ap.uid
145 FROM account_profiles AS ap
146 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
147 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
148 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
149 WHERE pe.entry_year < {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
151 new UFC_Promo('<', UserFilter
::GRADE_ING
, 1900), 0),
153 /* XXX : tests disabled until there are Masters and doctors in the DB
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.grad_year = {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
161 new UFC_Promo('=', UserFilter::GRADE_MST, 2009), -1),
162 array(XDB::format('SELECT DISTINCT ap.uid
163 FROM account_profiles AS ap
164 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
165 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
166 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
167 WHERE pe.grad_year <= {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
169 new UFC_Promo('<=', UserFilter::GRADE_MST, 2009), -1),
170 array(XDB::format('SELECT DISTINCT ap.uid
171 FROM account_profiles AS ap
172 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
173 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
174 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
175 WHERE pe.grad_year > {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
177 new UFC_Promo('>', UserFilter::GRADE_MST, 2009), -1),
178 array(XDB::format('SELECT DISTINCT ap.uid
179 FROM account_profiles AS ap
180 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
181 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
182 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
183 WHERE pe.grad_year < {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
185 new UFC_Promo('<', UserFilter::GRADE_MST, 1980), 0),
187 array(XDB::format('SELECT DISTINCT ap.uid
188 FROM account_profiles AS ap
189 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
190 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
191 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
192 WHERE pe.grad_year = {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
194 new UFC_Promo('=', UserFilter::GRADE_PHD, 2009), -1),
195 array(XDB::format('SELECT DISTINCT ap.uid
196 FROM account_profiles AS ap
197 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
198 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
199 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
200 WHERE pe.grad_year <= {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
202 new UFC_Promo('<=', UserFilter::GRADE_PHD, 2009), -1),
203 array(XDB::format('SELECT DISTINCT ap.uid
204 FROM account_profiles AS ap
205 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
206 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
207 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
208 WHERE pe.grad_year > {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
210 new UFC_Promo('>', UserFilter::GRADE_PHD, 2009), -1),
211 array(XDB::format('SELECT DISTINCT ap.uid
212 FROM account_profiles AS ap
213 INNER JOIN profile_education AS pe ON (pe.pid = ap.pid AND FIND_IN_SET(\'owner\', ap.perms))
214 LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
215 LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
216 WHERE pe.grad_year < {?} AND pee.abbreviation = \'X\' AND pede.abbreviation = {?}',
218 new UFC_Promo('<', UserFilter::GRADE_PHD, 1980), 0),
224 * @dataProvider simpleUserProvider
225 * @param $query A MySQL query
226 * @param $cond The UFC to test
227 * @param $expcount The expected number of results (-1 if that number is unknown)
229 public function testSimpleUser($query, $cond, $expcount = null
)
231 global $globals, $platal;
232 $platal = new Xorg();
234 $query = XDB
::query($query);
235 $count = $query->numRows();
236 if (!is_null($expcount)) {
238 $this->assertNotEquals(0, $count);
240 $this->assertEquals($expcount, $count);
243 $ids = $query->fetchColumn();
244 $this->assertEquals($count, count($ids));
247 $uf = new UserFilter($cond);
248 $this->assertEquals($count, $uf->getTotalUserCount());
249 $got = $uf->getUIDs();
250 $this->assertEquals($count, count($got));
252 $this->assertEquals($ids, $got);
254 $uf = new UserFilter($cond);
255 $got = $uf->getUIDs();
256 $this->assertEquals($count, count($got));
258 $this->assertEquals($ids, $got);
259 $this->assertEquals($count, $uf->getTotalCount());
263 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: