Move db tests to Query only

This commit is contained in:
Timothy Warren 2012-04-13 13:21:06 -04:00
parent 036cb83b33
commit b559ec1bab
14 changed files with 7 additions and 1442 deletions

2
sys/db

@ -1 +1 @@
Subproject commit 773e7b8b805783ccefcfae17583f077ce8672996
Subproject commit e745750eca9bf718094c27af26873be646bf9ef6

View File

@ -1,273 +0,0 @@
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Parent Database Test Class
*/
abstract class DBTest extends UnitTestCase {
abstract function TestConnection();
function tearDown()
{
$this->db = NULL;
}
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);
}
}
// --------------------------------------------------------------------------
/**
* 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('id')
->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');
}
function TestGetViews()
{
if (empty($this->db)) return;
$this->assertTrue(is_array($this->db->get_views()));
}
}
// End of parent.php

View File

@ -1,224 +0,0 @@
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Firebird Query Builder Tests
*/
class FirebirdQBTest extends QBTest {
function __construct()
{
parent::__construct();
$dbpath = TEST_DIR.DS.'db_files'.DS.'FB_TEST_DB.FDB';
// Test the query builder
$params = new Stdclass();
$params->type = 'firebird';
$params->file = $dbpath;
$params->host = 'localhost';
$params->user = 'sysdba';
$params->pass = 'masterkey';
$this->db = new Query_Builder($params);
// echo '<hr /> Firebird Queries <hr />';
}
function TestGet()
{
$query = $this->db->get('create_test ct');
$this->assertIsA($query, 'Firebird_Result');
}
function TestGetLimit()
{
$query = $this->db->get('create_test', 2);
$this->assertIsA($query, 'Firebird_Result');
}
function TestGetLimitSkip()
{
$query = $this->db->get('create_test', 2, 1);
$this->assertIsA($query, 'Firebird_Result');
}
function TestSelectWhereGet()
{
$query = $this->db->select('id, key as k, val')
->where('id >', 1)
->where('id <', 800)
->get('create_test', 2, 1);
$this->assertIsA($query, 'Firebird_Result');
}
function TestSelectWhereGet2()
{
$query = $this->db->select('id, key as k, val')
->where(' id ', 1)
->get('create_test', 2, 1);
$this->assertIsA($query, 'Firebird_Result');
}
function TestSelectGet()
{
$query = $this->db->select('id, key as k, val')
->get('create_test', 2, 1);
$this->assertIsA($query, 'Firebird_Result');
}
function TestSelectFromGet()
{
$query = $this->db->select('id, key as k, val')
->from('create_test ct')
->where('id >', 1)
->get();
$this->assertIsA($query, 'Firebird_Result');
}
function TestSelectFromLimitGet()
{
$query = $this->db->select('id, key as k, val')
->from('create_test ct')
->where('id >', 1)
->limit(3)
->get();
$this->assertIsA($query, 'Firebird_Result');
}
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, 'Firebird_Result');
}
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, 'Firebird_Result');
}
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, 'Firebird_Result');
}
function TestGroupBy()
{
}
/*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, 'Firebird_Result');
}*/
function TestLike()
{
$query = $this->db->from('create_test')
->like('key', 'og')
->get();
$this->assertIsA($query, 'Firebird_Result');
}
function TestWhereIn()
{
$query = $this->db->from('create_test')
->where_in('key', array(12, 96, "works"))
->get();
$this->assertIsA($query, 'Firebird_Result');
}
function TestJoin()
{
$query = $this->db->from('create_test')
->join('create_join cj', 'cj.id = create_test.id')
->get();
$this->assertIsA($query, 'Firebird_Result');
}
function TestInsert()
{
$query = $this->db->set('id', 4)
->set('key', 4)
->set('val', 5)
->insert('create_test');
$this->assertTrue($query);
}
function TestUpdate()
{
$query = $this->db->set('id', 4)
->set('key', 'gogle')
->set('val', 'non-word')
->where('id', 4)
->update('create_test');
$this->assertTrue($query);
}
function TestDelete()
{
$query = $this->db->where('id', 4)->delete('create_test');
$this->assertTrue($query);
}
}

