self::checkPlatal();
$tests = array();
- $tests[] = array(
+ $tests['id'] = array(
/* UFC_Hrpid
*/
array(self::buildAccountQuery('INNER JOIN account_profiles AS ap2 ON (ap2.uid = a.uid)
/* UFC_Promo
*/
- $tests[] = array(
+ $tests['promo'] = array(
array(self::buildProfileQuery('INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
WHERE pd.promo = {?}', 'X2004'),
new UFC_Promo('=', UserFilter::DISPLAY, 'X2004'), -1),
- array(self::buildProfileQuery('INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
- WHERE pd.promo < {?}', 'X2004'),
- new UFC_Promo('<', UserFilter::DISPLAY, 'X2004'), -1),
- array(self::buildProfileQuery('INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
- WHERE pd.promo > {?}', 'X2004'),
- new UFC_Promo('>', UserFilter::DISPLAY, 'X2004'), -1),
- array(self::buildProfileQuery('INNER JOIN profile_display AS pd ON (pd.pid = p.pid)
- WHERE pd.promo < {?}', 'X1900'),
- new UFC_Promo('<', UserFilter::DISPLAY, 'X1900'), 0),
array(self::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
/* UFC_SchoolId
*/
- $tests[] = array(
+ $tests['schoolid'] = array(
array(self::buildProfileQuery('WHERE p.xorg_id = {?}', 20060076),
new UFC_SchoolId(UFC_SchoolId::Xorg, 20060076), 1),
array(self::buildProfileQuery('WHERE p.ax_id = {?}', 20060062),
$id_HEC = XDB::fetchOneCell('SELECT id
FROM profile_education_enum
WHERE abbreviation = {?}', 'HEC');
- $tests[] = array(
+ $tests['school'] = array(
array(self::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
LEFT JOIN profile_education_enum AS pee ON (pe.eduid = pee.id)
WHERE pee.abbreviation = {?}', 'X'),
$id_DegreePhd = XDB::fetchOneCell('SELECT id
FROM profile_education_degree_enum
WHERE abbreviation = {?}', 'PhD');
- $tests[] = array(
+ $tests['degree'] = array(
array(self::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
LEFT JOIN profile_education_degree_enum AS pede ON (pe.degreeid = pede.id)
WHERE pede.abbreviation = {?}', 'Ing.'),
FROM profile_education_field_enum
WHERE field = {?}', 'Droit');
// FIXME: Replace 0 by -1 in following queries when profile_education will be filled with fieldids
- $tests[] = array(
+ $tests['edufield'] = array(
array(self::buildProfileQuery('INNER JOIN profile_education AS pe ON (pe.pid = p.pid)
LEFT JOIN profile_education_field_enum AS pefe ON (pe.fieldid = pefe.id)
WHERE pefe.field = {?}', 'Informatique'),
$id_Lastname_Marital = DirEnum::getID(DirEnum::NAMETYPES, Profile::LASTNAME . '_' . Profile::VN_MARITAL);
$id_Lastname_Ordinary = DirEnum::getID(DirEnum::NAMETYPES, Profile::LASTNAME . '_' . Profile::VN_ORDINARY);
- $tests[] = array(
+ $tests['name'] = array(
// Lastname
array(self::buildProfileQuery('LEFT JOIN profile_name AS pn ON (pn.pid = p.pid)
WHERE pn.name LIKE {?} AND pn.typeid = {?}', 'BARROIS', $id_Lastname),
/* UFC_NameTokens
*/
- $tests[] = array(
+ $tests['nametoken'] = array(
// !soundex, !exact
array(self::buildProfileQuery('LEFT JOIN search_name AS sn ON (p.pid = sn.pid)
WHERE sn.token LIKE \'xelnor%\''),
/* UFC_Nationality
*/
- $tests[] = array(
+ $tests['nationality'] = array(
array(self::buildProfileQuery('WHERE p.nationality1 IN {?} OR p.nationality2 IN {?} OR p.nationality3 IN {?}', array('BR'), array('BR'), array('BR')),
new UFC_Nationality('BR'), -1),
array(self::buildProfileQuery('WHERE p.nationality1 IN {?} OR p.nationality2 IN {?} OR p.nationality3 IN {?}', array('BR', 'US'), array('BR', 'US'), array('BR', 'US')),
/* UFC_Dead
*/
- $tests[] = array(
+ $tests['dead'] = array(
array(self::buildProfileQuery('WHERE p.deathdate IS NOT NULL'),
new UFC_Dead(), -1),
array(self::buildProfileQuery('WHERE p.deathdate IS NOT NULL AND p.deathdate > {?}', '2008-01-01'),
new UFC_Dead('>', '2008-01-01'), -1),
- array(self::buildProfileQuery('WHERE p.deathdate IS NOT NULL AND p.deathdate > {?}', '2008-01-01'),
- new UFC_Dead('>', new DateTime('2008-01-01')), -1),
- array(self::buildProfileQuery('WHERE p.deathdate IS NOT NULL AND p.deathdate > {?}', '2008-01-01'),
- new UFC_Dead('>', strftime('2008-01-01')), -1),
array(self::buildProfileQuery('WHERE p.deathdate IS NOT NULL AND p.deathdate < {?}', '1600-01-01'),
new UFC_Dead('<', '1600-01-01'), 0),
- array(self::buildProfileQuery('WHERE p.deathdate IS NOT NULL AND p.deathdate < {?}', '1600-01-01'),
- new UFC_Dead('<', new DateTime('1600-01-01')), 0),
array(self::buildProfileQuery('WHERE p.deathdate IS NOT NULL AND p.deathdate > {?}', date('Y-m-d')),
new UFC_Dead('>', 'now'), 0),
- array(self::buildProfileQuery('WHERE p.deathdate IS NOT NULL AND p.deathdate > {?}', date('Y-m-d')),
- new UFC_Dead('>', new DateTime()), 0),
- array(self::buildProfileQuery('WHERE p.deathdate IS NOT NULL AND p.deathdate > {?}', date('Y-m-d')),
- new UFC_Dead('>', time()), 0),
+ );
+
+ /* UFC_Registered
+ */
+ $tests['register'] = array(
+ array(self::buildAccountQuery('WHERE a.uid IS NOT NULL AND a.state = \'active\''),
+ new UFC_Registered(true), -1),
+ array(self::buildAccountQuery('WHERE a.uid IS NOT NULL AND a.state != \'pending\''),
+ new UFC_Registered(), -1),
+ array(self::buildAccountQuery('WHERE a.uid IS NOT NULL AND a.state = \'active\' AND a.registration_date != \'0000-00-00 00:00:00\' AND a.registration_date > {?}', '2008-01-01'),
+ new UFC_Registered(true, '>', '2008-01-01'), -1),
+ array(self::buildAccountQuery('WHERE a.uid IS NOT NULL AND a.state != \'pending\' AND a.registration_date != \'0000-00-00 00:00:00\' AND a.registration_date > {?}', '2008-01-01'),
+ new UFC_Registered(false, '>', '2008-01-01'), -1),
+ array(self::buildAccountQuery('WHERE a.uid IS NOT NULL AND a.state = \'active\' AND a.registration_date != \'0000-00-00 00:00:00\' AND a.registration_date < {?}', '1700-01-01'),
+ new UFC_Registered(true, '<', '1700-01-01'), 0),
+ array(self::buildAccountQuery('WHERE a.uid IS NOT NULL AND a.state != \'pending\' AND a.registration_date != \'0000-00-00 00:00:00\' AND a.registration_date < {?}', '1700-01-01'),
+ new UFC_Registered(false, '<', '1700-01-01'), 0),
+ array(self::buildAccountQuery('WHERE a.uid IS NOT NULL AND a.state = \'active\' AND a.registration_date != \'0000-00-00 00:00:00\' AND a.registration_date > {?}', date('Y-m-d')),
+ new UFC_Registered(true, '>', 'now'), 0),
+ array(self::buildAccountQuery('WHERE a.uid IS NOT NULL AND a.state != \'pending\' AND a.registration_date != \'0000-00-00 00:00:00\' AND a.registration_date > {?}', date('Y-m-d')),
+ new UFC_Registered(false, '>', 'now'), 0),
);
$testcases = array();
- foreach ($tests as $t) {
- $testcases = array_merge($testcases, $t);
+ foreach ($tests as $name => $t) {
+ foreach ($t as $id => $case) {
+ $testcases[$name . '-' . $id] = $case;
+ }
}
return $testcases;
}
$this->assertEquals($count, $uf->getTotalProfileCount());
}
+
+ public static function sortProvider()
+ {
+ return array(
+ array(self::buildAccountQuery('ORDER BY a.uid'), new UFO_Uid()),
+ array(self::buildAccountQuery('ORDER BY a.hruid'), new UFO_Hruid()),
+ array(self::buildAccountQuery('ORDER BY a.uid DESC'), new UFO_Uid(true)),
+ array(self::buildAccountQuery('ORDER BY a.hruid DESC'), new UFO_Hruid(true)),
+ array(self::buildProfileQuery('ORDER BY p.pid'), new UFO_Pid()),
+ array(self::buildProfileQuery('ORDER BY p.hrpid'), new UFO_Hrpid()),
+ array(self::buildProfileQuery('ORDER BY p.pid DESC'), new UFO_Pid(true)),
+ array(self::buildProfileQuery('ORDER BY p.hrpid DESC'), new UFO_Hrpid(true)),
+ array(self::buildProfileQuery('WHERE p.deathdate IS NOT NULL
+ ORDER BY p.deathdate, p.pid'),
+ array(new UFO_Death(), new UFO_Pid()), new UFC_Dead()),
+ array(self::buildProfileQuery('WHERE p.deathdate IS NOT NULL
+ ORDER BY p.deathdate DESC, p.pid'),
+ array(new UFO_Death(true), new UFO_Pid()), new UFC_Dead()),
+ array(self::buildProfileQuery('ORDER BY p.next_birthday, p.pid'),
+ array(new UFO_Birthday(), new UFO_Pid())),
+ array(self::buildProfileQuery('ORDER BY p.next_birthday DESC, p.pid'),
+ array(new UFO_Birthday(true), new UFO_Pid())),
+ array(self::buildProfileQuery('ORDER BY p.last_change, p.pid'),
+ array(new UFO_ProfileUpdate(), new UFO_Pid())),
+ array(self::buildProfileQuery('ORDER BY p.last_change DESC, p.pid'),
+ array(new UFO_ProfileUpdate(true), new UFO_Pid())),
+ array(self::buildAccountQuery('ORDER BY a.registration_date, a.uid'),
+ array(new UFO_Registration(), new UFO_Uid())),
+ array(self::buildAccountQuery('ORDER BY a.registration_date DESC, a.uid'),
+ array(new UFO_Registration(true), new UFO_Uid())),
+ );
+ }
+
+ /**
+ * @dataProvider sortProvider
+ */
+ public function testUserSortAndLimits($query, $sort, $cond = null)
+ {
+ self::checkPlatal();
+
+ $query = XDB::query($query[0]);
+ $count = $query->numRows();
+ $ids = $query->fetchColumn();
+ $this->assertSame($count, count($ids));
+
+ if ($cond == null ) {
+ $cond = new PFC_True();
+ }
+ $uf = new UserFilter($cond, $sort);
+ for ($i = 0 ; $i < $count ; $i += 7987) {
+ $got = $uf->getUIDs(new PlLimit(100, $i));
+ $this->assertSame($count, $uf->getTotalUserCount());
+ $part = array_slice($ids, $i, 100);
+ $this->assertSame($part, $got);
+ }
+ }
+
+ /**
+ * @dataProvider sortProvider
+ */
+ public function testProfileSortAndLimits($query, $sort, $cond = null)
+ {
+ self::checkPlatal();
+
+ $query = XDB::query($query[1]);
+ $count = $query->numRows();
+ $ids = $query->fetchColumn();
+ $this->assertSame($count, count($ids));
+
+ if ($cond == null ) {
+ $cond = new PFC_True();
+ }
+ $uf = new UserFilter($cond, $sort);
+ for ($i = 0 ; $i < $count ; $i += 7987) {
+ $got = $uf->getPIDs(new PlLimit(100, $i));
+ $this->assertSame($count, $uf->getTotalProfileCount());
+ $part = array_slice($ids, $i, 100);
+ $this->assertSame($part, $got);
+ }
+ }
}
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: