dblayeroo : review the join process and add the unit tests for it
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3538 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
@@ -38,7 +38,7 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db1 = new dblayeroo ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$db1->table ("groupedoo");
|
||||
$db1->fields (array ("group"=>array ("varchar(255)", "not null"),
|
||||
"object"=>array ("varchar(255)", "not null"),
|
||||
@@ -53,7 +53,7 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db2 = new dblayeroo ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$db2->table ("usersoo");
|
||||
$db2->fields (array ("uid"=>array ("integer", "not null", "autoincrement"),
|
||||
"gecos"=>array ("varchar(255)", "not null"),
|
||||
@@ -62,7 +62,8 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
||||
));
|
||||
$db2->unique (array ("gecos","password"));
|
||||
$db2->primary ("uid");
|
||||
$db2->foreign (array ("group" => array ("groupedoo", "group", "ON DELETE CASCADE")));
|
||||
$db2->foreign (array ("group" => array ("groupedoo", "group",
|
||||
"ON DELETE CASCADE")));
|
||||
return $db2;
|
||||
}
|
||||
|
||||
@@ -70,16 +71,34 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db3 = new dblayeroo ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
return $db3;
|
||||
}
|
||||
|
||||
private function db4 ()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db4 = new dblayeroo ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
$db4->table ("rightsoo");
|
||||
$db4->fields (array ("id"=>array ("integer", "not null", "autoincrement"),
|
||||
"name"=>array ("varchar(255)", "not null"),
|
||||
"group" => array ("varchar(255)", "not null"),
|
||||
));
|
||||
$db4->unique (array ("name"));
|
||||
$db4->primary ("id");
|
||||
$db4->foreign (array ("group" => array ("groupedoo", "group",
|
||||
"ON DELETE CASCADE")));
|
||||
return $db4;
|
||||
}
|
||||
|
||||
public function test_dropTable ()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new dblayeroo ($dbconfig["dsn"], $dbconfig["username"],
|
||||
$dbconfig["password"], $dbconfig["driver_options"]);
|
||||
foreach (array ("usersoo", "groupedoo", "multipleoo", "multiple2oo", "users3oo",
|
||||
foreach (array ("rightsoo", "usersoo", "groupedoo",
|
||||
"multipleoo", "multiple2oo", "users3oo",
|
||||
"readORoo") as
|
||||
$table)
|
||||
{
|
||||
@@ -115,6 +134,15 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
||||
$this->assertSame (0, $res);
|
||||
}
|
||||
|
||||
public function test_createTable4 ()
|
||||
{
|
||||
// Create a table named rightsoo
|
||||
$db4 = $this->db4 ();
|
||||
$res = $db4->createTable ();
|
||||
$db4->disconnect ();
|
||||
$this->assertSame (0, $res);
|
||||
}
|
||||
|
||||
public function test_select1 ()
|
||||
{
|
||||
// Select all on the table : nothing
|
||||
@@ -511,9 +539,10 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function test_leftJoin3 ()
|
||||
{
|
||||
// Filter on the db1
|
||||
// Filter on the db1, do not display db2
|
||||
$db1 = $this->db1 ();
|
||||
$db2 = $this->db2 ();
|
||||
$db2->displayColumn ();
|
||||
$res = $db1->select ()
|
||||
->displayColumn ("group")
|
||||
->joinLeft ($db2, array ("group"=>"group"))
|
||||
@@ -541,7 +570,7 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
||||
|
||||
public function test_leftJoin4 ()
|
||||
{
|
||||
// Filter on the db1
|
||||
// Filter on the db1, display one column in db2
|
||||
$db1 = $this->db1 ();
|
||||
$db2 = $this->db2 ();
|
||||
$db2->displayColumn ("group");
|
||||
@@ -553,24 +582,125 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
|
||||
$db2->disconnect ();
|
||||
$this->assertSame (array (
|
||||
array (
|
||||
'usersoo.group' => 'group1',
|
||||
'groupedoo.group' => 'group1',
|
||||
'usersoo.group' => 'group1',
|
||||
),
|
||||
array (
|
||||
'usersoo.group' => 'group1',
|
||||
'groupedoo.group' => 'group1',
|
||||
'usersoo.group' => 'group1',
|
||||
),
|
||||
array (
|
||||
'usersoo.group' => 'group1',
|
||||
'groupedoo.group' => 'group1',
|
||||
'usersoo.group' => 'group1',
|
||||
),
|
||||
array (
|
||||
'usersoo.group' => 'group1',
|
||||
'groupedoo.group' => 'group1',
|
||||
'usersoo.group' => 'group1',
|
||||
),
|
||||
array (
|
||||
'usersoo.group' => NULL,
|
||||
'groupedoo.group' => 'group2',
|
||||
'usersoo.group' => NULL,
|
||||
),
|
||||
), $res);
|
||||
}
|
||||
|
||||
public function test_leftJoin5 ()
|
||||
{
|
||||
// Filter on the db1 and add order in full mode
|
||||
$db1 = $this->db1 ();
|
||||
$db2 = $this->db2 ();
|
||||
$db2->displayColumn ("group");
|
||||
$res = $db1->select ()
|
||||
->displayColumn ("group")
|
||||
->joinLeft ($db2, array ("group"=>"group"))
|
||||
->orderAdd ("group", "DESC")
|
||||
->execute ();
|
||||
$db1->disconnect ();
|
||||
$db2->disconnect ();
|
||||
$this->assertSame (array (
|
||||
array (
|
||||
'groupedoo.group' => 'group2',
|
||||
'usersoo.group' => NULL,
|
||||
),
|
||||
array (
|
||||
'groupedoo.group' => 'group1',
|
||||
'usersoo.group' => 'group1',
|
||||
),
|
||||
array (
|
||||
'groupedoo.group' => 'group1',
|
||||
'usersoo.group' => 'group1',
|
||||
),
|
||||
array (
|
||||
'groupedoo.group' => 'group1',
|
||||
'usersoo.group' => 'group1',
|
||||
),
|
||||
array (
|
||||
'groupedoo.group' => 'group1',
|
||||
'usersoo.group' => 'group1',
|
||||
),
|
||||
), $res);
|
||||
}
|
||||
|
||||
/// THREE TABLES ///
|
||||
public function test_insert6 ()
|
||||
{
|
||||
$db1 = $this->db1 ();
|
||||
$db4 = $this->db4 ();
|
||||
$db4->setForeignObj ($db1);
|
||||
$res = $db4->insert ()
|
||||
->setValues(array ("name"=>"RO",
|
||||
"group"=>"group1"))
|
||||
->execute ();
|
||||
$db4->disconnect ();
|
||||
// As the key is not an autoincrement, the lastInsertID can be 0 or 1
|
||||
$this->assertGreaterThanOrEqual ($res, "0");
|
||||
}
|
||||
|
||||
public function test_leftJoin6 ()
|
||||
{
|
||||
// Two joins tables in left join
|
||||
$db1 = $this->db1 (); // Do not display anything from groupedoo
|
||||
$db1->displayColumn ("group");
|
||||
|
||||
$db2 = $this->db2 (); // Display the gecos and group from usersoo
|
||||
$db2->displayColumn ("gecos")
|
||||
->orderAdd ("gecos", "ASC");
|
||||
|
||||
$db4 = $this->db4 (); // Display the name in rightsoo
|
||||
$db4->displayColumn ("name");
|
||||
$db1->joinLeft ($db4, array ("group"=>"group"));
|
||||
$res = $db1->select ()
|
||||
->joinLeft ($db2, array ("group"=>"group"))
|
||||
->orderAdd ("group", "DESC")
|
||||
->execute ();
|
||||
$db1->disconnect ();
|
||||
$db2->disconnect ();
|
||||
$db4->disconnect ();
|
||||
$this->assertSame (array (
|
||||
array (
|
||||
'groupedoo.group' => 'group1',
|
||||
'rightsoo.name' => 'RO',
|
||||
'usersoo.gecos' => 'name',
|
||||
),
|
||||
array (
|
||||
'groupedoo.group' => 'group1',
|
||||
'rightsoo.name' => 'RO',
|
||||
'usersoo.gecos' => 'name2',
|
||||
),
|
||||
array (
|
||||
'groupedoo.group' => 'group1',
|
||||
'rightsoo.name' => 'RO',
|
||||
'usersoo.gecos' => 'name3',
|
||||
),
|
||||
array (
|
||||
'groupedoo.group' => 'group1',
|
||||
'rightsoo.name' => 'RO',
|
||||
'usersoo.gecos' => 'name4',
|
||||
),
|
||||
array (
|
||||
'groupedoo.group' => 'group2',
|
||||
'rightsoo.name' => NULL,
|
||||
'usersoo.gecos' => NULL,
|
||||
),
|
||||
), $res);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user