2012-02-02 19:04:10 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* OpenSQLManager
|
|
|
|
*
|
|
|
|
* Free Database manager for Open Source Databases
|
|
|
|
*
|
|
|
|
* @author Timothy J. Warren
|
|
|
|
* @copyright Copyright (c) 2012
|
|
|
|
* @link https://github.com/aviat4ion/OpenSQLManager
|
2012-04-02 10:52:46 -04:00
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
2012-02-02 19:04:10 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PgTest class.
|
2012-04-02 10:52:46 -04:00
|
|
|
*
|
2012-02-02 19:04:10 -05:00
|
|
|
* @extends UnitTestCase
|
|
|
|
*/
|
2012-03-19 14:30:52 -04:00
|
|
|
class PgTest extends DBTest {
|
2012-02-02 19:04:10 -05:00
|
|
|
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-19 10:19:34 -04:00
|
|
|
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;
|
2012-04-02 10:52:46 -04:00
|
|
|
|
|
|
|
$this->db = new PgSQL("host={$params->host};port={$params->port};dbname={$params->conn_db}", $params->user, $params->pass);
|
2012-03-19 10:19:34 -04:00
|
|
|
}
|
2012-03-23 15:29:34 -04:00
|
|
|
elseif (($var = getenv('CI')))
|
|
|
|
{
|
|
|
|
$this->db = new PgSQL('host=127.0.0.1;port=5432;dbname=test', 'postgres');
|
|
|
|
}
|
2012-03-19 10:19:34 -04:00
|
|
|
}
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-12 11:17:49 -04:00
|
|
|
function TestExists()
|
|
|
|
{
|
|
|
|
$this->assertTrue(in_array('pgsql', pdo_drivers()));
|
|
|
|
}
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-19 10:19:34 -04:00
|
|
|
function TestConnection()
|
|
|
|
{
|
2012-04-02 10:52:46 -04:00
|
|
|
if (empty($this->db)) return;
|
|
|
|
|
2012-03-19 10:19:34 -04:00
|
|
|
$this->assertIsA($this->db, 'PgSQL');
|
|
|
|
}
|
|
|
|
|
2012-03-23 15:29:34 -04:00
|
|
|
function TestCreateTable()
|
2012-03-19 10:19:34 -04:00
|
|
|
{
|
2012-04-02 10:52:46 -04:00
|
|
|
if (empty($this->db)) return;
|
|
|
|
|
2012-03-23 15:29:34 -04:00
|
|
|
// 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);
|
2012-04-02 10:52:46 -04:00
|
|
|
|
|
|
|
|
2012-03-19 10:19:34 -04:00
|
|
|
//Attempt to create the table
|
2012-04-02 10:52:46 -04:00
|
|
|
$sql = $this->db->sql->create_table('create_test',
|
2012-03-19 10:19:34 -04:00
|
|
|
array(
|
|
|
|
'id' => 'integer',
|
|
|
|
'key' => 'TEXT',
|
|
|
|
'val' => 'TEXT',
|
2012-04-02 10:52:46 -04:00
|
|
|
),
|
2012-03-19 10:19:34 -04:00
|
|
|
array(
|
|
|
|
'id' => 'PRIMARY KEY'
|
|
|
|
)
|
|
|
|
);
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-19 10:19:34 -04:00
|
|
|
$this->db->query($sql);
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-19 10:19:34 -04:00
|
|
|
//Attempt to create the table
|
2012-04-02 10:52:46 -04:00
|
|
|
$sql = $this->db->sql->create_table('create_join',
|
2012-03-19 10:19:34 -04:00
|
|
|
array(
|
|
|
|
'id' => 'integer',
|
|
|
|
'key' => 'TEXT',
|
|
|
|
'val' => 'TEXT',
|
2012-04-02 10:52:46 -04:00
|
|
|
),
|
2012-03-19 10:19:34 -04:00
|
|
|
array(
|
|
|
|
'id' => 'PRIMARY KEY'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->db->query($sql);
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-23 15:29:34 -04:00
|
|
|
//echo $sql.'<br />';
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-23 15:29:34 -04:00
|
|
|
//Reset
|
|
|
|
unset($this->db);
|
|
|
|
$this->setUp();
|
2012-03-19 10:19:34 -04:00
|
|
|
|
|
|
|
//Check
|
|
|
|
$dbs = $this->db->get_tables();
|
|
|
|
$this->assertTrue(in_array('create_test', $dbs));
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-23 15:29:34 -04:00
|
|
|
}
|
2012-02-02 19:04:10 -05:00
|
|
|
}
|