View File

@ -1,191 +0,0 @@
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* FirebirdTest class.
*
* @extends UnitTestCase
*/
class FirebirdTest extends DBTest {
function setUp()
{
$dbpath = TEST_DIR.DS.'db_files'.DS.'FB_TEST_DB.FDB';
// Test the db driver directly
$this->db = new Firebird('localhost:'.$dbpath);
$this->tables = $this->db->get_tables();
}
function tearDown()
{
unset($this->db);
unset($this->tables);
}
function TestConnection()
{
$this->assertIsA($this->db, 'Firebird');
}
function TestGetTables()
{
$tables = $this->tables;
$this->assertTrue(is_array($tables));
}
function TestGetSystemTables()
{
$only_system = TRUE;
$tables = $this->db->get_system_tables();
foreach($tables as $t)
{
if(stripos($t, 'rdb$') !== 0 && stripos($t, 'mon$') !== 0)
{
$only_system = FALSE;
break;
}
}
$this->assertTrue($only_system);
}
function TestCreateTransaction()
{
$res = $this->db->beginTransaction();
$this->assertTrue($res);
}
/*function TestCreateTable()
{
//Attempt to create the table
$sql = $this->db->sql->create_table('create_join', array(
'id' => 'SMALLINT',
'key' => 'VARCHAR(64)',
'val' => 'BLOB SUB_TYPE TEXT'
));
$this->db->query($sql);
//This test fails for an unknown reason, when clearly the table exists
//Reset
$this->tearDown();
$this->setUp();
//Check
$table_exists = (bool)in_array('create_test', $this->tables);
echo "create_test exists :".(int)$table_exists.'<br />';
$this->assertTrue($table_exists);
}*/
function TestTruncate()
{
$this->db->truncate('create_test');
$this->assertTrue($this->db->affected_rows() > 0);
}
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);
}
function TestPreparedStatements()
{
$sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$query = $this->db->prepare($sql);
$query->execute(array(1,"booger's", "Gross"));
}
function TestPrepareExecute()
{
$sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$this->db->prepare_execute($sql, array(
2, "works", 'also?'
));
}
function TestPrepareQuery()
{
$this->assertFalse($this->db->prepare_query('', array()));
}
/*function TestDeleteTable()
{
//Attempt to delete the table
$sql = $this->db->sql->delete_table('create_test');
$this->db->query($sql);
//Reset
$this->tearDown();
$this->setUp();
//Check
$table_exists = in_array('create_test', $this->tables);
$this->assertFalse($table_exists);
}*/
function TestGetSequences()
{
$this->assertTrue(is_array($this->db->get_sequences()));
}
function TestGetProcedures()
{
$this->assertTrue(is_array($this->db->get_procedures()));
}
function TestGetFunctions()
{
$this->assertTrue(is_array($this->db->get_functions()));
}
function TestGetTriggers()
{
$this->assertTrue(is_array($this->db->get_triggers()));
}
}

View File

@ -1,52 +0,0 @@
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
class MySQLQBTest extends QBTest {
function __construct()
{
parent::__construct();
// Attempt to connect, if there is a test config file
if (is_file("../test_config.json"))
{
$params = json_decode(file_get_contents("../test_config.json"));
$params = $params->mysql;
$params->type = "mysql";
$this->db = new Query_Builder($params);
// echo '<hr /> MySQL Queries <hr />';
}
elseif (($var = getenv('CI')))
{
$params = array(
'host' => '127.0.0.1',
'port' => '3306',
'conn_db' => 'test',
'user' => 'root',
'pass' => NULL,
'type' => 'mysql'
);
$this->db = new Query_Builder($params);
}
}
function TestExists()
{
$this->assertTrue(in_array('mysql', pdo_drivers()));
}
}

