Moving to GitHub.
[platal.git] / ut / userfiltertest.php
index dd608fc..802b26b 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2014 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -35,7 +35,7 @@ class UserFilterTest extends PlTestCase
     private static function buildAccountQuery()
     {
         $args = func_get_args();
-        $joinsAndWhere = XDB::_prepare($args);
+        $joinsAndWhere = XDB::prepare($args);
         return array('SELECT  DISTINCT a.uid
                         FROM  accounts AS a
                           ' . $joinsAndWhere,
@@ -49,7 +49,7 @@ class UserFilterTest extends PlTestCase
     private static function buildProfileQuery()
     {
         $args = func_get_args();
-        $joinsAndWhere = XDB::_prepare($args);
+        $joinsAndWhere = XDB::prepare($args);
         return array('SELECT  DISTINCT a.uid
                         FROM  accounts AS a
                   INNER JOIN  account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET(\'owner\', perms))
@@ -65,7 +65,7 @@ class UserFilterTest extends PlTestCase
         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)
@@ -110,7 +110,7 @@ class UserFilterTest extends PlTestCase
 
             /* 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),
@@ -211,7 +211,7 @@ class UserFilterTest extends PlTestCase
 
             /* 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),
@@ -235,7 +235,7 @@ class UserFilterTest extends PlTestCase
         $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'),
@@ -254,7 +254,7 @@ class UserFilterTest extends PlTestCase
         $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.'),
@@ -273,7 +273,7 @@ class UserFilterTest extends PlTestCase
                                               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'),
@@ -292,7 +292,7 @@ class UserFilterTest extends PlTestCase
         $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),
@@ -386,7 +386,7 @@ class UserFilterTest extends PlTestCase
 
             /* 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%\''),
@@ -424,21 +424,18 @@ class UserFilterTest extends PlTestCase
             // soundex, !exact
             array(self::buildProfileQuery('LEFT JOIN  search_name AS sn ON (p.pid = sn.pid)
                                                WHERE  sn.soundex = \'XLNO\''),
-                new UFC_NameTokens('XLNO', array(), true), -1),
+                new UFC_NameTokens('xelnor', array(), true), -1),
             array(self::buildProfileQuery('LEFT JOIN  search_name AS sn ON (p.pid = sn.pid)
                                                WHERE  sn.soundex IN (\'XLNO\', \'BROS\')'),
-                new UFC_NameTokens(array('XLNO', 'BROS'), array(), true), -1),
-            array(self::buildProfileQuery('LEFT JOIN  search_name AS sn ON (p.pid = sn.pid)
-                                               WHERE  sn.soundex = \'ZZZZZZ\''),
-                new UFC_NameTokens('ZZZZZZ', array(), true), 0),
+                new UFC_NameTokens(array('xelnor', 'barrois'), array(), true), -1),
             array(self::buildProfileQuery('LEFT JOIN  search_name AS sn ON (p.pid = sn.pid)
                                                WHERE  sn.soundex = \'BROS\' AND FIND_IN_SET(\'public\', sn.flags)'),
-                new UFC_NameTokens('BROS', UFC_NameTokens::FLAG_PUBLIC, true), -1),
+                new UFC_NameTokens('barrois', UFC_NameTokens::FLAG_PUBLIC, true), -1),
         );
 
         /* 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')),
@@ -449,7 +446,7 @@ class UserFilterTest extends PlTestCase
 
         /* 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'),
@@ -462,7 +459,7 @@ class UserFilterTest extends PlTestCase
 
         /* UFC_Registered
          */
-        $tests[] = array(
+        $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\''),
@@ -482,8 +479,10 @@ class UserFilterTest extends PlTestCase
         );
 
         $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;
     }
@@ -592,6 +591,18 @@ class UserFilterTest extends PlTestCase
             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())),
         );
     }
 
@@ -644,5 +655,5 @@ class UserFilterTest extends PlTestCase
     }
 }
 
-// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8:
 ?>