BUG : dblayer : allow to prepare the SQL with fields containing spaces

BUG : dblayer : add more unit tests


git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1809 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2014-09-11 13:05:53 +00:00
parent b496dadc62
commit 50c328cdd6
2 changed files with 365 additions and 171 deletions

View File

@@ -16,5 +16,113 @@ class test_dblayer extends PHPUnit_Framework_TestCase
$dbconfig["tableprefix"] = "";
}
// Test with column name 'group', 'object', 'where', 'with space'
// Test with table name 'group', 'object', 'where', 'with space'
// For the 3 DB engines
public function test_createTable ()
{
// Create a table named group
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$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 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$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 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$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 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$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";
$db->update ("gr ou\"p", array ("object"=>"%éàoppp",
"with space"=>"WITH SPACE"));
}
public function test_read2 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$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);
}
}