+ $this->assertEquals($count, $uf->getTotalUserCount());
+ }
+
+ /**
+ * @dataProvider simpleUserProvider
+ */
+ public function testSimpleProfile($query, $cond, $expcount = null)
+ {
+ /*
+ * @param $query A pair MySQL query (one for user selector, one for profile selector)
+ * @param $cond The UFC to test
+ * @param $expcount The expected number of results (-1 if that number is unknown)
+ */
+
+ $query = $query[1];
+
+ self::checkPlatal();
+
+ $query = XDB::query($query);
+ $count = $query->numRows();
+ if (!is_null($expcount)) {
+ if ($expcount < 0) {
+ $this->assertNotEquals(0, $count);
+ } else {
+ $this->assertEquals($expcount, $count);
+ }
+ }
+ $ids = $query->fetchColumn();
+ $this->assertEquals($count, count($ids));
+ sort($ids);
+
+ $uf = new UserFilter($cond);
+ $this->assertEquals($count, $uf->getTotalProfileCount());
+ $got = $uf->getPIDs();
+ $this->assertEquals($count, count($got));
+ sort($got);
+ $this->assertEquals($ids, $got);
+
+ $uf = new UserFilter($cond);
+ $got = $uf->getPIDs();
+ $this->assertEquals($count, count($got));
+ sort($got);
+ $this->assertEquals($ids, $got);
+ $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);
+ }