Split query builder tests
This commit is contained in:
parent
6e454f4585
commit
80a878d16e
@ -91,7 +91,7 @@ class Query_Builder {
|
||||
|
||||
$sql = $this->_compile('select');
|
||||
|
||||
echo $sql."<br />";
|
||||
//echo $sql."<br />";
|
||||
|
||||
// Do prepared statements for anything involving a "where" clause
|
||||
if ( ! empty($this->where_string))
|
||||
|
114
tests/databases/firebird-qb.php
Normal file
114
tests/databases/firebird-qb.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?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 UnitTestCase {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function setUp()
|
||||
{
|
||||
$dbpath = TEST_DIR.DS.'test_dbs'.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->qb = new Query_Builder($params);
|
||||
}
|
||||
|
||||
function tearDown()
|
||||
{
|
||||
unset($this->qb);
|
||||
}
|
||||
|
||||
function TestQBGet()
|
||||
{
|
||||
$query = $this->qb->get('create_test');
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
function TestQBGetLimit()
|
||||
{
|
||||
$query = $this->qb->get('create_test', 2);
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
function TestQBGetLimitSkip()
|
||||
{
|
||||
$query = $this->qb->get('create_test', 2, 1);
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
function TestQBSelectWhereGet()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->where('id >', 1)
|
||||
->where('id <', 800)
|
||||
->get('create_test', 2, 1);
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
function TestQBSelectWhereGet2()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->where(' id ', 1)
|
||||
|
||||
->get('create_test', 2, 1);
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
|
||||
function TestQBSelectGet()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->get('create_test', 2, 1);
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
function TestSelectFromGet()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->from('create_test ct')
|
||||
->where('id >', 1)
|
||||
->get();
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
function TestSelectFromLimitGet()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->from('create_test ct')
|
||||
->where('id >', 1)
|
||||
->limit(3)
|
||||
->get();
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
}
|
@ -170,104 +170,3 @@ SQL;
|
||||
$this->assertFalse($table_exists);
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Firebird Query Builder Tests
|
||||
*/
|
||||
class FirebirdQBTest extends UnitTestCase {
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function setUp()
|
||||
{
|
||||
$dbpath = TEST_DIR.DS.'test_dbs'.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->qb = new Query_Builder($params);
|
||||
}
|
||||
|
||||
function tearDown()
|
||||
{
|
||||
unset($this->qb);
|
||||
}
|
||||
|
||||
function TestQBGet()
|
||||
{
|
||||
$query = $this->qb->get('create_test');
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
function TestQBGetLimit()
|
||||
{
|
||||
$query = $this->qb->get('create_test', 2);
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
function TestQBGetLimitSkip()
|
||||
{
|
||||
$query = $this->qb->get('create_test', 2, 1);
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
function TestQBSelectWhereGet()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->where('id >', 1)
|
||||
->where('id <', 800)
|
||||
->get('create_test', 2, 1);
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
function TestQBSelectWhereGet2()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->where(' id ', 1)
|
||||
|
||||
->get('create_test', 2, 1);
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
|
||||
function TestQBSelectGet()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->get('create_test', 2, 1);
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
function TestSelectFromGet()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->from('create_test ct')
|
||||
->where('id >', 1)
|
||||
->get();
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
|
||||
function TestSelectFromLimitGet()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->from('create_test ct')
|
||||
->where('id >', 1)
|
||||
->limit(3)
|
||||
->get();
|
||||
|
||||
$this->assertTrue(is_resource($query));
|
||||
}
|
||||
}
|
@ -28,18 +28,5 @@ class ODBCTest extends UnitTestCase {
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
// Connection Test with SQLite
|
||||
$path = dirname(__FILE__)."/../test_dbs/test_sqlite.db";
|
||||
|
||||
try
|
||||
{
|
||||
$this->db = new ODBC("Driver=/usr/lib/libsqlite3odbc.so;Database={$path}");
|
||||
}
|
||||
catch(PDOException $e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
103
tests/databases/sqlite-qb.php
Normal file
103
tests/databases/sqlite-qb.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?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 UnitTestCase {
|
||||
|
||||
function setUp()
|
||||
{
|
||||
$path = TEST_DIR.DS.'test_dbs'.DS.'test_sqlite.db';
|
||||
$params = new Stdclass();
|
||||
$params->type = 'sqlite';
|
||||
$params->file = $path;
|
||||
$params->host = 'localhost';
|
||||
$this->qb = new Query_Builder($params);
|
||||
}
|
||||
|
||||
function tearDown()
|
||||
{
|
||||
unset($this->qb);
|
||||
}
|
||||
|
||||
function TestGet()
|
||||
{
|
||||
$query = $this->qb->get('create_test');
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
|
||||
function TestGetLimit()
|
||||
{
|
||||
$query = $this->qb->get('create_test', 2);
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
|
||||
function TestGetLimitSkip()
|
||||
{
|
||||
$query = $this->qb->get('create_test', 2, 1);
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
|
||||
function TestSelectWhereGet()
|
||||
{
|
||||
$query = $this->qb->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->qb->select('id, key as k, val')
|
||||
->where('id !=', 1)
|
||||
->get('create_test', 2, 1);
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
|
||||
function TestSelectGet()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->get('create_test', 2, 1);
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
|
||||
function TestSelectFromGet()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->from('create_test ct')
|
||||
->where('id >', 1)
|
||||
->get();
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
|
||||
function TestSelectFromLimitGet()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->from('create_test ct')
|
||||
->where('id >', 1)
|
||||
->limit(3)
|
||||
->get();
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
}
|
@ -142,95 +142,3 @@ SQL;
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Class for testing Query Builder with SQLite
|
||||
*/
|
||||
class SQLiteQBTest extends UnitTestCase {
|
||||
|
||||
function setUp()
|
||||
{
|
||||
$path = TEST_DIR.DS.'test_dbs'.DS.'test_sqlite.db';
|
||||
$params = new Stdclass();
|
||||
$params->type = 'sqlite';
|
||||
$params->file = $path;
|
||||
$params->host = 'localhost';
|
||||
$this->qb = new Query_Builder($params);
|
||||
}
|
||||
|
||||
function tearDown()
|
||||
{
|
||||
unset($this->qb);
|
||||
}
|
||||
|
||||
function TestGet()
|
||||
{
|
||||
$query = $this->qb->get('create_test');
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
|
||||
function TestGetLimit()
|
||||
{
|
||||
$query = $this->qb->get('create_test', 2);
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
|
||||
function TestGetLimitSkip()
|
||||
{
|
||||
$query = $this->qb->get('create_test', 2, 1);
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
|
||||
function TestSelectWhereGet()
|
||||
{
|
||||
$query = $this->qb->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->qb->select('id, key as k, val')
|
||||
->where('id !=', 1)
|
||||
->get('create_test', 2, 1);
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
|
||||
function TestSelectGet()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->get('create_test', 2, 1);
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
|
||||
function TestSelectFromGet()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->from('create_test ct')
|
||||
->where('id >', 1)
|
||||
->get();
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
|
||||
function TestSelectFromLimitGet()
|
||||
{
|
||||
$query = $this->qb->select('id, key as k, val')
|
||||
->from('create_test ct')
|
||||
->where('id >', 1)
|
||||
->limit(3)
|
||||
->get();
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user