Add a base for sort/limits testing.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 9 May 2010 14:53:06 +0000 (16:53 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 9 May 2010 14:53:06 +0000 (16:53 +0200)
Also in this commit:
 * Add UFO_(Hr)?[up]id.
 * Add missing requireProfile/Accounts in UFOs.
 * Disallow ordering comparions on displayed promos.

Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/userfilter.php
ut/userfiltertest.php

index 0e178d9..0b57794 100644 (file)
@@ -155,6 +155,9 @@ class UFC_Promo implements UserFilterCondition
         if ($this->grade != UserFilter::DISPLAY) {
             UserFilter::assertGrade($this->grade);
         }
+        if ($this->grade == UserFilter::DISPLAY && $this->comparison != '=') {
+            Platal::page()->killError('Comparison ' . $this->comparison . ' not allowed on displaid promo');
+        }
     }
 
     public function buildCondition(PlFilter &$uf)
@@ -1430,6 +1433,7 @@ class UFO_Registration extends UserFilterOrder
 {
     protected function getSortTokens(PlFilter &$uf)
     {
+        $uf->requireAccounts();
         return 'a.registration_date';
     }
 }
@@ -1442,6 +1446,7 @@ class UFO_Birthday extends UserFilterOrder
 {
     protected function getSortTokens(PlFilter &$uf)
     {
+        $uf->requireProfiles();
         return 'p.next_birthday';
     }
 }
@@ -1454,6 +1459,7 @@ class UFO_ProfileUpdate extends UserFilterOrder
 {
     protected function getSortTokens(PlFilter &$uf)
     {
+        $uf->requireProfiles();
         return 'p.last_change';
     }
 }
@@ -1466,11 +1472,64 @@ class UFO_Death extends UserFilterOrder
 {
     protected function getSortTokens(PlFilter &$uf)
     {
+        $uf->requireProfiles();
         return 'p.deathdate';
     }
 }
 // }}}
 
+// {{{ class UFO_Uid
+/** Sorts users based on their uid
+ */
+class UFO_Uid extends UserFilterOrder
+{
+    protected function getSortTokens(PlFilter &$uf)
+    {
+        $uf->requireAccounts();
+        return 'a.uid';
+    }
+}
+// }}
+
+// {{{ class UFO_Hruid
+/** Sorts users based on their hruid
+ */
+class UFO_Hruid extends UserFilterOrder
+{
+    protected function getSortTokens(PlFilter &$uf)
+    {
+        $uf->requireAccounts();
+        return 'a.hruid';
+    }
+}
+// }}}
+
+// {{{ class UFO_Pid
+/** Sorts users based on their pid
+ */
+class UFO_Pid extends UserFilterOrder
+{
+    protected function getSortTokens(PlFilter &$uf)
+    {
+        $uf->requireProfiles();
+        return 'p.pid';
+    }
+}
+// }}
+
+// {{{ class UFO_Hrpid
+/** Sorts users based on their hrpid
+ */
+class UFO_Hrpid extends UserFilterOrder
+{
+    protected function getSortTokens(PlFilter &$uf)
+    {
+        $uf->requireProfiles();
+        return 'p.hrpid';
+    }
+}
+// }}}
+
 
 /***********************************
   *********************************
index e953ce5..dd608fc 100644 (file)
@@ -114,15 +114,6 @@ class UserFilterTest extends PlTestCase
             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)
@@ -583,6 +574,74 @@ class UserFilterTest extends PlTestCase
         $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()),
+        );
+    }
+
+    /**
+     * @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: