First version of tests for dblayer with support of 3 db engines. The tests files are generated from dblayerComplet
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1810 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -14,6 +14,16 @@ if (file_exists ("/tmp/database.db"))
|
|||||||
unlink ("/tmp/database.db");
|
unlink ("/tmp/database.db");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
file_put_contents ("Tests/dblayerSqliteTest.php",
|
||||||
|
str_replace ("{ENGINE}", "sqlite",
|
||||||
|
file_get_contents ("Tests/dblayerComplet.php")));
|
||||||
|
file_put_contents ("Tests/dblayerMySQLTest.php",
|
||||||
|
str_replace ("{ENGINE}", "mysql",
|
||||||
|
file_get_contents ("Tests/dblayerComplet.php")));
|
||||||
|
file_put_contents ("Tests/dblayerPostgreSQLTest.php",
|
||||||
|
str_replace ("{ENGINE}", "pgsql",
|
||||||
|
file_get_contents ("Tests/dblayerComplet.php")));
|
||||||
|
|
||||||
require_once ("domframework/config.php");
|
require_once ("domframework/config.php");
|
||||||
/** The class need to take care of configuration parameters */
|
/** The class need to take care of configuration parameters */
|
||||||
class configuration extends config
|
class configuration extends config
|
||||||
|
|||||||
@@ -3,30 +3,45 @@
|
|||||||
@package domframework
|
@package domframework
|
||||||
@author Dominique Fournier <dominique@fournier38.fr> */
|
@author Dominique Fournier <dominique@fournier38.fr> */
|
||||||
|
|
||||||
/** Test the dblayer.php file */
|
class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
|
||||||
class test_dblayer extends PHPUnit_Framework_TestCase
|
|
||||||
{
|
{
|
||||||
public function test_createDB ()
|
|
||||||
{
|
|
||||||
// Must use the model to create the database structure as there is no
|
|
||||||
// creation of tables in controller
|
|
||||||
$configuration = new configuration ();
|
|
||||||
$dbconfig = $configuration->get ("database");
|
|
||||||
if (! isset ($dbconfig["tableprefix"]))
|
|
||||||
$dbconfig["tableprefix"] = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test with column name 'group', 'object', 'where', 'with space'
|
// Test with column name 'group', 'object', 'where', 'with space'
|
||||||
// Test with table name 'group', 'object', 'where', 'with space'
|
// Test with table name 'group', 'object', 'where', 'with space'
|
||||||
// For the 3 DB engines
|
// For the 3 DB engines
|
||||||
|
|
||||||
|
public $engine="{ENGINE}";
|
||||||
|
public $confs = array (
|
||||||
|
"sqlite" => array (
|
||||||
|
"dsn" => "sqlite:/tmp/database.db",
|
||||||
|
"username" => null,
|
||||||
|
"password" => null,
|
||||||
|
"driver_options" => null,
|
||||||
|
"tableprefix" => "",
|
||||||
|
),
|
||||||
|
"mysql" => array (
|
||||||
|
"dsn" => "mysql:host=127.0.0.1;port=3306;dbname=test",
|
||||||
|
"username" => "root",
|
||||||
|
"password" => "lqsym",
|
||||||
|
"driver_options" => null,
|
||||||
|
"tableprefix" => "",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
public function test_dropTable ()
|
||||||
|
{
|
||||||
|
$dbconfig = $this->confs["{ENGINE}"];
|
||||||
|
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
||||||
|
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||||
|
$db->table = "grouped";
|
||||||
|
$this->setExpectedException ("Exception");
|
||||||
|
$res = $db->dropTable();
|
||||||
|
// Never generate an error
|
||||||
|
}
|
||||||
|
|
||||||
public function test_createTable ()
|
public function test_createTable ()
|
||||||
{
|
{
|
||||||
// Create a table named group
|
// Create a table named group
|
||||||
$configuration = new configuration ();
|
$dbconfig = $this->confs["{ENGINE}"];
|
||||||
$dbconfig = $configuration->get ("database");
|
|
||||||
if (! isset ($dbconfig["tableprefix"]))
|
|
||||||
$dbconfig["tableprefix"] = "";
|
|
||||||
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
||||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||||
$db->table = "grouped";
|
$db->table = "grouped";
|
||||||
@@ -40,10 +55,7 @@ class test_dblayer extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function test_insert ()
|
public function test_insert ()
|
||||||
{
|
{
|
||||||
$configuration = new configuration ();
|
$dbconfig = $this->confs["{ENGINE}"];
|
||||||
$dbconfig = $configuration->get ("database");
|
|
||||||
if (! isset ($dbconfig["tableprefix"]))
|
|
||||||
$dbconfig["tableprefix"] = "";
|
|
||||||
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
||||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||||
$db->table = "grouped";
|
$db->table = "grouped";
|
||||||
@@ -61,10 +73,7 @@ class test_dblayer extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function test_read1 ()
|
public function test_read1 ()
|
||||||
{
|
{
|
||||||
$configuration = new configuration ();
|
$dbconfig = $this->confs["{ENGINE}"];
|
||||||
$dbconfig = $configuration->get ("database");
|
|
||||||
if (! isset ($dbconfig["tableprefix"]))
|
|
||||||
$dbconfig["tableprefix"] = "";
|
|
||||||
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
||||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||||
$db->table = "grouped";
|
$db->table = "grouped";
|
||||||
@@ -85,10 +94,7 @@ class test_dblayer extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function test_update1 ()
|
public function test_update1 ()
|
||||||
{
|
{
|
||||||
$configuration = new configuration ();
|
$dbconfig = $this->confs["{ENGINE}"];
|
||||||
$dbconfig = $configuration->get ("database");
|
|
||||||
if (! isset ($dbconfig["tableprefix"]))
|
|
||||||
$dbconfig["tableprefix"] = "";
|
|
||||||
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
||||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||||
$db->table = "grouped";
|
$db->table = "grouped";
|
||||||
@@ -98,16 +104,14 @@ class test_dblayer extends PHPUnit_Framework_TestCase
|
|||||||
"with space"=>array ("varchar", "255", "not null"));
|
"with space"=>array ("varchar", "255", "not null"));
|
||||||
$db->unique = array ();
|
$db->unique = array ();
|
||||||
$db->primary = "group";
|
$db->primary = "group";
|
||||||
$db->update ("gr ou\"p", array ("object"=>"%éàoppp",
|
$res = $db->update ("gr ou\"p", array ("object"=>"%éàoppp",
|
||||||
"with space"=>"WITH SPACE"));
|
"with space"=>"WITH SPACE"));
|
||||||
|
$this->assertSame (1, $res);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_read2 ()
|
public function test_read2 ()
|
||||||
{
|
{
|
||||||
$configuration = new configuration ();
|
$dbconfig = $this->confs["{ENGINE}"];
|
||||||
$dbconfig = $configuration->get ("database");
|
|
||||||
if (! isset ($dbconfig["tableprefix"]))
|
|
||||||
$dbconfig["tableprefix"] = "";
|
|
||||||
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
||||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||||
$db->table = "grouped";
|
$db->table = "grouped";
|
||||||
Reference in New Issue
Block a user