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:
132
Tests/dblayerComplet.php
Normal file
132
Tests/dblayerComplet.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
/** DomFramework - Tests
|
||||
@package domframework
|
||||
@author Dominique Fournier <dominique@fournier38.fr> */
|
||||
|
||||
class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
// Test with column name 'group', 'object', 'where', 'with space'
|
||||
// Test with table name 'group', 'object', 'where', 'with space'
|
||||
// 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 ()
|
||||
{
|
||||
// Create a table named group
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group"=>array ("varchar", "255", "not null"),
|
||||
"object"=>array ("varchar", "255", "not null"),
|
||||
"where"=>array ("varchar", "255", "not null"),
|
||||
"with space"=>array ("varchar", "255", "not null"));
|
||||
$res = $db->createTable ();
|
||||
$this->assertSame (0, $res);
|
||||
}
|
||||
|
||||
public function test_insert ()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group"=>array ("varchar", "255", "not null"),
|
||||
"object"=>array ("varchar", "255", "not null"),
|
||||
"where"=>array ("varchar", "255", "not null"),
|
||||
"with space"=>array ("varchar", "255", "not null"));
|
||||
$db->unique = array ();
|
||||
$res = $db->insert (array ("group"=>"gr ou\"p",
|
||||
"object"=>"/éobj%",
|
||||
"where"=>"\$'\"",
|
||||
"with space"=>"with space"));
|
||||
$this->assertSame ("1", $res);
|
||||
}
|
||||
|
||||
public function test_read1 ()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group"=>array ("varchar", "255", "not null"),
|
||||
"object"=>array ("varchar", "255", "not null"),
|
||||
"where"=>array ("varchar", "255", "not null"),
|
||||
"with space"=>array ("varchar", "255", "not null"));
|
||||
$db->unique = array ();
|
||||
$res = $db->read (array (array ("group", "gr ou\"p"),
|
||||
array ("object","/éobj%"),
|
||||
array ("where","\$'\""),
|
||||
array ("with space","with space")));
|
||||
$this->assertSame (array (0=>array ("group"=>"gr ou\"p",
|
||||
"object"=>"/éobj%",
|
||||
"where"=>"\$'\"",
|
||||
"with space"=>"with space")), $res);
|
||||
}
|
||||
|
||||
public function test_update1 ()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group"=>array ("varchar", "255", "not null"),
|
||||
"object"=>array ("varchar", "255", "not null"),
|
||||
"where"=>array ("varchar", "255", "not null"),
|
||||
"with space"=>array ("varchar", "255", "not null"));
|
||||
$db->unique = array ();
|
||||
$db->primary = "group";
|
||||
$res = $db->update ("gr ou\"p", array ("object"=>"%éàoppp",
|
||||
"with space"=>"WITH SPACE"));
|
||||
$this->assertSame (1, $res);
|
||||
}
|
||||
|
||||
public function test_read2 ()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new dblayer ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group"=>array ("varchar", "255", "not null"),
|
||||
"object"=>array ("varchar", "255", "not null"),
|
||||
"where"=>array ("varchar", "255", "not null"),
|
||||
"with space"=>array ("varchar", "255", "not null"));
|
||||
$db->unique = array ();
|
||||
$res = $db->read (array (array ("group", "gr ou\"p"),
|
||||
array ("object","%éàoppp"),
|
||||
array ("where","\$'\""),
|
||||
array ("with space","WITH SPACE")));
|
||||
$this->assertSame (array (0=>array ("group"=>"gr ou\"p",
|
||||
"object"=>"%éàoppp",
|
||||
"where"=>"\$'\"",
|
||||
"with space"=>"WITH SPACE")), $res);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user