diff --git a/tests/databases/firebird-qb.php b/tests/databases/firebird-qb.php
index f0345b3..9c8a6be 100644
--- a/tests/databases/firebird-qb.php
+++ b/tests/databases/firebird-qb.php
@@ -15,7 +15,7 @@
/**
* Firebird Query Builder Tests
*/
-class FirebirdQBTest extends UnitTestCase {
+class FirebirdQBTest extends QBTest {
function __construct()
{
@@ -32,7 +32,7 @@ class FirebirdQBTest extends UnitTestCase {
$params->pass = 'masterkey';
$this->db = new Query_Builder($params);
- echo '
Firebird Queries
';
+ // echo '
Firebird Queries
';
}
function TestGet()
@@ -119,7 +119,7 @@ class FirebirdQBTest extends UnitTestCase {
$this->assertIsA($query, 'Firebird_Result');
}
- function TestOrderByRand()
+ function TestOrderByRandom()
{
$query = $this->db->select('id, key as k, val')
->from('create_test')
@@ -144,6 +144,11 @@ class FirebirdQBTest extends UnitTestCase {
$this->assertIsA($query, 'Firebird_Result');
}
+ function TestGroupBy()
+ {
+
+ }
+
/*function TestGroupBy()
{
$query = $this->db->select('id, key as k, val')
diff --git a/tests/databases/firebird.php b/tests/databases/firebird.php
index 8b0c166..9697d1a 100644
--- a/tests/databases/firebird.php
+++ b/tests/databases/firebird.php
@@ -17,18 +17,7 @@
*
* @extends UnitTestCase
*/
-class FirebirdTest extends UnitTestCase {
-
- /**
- * __construct function.
- *
- * @access public
- * @return void
- */
- function __construct()
- {
- parent::__construct();
- }
+class FirebirdTest extends DBTest {
function setUp()
{
diff --git a/tests/databases/mysql-qb.php b/tests/databases/mysql-qb.php
index ff31744..8c444ee 100644
--- a/tests/databases/mysql-qb.php
+++ b/tests/databases/mysql-qb.php
@@ -12,7 +12,7 @@
// --------------------------------------------------------------------------
-class MySQLQBTest extends UnitTestCase {
+class MySQLQBTest extends QBTest {
function __construct()
{
@@ -27,8 +27,7 @@ class MySQLQBTest extends UnitTestCase {
$this->db = new Query_Builder($params);
- echo '
MySQL Queries
';
-
+ // echo '
MySQL Queries
';
}
}
@@ -37,208 +36,4 @@ class MySQLQBTest extends UnitTestCase {
{
$this->assertTrue(in_array('mysql', pdo_drivers()));
}
-
- function TestGet()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->get('create_test');
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestGetLimit()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->get('create_test', 2);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestGetLimitSkip()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->get('create_test', 2, 1);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectWhereGet()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->where('id >', 1)
- ->where('id <', 900)
- ->get('create_test', 2, 1);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectWhereGet2()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->where('id !=', 1)
- ->get('create_test', 2, 1);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectGet()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->get('create_test', 2, 1);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectFromGet()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->from('create_test ct')
- ->where('id >', 1)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectFromLimitGet()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->from('create_test ct')
- ->where('id >', 1)
- ->limit(3)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestOrderBy()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->from('create_test')
- ->where('id >', 0)
- ->where('id <', 9000)
- ->order_by('id', 'DESC')
- ->order_by('k', 'ASC')
- ->limit(5,2)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestOrderByRandom()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->from('create_test')
- ->where('id >', 0)
- ->where('id <', 9000)
- ->order_by('id', 'rand')
- ->limit(5,2)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestGroupBy()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->from('create_test')
- ->where('id >', 0)
- ->where('id <', 9000)
- ->group_by('k')
- ->group_by('val')
- ->order_by('id', 'DESC')
- ->order_by('k', 'ASC')
- ->limit(5,2)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestOrWhere()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->from('create_test')
- ->where(' id ', 1)
- ->or_where('key >', 0)
- ->limit(2, 1)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestLike()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->from('create_test')
- ->like('key', 'og')
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestJoin()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->from('create_test')
- ->join('create_join cj', 'cj.id = create_test.id')
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestInsert()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->set('id', 4)
- ->set('key', 4)
- ->set('val', 5)
- ->insert('create_test');
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestUpdate()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->set('id', 4)
- ->set('key', 'gogle')
- ->set('val', 'non-word')
- ->where('id', 4)
- ->update('create_test');
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestDelete()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->where('id', 4)->delete('create_test');
-
- $this->assertIsA($query, 'PDOStatement');
- }
}
\ No newline at end of file
diff --git a/tests/databases/mysql.php b/tests/databases/mysql.php
index b34593a..923258c 100644
--- a/tests/databases/mysql.php
+++ b/tests/databases/mysql.php
@@ -17,12 +17,7 @@
*
* @extends UnitTestCase
*/
-class MySQLTest extends UnitTestCase {
-
- function __construct()
- {
- parent::__construct();
- }
+class MySQLTest extends DBTest {
function setUp()
{
@@ -36,11 +31,6 @@ class MySQLTest extends UnitTestCase {
}
}
- function tearDown()
- {
- unset($this->db);
- }
-
function TestExists()
{
$this->assertTrue(in_array('mysql', pdo_drivers()));
@@ -52,32 +42,6 @@ class MySQLTest extends UnitTestCase {
$this->assertIsA($this->db, 'MySQL');
}
-
- function TestGetTables()
- {
- if (empty($this->db)) return;
-
- $tables = $this->db->get_tables();
-
- $this->assertTrue(is_array($tables));
- }
-
- function TestGetSystemTables()
- {
- if (empty($this->db)) return;
-
- $tables = $this->db->get_system_tables();
-
- $this->assertTrue(is_array($tables));
- }
-
- function TestCreateTransaction()
- {
- if (empty($this->db)) return;
-
- $res = $this->db->beginTransaction();
- $this->assertTrue($res);
- }
function TestCreateTable()
{
@@ -116,67 +80,5 @@ class MySQLTest extends UnitTestCase {
$this->assertTrue(in_array('create_test', $dbs));
}
-
- /*function TestTruncate()
- {
- if (empty($this->db)) return;
-
- $this->db->truncate('create_test');
- $this->assertIsA($this->db->affected_rows(), 'int');
- }*/
-
- function TestPreparedStatements()
- {
- if (empty($this->db)) return;
-
- $sql = <<db->prepare_query($sql, array(1,"boogers", "Gross"));
-
- $statement->execute();
-
- }
-
- function TestPrepareExecute()
- {
- if (empty($this->db)) return;
-
- $sql = <<db->prepare_execute($sql, array(
- 2, "works", 'also?'
- ));
-
- }
-
- function TestCommitTransaction()
- {
- if (empty($this->db)) return;
-
- $res = $this->db->beginTransaction();
-
- $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
- $this->db->query($sql);
-
- $res = $this->db->commit();
- $this->assertTrue($res);
- }
-
- function TestRollbackTransaction()
- {
- if (empty($this->db)) return;
-
- $res = $this->db->beginTransaction();
-
- $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
- $this->db->query($sql);
-
- $res = $this->db->rollback();
- $this->assertTrue($res);
- }
-
}
+
diff --git a/tests/databases/odbc-qb.php b/tests/databases/odbc-qb.php
index f95d788..26022da 100644
--- a/tests/databases/odbc-qb.php
+++ b/tests/databases/odbc-qb.php
@@ -12,12 +12,7 @@
// --------------------------------------------------------------------------
-class ODBCQBTest extends UnitTestCase {
-
- function __construct()
- {
-
- }
+class ODBCQBTest extends QBTest {
function TestExists()
{
diff --git a/tests/databases/odbc.php b/tests/databases/odbc.php
index 6f342d0..1ad4072 100644
--- a/tests/databases/odbc.php
+++ b/tests/databases/odbc.php
@@ -18,11 +18,6 @@
* @extends UnitTestCase
*/
class ODBCTest extends UnitTestCase {
-
- function __construct()
- {
-
- }
function TestExists()
{
diff --git a/tests/databases/pgsql-qb.php b/tests/databases/pgsql-qb.php
index f9fb634..7ccd13b 100644
--- a/tests/databases/pgsql-qb.php
+++ b/tests/databases/pgsql-qb.php
@@ -12,7 +12,7 @@
// --------------------------------------------------------------------------
-class PgSQLQBTest extends UnitTestCase {
+class PgSQLQBTest extends QBTest {
function __construct()
{
@@ -27,219 +27,13 @@ class PgSQLQBTest extends UnitTestCase {
$this->db = new Query_Builder($params);
- echo '
Postgres Queries
';
+ // echo '
Postgres Queries
';
}
}
-
function TestExists()
{
$this->assertTrue(in_array('pgsql', pdo_drivers()));
}
-
- function TestGet()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->get('create_test');
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestGetLimit()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->get('create_test', 2);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestGetLimitSkip()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->get('create_test', 2, 1);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectWhereGet()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->where('id >', 1)
- ->where('id <', 900)
- ->get('create_test', 2, 1);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectWhereGet2()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->where('id !=', 1)
- ->get('create_test', 2, 1);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectGet()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->get('create_test', 2, 1);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectFromGet()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->from('create_test ct')
- ->where('id >', 1)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectFromLimitGet()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->from('create_test ct')
- ->where('id >', 1)
- ->limit(3)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestOrderBy()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->from('create_test')
- ->where('id >', 0)
- ->where('id <', 9000)
- ->order_by('id', 'DESC')
- ->order_by('k', 'ASC')
- ->limit(5,2)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestOrderByRandom()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->from('create_test')
- ->where('id >', 0)
- ->where('id <', 9000)
- ->order_by('id', 'rand')
- ->limit(5,2)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestGroupBy()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->from('create_test')
- ->where('id >', 0)
- ->where('id <', 9000)
- ->group_by('k')
- ->group_by('val')
- ->order_by('id', 'DESC')
- ->order_by('k', 'ASC')
- ->limit(5,2)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestOrWhere()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->select('id, key as k, val')
- ->from('create_test')
- ->where(' id ', 1)
- ->or_where('key >', 0)
- ->limit(2, 1)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestLike()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->from('create_test')
- ->like('key', 'og')
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestJoin()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->from('create_test')
- ->join('create_join cj', 'cj.id = create_test.id')
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestInsert()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->set('id', 4)
- ->set('key', 4)
- ->set('val', 5)
- ->insert('create_test');
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestUpdate()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->set('id', 4)
- ->set('key', 'gogle')
- ->set('val', 'non-word')
- ->where('id', 4)
- ->update('create_test');
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestDelete()
- {
- if (empty($this->db)) return;
-
- $query = $this->db->where('id', 4)->delete('create_test');
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
}
\ No newline at end of file
diff --git a/tests/databases/pgsql.php b/tests/databases/pgsql.php
index 701e83b..8acae01 100644
--- a/tests/databases/pgsql.php
+++ b/tests/databases/pgsql.php
@@ -17,7 +17,7 @@
*
* @extends UnitTestCase
*/
-class PgTest extends UnitTestCase {
+class PgTest extends DBTest {
function __construct()
{
@@ -36,11 +36,6 @@ class PgTest extends UnitTestCase {
}
}
- function tearDown()
- {
- unset($this->db);
- }
-
function TestExists()
{
$this->assertTrue(in_array('pgsql', pdo_drivers()));
@@ -52,32 +47,6 @@ class PgTest extends UnitTestCase {
$this->assertIsA($this->db, 'PgSQL');
}
-
- function TestGetTables()
- {
- if (empty($this->db)) return;
-
- $tables = $this->db->get_tables();
-
- $this->assertTrue(is_array($tables));
- }
-
- function TestGetSystemTables()
- {
- if (empty($this->db)) return;
-
- $tables = $this->db->get_system_tables();
-
- $this->assertTrue(is_array($tables));
- }
-
- function TestCreateTransaction()
- {
- if (empty($this->db)) return;
-
- $res = $this->db->beginTransaction();
- $this->assertTrue($res);
- }
/*function TestCreateTable()
{
@@ -118,67 +87,4 @@ class PgTest extends UnitTestCase {
$this->assertTrue(in_array('create_test', $dbs));
}*/
-
- /*function TestTruncate()
- {
- if (empty($this->db)) return;
-
- $this->db->truncate('create_test');
- $this->assertIsA($this->db->affected_rows(), 'int');
- }*/
-
- function TestPreparedStatements()
- {
- if (empty($this->db)) return;
-
- $sql = <<db->prepare_query($sql, array(1,"boogers", "Gross"));
-
- $statement->execute();
-
- }
-
- function TestPrepareExecute()
- {
- if (empty($this->db)) return;
-
- $sql = <<db->prepare_execute($sql, array(
- 2, "works", 'also?'
- ));
-
- }
-
- function TestCommitTransaction()
- {
- if (empty($this->db)) return;
-
- $res = $this->db->beginTransaction();
-
- $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
- $this->db->query($sql);
-
- $res = $this->db->commit();
- $this->assertTrue($res);
- }
-
- function TestRollbackTransaction()
- {
- if (empty($this->db)) return;
-
- $res = $this->db->beginTransaction();
-
- $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
- $this->db->query($sql);
-
- $res = $this->db->rollback();
- $this->assertTrue($res);
- }
-
}
\ No newline at end of file
diff --git a/tests/databases/sqlite-qb.php b/tests/databases/sqlite-qb.php
index 5798244..f262666 100644
--- a/tests/databases/sqlite-qb.php
+++ b/tests/databases/sqlite-qb.php
@@ -15,7 +15,7 @@
/**
* Class for testing Query Builder with SQLite
*/
- class SQLiteQBTest extends UnitTestCase {
+ class SQLiteQBTest extends QBTest {
function __construct()
{
@@ -28,176 +28,6 @@
$params->host = 'localhost';
$this->db = new Query_Builder($params);
- echo '
SQLite Queries
';
+ // echo '
SQLite Queries
';
}
-
- function TestGet()
- {
- $query = $this->db->get('create_test ct');
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestGetLimit()
- {
- $query = $this->db->get('create_test', 2);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestGetLimitSkip()
- {
- $query = $this->db->get('create_test', 2, 1);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectWhereGet()
- {
- $query = $this->db->select('id, key as k, val')
- ->where('id >', 1)
- ->where('id <', 900)
- ->get('create_test', 2, 1);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectWhereGet2()
- {
- $query = $this->db->select('id, key as k, val')
- ->where('id !=', 1)
- ->get('create_test', 2, 1);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectGet()
- {
- $query = $this->db->select('id, key as k, val')
- ->get('create_test', 2, 1);
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectFromGet()
- {
- $query = $this->db->select('id, key as k, val')
- ->from('create_test ct')
- ->where('id >', 1)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestSelectFromLimitGet()
- {
- $query = $this->db->select('id, key as k, val')
- ->from('create_test ct')
- ->where('id >', 1)
- ->limit(3)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestOrderBy()
- {
- $query = $this->db->select('id, key as k, val')
- ->from('create_test')
- ->where('id >', 0)
- ->where('id <', 9000)
- ->order_by('id', 'DESC')
- ->order_by('k', 'ASC')
- ->limit(5,2)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestOrderByRandom()
- {
- $query = $this->db->select('id, key as k, val')
- ->from('create_test')
- ->where('id >', 0)
- ->where('id <', 9000)
- ->order_by('id', 'rand')
- ->limit(5,2)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestGroupBy()
- {
- $query = $this->db->select('id, key as k, val')
- ->from('create_test')
- ->where('id >', 0)
- ->where('id <', 9000)
- ->group_by('k')
- ->group_by('val')
- ->order_by('id', 'DESC')
- ->order_by('k', 'ASC')
- ->limit(5,2)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestOrWhere()
- {
- $query = $this->db->select('id, key as k, val')
- ->from('create_test')
- ->where(' id ', 1)
- ->or_where('key >', 0)
- ->limit(2, 1)
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestLike()
- {
- $query = $this->db->from('create_test')
- ->like('key', 'og')
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestJoin()
- {
- $query = $this->db->from('create_test')
- ->join('create_join cj', 'cj.id = create_test.id')
- ->get();
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestInsert()
- {
- $query = $this->db->set('id', 4)
- ->set('key', 4)
- ->set('val', 5)
- ->insert('create_test');
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestUpdate()
- {
- $query = $this->db->set('id', 4)
- ->set('key', 'gogle')
- ->set('val', 'non-word')
- ->where('id', 4)
- ->update('create_test');
-
- $this->assertIsA($query, 'PDOStatement');
- }
-
- function TestDelete()
- {
- $query = $this->db->where('id', 4)->delete('create_test');
-
- $this->assertIsA($query, 'PDOStatement');
- }
}
\ No newline at end of file
diff --git a/tests/index.php b/tests/index.php
index ac4095a..672abae 100644
--- a/tests/index.php
+++ b/tests/index.php
@@ -23,6 +23,8 @@ define('DS', DIRECTORY_SEPARATOR);
// it has to be set in your php path, or put in the tests folder
require_once('simpletest/autorun.php');
+// Require base testing classes
+require_once(TEST_DIR.'/parent.php');
// Bulk loading wrapper workaround for PHP < 5.4
function do_include($path)
diff --git a/tests/parent.php b/tests/parent.php
new file mode 100644
index 0000000..792d129
--- /dev/null
+++ b/tests/parent.php
@@ -0,0 +1,308 @@
+db);
+ }
+
+ function TestGetTables()
+ {
+ $tables = $this->db->get_tables();
+ $this->assertTrue(is_array($tables));
+ }
+
+ function TestGetSystemTables()
+ {
+ $tables = $this->db->get_system_tables();
+
+ $this->assertTrue(is_array($tables));
+ }
+
+ function TestCreateTransaction()
+ {
+ $res = $this->db->beginTransaction();
+ $this->assertTrue($res);
+ }
+
+ function TestPreparedStatements()
+ {
+ $sql = <<db->prepare_query($sql, array(1,"boogers", "Gross"));
+
+ $statement->execute();
+
+ }
+
+ function TestPrepareExecute()
+ {
+ $sql = <<db->prepare_execute($sql, array(
+ 2, "works", 'also?'
+ ));
+
+ }
+
+ function TestCommitTransaction()
+ {
+ $res = $this->db->beginTransaction();
+
+ $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
+ $this->db->query($sql);
+
+ $res = $this->db->commit();
+ $this->assertTrue($res);
+ }
+
+ function TestRollbackTransaction()
+ {
+ $res = $this->db->beginTransaction();
+
+ $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
+ $this->db->query($sql);
+
+ $res = $this->db->rollback();
+ $this->assertTrue($res);
+ }
+}
+
+// --------------------------------------------------------------------------
+
+/**
+ * Query builder parent test class
+ */
+abstract class QBTest extends UnitTestCase {
+
+ function TestGet()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->get('create_test');
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestGetLimit()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->get('create_test', 2);
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestGetLimitSkip()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->get('create_test', 2, 1);
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestSelectWhereGet()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->select('id, key as k, val')
+ ->where('id >', 1)
+ ->where('id <', 900)
+ ->get('create_test', 2, 1);
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestSelectWhereGet2()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->select('id, key as k, val')
+ ->where('id !=', 1)
+ ->get('create_test', 2, 1);
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestSelectGet()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->select('id, key as k, val')
+ ->get('create_test', 2, 1);
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestSelectFromGet()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->select('id, key as k, val')
+ ->from('create_test ct')
+ ->where('id >', 1)
+ ->get();
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestSelectFromLimitGet()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->select('id, key as k, val')
+ ->from('create_test ct')
+ ->where('id >', 1)
+ ->limit(3)
+ ->get();
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestOrderBy()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->select('id, key as k, val')
+ ->from('create_test')
+ ->where('id >', 0)
+ ->where('id <', 9000)
+ ->order_by('id', 'DESC')
+ ->order_by('k', 'ASC')
+ ->limit(5,2)
+ ->get();
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestOrderByRandom()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->select('id, key as k, val')
+ ->from('create_test')
+ ->where('id >', 0)
+ ->where('id <', 9000)
+ ->order_by('id', 'rand')
+ ->limit(5,2)
+ ->get();
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestGroupBy()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->select('id, key as k, val')
+ ->from('create_test')
+ ->where('id >', 0)
+ ->where('id <', 9000)
+ ->group_by('k')
+ ->group_by('val')
+ ->order_by('id', 'DESC')
+ ->order_by('k', 'ASC')
+ ->limit(5,2)
+ ->get();
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestOrWhere()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->select('id, key as k, val')
+ ->from('create_test')
+ ->where(' id ', 1)
+ ->or_where('key >', 0)
+ ->limit(2, 1)
+ ->get();
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestLike()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->from('create_test')
+ ->like('key', 'og')
+ ->get();
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestJoin()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->from('create_test')
+ ->join('create_join cj', 'cj.id = create_test.id')
+ ->get();
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestInsert()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->set('id', 4)
+ ->set('key', 4)
+ ->set('val', 5)
+ ->insert('create_test');
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestUpdate()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->set('id', 4)
+ ->set('key', 'gogle')
+ ->set('val', 'non-word')
+ ->where('id', 4)
+ ->update('create_test');
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+ function TestDelete()
+ {
+ if (empty($this->db)) return;
+
+ $query = $this->db->where('id', 4)->delete('create_test');
+
+ $this->assertIsA($query, 'PDOStatement');
+ }
+
+}
+
+// End of parent.php
\ No newline at end of file