View File

@ -1,171 +0,0 @@
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* MySQLTest class.
*
* @extends UnitTestCase
*/
class MySQLTest extends DBTest {
function setUp()
{
// Attempt to connect, if there is a test config file
if (is_file("../test_config.json"))
{
$params = json_decode(file_get_contents("../test_config.json"));
$params = $params->mysql;
$this->db = new MySQL("host={$params->host};port={$params->port};dbname={$params->conn_db}", $params->user, $params->pass);
}
elseif (($var = getenv('CI')))
{
$this->db = new MySQL('host=127.0.0.1;port=3306;dbname=test', 'root');
}
}
function TestExists()
{
$this->assertTrue(in_array('mysql', pdo_drivers()));
}
function TestConnection()
{
if (empty($this->db)) return;
$this->assertIsA($this->db, 'MySQL');
}
function TestCreateTable()
{
if (empty($this->db)) return;
//Attempt to create the table
$sql = $this->db->sql->create_table('create_test',
array(
'id' => 'int(10)',
'key' => 'TEXT',
'val' => 'TEXT',
),
array(
'id' => 'PRIMARY KEY'
)
);
$this->db->query($sql);
//Attempt to create the table
$sql = $this->db->sql->create_table('create_join',
array(
'id' => 'int(10)',
'key' => 'TEXT',
'val' => 'TEXT',
),
array(
'id' => 'PRIMARY KEY'
)
);
$this->db->query($sql);
//Check
$dbs = $this->db->get_tables();
$this->assertTrue(in_array('create_test', $dbs));
}
function TestTruncate()
{
$this->db->truncate('create_test');
$this->db->truncate('create_join');
$ct_query = $this->db->query('SELECT * FROM create_test');
$cj_query = $this->db->query('SELECT * FROM create_join');
}
function TestPreparedStatements()
{
if (empty($this->db)) return;
$sql = <<<SQL
INSERT INTO `create_test` (`id`, `key`, `val`)
VALUES (?,?,?)
SQL;
$statement = $this->db->prepare_query($sql, array(1,"boogers", "Gross"));
$statement->execute();
}
function TestPrepareExecute()
{
if (empty($this->db)) return;
$sql = <<<SQL
INSERT INTO `create_test` (`id`, `key`, `val`)
VALUES (?,?,?)
SQL;
$this->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);
}
function TestGetSchemas()
{
$this->assertFalse($this->db->get_schemas());
}
function TestGetsProcedures()
{
$this->assertTrue(is_array($this->db->get_procedures()));
}
function TestGetTriggers()
{
$this->assertTrue(is_array($this->db->get_triggers()));
}
function TestGetSequences()
{
$this->assertFalse($this->db->get_sequences());
}
}

View File

@ -1,21 +0,0 @@
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
class ODBCQBTest extends UnitTestCase {
function TestExists()
{
$this->assertTrue(in_array('odbc', pdo_drivers()));
}
}

View File

@ -1,26 +0,0 @@
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* ODBCTest class.
*
* @extends UnitTestCase
*/
class ODBCTest extends UnitTestCase {
function TestExists()
{
$this->assertTrue(in_array('odbc', pdo_drivers()));
}
}

View File

@ -1,52 +0,0 @@
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
class PgSQLQBTest extends QBTest {
function __construct()
{
parent::__construct();
// Attempt to connect, if there is a test config file
if (is_file("../test_config.json"))
{
$params = json_decode(file_get_contents("../test_config.json"));
$params = $params->pgsql;
$params->type = "pgsql";
$this->db = new Query_Builder($params);
// echo '<hr /> Postgres Queries <hr />';
}
elseif (($var = getenv('CI')))
{
$params = array(
'host' => '127.0.0.1',
'port' => '5432',
'conn_db' => 'test',
'user' => 'postgres',
'pass' => '',
'type' => 'pgsql'
);
$this->db = new Query_Builder($params);
}
}
function TestExists()
{
$this->assertTrue(in_array('pgsql', pdo_drivers()));
}
}

