dblayeroo : Update tests to be valid without the GROUP BY as they were in rev 3538

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@3827 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2017-07-25 09:32:42 +00:00
parent eea451b131
commit 391eb9e83b

View File

@@ -34,62 +34,62 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
), ),
); );
private function db1 () private function tbl1 ()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db1 = new dblayeroo ($dbconfig["dsn"], $dbconfig["username"], $tbl1 = new dblayeroo ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]); $dbconfig["password"], $dbconfig["driver_options"]);
$db1->table ("groupedoo"); $tbl1->table ("groupedoo");
$db1->fields (array ("group"=>array ("varchar(255)", "not null"), $tbl1->fields (array ("group"=>array ("varchar(255)", "not null"),
"object"=>array ("varchar(255)", "not null"), "object"=>array ("varchar(255)", "not null"),
"where"=>array ("varchar(255)", "not null"), "where"=>array ("varchar(255)", "not null"),
"with space"=>array ("varchar(255)"))); "with space"=>array ("varchar(255)")));
$db1->unique (array ()); $tbl1->unique (array ());
$db1->primary ("group"); $tbl1->primary ("group");
return $db1; return $tbl1;
} }
private function db2 () private function tbl2 ()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db2 = new dblayeroo ($dbconfig["dsn"], $dbconfig["username"], $tbl2 = new dblayeroo ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]); $dbconfig["password"], $dbconfig["driver_options"]);
$db2->table ("usersoo"); $tbl2->table ("usersoo");
$db2->fields (array ("uid"=>array ("integer", "not null", "autoincrement"), $tbl2->fields (array ("uid"=>array ("integer", "not null", "autoincrement"),
"gecos"=>array ("varchar(255)", "not null"), "gecos"=>array ("varchar(255)", "not null"),
"password"=>array ("varchar(255)", "not null"), "password"=>array ("varchar(255)", "not null"),
"group" => array ("varchar(255)", "not null"), "group" => array ("varchar(255)", "not null"),
)); ));
$db2->unique (array ("gecos","password")); $tbl2->unique (array ("gecos","password"));
$db2->primary ("uid"); $tbl2->primary ("uid");
$db2->foreign (array ("group" => array ("groupedoo", "group", $tbl2->foreign (array ("group" => array ("groupedoo", "group",
"ON DELETE CASCADE"))); "ON DELETE CASCADE")));
return $db2; return $tbl2;
} }
private function db3 () private function tbl3 ()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db3 = new dblayeroo ($dbconfig["dsn"], $dbconfig["username"], $tbl3 = new dblayeroo ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]); $dbconfig["password"], $dbconfig["driver_options"]);
return $db3; return $tbl3;
} }
private function db4 () private function tbl4 ()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db4 = new dblayeroo ($dbconfig["dsn"], $dbconfig["username"], $tbl4 = new dblayeroo ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]); $dbconfig["password"], $dbconfig["driver_options"]);
$db4->table ("rightsoo"); $tbl4->table ("rightsoo");
$db4->fields (array ("id"=>array ("integer", "not null", "autoincrement"), $tbl4->fields (array ("id"=>array ("integer", "not null", "autoincrement"),
"name"=>array ("varchar(255)", "not null"), "name"=>array ("varchar(255)", "not null"),
"group" => array ("varchar(255)", "not null"), "group" => array ("varchar(255)", "not null"),
)); ));
$db4->unique (array ("name")); $tbl4->unique (array ("name"));
$db4->primary ("id"); $tbl4->primary ("id");
$db4->foreign (array ("group" => array ("groupedoo", "group", $tbl4->foreign (array ("group" => array ("groupedoo", "group",
"ON DELETE CASCADE"))); "ON DELETE CASCADE")));
return $db4; return $tbl4;
} }
public function test_dropTable () public function test_dropTable ()
@@ -119,36 +119,36 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
public function test_createTable1 () public function test_createTable1 ()
{ {
// Create a table named groupedoo // Create a table named groupedoo
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->createTable (); $res = $tbl1->createTable ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (0, $res); $this->assertSame (0, $res);
} }
public function test_createTable2 () public function test_createTable2 ()
{ {
// Create a table named usersoo // Create a table named usersoo
$db2 = $this->db2 (); $tbl2 = $this->tbl2 ();
$res = $db2->createTable (); $res = $tbl2->createTable ();
$db2->disconnect (); $tbl2->disconnect ();
$this->assertSame (0, $res); $this->assertSame (0, $res);
} }
public function test_createTable4 () public function test_createTable4 ()
{ {
// Create a table named rightsoo // Create a table named rightsoo
$db4 = $this->db4 (); $tbl4 = $this->tbl4 ();
$res = $db4->createTable (); $res = $tbl4->createTable ();
$db4->disconnect (); $tbl4->disconnect ();
$this->assertSame (0, $res); $this->assertSame (0, $res);
} }
public function test_select1 () public function test_select1 ()
{ {
// Select all on the table : nothing // Select all on the table : nothing
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->select()->execute (); $res = $tbl1->select()->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array (), $res); $this->assertSame (array (), $res);
} }
@@ -156,29 +156,30 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
{ {
// Insert without value : raise an exception // Insert without value : raise an exception
$this->setExpectedException ("Exception"); $this->setExpectedException ("Exception");
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->insert()->execute (); $res = $tbl1->insert()->execute ();
$db1->disconnect (); $tbl1->disconnect ();
} }
public function test_insert2 () public function test_insert2 ()
{ {
// Insert : missing not null field : exception // Insert : missing not null field : exception
$this->setExpectedException ("Exception"); $this->setExpectedException ("Exception");
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->insert() $res = $tbl1->insert()
->setValues(array ("group"=>"group1", "where"=>"where")) ->setValues(array ("group"=>"group1", "where"=>"where"))
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
} }
public function test_insert3 () public function test_insert3 ()
{ {
// Insert : first row inserted // Insert : first row inserted
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->insert()->setValues(array ("group"=>"group1", "where"=>"where", $res = $tbl1->insert()->setValues(array ("group"=>"group1",
"object"=>"object"))->execute (); "where"=>"where",
$db1->disconnect (); "object"=>"object"))->execute ();
$tbl1->disconnect ();
// As the key is not an autoincrement, the lastInsertID can be 0 or 1 // As the key is not an autoincrement, the lastInsertID can be 0 or 1
$this->assertGreaterThanOrEqual ($res, "0"); $this->assertGreaterThanOrEqual ($res, "0");
} }
@@ -186,9 +187,9 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
public function test_select2 () public function test_select2 ()
{ {
// Select all on the table : nothing // Select all on the table : nothing
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->select()->execute (); $res = $tbl1->select()->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array (array ("group"=>"group1", "object"=>"object", $this->assertSame (array (array ("group"=>"group1", "object"=>"object",
"where"=>"where", "with space"=>null)), "where"=>"where", "with space"=>null)),
$res); $res);
@@ -197,19 +198,20 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
public function test_update1 () public function test_update1 ()
{ {
// update the all the rows of the table (without WHERE) // update the all the rows of the table (without WHERE)
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->update()->setValues(array ("group"=>"group2", "where"=>"where", $res = $tbl1->update()->setValues(array ("group"=>"group2",
"object"=>"object"))->execute (); "where"=>"where",
$db1->disconnect (); "object"=>"object"))->execute ();
$tbl1->disconnect ();
$this->assertSame (1, $res); $this->assertSame (1, $res);
} }
public function test_select3 () public function test_select3 ()
{ {
// Select all on the table after update // Select all on the table after update
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->select()->execute (); $res = $tbl1->select()->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array (array ("group"=>"group2", "object"=>"object", $this->assertSame (array (array ("group"=>"group2", "object"=>"object",
"where"=>"where", "with space"=>null)), "where"=>"where", "with space"=>null)),
$res); $res);
@@ -218,26 +220,26 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
public function test_update2 () public function test_update2 ()
{ {
// update the all the rows of the table (with inexisting WHERE) // update the all the rows of the table (with inexisting WHERE)
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->update() $res = $tbl1->update()
->setValues(array ("group"=>"group2", "where"=>"where", ->setValues(array ("group"=>"group2", "where"=>"where",
"object"=>"object")) "object"=>"object"))
->whereAdd ("group", "=", "group1") ->whereAdd ("group", "=", "group1")
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (0, $res); $this->assertSame (0, $res);
} }
public function test_update3 () public function test_update3 ()
{ {
// update the all the rows of the table (with existing WHERE) // update the all the rows of the table (with existing WHERE)
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->update() $res = $tbl1->update()
->setValues(array ("group"=>"group1", "where"=>"where", ->setValues(array ("group"=>"group1", "where"=>"where",
"object"=>"object")) "object"=>"object"))
->whereAdd ("group", "=", "group2") ->whereAdd ("group", "=", "group2")
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (1, $res); $this->assertSame (1, $res);
} }
@@ -245,51 +247,52 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
{ {
// update the all the rows of the table : NOT NULL value not provided // update the all the rows of the table : NOT NULL value not provided
// (already existing in the table) // (already existing in the table)
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->update() $res = $tbl1->update()
->setValues(array ("group"=>"group1")) ->setValues(array ("group"=>"group1"))
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (1, $res); $this->assertSame (1, $res);
} }
public function test_delete1 () public function test_delete1 ()
{ {
// Delete : WHERE return nothing // Delete : WHERE return nothing
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->delete () $res = $tbl1->delete ()
->whereAdd ("group", "=", "group2") ->whereAdd ("group", "=", "group2")
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (0, $res); $this->assertSame (0, $res);
} }
public function test_delete2 () public function test_delete2 ()
{ {
// Delete all // Delete all
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->delete () $res = $tbl1->delete ()
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (1, $res); $this->assertSame (1, $res);
} }
public function test_select4 () public function test_select4 ()
{ {
// Select all on the table : nothing // Select all on the table : nothing
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->select()->execute (); $res = $tbl1->select()->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array (), $res); $this->assertSame (array (), $res);
} }
public function test_insert5 () public function test_insert5 ()
{ {
// Insert : first row inserted for TABLE 2 tests // Insert : first row inserted for TABLE 2 tests
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->insert()->setValues(array ("group"=>"group1", "where"=>"where", $res = $tbl1->insert()->setValues(array ("group"=>"group1",
"object"=>"object"))->execute (); "where"=>"where",
$db1->disconnect (); "object"=>"object"))->execute ();
$tbl1->disconnect ();
// As the key is not an autoincrement, the lastInsertID can be 0 or 1 // As the key is not an autoincrement, the lastInsertID can be 0 or 1
$this->assertGreaterThanOrEqual ($res, "0"); $this->assertGreaterThanOrEqual ($res, "0");
} }
@@ -300,68 +303,68 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
public function test_insertAutoincrement1 () public function test_insertAutoincrement1 ()
{ {
// Test autoincrement // Test autoincrement
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db2 = $this->db2 (); $tbl2 = $this->tbl2 ();
$db2->setForeignObj ($db1); $tbl2->setForeignObj ($tbl1);
$res = $db2->insert()->setValues(array ("gecos"=>"name", $res = $tbl2->insert()->setValues(array ("gecos"=>"name",
"password"=>"toto", "password"=>"toto",
"group"=>"group1"))->execute (); "group"=>"group1"))->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$db2->disconnect (); $tbl2->disconnect ();
$this->assertSame ("1", $res); $this->assertSame ("1", $res);
} }
public function test_insertAutoincrement2 () public function test_insertAutoincrement2 ()
{ {
// Test autoincrement // Test autoincrement
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db2 = $this->db2 (); $tbl2 = $this->tbl2 ();
$db2->setForeignObj ($db1); $tbl2->setForeignObj ($tbl1);
$res = $db2->insert()->setValues(array ("gecos"=>"firstname2", $res = $tbl2->insert()->setValues(array ("gecos"=>"firstname2",
"password"=>"toto2", "password"=>"toto2",
"group"=>"group1"))->execute (); "group"=>"group1"))->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$db2->disconnect (); $tbl2->disconnect ();
$this->assertSame ("2", $res); $this->assertSame ("2", $res);
} }
public function test_insertAutoincrement3 () public function test_insertAutoincrement3 ()
{ {
// Test autoincrement // Test autoincrement
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db2 = $this->db2 (); $tbl2 = $this->tbl2 ();
$db2->setForeignObj ($db1); $tbl2->setForeignObj ($tbl1);
$res = $db2->insert()->setValues(array ("gecos"=>"firstname3", $res = $tbl2->insert()->setValues(array ("gecos"=>"firstname3",
"password"=>"toto3", "password"=>"toto3",
"group"=>"group1"))->execute (); "group"=>"group1"))->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$db2->disconnect (); $tbl2->disconnect ();
$this->assertSame ("3", $res); $this->assertSame ("3", $res);
} }
public function test_delete3 () public function test_delete3 ()
{ {
// Delete with WHERE clause // Delete with WHERE clause
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db2 = $this->db2 (); $tbl2 = $this->tbl2 ();
$db2->setForeignObj ($db1); $tbl2->setForeignObj ($tbl1);
$res = $db2->delete () $res = $tbl2->delete ()
->whereAdd ("gecos", "LIKE", "firstname%") ->whereAdd ("gecos", "LIKE", "firstname%")
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$db2->disconnect (); $tbl2->disconnect ();
$this->assertSame (2, $res); $this->assertSame (2, $res);
} }
public function test_select5 () public function test_select5 ()
{ {
// Select all on the table : one entry "gecos"=>"name" // Select all on the table : one entry "gecos"=>"name"
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db2 = $this->db2 (); $tbl2 = $this->tbl2 ();
$db2->setForeignObj ($db1); $tbl2->setForeignObj ($tbl1);
$res = $db2->select()->execute (); $res = $tbl2->select()->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$db2->disconnect (); $tbl2->disconnect ();
$this->assertSame (array (array ("uid"=>1, $this->assertSame (array (array ("uid"=>1,
"gecos"=>"name", "gecos"=>"name",
"password"=>"toto", "password"=>"toto",
@@ -371,9 +374,9 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
/// SCHEMA MANAGEMENT /// /// SCHEMA MANAGEMENT ///
public function test_getTableSchema1 () public function test_getTableSchema1 ()
{ {
$db3 = $this->db3 (); $tbl3 = $this->tbl3 ();
$res = $db3->getTableSchema ("usersoo"); $res = $tbl3->getTableSchema ("usersoo");
$db3->disconnect (); $tbl3->disconnect ();
$this->assertSame ( $this->assertSame (
array ("fields"=>array ( array ("fields"=>array (
"uid"=>array ("integer", "not null", "autoincrement"), "uid"=>array ("integer", "not null", "autoincrement"),
@@ -392,43 +395,43 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
// JOINS // JOINS
public function test_insertJoin1 () public function test_insertJoin1 ()
{ {
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db1->insert() $tbl1->insert()
->setValues(array ("group"=>"group2", ->setValues(array ("group"=>"group2",
"object"=>"object", "object"=>"object",
"where"=>"where")) "where"=>"where"))
->execute (); ->execute ();
$db2 = $this->db2 (); $tbl2 = $this->tbl2 ();
$db2->setForeignObj ($db1); $tbl2->setForeignObj ($tbl1);
$res = $db2->insert() $res = $tbl2->insert()
->setValues(array ("gecos"=>"name2", ->setValues(array ("gecos"=>"name2",
"password"=>"pwd2", "password"=>"pwd2",
"group"=>"group1")) "group"=>"group1"))
->execute (); ->execute ();
$res = $db2->insert() $res = $tbl2->insert()
->setValues(array ("gecos"=>"name3", ->setValues(array ("gecos"=>"name3",
"password"=>"pwd3", "password"=>"pwd3",
"group"=>"group1")) "group"=>"group1"))
->execute (); ->execute ();
$res = $db2->insert() $res = $tbl2->insert()
->setValues(array ("gecos"=>"name4", ->setValues(array ("gecos"=>"name4",
"password"=>"pwd4", "password"=>"pwd4",
"group"=>"group1")) "group"=>"group1"))
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$db2->disconnect (); $tbl2->disconnect ();
} }
public function test_innerJoin1 () public function test_innerJoin1 ()
{ {
// No filter // No filter
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db2 = $this->db2 (); $tbl2 = $this->tbl2 ();
$res = $db2->select () $res = $tbl2->select ()
->joinInner ($db1, array ("group"=>"group")) ->joinInner ($tbl1, array ("group"=>"group"))
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$db2->disconnect (); $tbl2->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
array ( array (
'usersoo.uid' => 1, 'usersoo.uid' => 1,
@@ -476,13 +479,13 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
public function test_leftJoin2 () public function test_leftJoin2 ()
{ {
// No filter // No filter
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db2 = $this->db2 (); $tbl2 = $this->tbl2 ();
$res = $db1->select () $res = $tbl1->select ()
->joinLeft ($db2, array ("group"=>"group")) ->joinLeft ($tbl2, array ("group"=>"group"))
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$db2->disconnect (); $tbl2->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
array ( array (
'groupedoo.group' => 'group1', 'groupedoo.group' => 'group1',
@@ -539,18 +542,27 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
public function test_leftJoin3 () public function test_leftJoin3 ()
{ {
// Filter on the db1, do not display db2 // Filter on the tbl1, do not display tbl2
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db2 = $this->db2 (); $tbl2 = $this->tbl2 ();
$db2->displayAdd (); $tbl2->displayAdd ();
$res = $db1->select () $res = $tbl1->select ()
->displayAdd ("group") ->displayAdd ("group")
->joinLeft ($db2, array ("group"=>"group")) ->joinLeft ($tbl2, array ("group"=>"group"))
->orderAdd ("group", "ASC") ->orderAdd ("group", "ASC")
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$db2->disconnect (); $tbl2->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
array (
'groupedoo.group' => 'group1',
),
array (
'groupedoo.group' => 'group1',
),
array (
'groupedoo.group' => 'group1',
),
array ( array (
'groupedoo.group' => 'group1', 'groupedoo.group' => 'group1',
), ),
@@ -562,17 +574,17 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
public function test_leftJoin4 () public function test_leftJoin4 ()
{ {
// Filter on the db1, display one column in db2 // Filter on the tbl1, display one column in tbl2
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db2 = $this->db2 (); $tbl2 = $this->tbl2 ();
$db2->displayAdd ("group"); $tbl2->displayAdd ("group");
$res = $db1->select () $res = $tbl1->select ()
->displayAdd ("group") ->displayAdd ("group")
->joinLeft ($db2, array ("group"=>"group")) ->joinLeft ($tbl2, array ("group"=>"group"))
->orderAdd ("group", "DESC") ->orderAdd ("group", "DESC")
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$db2->disconnect (); $tbl2->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
array ( array (
'usersoo.group' => NULL, 'usersoo.group' => NULL,
@@ -582,22 +594,34 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
'usersoo.group' => 'group1', 'usersoo.group' => 'group1',
'groupedoo.group' => 'group1', 'groupedoo.group' => 'group1',
), ),
array (
'usersoo.group' => 'group1',
'groupedoo.group' => 'group1',
),
array (
'usersoo.group' => 'group1',
'groupedoo.group' => 'group1',
),
array (
'usersoo.group' => 'group1',
'groupedoo.group' => 'group1',
),
), $res); ), $res);
} }
public function test_leftJoin5 () public function test_leftJoin5 ()
{ {
// Filter on the db1 and add order in full mode // Filter on the tbl1 and add order in full mode
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db2 = $this->db2 (); $tbl2 = $this->tbl2 ();
$db2->displayAdd ("group"); $tbl2->displayAdd ("group");
$res = $db1->select () $res = $tbl1->select ()
->displayAdd ("group") ->displayAdd ("group")
->joinLeft ($db2, array ("group"=>"group")) ->joinLeft ($tbl2, array ("group"=>"group"))
->orderAdd ("group", "DESC") ->orderAdd ("group", "DESC")
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$db2->disconnect (); $tbl2->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
array ( array (
'usersoo.group' => NULL, 'usersoo.group' => NULL,
@@ -607,20 +631,32 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
'usersoo.group' => 'group1', 'usersoo.group' => 'group1',
'groupedoo.group' => 'group1', 'groupedoo.group' => 'group1',
), ),
array (
'usersoo.group' => 'group1',
'groupedoo.group' => 'group1',
),
array (
'usersoo.group' => 'group1',
'groupedoo.group' => 'group1',
),
array (
'usersoo.group' => 'group1',
'groupedoo.group' => 'group1',
),
), $res); ), $res);
} }
/// THREE TABLES /// /// THREE TABLES ///
public function test_insert6 () public function test_insert6 ()
{ {
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db4 = $this->db4 (); $tbl4 = $this->tbl4 ();
$db4->setForeignObj ($db1); $tbl4->setForeignObj ($tbl1);
$res = $db4->insert () $res = $tbl4->insert ()
->setValues(array ("name"=>"RO", ->setValues(array ("name"=>"RO",
"group"=>"group1")) "group"=>"group1"))
->execute (); ->execute ();
$db4->disconnect (); $tbl4->disconnect ();
// As the key is not an autoincrement, the lastInsertID can be 0 or 1 // As the key is not an autoincrement, the lastInsertID can be 0 or 1
$this->assertGreaterThanOrEqual ($res, "0"); $this->assertGreaterThanOrEqual ($res, "0");
} }
@@ -628,23 +664,23 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
public function test_leftJoin6 () public function test_leftJoin6 ()
{ {
// Two joins tables in left join // Two joins tables in left join
$db1 = $this->db1 (); // Do not display anything from groupedoo $tbl1 = $this->tbl1 (); // Do not display anything from groupedoo
$db1->displayAdd ("group") $tbl1->displayAdd ("group")
->orderAdd ("group", "DESC"); ->orderAdd ("group", "DESC");
$db2 = $this->db2 (); // Display the gecos and group from usersoo $tbl2 = $this->tbl2 (); // Display the gecos and group from usersoo
$db2->displayAdd ("gecos") $tbl2->displayAdd ("gecos")
->orderAdd ("gecos", "ASC"); ->orderAdd ("gecos", "ASC");
$db4 = $this->db4 (); // Display the name in rightsoo $tbl4 = $this->tbl4 (); // Display the name in rightsoo
$db4->displayAdd ("name"); $tbl4->displayAdd ("name");
$db1->joinLeft ($db4, array ("group"=>"group")); $tbl1->joinLeft ($tbl4, array ("group"=>"group"));
$res = $db1->select () $res = $tbl1->select ()
->joinLeft ($db2, array ("group"=>"group")) ->joinLeft ($tbl2, array ("group"=>"group"))
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$db2->disconnect (); $tbl2->disconnect ();
$db4->disconnect (); $tbl4->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
array ( array (
'groupedoo.group' => 'group2', 'groupedoo.group' => 'group2',
@@ -676,156 +712,156 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
public function test_sortOrder1 () public function test_sortOrder1 ()
{ {
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->getSortOrder (); $res = $tbl1->getSortOrder ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame ("order1", $res); $this->assertSame ("order1", $res);
} }
public function test_sortOrder2 () public function test_sortOrder2 ()
{ {
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db1->getSortOrder (); $tbl1->getSortOrder ();
$res = $db1->getSortOrder (); $res = $tbl1->getSortOrder ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame ("order2", $res); $this->assertSame ("order2", $res);
} }
public function test_sortOrder3 () public function test_sortOrder3 ()
{ {
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db2 = $this->db2 (); $tbl2 = $this->tbl2 ();
$db1->getSortOrder (); $tbl1->getSortOrder ();
$db1->getSortOrder (); $tbl1->getSortOrder ();
$res = $db2->getSortOrder (); $res = $tbl2->getSortOrder ();
$db1->disconnect (); $tbl1->disconnect ();
$db2->disconnect (); $tbl2->disconnect ();
$this->assertSame ("order3", $res); $this->assertSame ("order3", $res);
} }
public function test_displayAdd_NotFull1 () public function test_displayAdd_NotFull1 ()
{ {
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db1->displayAdd ("group"); $tbl1->displayAdd ("group");
$res = $db1->displayGet (); $res = $tbl1->displayGet ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array ("order1" => $db1->sep()."group".$db1->sep()), $this->assertSame (array ("order1" => $tbl1->sep()."group".$tbl1->sep()),
$res); $res);
} }
public function test_displayAdd_NotFull2 () public function test_displayAdd_NotFull2 ()
{ {
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db1->displayAdd ("distinct group"); $tbl1->displayAdd ("distinct group");
$res = $db1->displayGet (); $res = $tbl1->displayGet ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
"order1" => "DISTINCT ".$db1->sep()."group".$db1->sep()), $res); "order1" => "DISTINCT ".$tbl1->sep()."group".$tbl1->sep()), $res);
} }
public function test_displayAdd_NotFull3 () public function test_displayAdd_NotFull3 ()
{ {
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db1->displayAdd ("group_concat ( group ) "); $tbl1->displayAdd ("group_concat ( group ) ");
$res = $db1->displayGet (); $res = $tbl1->displayGet ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
"order1" => "GROUP_CONCAT(".$db1->sep()."group".$db1->sep().")"), $res); "order1" => "GROUP_CONCAT(".$tbl1->sep()."group".$tbl1->sep().")"), $res);
} }
public function test_displayAdd_NotFull4 () public function test_displayAdd_NotFull4 ()
{ {
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db1->displayAdd ("group_concat (distinct group ) "); $tbl1->displayAdd ("group_concat (distinct group ) ");
$res = $db1->displayGet (); $res = $tbl1->displayGet ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
"order1" => "GROUP_CONCAT(DISTINCT ". "order1" => "GROUP_CONCAT(DISTINCT ".
$db1->sep()."group".$db1->sep().")"), $res); $tbl1->sep()."group".$tbl1->sep().")"), $res);
} }
public function test_displayAdd_NotFull5 () public function test_displayAdd_NotFull5 ()
{ {
// With alias // With alias
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db1->displayAdd ("group_concat (distinct group ) ", "Group Alias"); $tbl1->displayAdd ("group_concat (distinct group ) ", "Group Alias");
$res = $db1->displayGet (); $res = $tbl1->displayGet ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
"order1" => "GROUP_CONCAT(DISTINCT ". "order1" => "GROUP_CONCAT(DISTINCT ".
$db1->sep()."group".$db1->sep().") AS ". $tbl1->sep()."group".$tbl1->sep().") AS ".
$db1->sep()."Group Alias".$db1->sep()), $res); $tbl1->sep()."Group Alias".$tbl1->sep()), $res);
} }
public function test_displayAdd_Full1 () public function test_displayAdd_Full1 ()
{ {
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db1->displayAdd ("group"); $tbl1->displayAdd ("group");
$res = $db1->displayGet (true); $res = $tbl1->displayGet (true);
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
"order1" => $db1->sep()."groupedoo".$db1->sep().".". "order1" => $tbl1->sep()."groupedoo".$tbl1->sep().".".
$db1->sep()."group".$db1->sep()), $tbl1->sep()."group".$tbl1->sep()),
$res); $res);
} }
public function test_displayAdd_Full2 () public function test_displayAdd_Full2 ()
{ {
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db1->displayAdd ("distinct group"); $tbl1->displayAdd ("distinct group");
$res = $db1->displayGet (true); $res = $tbl1->displayGet (true);
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
"order1" => "DISTINCT ".$db1->sep()."groupedoo".$db1->sep().".". "order1" => "DISTINCT ".$tbl1->sep()."groupedoo".$tbl1->sep().".".
$db1->sep()."group".$db1->sep()), $res); $tbl1->sep()."group".$tbl1->sep()), $res);
} }
public function test_displayAdd_Full3 () public function test_displayAdd_Full3 ()
{ {
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db1->displayAdd ("group_concat ( group ) "); $tbl1->displayAdd ("group_concat ( group ) ");
$res = $db1->displayGet (true); $res = $tbl1->displayGet (true);
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
"order1" => "GROUP_CONCAT(".$db1->sep()."groupedoo".$db1->sep().".". "order1" => "GROUP_CONCAT(".$tbl1->sep()."groupedoo".$tbl1->sep().".".
$db1->sep()."group".$db1->sep().")"), $res); $tbl1->sep()."group".$tbl1->sep().")"), $res);
} }
public function test_displayAdd_Full4 () public function test_displayAdd_Full4 ()
{ {
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db1->displayAdd ("group_concat (distinct group ) "); $tbl1->displayAdd ("group_concat (distinct group ) ");
$res = $db1->displayGet (true); $res = $tbl1->displayGet (true);
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
"order1" => "GROUP_CONCAT(DISTINCT ". "order1" => "GROUP_CONCAT(DISTINCT ".
$db1->sep()."groupedoo".$db1->sep().".". $tbl1->sep()."groupedoo".$tbl1->sep().".".
$db1->sep()."group".$db1->sep().")"), $res); $tbl1->sep()."group".$tbl1->sep().")"), $res);
} }
public function test_displayAdd_Full5 () public function test_displayAdd_Full5 ()
{ {
// With alias // With alias
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db1->displayAdd ("group_concat (distinct group ) ", "Group Alias"); $tbl1->displayAdd ("group_concat (distinct group ) ", "Group Alias");
$res = $db1->displayGet (true); $res = $tbl1->displayGet (true);
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array ( $this->assertSame (array (
"order1" => "GROUP_CONCAT(DISTINCT ". "order1" => "GROUP_CONCAT(DISTINCT ".
$db1->sep()."groupedoo".$db1->sep().".". $tbl1->sep()."groupedoo".$tbl1->sep().".".
$db1->sep()."group".$db1->sep().") AS ". $tbl1->sep()."group".$tbl1->sep().") AS ".
$db1->sep()."Group Alias".$db1->sep()), $res); $tbl1->sep()."Group Alias".$tbl1->sep()), $res);
} }
public function test_displayAdd_Multiple1 () public function test_displayAdd_Multiple1 ()
{ {
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$db1->displayAdd ("group"); $tbl1->displayAdd ("group");
$db1->displayAdd ("where"); $tbl1->displayAdd ("where");
$res = $db1->displayGet (); $res = $tbl1->displayGet ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (array ("order1" => $db1->sep()."group".$db1->sep(), $this->assertSame (array ("order1" => $tbl1->sep()."group".$tbl1->sep(),
"order2" => $db1->sep()."where".$db1->sep(),), "order2" => $tbl1->sep()."where".$tbl1->sep(),),
$res); $res);
} }
@@ -834,11 +870,11 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
// Manage to update the non unique fields // Manage to update the non unique fields
// the "where" column is not unique, so it allow to have twice the same // the "where" column is not unique, so it allow to have twice the same
// value // value
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$res = $db1->update() $res = $tbl1->update()
->setValues(array ("where"=>"where2")) ->setValues(array ("where"=>"where2"))
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
$this->assertSame (2, $res); $this->assertSame (2, $res);
} }
@@ -847,11 +883,11 @@ class test_dblayeroo_{ENGINE} extends PHPUnit_Framework_TestCase
// Manage to update the primary / unique fields // Manage to update the primary / unique fields
// There is 2 lines in the DB, so the unique key "group" can not be updated // There is 2 lines in the DB, so the unique key "group" can not be updated
// with the same value twice (the result can not be unique) // with the same value twice (the result can not be unique)
$db1 = $this->db1 (); $tbl1 = $this->tbl1 ();
$this->setExpectedException ("Exception"); $this->setExpectedException ("Exception");
$res = $db1->update() $res = $tbl1->update()
->setValues(array ("group"=>"group3")) ->setValues(array ("group"=>"group3"))
->execute (); ->execute ();
$db1->disconnect (); $tbl1->disconnect ();
} }
} }