*/ 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"; 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); } }