This commit is contained in:
2022-11-25 21:21:30 +01:00
parent 2d6df0d5f0
commit 94deb06f52
132 changed files with 44887 additions and 41368 deletions

View File

@@ -1,4 +1,5 @@
<?php
/** DomFramework - Tests
* @package domframework
* @author Dominique Fournier <dominique@fournier38.fr>
@@ -9,13 +10,13 @@ namespace Domframework\Tests;
use Domframework\Dblayer;
class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
class DblayerTest { 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 $engine = "{ENGINE}";
public $confs = array (
"sqlite" => array (
"dsn" => "sqlite:/tmp/databaseDBLayer.db",
@@ -41,353 +42,426 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
);
/** @group singleton */
public function test_dropTable ()
public function test_dropTable()
{
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
foreach (array ("users", "grouped", "multiple", "multiple2", "users3",
"readOR") as
$table)
{
$db->table = $table;
try
{
$res = $db->dropTable();
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer(
$dbconfig["dsn"],
$dbconfig["username"],
$dbconfig["password"],
$dbconfig["driver_options"]
);
foreach (
array ("users", "grouped", "multiple", "multiple2", "users3",
"readOR") as $table
) {
$db->table = $table;
try {
$res = $db->dropTable();
} catch (\Exception $e) {
}
}
catch (\Exception $e)
{
}
}
$db->disconnect ();
$db->disconnect();
// Never generate an error, just drop the table if it exists, and do noting
// if it doesn't exists
}
/** @group singleton */
public function test_createTable1 ()
public function test_createTable1()
{
// Create a table named grouped
$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->createTable ();
$db->disconnect ();
$this->assertSame (0, $res);
$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->createTable();
$db->disconnect();
$this->assertSame(0, $res);
}
/** @group singleton */
public function test_insert1 ()
public function test_insert1()
{
$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->insert (array ("group"=>"gr ou\"p",
"object"=>"/éobj%",
"where"=>"\$'\"",
"with space"=>"with space"));
$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->insert(array ("group" => "gr ou\"p",
"object" => "/éobj%",
"where" => "\$'\"",
"with space" => "with space"));
// SQLite start at 1, MySQL start at 0...
$this->assertSame ($res, "gr ou\"p");
$this->assertSame($res, "gr ou\"p");
}
public function test_read1 ()
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"),
$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);
$this->assertSame(array (0 => array ("group" => "gr ou\"p",
"object" => "/éobj%",
"where" => "\$'\"",
"with space" => "with space")), $res);
}
public function test_update1 ()
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";
$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";
// Don't update primary key
$res = $db->update ("gr ou\"p", array ("object"=>"%éàoppp",
"with space"=>"WITH SPACE"));
$this->assertSame (1, $res);
$res = $db->update("gr ou\"p", array ("object" => "%éàoppp",
"with space" => "WITH SPACE"));
$this->assertSame(1, $res);
}
public function test_read2 ()
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"),
$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);
$this->assertSame(array (0 => array ("group" => "gr ou\"p",
"object" => "%éàoppp",
"where" => "\$'\"",
"with space" => "WITH SPACE")), $res);
}
public function test_update2 ()
public function test_update2()
{
$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 (array ("group","object"));
$db->primary = "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"));
$db->unique = array (array ("group","object"));
$db->primary = "group";
// Update primary key
$res = $db->update ("gr ou\"p", array ("group"=>"NEW GROUP",
"object"=>"%éàoppp",
"with space"=>"WITH SPACE"));
$this->assertSame (1, $res);
$res = $db->update("gr ou\"p", array ("group" => "NEW GROUP",
"object" => "%éàoppp",
"with space" => "WITH SPACE"));
$this->assertSame(1, $res);
}
public function test_read3 ()
public function test_read3()
{
$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", "NEW 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"));
$db->unique = array ();
$res = $db->read(array (array ("group", "NEW GROUP"),
array ("object","%éàoppp"),
array ("where","\$'\""),
array ("with space","WITH SPACE")));
$this->assertSame (array (0=>array ("group"=>"NEW GROUP",
"object"=>"%éàoppp",
"where"=>"\$'\"",
"with space"=>"WITH SPACE")), $res);
$this->assertSame(array (0 => array ("group" => "NEW GROUP",
"object" => "%éàoppp",
"where" => "\$'\"",
"with space" => "WITH SPACE")), $res);
}
public function test_update3 ()
public function test_update3()
{
$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 ("group");
$db->primary = "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"));
$db->unique = array ("group");
$db->primary = "group";
// Update primary key with primary key in unique with same values to test if
// the exception is NOT raised
$res = $db->update ("NEW GROUP", array ("group"=>"NEW GROUP",
"object"=>"%éàoppp",
"with space"=>"WITH SPACE"));
$res = $db->update("NEW GROUP", array ("group" => "NEW GROUP",
"object" => "%éàoppp",
"with space" => "WITH SPACE"));
// SQLite and PostgreSQL return 1 line modified
// MySQL return 0 by default because there is no modification on the line
// http://fr2.php.net/manual/en/pdostatement.rowcount.php#104930
// Now, the MYSQL_ATTR_FOUND_ROWS is added to connection to be the same in
// all the engines
$this->assertSame (1, $res);
$this->assertSame(1, $res);
}
/** @group singleton */
// Part to test the foreign keys
public function test_createTable2 ()
public function test_createTable2()
{
// Create a table named group
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db->disconnect ();
$db = new Dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db->table = "users";
$db->fields = array ("user"=>array ("varchar", "255", "not null"),
"groupmember"=>array ("varchar", "255", "not null"),
"where"=>array ("varchar", "255", "not null"),
"with space"=>array ("varchar", "255", "not null"));
$db->foreign = array (
"groupmember"=>array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
);
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer(
$dbconfig["dsn"],
$dbconfig["username"],
$dbconfig["password"],
$dbconfig["driver_options"]
);
$db->disconnect();
$db = new Dblayer(
$dbconfig["dsn"],
$dbconfig["username"],
$dbconfig["password"],
$dbconfig["driver_options"]
);
$db->table = "users";
$db->fields = array ("user" => array ("varchar", "255", "not null"),
"groupmember" => array ("varchar", "255", "not null"),
"where" => array ("varchar", "255", "not null"),
"with space" => array ("varchar", "255", "not null"));
$db->foreign = array (
"groupmember" => array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
);
$res = $db->createTable ();
$this->assertSame (0, $res);
$res = $db->createTable();
$this->assertSame(0, $res);
}
public function test_insert2 ()
public function test_insert2()
{
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db->table = "users";
$db->fields = array ("user"=>array ("varchar", "255", "not null"),
"groupmember"=>array ("varchar", "255", "not null"),
"where"=>array ("varchar", "255", "not null"),
"with space"=>array ("varchar", "255", "not null"));
$db->unique = array ("user");
$db->primary = "user";
$db->foreign = array (
"groupmember"=>array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
);
$res = $db->insert (array ("user"=>"Us ou\"r",
"groupmember"=>"NEW GROUP",
"where"=>"\$'\"",
"with space"=>"with space"));
$db->disconnect ();
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer(
$dbconfig["dsn"],
$dbconfig["username"],
$dbconfig["password"],
$dbconfig["driver_options"]
);
$db->table = "users";
$db->fields = array ("user" => array ("varchar", "255", "not null"),
"groupmember" => array ("varchar", "255", "not null"),
"where" => array ("varchar", "255", "not null"),
"with space" => array ("varchar", "255", "not null"));
$db->unique = array ("user");
$db->primary = "user";
$db->foreign = array (
"groupmember" => array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
);
$res = $db->insert(array ("user" => "Us ou\"r",
"groupmember" => "NEW GROUP",
"where" => "\$'\"",
"with space" => "with space"));
$db->disconnect();
// SQLite start at 1, MySQL start at 0...
$this->assertLessThanOrEqual ($res, 2);
$this->assertLessThanOrEqual($res, 2);
}
// Test the unique feature
public function test_insert3 ()
public function test_insert3()
{
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db->table = "users";
$db->fields = array ("user"=>array ("varchar", "255", "not null"),
"groupmember"=>array ("varchar", "255", "not null"),
"where"=>array ("varchar", "255", "not null"),
"with space"=>array ("varchar", "255", "not null"));
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer(
$dbconfig["dsn"],
$dbconfig["username"],
$dbconfig["password"],
$dbconfig["driver_options"]
);
$db->table = "users";
$db->fields = array ("user" => array ("varchar", "255", "not null"),
"groupmember" => array ("varchar", "255", "not null"),
"where" => array ("varchar", "255", "not null"),
"with space" => array ("varchar", "255", "not null"));
// Unique simple in insert
$db->unique = array ("user");
$db->primary = "user";
$db->foreign = array (
"groupmember"=>array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
);
$this->setExpectedException ("Exception");
$res = $db->insert (array ("user"=>"Us ou\"r",
"groupmember"=>"NEW GROUP",
"where"=>"\$'\"",
"with space"=>"with space"));
$db->unique = array ("user");
$db->primary = "user";
$db->foreign = array (
"groupmember" => array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
);
$this->setExpectedException("Exception");
$res = $db->insert(array ("user" => "Us ou\"r",
"groupmember" => "NEW GROUP",
"where" => "\$'\"",
"with space" => "with space"));
}
public function test_insert4 ()
public function test_insert4()
{
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db->table = "users";
$db->fields = array ("user"=>array ("varchar", "255", "not null"),
"groupmember"=>array ("varchar", "255", "not null"),
"where"=>array ("varchar", "255", "not null"),
"with space"=>array ("varchar", "255", "not null"));
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer(
$dbconfig["dsn"],
$dbconfig["username"],
$dbconfig["password"],
$dbconfig["driver_options"]
);
$db->table = "users";
$db->fields = array ("user" => array ("varchar", "255", "not null"),
"groupmember" => array ("varchar", "255", "not null"),
"where" => array ("varchar", "255", "not null"),
"with space" => array ("varchar", "255", "not null"));
// Unique multiple in insert
$db->unique = array (array ("user", "groupmember"));
$db->primary = "user";
$db->foreign = array (
"groupmember"=>array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
);
$this->setExpectedException ("Exception");
$res = $db->insert (array ("user"=>"Us ou\"r",
"groupmember"=>"NEW GROUP",
"where"=>"\$'\"",
"with space"=>"with space"));
$db->unique = array (array ("user", "groupmember"));
$db->primary = "user";
$db->foreign = array (
"groupmember" => array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
);
$this->setExpectedException("Exception");
$res = $db->insert(array ("user" => "Us ou\"r",
"groupmember" => "NEW GROUP",
"where" => "\$'\"",
"with space" => "with space"));
}
/** @group singleton */
// Test multiple actions in one single connection
public function test_multiple1 ()
public function test_multiple1()
{
// Create a table named group
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db->table = "multiple";
$db->fields = array ("user"=>array ("varchar", "255", "not null"),
"groupmember"=>array ("varchar", "255", "not null"),
"where"=>array ("varchar", "255", "not null"),
"with space"=>array ("varchar", "255", "not null"));
$db->createTable ();
$db2 = new Dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db2->table = "multiple2";
$db2->fields = array ("user"=>array ("varchar", "255", "not null"),
"groupmember"=>array ("varchar", "255", "not null"),
"where"=>array ("varchar", "255", "not null"),
"with space"=>array ("varchar", "255", "not null"));
$db2->createTable ();
$res = $db2->read (array (array ("user", "toto")));
$res = $db->read (array (array ("user", "toto")));
$db->disconnect ();
$this->assertSame (array (), $res);
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer(
$dbconfig["dsn"],
$dbconfig["username"],
$dbconfig["password"],
$dbconfig["driver_options"]
);
$db->table = "multiple";
$db->fields = array ("user" => array ("varchar", "255", "not null"),
"groupmember" => array ("varchar", "255", "not null"),
"where" => array ("varchar", "255", "not null"),
"with space" => array ("varchar", "255", "not null"));
$db->createTable();
$db2 = new Dblayer(
$dbconfig["dsn"],
$dbconfig["username"],
$dbconfig["password"],
$dbconfig["driver_options"]
);
$db2->table = "multiple2";
$db2->fields = array ("user" => array ("varchar", "255", "not null"),
"groupmember" => array ("varchar", "255", "not null"),
"where" => array ("varchar", "255", "not null"),
"with space" => array ("varchar", "255", "not null"));
$db2->createTable();
$res = $db2->read(array (array ("user", "toto")));
$res = $db->read(array (array ("user", "toto")));
$db->disconnect();
$this->assertSame(array (), $res);
}
/** @group singleton */
public function test_createTable3 ()
public function test_createTable3()
{
// Create a table named group
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db->table = "users3";
$db->fields = array ("user"=>array ("varchar", "255", "not null"),
"groupmember"=>array ("varchar", "255", "not null"),
"where"=>array ("varchar", "255", "not null"),
"with space"=>array ("varchar", "255", "not null"));
$res = $db->createTable ();
$db->disconnect ();
$this->assertSame (0, $res);
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer(
$dbconfig["dsn"],
$dbconfig["username"],
$dbconfig["password"],
$dbconfig["driver_options"]
);
$db->table = "users3";
$db->fields = array ("user" => array ("varchar", "255", "not null"),
"groupmember" => array ("varchar", "255", "not null"),
"where" => array ("varchar", "255", "not null"),
"with space" => array ("varchar", "255", "not null"));
$res = $db->createTable();
$db->disconnect();
$this->assertSame(0, $res);
}
/** Check the OR feature on the same column with different value */
public function test_readOR1 ()
public function test_readOR1()
{
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$db->table = "readOR";
$db->fields = array ("id"=>array ("integer"),
"user"=>array ("varchar", "255", "not null"));
$db->primary = "id";
$db->unique = array ("id");
$db->createTable ();
$db->insert (array ("id"=>"0", "user"=>"test0"));
$db->insert (array ("id"=>"1", "user"=>"test1"));
$res = $db->read (array (array ("id", 0), array ("id", 1)), array ("user"),
null, true);
$db->disconnect ();
$this->assertSame (array (0=>array ("user"=>"test0"),
1=>array ("user"=>"test1")), $res);
$dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer(
$dbconfig["dsn"],
$dbconfig["username"],
$dbconfig["password"],
$dbconfig["driver_options"]
);
$db->table = "readOR";
$db->fields = array ("id" => array ("integer"),
"user" => array ("varchar", "255", "not null"));
$db->primary = "id";
$db->unique = array ("id");
$db->createTable();
$db->insert(array ("id" => "0", "user" => "test0"));
$db->insert(array ("id" => "1", "user" => "test1"));
$res = $db->read(
array (array ("id", 0), array ("id", 1)),
array ("user"),
null,
true
);
$db->disconnect();
$this->assertSame(array (0 => array ("user" => "test0"),
1 => array ("user" => "test1")), $res);
}
}
}