BUG : dblayer : add more unit tests git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1809 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
129 lines
5.6 KiB
PHP
129 lines
5.6 KiB
PHP
<?php
|
|
/** DomFramework - Tests
|
|
@package domframework
|
|
@author Dominique Fournier <dominique@fournier38.fr> */
|
|
|
|
/** Test the dblayer.php file */
|
|
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 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);
|
|
}
|
|
}
|