Fix some tests

This commit is contained in:
Timothy Warren 2012-04-02 10:52:46 -04:00
parent fdc37f8819
commit 96ada089ee
6 changed files with 78 additions and 60 deletions

View File

@ -20,7 +20,7 @@
*/ */
class DB_Reg { class DB_Reg {
private static $instance; private static $instance=array();
/** /**
* Registry access method * Registry access method

View File

@ -180,7 +180,25 @@ class Connection_Sidebar extends GtkVBox {
*/ */
public function set_status_icon($col, $cell, $model, $iter) public function set_status_icon($col, $cell, $model, $iter)
{ {
$col->set_reorderable(TRUE);
$info = $model->get_value($iter, 0);
list($width, $height) = Gtk::icon_size_lookup(Gtk::ICON_SIZE_SMALL_TOOLBAR);
$conns = DB_Reg::get_connections();
/*if(in_array($info->name, $conns))
{
$img = new GTKImage();
$img->set_from_stock(GTK::STOCK_YES, Gtk::ICON_SIZE_SMALL_TOOLBAR);
$cell->set_property('pixbuf', $img->get_pixbuf());
}
else
{
$img = new GTKImage();
$img->set_from_stock(GTK::STOCK_NO, Gtk::ICON_SIZE_SMALL_TOOLBAR);
$cell->set_property('pixbuf', $img->get_pixbuf());
}*/
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

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
*/ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -17,34 +17,34 @@ class MySQLQBTest extends QBTest {
function __construct() function __construct()
{ {
parent::__construct(); parent::__construct();
// Attempt to connect, if there is a test config file // Attempt to connect, if there is a test config file
if (is_file("../test_config.json")) if (is_file("../test_config.json"))
{ {
$params = json_decode(file_get_contents("../test_config.json")); $params = json_decode(file_get_contents("../test_config.json"));
$params = $params->mysql; $params = $params->mysql;
$params->type = "mysql"; $params->type = "mysql";
$this->db = new Query_Builder($params); $this->db = new Query_Builder($params);
// echo '<hr /> MySQL Queries <hr />'; // echo '<hr /> MySQL Queries <hr />';
} }
elseif (($var = getenv('CI'))) elseif (($var = getenv('CI')))
{ {
$params = array( $params = array(
'host' => '127.0.0.1', 'host' => '127.0.0.1',
'port' => '3306', 'port' => '3306',
'database' => 'test', 'conn_db' => 'test',
'user' => 'root', 'user' => 'root',
'pass' => NULL, 'pass' => NULL,
'type' => 'mysql' 'type' => 'mysql'
); );
$this->db = new Query_Builder($params); $this->db = new Query_Builder($params);
} }
} }
function TestExists() function TestExists()
{ {
$this->assertTrue(in_array('mysql', pdo_drivers())); $this->assertTrue(in_array('mysql', pdo_drivers()));

View File

@ -7,18 +7,18 @@
* @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
*/ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* MySQLTest class. * MySQLTest class.
* *
* @extends UnitTestCase * @extends UnitTestCase
*/ */
class MySQLTest extends DBTest { class MySQLTest extends DBTest {
function setUp() function setUp()
{ {
// Attempt to connect, if there is a test config file // Attempt to connect, if there is a test config file
@ -26,52 +26,52 @@ class MySQLTest extends DBTest {
{ {
$params = json_decode(file_get_contents("../test_config.json")); $params = json_decode(file_get_contents("../test_config.json"));
$params = $params->mysql; $params = $params->mysql;
$this->db = new MySQL("host={$params->host};port={$params->port};dbname={$params->database}", $params->user, $params->pass); $this->db = new MySQL("host={$params->host};port={$params->port};dbname={$params->conn_db}", $params->user, $params->pass);
} }
elseif (($var = getenv('CI'))) elseif (($var = getenv('CI')))
{ {
$this->db = new MySQL('host=127.0.0.1;port=3306;dbname=test', 'root'); $this->db = new MySQL('host=127.0.0.1;port=3306;dbname=test', 'root');
} }
} }
function TestExists() function TestExists()
{ {
$this->assertTrue(in_array('mysql', pdo_drivers())); $this->assertTrue(in_array('mysql', pdo_drivers()));
} }
function TestConnection() function TestConnection()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$this->assertIsA($this->db, 'MySQL'); $this->assertIsA($this->db, 'MySQL');
} }
function TestCreateTable() function TestCreateTable()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
//Attempt to create the table //Attempt to create the table
$sql = $this->db->sql->create_table('create_test', $sql = $this->db->sql->create_table('create_test',
array( array(
'id' => 'int(10)', 'id' => 'int(10)',
'key' => 'TEXT', 'key' => 'TEXT',
'val' => 'TEXT', 'val' => 'TEXT',
), ),
array( array(
'id' => 'PRIMARY KEY' 'id' => 'PRIMARY KEY'
) )
); );
$this->db->query($sql); $this->db->query($sql);
//Attempt to create the table //Attempt to create the table
$sql = $this->db->sql->create_table('create_join', $sql = $this->db->sql->create_table('create_join',
array( array(
'id' => 'int(10)', 'id' => 'int(10)',
'key' => 'TEXT', 'key' => 'TEXT',
'val' => 'TEXT', 'val' => 'TEXT',
), ),
array( array(
'id' => 'PRIMARY KEY' 'id' => 'PRIMARY KEY'
) )
@ -80,9 +80,9 @@ class MySQLTest extends DBTest {
//Check //Check
$dbs = $this->db->get_tables(); $dbs = $this->db->get_tables();
$this->assertTrue(in_array('create_test', $dbs)); $this->assertTrue(in_array('create_test', $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
*/ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -17,34 +17,34 @@ class PgSQLQBTest extends QBTest {
function __construct() function __construct()
{ {
parent::__construct(); parent::__construct();
// Attempt to connect, if there is a test config file // Attempt to connect, if there is a test config file
if (is_file("../test_config.json")) if (is_file("../test_config.json"))
{ {
$params = json_decode(file_get_contents("../test_config.json")); $params = json_decode(file_get_contents("../test_config.json"));
$params = $params->pgsql; $params = $params->pgsql;
$params->type = "pgsql"; $params->type = "pgsql";
$this->db = new Query_Builder($params); $this->db = new Query_Builder($params);
// echo '<hr /> Postgres Queries <hr />'; // echo '<hr /> Postgres Queries <hr />';
} }
elseif (($var = getenv('CI'))) elseif (($var = getenv('CI')))
{ {
$params = array( $params = array(
'host' => '127.0.0.1', 'host' => '127.0.0.1',
'port' => '5432', 'port' => '5432',
'database' => 'test', 'conn_db' => 'test',
'user' => 'postgres', 'user' => 'postgres',
'pass' => '', 'pass' => '',
'type' => 'pgsql' 'type' => 'pgsql'
); );
$this->db = new Query_Builder($params); $this->db = new Query_Builder($params);
} }
} }
function TestExists() function TestExists()
{ {
$this->assertTrue(in_array('pgsql', pdo_drivers())); $this->assertTrue(in_array('pgsql', pdo_drivers()));

View File

@ -7,14 +7,14 @@
* @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
*/ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/** /**
* PgTest class. * PgTest class.
* *
* @extends UnitTestCase * @extends UnitTestCase
*/ */
class PgTest extends DBTest { class PgTest extends DBTest {
@ -23,7 +23,7 @@ class PgTest extends DBTest {
{ {
parent::__construct(); parent::__construct();
} }
function setUp() function setUp()
{ {
// Attempt to connect, if there is a test config file // Attempt to connect, if there is a test config file
@ -31,67 +31,67 @@ class PgTest extends DBTest {
{ {
$params = json_decode(file_get_contents("../test_config.json")); $params = json_decode(file_get_contents("../test_config.json"));
$params = $params->pgsql; $params = $params->pgsql;
$this->db = new PgSQL("host={$params->host};port={$params->port};dbname={$params->database}", $params->user, $params->pass); $this->db = new PgSQL("host={$params->host};port={$params->port};dbname={$params->conn_db}", $params->user, $params->pass);
} }
elseif (($var = getenv('CI'))) elseif (($var = getenv('CI')))
{ {
$this->db = new PgSQL('host=127.0.0.1;port=5432;dbname=test', 'postgres'); $this->db = new PgSQL('host=127.0.0.1;port=5432;dbname=test', 'postgres');
} }
} }
function TestExists() function TestExists()
{ {
$this->assertTrue(in_array('pgsql', pdo_drivers())); $this->assertTrue(in_array('pgsql', pdo_drivers()));
} }
function TestConnection() function TestConnection()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
$this->assertIsA($this->db, 'PgSQL'); $this->assertIsA($this->db, 'PgSQL');
} }
function TestCreateTable() function TestCreateTable()
{ {
if (empty($this->db)) return; if (empty($this->db)) return;
// Drop the table(s) if they exist // Drop the table(s) if they exist
$sql = 'DROP TABLE IF EXISTS "create_test"'; $sql = 'DROP TABLE IF EXISTS "create_test"';
$this->db->query($sql); $this->db->query($sql);
$sql = 'DROP TABLE IF EXISTS "create_join"'; $sql = 'DROP TABLE IF EXISTS "create_join"';
$this->db->query($sql); $this->db->query($sql);
//Attempt to create the table //Attempt to create the table
$sql = $this->db->sql->create_table('create_test', $sql = $this->db->sql->create_table('create_test',
array( array(
'id' => 'integer', 'id' => 'integer',
'key' => 'TEXT', 'key' => 'TEXT',
'val' => 'TEXT', 'val' => 'TEXT',
), ),
array( array(
'id' => 'PRIMARY KEY' 'id' => 'PRIMARY KEY'
) )
); );
$this->db->query($sql); $this->db->query($sql);
//Attempt to create the table //Attempt to create the table
$sql = $this->db->sql->create_table('create_join', $sql = $this->db->sql->create_table('create_join',
array( array(
'id' => 'integer', 'id' => 'integer',
'key' => 'TEXT', 'key' => 'TEXT',
'val' => 'TEXT', 'val' => 'TEXT',
), ),
array( array(
'id' => 'PRIMARY KEY' 'id' => 'PRIMARY KEY'
) )
); );
$this->db->query($sql); $this->db->query($sql);
//echo $sql.'<br />'; //echo $sql.'<br />';
//Reset //Reset
unset($this->db); unset($this->db);
$this->setUp(); $this->setUp();
@ -99,6 +99,6 @@ class PgTest extends DBTest {
//Check //Check
$dbs = $this->db->get_tables(); $dbs = $this->db->get_tables();
$this->assertTrue(in_array('create_test', $dbs)); $this->assertTrue(in_array('create_test', $dbs));
} }
} }