Some new tests

This commit is contained in:
Timothy Warren 2012-04-09 09:02:06 -04:00
parent a94a92e73e
commit 724e09371a
2 changed files with 71 additions and 62 deletions

View File

@ -161,4 +161,8 @@ SQL;
$this->assertFalse(in_array('create_test', $dbs)); $this->assertFalse(in_array('create_test', $dbs));
}*/ }*/
function TestGetDBs()
{
$this->assertFalse($this->db->get_dbs());
}
} }

View File

@ -7,7 +7,7 @@
* @author Timothy J. Warren * @author Timothy J. Warren
* @copyright Copyright (c) 2012 * @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager * @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license * @license http://philsturgeon.co.uk/code/dbad-license
*/ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -23,7 +23,7 @@ abstract class DBTest extends UnitTestCase {
{ {
$this->db = NULL; $this->db = NULL;
} }
function TestGetTables() function TestGetTables()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
@ -31,16 +31,16 @@ abstract class DBTest extends UnitTestCase {
$tables = $this->db->get_tables(); $tables = $this->db->get_tables();
$this->assertTrue(is_array($tables)); $this->assertTrue(is_array($tables));
} }
function TestGetSystemTables() function TestGetSystemTables()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$tables = $this->db->get_system_tables(); $tables = $this->db->get_system_tables();
$this->assertTrue(is_array($tables)); $this->assertTrue(is_array($tables));
} }
function TestCreateTransaction() function TestCreateTransaction()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
@ -48,57 +48,57 @@ abstract class DBTest extends UnitTestCase {
$res = $this->db->beginTransaction(); $res = $this->db->beginTransaction();
$this->assertTrue($res); $this->assertTrue($res);
} }
function TestPreparedStatements() function TestPreparedStatements()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$sql = <<<SQL $sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val") INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?) VALUES (?,?,?)
SQL; SQL;
$statement = $this->db->prepare_query($sql, array(1,"boogers", "Gross")); $statement = $this->db->prepare_query($sql, array(1,"boogers", "Gross"));
$statement->execute(); $statement->execute();
} }
function TestPrepareExecute() function TestPrepareExecute()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$sql = <<<SQL $sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val") INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?) VALUES (?,?,?)
SQL; SQL;
$this->db->prepare_execute($sql, array( $this->db->prepare_execute($sql, array(
2, "works", 'also?' 2, "works", 'also?'
)); ));
} }
function TestCommitTransaction() function TestCommitTransaction()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$res = $this->db->beginTransaction(); $res = $this->db->beginTransaction();
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)'; $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)';
$this->db->query($sql); $this->db->query($sql);
$res = $this->db->commit(); $res = $this->db->commit();
$this->assertTrue($res); $this->assertTrue($res);
} }
function TestRollbackTransaction() function TestRollbackTransaction()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$res = $this->db->beginTransaction(); $res = $this->db->beginTransaction();
$sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)'; $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)';
$this->db->query($sql); $this->db->query($sql);
$res = $this->db->rollback(); $res = $this->db->rollback();
$this->assertTrue($res); $this->assertTrue($res);
} }
@ -114,34 +114,34 @@ abstract class QBTest extends UnitTestCase {
function TestGet() function TestGet()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->get('create_test'); $query = $this->db->get('create_test');
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestGetLimit() function TestGetLimit()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->get('create_test', 2); $query = $this->db->get('create_test', 2);
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestGetLimitSkip() function TestGetLimitSkip()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->get('create_test', 2, 1); $query = $this->db->get('create_test', 2, 1);
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestSelectWhereGet() function TestSelectWhereGet()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->select('id, key as k, val') $query = $this->db->select('id, key as k, val')
->where('id >', 1) ->where('id >', 1)
->where('id <', 900) ->where('id <', 900)
@ -149,11 +149,11 @@ abstract class QBTest extends UnitTestCase {
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestSelectWhereGet2() function TestSelectWhereGet2()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->select('id, key as k, val') $query = $this->db->select('id, key as k, val')
->where('id !=', 1) ->where('id !=', 1)
->get('create_test', 2, 1); ->get('create_test', 2, 1);
@ -164,42 +164,42 @@ abstract class QBTest extends UnitTestCase {
function TestSelectGet() function TestSelectGet()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->select('id, key as k, val') $query = $this->db->select('id, key as k, val')
->get('create_test', 2, 1); ->get('create_test', 2, 1);
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestSelectFromGet() function TestSelectFromGet()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->select('id, key as k, val') $query = $this->db->select('id, key as k, val')
->from('create_test ct') ->from('create_test ct')
->where('id >', 1) ->where('id >', 1)
->get(); ->get();
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestSelectFromLimitGet() function TestSelectFromLimitGet()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->select('id, key as k, val') $query = $this->db->select('id, key as k, val')
->from('create_test ct') ->from('create_test ct')
->where('id >', 1) ->where('id >', 1)
->limit(3) ->limit(3)
->get(); ->get();
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestOrderBy() function TestOrderBy()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->select('id, key as k, val') $query = $this->db->select('id, key as k, val')
->from('create_test') ->from('create_test')
->where('id >', 0) ->where('id >', 0)
@ -208,14 +208,14 @@ abstract class QBTest extends UnitTestCase {
->order_by('k', 'ASC') ->order_by('k', 'ASC')
->limit(5,2) ->limit(5,2)
->get(); ->get();
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestOrderByRandom() function TestOrderByRandom()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->select('id, key as k, val') $query = $this->db->select('id, key as k, val')
->from('create_test') ->from('create_test')
->where('id >', 0) ->where('id >', 0)
@ -223,14 +223,14 @@ abstract class QBTest extends UnitTestCase {
->order_by('id', 'rand') ->order_by('id', 'rand')
->limit(5,2) ->limit(5,2)
->get(); ->get();
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestGroupBy() function TestGroupBy()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->select('id, key as k, val') $query = $this->db->select('id, key as k, val')
->from('create_test') ->from('create_test')
->where('id >', 0) ->where('id >', 0)
@ -241,80 +241,85 @@ abstract class QBTest extends UnitTestCase {
->order_by('k', 'ASC') ->order_by('k', 'ASC')
->limit(5,2) ->limit(5,2)
->get(); ->get();
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestOrWhere() function TestOrWhere()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->select('id, key as k, val') $query = $this->db->select('id, key as k, val')
->from('create_test') ->from('create_test')
->where(' id ', 1) ->where(' id ', 1)
->or_where('key >', 0) ->or_where('key >', 0)
->limit(2, 1) ->limit(2, 1)
->get(); ->get();
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestLike() function TestLike()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->from('create_test') $query = $this->db->from('create_test')
->like('key', 'og') ->like('key', 'og')
->get(); ->get();
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestJoin() function TestJoin()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->from('create_test') $query = $this->db->from('create_test')
->join('create_join cj', 'cj.id = create_test.id') ->join('create_join cj', 'cj.id = create_test.id')
->get(); ->get();
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestInsert() function TestInsert()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->set('id', 4) $query = $this->db->set('id', 4)
->set('key', 4) ->set('key', 4)
->set('val', 5) ->set('val', 5)
->insert('create_test'); ->insert('create_test');
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestUpdate() function TestUpdate()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->set('id', 4) $query = $this->db->set('id', 4)
->set('key', 'gogle') ->set('key', 'gogle')
->set('val', 'non-word') ->set('val', 'non-word')
->where('id', 4) ->where('id', 4)
->update('create_test'); ->update('create_test');
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestDelete() function TestDelete()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$query = $this->db->where('id', 4)->delete('create_test'); $query = $this->db->where('id', 4)->delete('create_test');
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
} }
function TestGetDBs()
{
$this->assertTrue(is_array($this->db->get_dbs()));
}
} }
// End of parent.php // End of parent.php