From c6442ce64072fd5080d1b2f3a3d595c62ccdc59c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 26 Mar 2010 21:02:56 +0100 Subject: [feature/dbal-tests] Tests for $db->sql_query_limit() --- tests/dbal/dbal.php | 44 ++++++++++++++++++++++++++++++++++++- tests/dbal/fixtures/three_users.xml | 19 ++++++++++++++++ tests/dbal/fixtures/two_users.xml | 15 ------------- 3 files changed, 62 insertions(+), 16 deletions(-) create mode 100644 tests/dbal/fixtures/three_users.xml delete mode 100644 tests/dbal/fixtures/two_users.xml diff --git a/tests/dbal/dbal.php b/tests/dbal/dbal.php index a77279105f..72e399adbe 100644 --- a/tests/dbal/dbal.php +++ b/tests/dbal/dbal.php @@ -14,7 +14,7 @@ class phpbb_dbal_test extends phpbb_database_test_case { public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/two_users.xml'); + return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/three_users.xml'); } public function test_select_row() @@ -39,5 +39,47 @@ class phpbb_dbal_test extends phpbb_database_test_case $this->assertEquals('foobar', $db->sql_fetchfield('username_clean')); } + + public static function query_limit_data() + { + return array( + array(0, 0, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'), + array('username_clean' => 'bertie'))), + array(0, 1, array(array('username_clean' => 'foobar'), + array('username_clean' => 'bertie'))), + array(1, 0, array(array('username_clean' => 'barfoo'))), + array(1, 1, array(array('username_clean' => 'foobar'))), + array(1, 2, array(array('username_clean' => 'bertie'))), + array(2, 0, array(array('username_clean' => 'barfoo'), + array('username_clean' => 'foobar'))), + array(2, 2, array(array('username_clean' => 'bertie'))), + array(2, 5, array()), + array(10, 1, array(array('username_clean' => 'foobar'), + array('username_clean' => 'bertie'))), + array(10, 5, array()), + ); + } + + /** + * @dataProvider query_limit_data + */ + public function test_query_limit($total, $offset, $expected) + { + $db = $this->new_dbal(); + + $result = $db->sql_query_limit('SELECT username_clean + FROM phpbb_users + ORDER BY user_id', $total, $offset); + + $ary = array(); + while ($row = $db->sql_fetchrow($result)) + { + $ary[] = $row; + } + $db->sql_freeresult($result); + + $this->assertEquals($expected, $ary); + } } diff --git a/tests/dbal/fixtures/three_users.xml b/tests/dbal/fixtures/three_users.xml new file mode 100644 index 0000000000..fff26d2b3f --- /dev/null +++ b/tests/dbal/fixtures/three_users.xml @@ -0,0 +1,19 @@ + + + + user_id + username_clean + + 1 + barfoo + + + 2 + foobar + + + 3 + bertie + +
+
diff --git a/tests/dbal/fixtures/two_users.xml b/tests/dbal/fixtures/two_users.xml deleted file mode 100644 index 255f061bd4..0000000000 --- a/tests/dbal/fixtures/two_users.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - user_id - username_clean - - 1 - barfoo - - - 2 - foobar - -
-
-- cgit v1.2.1