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
|
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MySQLTest 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 MySQLTest extends DBTest {
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-15 16:39:01 -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->mysql;
|
2012-04-02 10:52:46 -04:00
|
|
|
|
|
|
|
$this->db = new MySQL("host={$params->host};port={$params->port};dbname={$params->conn_db}", $params->user, $params->pass);
|
2012-03-15 16:39:01 -04:00
|
|
|
}
|
2012-03-23 15:29:34 -04:00
|
|
|
elseif (($var = getenv('CI')))
|
|
|
|
{
|
|
|
|
$this->db = new MySQL('host=127.0.0.1;port=3306;dbname=test', 'root');
|
|
|
|
}
|
2012-03-15 16:39:01 -04:00
|
|
|
}
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-12 11:17:49 -04:00
|
|
|
function TestExists()
|
|
|
|
{
|
|
|
|
$this->assertTrue(in_array('mysql', pdo_drivers()));
|
|
|
|
}
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-15 16:39:01 -04:00
|
|
|
function TestConnection()
|
|
|
|
{
|
2012-04-02 10:52:46 -04:00
|
|
|
if (empty($this->db)) return;
|
|
|
|
|
2012-03-15 16:39:01 -04:00
|
|
|
$this->assertIsA($this->db, 'MySQL');
|
|
|
|
}
|
|
|
|
|
|
|
|
function TestCreateTable()
|
|
|
|
{
|
2012-04-02 10:52:46 -04:00
|
|
|
if (empty($this->db)) return;
|
|
|
|
|
2012-03-15 16:39:01 -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-15 16:39:01 -04:00
|
|
|
array(
|
|
|
|
'id' => 'int(10)',
|
|
|
|
'key' => 'TEXT',
|
|
|
|
'val' => 'TEXT',
|
2012-04-02 10:52:46 -04:00
|
|
|
),
|
2012-03-15 16:39:01 -04:00
|
|
|
array(
|
|
|
|
'id' => 'PRIMARY KEY'
|
|
|
|
)
|
|
|
|
);
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-15 16:39:01 -04:00
|
|
|
$this->db->query($sql);
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-15 16:39:01 -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-15 16:39:01 -04:00
|
|
|
array(
|
|
|
|
'id' => 'int(10)',
|
|
|
|
'key' => 'TEXT',
|
|
|
|
'val' => 'TEXT',
|
2012-04-02 10:52:46 -04:00
|
|
|
),
|
2012-03-15 16:39:01 -04:00
|
|
|
array(
|
|
|
|
'id' => 'PRIMARY KEY'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$this->db->query($sql);
|
|
|
|
|
|
|
|
//Check
|
|
|
|
$dbs = $this->db->get_tables();
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-15 16:39:01 -04:00
|
|
|
$this->assertTrue(in_array('create_test', $dbs));
|
2012-04-02 10:52:46 -04:00
|
|
|
|
2012-03-15 16:39:01 -04:00
|
|
|
}
|
2012-04-09 09:57:21 -04:00
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2012-02-02 19:04:10 -05:00
|
|
|
}
|
2012-04-02 10:52:46 -04:00
|
|
|
|