View File

@ -1,187 +0,0 @@
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* PgTest class.
*
* @extends UnitTestCase
*/
class PgTest extends DBTest {
function __construct()
{
parent::__construct();
}
function setUp()
{
// Attempt to connect, if there is a test config file
if (is_file("../test_config.json"))
{
$params = json_decode(file_get_contents("../test_config.json"));
$params = $params->pgsql;
$this->db = new PgSQL("host={$params->host};port={$params->port};dbname={$params->conn_db}", $params->user, $params->pass);
}
elseif (($var = getenv('CI')))
{
$this->db = new PgSQL('host=127.0.0.1;port=5432;dbname=test', 'postgres');
}
}
function TestExists()
{
$this->assertTrue(in_array('pgsql', pdo_drivers()));
}
function TestConnection()
{
if (empty($this->db)) return;
$this->assertIsA($this->db, 'PgSQL');
}
function TestCreateTable()
{
if (empty($this->db)) return;
// Drop the table(s) if they exist
$sql = 'DROP TABLE IF EXISTS "create_test"';
$this->db->query($sql);
$sql = 'DROP TABLE IF EXISTS "create_join"';
$this->db->query($sql);
//Attempt to create the table
$sql = $this->db->sql->create_table('create_test',
array(
'id' => 'integer',
'key' => 'TEXT',
'val' => 'TEXT',
),
array(
'id' => 'PRIMARY KEY'
)
);
$this->db->query($sql);
//Attempt to create the table
$sql = $this->db->sql->create_table('create_join',
array(
'id' => 'integer',
'key' => 'TEXT',
'val' => 'TEXT',
),
array(
'id' => 'PRIMARY KEY'
)
);
$this->db->query($sql);
//echo $sql.'<br />';
//Reset
unset($this->db);
$this->setUp();
//Check
$dbs = $this->db->get_tables();
$this->assertTrue(in_array('create_test', $dbs));
}
function TestTruncate()
{
$this->db->truncate('create_test');
$this->db->truncate('create_join');
$ct_query = $this->db->query('SELECT * FROM create_test');
$cj_query = $this->db->query('SELECT * FROM create_join');
}
function TestPreparedStatements()
{
if (empty($this->db)) return;
$sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$statement = $this->db->prepare_query($sql, array(1,"boogers", "Gross"));
$statement->execute();
}
function TestPrepareExecute()
{
if (empty($this->db)) return;
$sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$this->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);
}
function TestGetSchemas()
{
$this->assertTrue(is_array($this->db->get_schemas()));
}
function TestGetSequences()
{
$this->assertTrue(is_array($this->db->get_sequences()));
}
function TestGetsProcedures()
{
$this->assertTrue(is_array($this->db->get_procedures()));
}
function TestGetTriggers()
{
$this->assertTrue(is_array($this->db->get_triggers()));
}
}

View File

@ -1,33 +0,0 @@
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Class for testing Query Builder with SQLite
*/
class SQLiteQBTest extends QBTest {
function __construct()
{
parent::__construct();
$path = TEST_DIR.DS.'db_files'.DS.'test_sqlite.db';
$params = new Stdclass();
$params->type = 'sqlite';
$params->file = $path;
$params->host = 'localhost';
$this->db = new Query_Builder($params);
// echo '<hr /> SQLite Queries <hr />';
}
}

View File

