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