Files
DomFramework/Tests/dblayerComplet.php
Dominique Fournier 2c21043a9e BUG : dblayer : UPDATE can now update the table primary key too
dblayer : add support of the differents field separator (choosed by DB engine)
Add more unit tests


git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@1813 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
2014-09-12 14:14:26 +00:00

148 lines
5.8 KiB
PHP

<?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" => "",
),
"pgsql" => array (
"dsn" => "pgsql:host=127.0.0.1;port=5432;dbname=dbname",
"username" => "root",
"password" => "root",
"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";
try
{
$res = $db->dropTable();
}
catch (Exception $e)
{
}
// Never generate an error, just drop the table if it exists, and do noting
// if it doesn't exists
}
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"));
// SQLite start at 1, MySQL start at 0...
$this->assertThat($res, $this->lessThanOrEqual(1));
}
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);
}
}