@ -1,173 +0,0 @@
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* SQLiteTest class.
*
* @extends UnitTestCase
*/
class SQLiteTest extends UnitTestCase {
function __construct()
{
parent::__construct();
}
function setUp()
{
$path = TEST_DIR.DS.'db_files'.DS.'test_sqlite.db';
$this->db = new SQLite($path);
}
function tearDown()
{
unset($this->db);
}
function TestConnection()
{
$this->assertIsA($this->db, 'SQLite');
}
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 TestCreateTable()
{
//Attempt to create the table
$sql = $this->db->sql->create_table('create_test',
array(
'id' => 'INTEGER',
'key' => 'TEXT',
'val' => 'TEXT',
),
array(
'id' => 'PRIMARY KEY'
)
);
$this->db->query($sql);
//Attempt to create the table
$sql = $this->db->sql->create_table('create_join',
array(
'id' => 'INTEGER',
'key' => 'TEXT',
'val' => 'TEXT',
),
array(
'id' => 'PRIMARY KEY'
)
);
$this->db->query($sql);
//Check
$dbs = $this->db->get_tables();
$this->assertTrue(in_array('create_test', $dbs));
}
function TestTruncate()
{
$this->db->truncate('create_test');
$this->assertIsA($this->db->affected_rows(), 'int');
}
function TestPreparedStatements()
{
$sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$statement = $this->db->prepare_query($sql, array(1,"boogers", "Gross"));
$statement->execute();
}
function TestPrepareExecute()
{
$sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?)
SQL;
$this->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);
}
// This is really time intensive ! Run only when needed
/*function TestDeleteTable()
{
//Make sure the table exists to delete
$dbs = $this->db->get_tables();
$this->assertTrue(isset($dbs['create_test']));
//Attempt to delete the table
$sql = $this->db->sql->delete_table('create_test');
$this->db->query($sql);
//Check
$dbs = $this->db->get_tables();
$this->assertFalse(in_array('create_test', $dbs));
}*/
function TestGetDBs()
{
$this->assertFalse($this->db->get_dbs());
}
function TestGetSchemas()
{
$this->assertFalse($this->db->get_schemas());
}
}

Binary file not shown.

View File

@ -15,53 +15,21 @@
/**
* Unit test bootstrap - Using php simpletest
*/
define('TEST_DIR', dirname(__FILE__).'/');
define('BASE_DIR', str_replace(basename(TEST_DIR).'/', '', TEST_DIR).'sys/');
define('DS', DIRECTORY_SEPARATOR);
define('OSL_TEST_DIR', dirname(__FILE__).'/');
define('OSL_BASE_DIR', str_replace(basename(OSL_TEST_DIR).'/', '', OSL_TEST_DIR).'sys/');
// --------------------------------------------------------------------------
// Include simpletest
// it has to be set in your php path, or put in the tests folder
require_once('simpletest/autorun.php');
// Include db_drivers
require_once(BASE_DIR . 'db/autoload.php');
require_once(OSL_BASE_DIR . 'db/autoload.php');
// Include core tests
array_map('do_include', glob(TEST_DIR . 'core/*.php'));
array_map('do_include', glob(OSL_TEST_DIR . 'core/*.php'));
// Include required methods
array_map('do_include', glob(BASE_DIR . 'common/*.php'));
array_map('do_include', glob(OSL_BASE_DIR . 'common/*.php'));
// Include db tests
// Load db classes based on capability
$src_path = BASE_DIR.'db/drivers/';
$test_path = TEST_DIR.'databases/';
foreach(pdo_drivers() as $d)
{
// PDO firebird isn't stable enough to
// bother, so skip it.
if ($d === 'firebird')
{
continue;
}
// Load by driver folder
$src_dir = "{$src_path}{$d}";
if(is_dir($src_dir))
{
require_once("{$test_path}{$d}/{$d}.php");
require_once("{$test_path}{$d}/{$d}-qb.php");
}
}
// Load Firebird if there is support
if(function_exists('fbird_connect'))
{
array_map('do_include', glob($src_path.'firebird/*.php'));
require_once("{$test_path}firebird/firebird.php");
require_once("{$test_path}firebird/firebird-qb.php");
}
require_once(OSL_BASE_DIR . 'db/tests/index.php');