1a97504d771f75d2069b62a2f7c690bc21a3a11b
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 * @dataProvider simpleUserProvider
96 public function testSimpleUser($query, $cond, $expcount = null
)
98 global $globals, $platal;
101 $query = XDB
::query($query);
102 $count = $query->numRows();
103 if (!is_null($expcount)) {
105 $this->assertNotEquals(0, $count);
107 $this->assertEquals($expcount, $count);
110 $ids = $query->fetchColumn();
111 $this->assertEquals($count, count($ids));
114 $uf = new UserFilter($cond);
115 /* XXX: API issue, there's no guarantee getTotalCount()
116 returns the number of users.
118 //$this->assertEquals($count, $uf->getTotalCount());
119 $got = $uf->getUIDs();
120 $this->assertEquals($count, count($got));
122 $this->assertEquals($ids, $got);
124 $uf = new UserFilter($cond);
125 $got = $uf->getUIDs();
126 $this->assertEquals($count, count($got));
128 $this->assertEquals($ids, $got);
129 $this->assertEquals($count, $uf->getTotalCount());
133 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: