Rearrange tests, add Settings class tests

This commit is contained in:
Timothy Warren 2012-04-13 13:48:38 -04:00
parent e745750eca
commit ebe1b1a647
6 changed files with 149 additions and 4 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ test_config.json
index.html index.html
tests/db_files/* tests/db_files/*
._* ._*
tests/settings.json

69
tests/core/core.php Normal file
View File

@ -0,0 +1,69 @@
<?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
*/
// --------------------------------------------------------------------------
/**
* CoreTest class - Compatibility and core functionality tests
*
* @extends UnitTestCase
*/
class CoreTest extends UnitTestCase {
/**
* __construct function.
*
* @access public
* @return void
*/
function __construct()
{
parent::__construct();
}
/**
* TestPHPVersion function.
*
* @access public
* @return void
*/
function TestPHPVersion()
{
$this->assertTrue(version_compare(PHP_VERSION, "5.2", "ge"));
}
/**
* TestHasPDO function.
*
* @access public
* @return void
*/
function TestHasPDO()
{
// PDO class exists
$this->assertTrue(class_exists('PDO'));
// Make sure at least one of the supported drivers is enabled
$supported = array(
'mysql',
'pgsql',
'odbc',
'sqlite',
);
$drivers = pdo_drivers();
$num_supported = count(array_intersect($drivers, $supported));
$this->assertTrue($num_supported > 0);
}
}

75
tests/core/settings.php Normal file
View File

@ -0,0 +1,75 @@
<?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
*/
// --------------------------------------------------------------------------
/**
* Settings Class Test Class
*/
class SettingsTest extends UnitTestCase {
function __construct()
{
parent::__construct();
$this->settings =& Settings::get_instance();
// Make sure to delete 'foo' if it exists
$this->settings->remove_db('foo');
}
function TestExists()
{
$this->assertIsA($this->settings, 'Settings');
}
function TestGetEmptyDBs()
{
$this->assertTrue(is_object($this->settings->get_dbs()));
}
function TestGetNull()
{
$this->assertFalse(isset($this->settings->foo));
}
function TestSet()
{
$bar = $this->settings->foo = 'bar';
$this->assertEqual('bar', $bar);
}
function TestGet()
{
$this->assertEqual('bar', $this->settings->foo);
}
function TestSetDBProperty()
{
$res = $this->settings->__set('dbs', 2);
$this->assertFalse($res);
}
function TestGetEmptyDB()
{
$this->assertFalse($this->settings->get_db('foo'));
}
function TestAddDB()
{
$this->settings->add_db('foo', array());
$db = $this->settings->get_db('foo');
$this->assertTrue(isset($db));
}
}

Binary file not shown.

View File

@ -23,12 +23,12 @@ define('DS', DIRECTORY_SEPARATOR);
// it has to be set in your php path, or put in the tests folder // it has to be set in your php path, or put in the tests folder
require_once('simpletest/autorun.php'); require_once('simpletest/autorun.php');
// Require base testing classes
require_once(TEST_DIR.'/parent.php');
// Include db classes // Include db classes
require_once(BASE_DIR.'autoload.php'); require_once(BASE_DIR.'autoload.php');
// Require base testing classes
array_map('do_include', glob(TEST_DIR . "/core/*.php"));
// Include db tests // Include db tests
// Load db classes based on capability // Load db classes based on capability
$src_path = BASE_DIR.'drivers/'; $src_path = BASE_DIR.'drivers/';