1604 lines
47 KiB
PHP
1604 lines
47 KiB
PHP
<?php
|
|
|
|
/**
|
|
* DomFramework - Tests
|
|
* @package domframework
|
|
* @author Dominique Fournier <dominique@fournier38.fr>
|
|
* @license BSD
|
|
*/
|
|
|
|
namespace Domframework\Tests;
|
|
|
|
use Domframework\Dblayeroo;
|
|
|
|
class DblayerooTest{ENGINE} extends \PHPUnit_Framework_TestCase
|
|
{
|
|
// Test with column name 'group', 'object', 'where', 'with space'
|
|
// Test with table name 'group', 'object', 'where', 'with space'
|
|
// For the 3 DB engines
|
|
|
|
public $engine = "{ENGINE}";
|
|
public $confs = [
|
|
"sqlite" => [
|
|
"dsn" => "sqlite:/tmp/databaseDBLayeroo.db",
|
|
"username" => null,
|
|
"password" => null,
|
|
"driver_options" => null,
|
|
"tableprefix" => "",
|
|
],
|
|
"mysql" => [
|
|
"dsn" => "mysql:host=127.0.0.1;port=3306;dbname=test",
|
|
"username" => "root",
|
|
"password" => "lqsym",
|
|
"driver_options" => null,
|
|
"tableprefix" => "",
|
|
],
|
|
"pgsql" => [
|
|
"dsn" => "pgsql:host=127.0.0.1;port=5432;dbname=dbname",
|
|
"username" => "root",
|
|
"password" => "root",
|
|
"driver_options" => null,
|
|
"tableprefix" => "",
|
|
],
|
|
];
|
|
|
|
private function tbl1()
|
|
{
|
|
$dbconfig = $this->confs["{ENGINE}"];
|
|
$tbl1 = new Dblayeroo(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$tbl1->table("groupedoo");
|
|
$tbl1->fields(["group" => ["varchar(255)", "not null"],
|
|
"object" => ["varchar(255)", "not null"],
|
|
"where" => ["varchar(255)", "not null"],
|
|
"with space" => ["varchar(255)"]]);
|
|
$tbl1->unique([]);
|
|
$tbl1->primary("group");
|
|
$tbl1->realTypes(["group" => "regex(/^\S{1,10}$/)"]);
|
|
return $tbl1;
|
|
}
|
|
|
|
private function tbl2()
|
|
{
|
|
$dbconfig = $this->confs["{ENGINE}"];
|
|
$tbl2 = new Dblayeroo(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$tbl2->table("usersoo");
|
|
$tbl2->fields(["uid" => ["integer", "not null", "autoincrement"],
|
|
"gecos" => ["varchar(255)", "not null"],
|
|
"password" => ["varchar(255)", "not null"],
|
|
"group" => ["varchar(255)", "not null"],
|
|
]);
|
|
$tbl2->unique(["gecos","password"]);
|
|
$tbl2->primary("uid");
|
|
$tbl2->foreign(["group" => ["groupedoo", "group",
|
|
"ON DELETE CASCADE"]]);
|
|
return $tbl2;
|
|
}
|
|
|
|
private function tbl3()
|
|
{
|
|
$dbconfig = $this->confs["{ENGINE}"];
|
|
$tbl3 = new Dblayeroo(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
return $tbl3;
|
|
}
|
|
|
|
private function tbl4()
|
|
{
|
|
$dbconfig = $this->confs["{ENGINE}"];
|
|
$tbl4 = new Dblayeroo(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
$tbl4->table("rightsoo");
|
|
$tbl4->fields(["id" => ["integer", "not null", "autoincrement"],
|
|
"name" => ["varchar(255)", "not null"],
|
|
"group" => ["varchar(255)", "not null"],
|
|
]);
|
|
$tbl4->unique(["name"]);
|
|
$tbl4->primary("id");
|
|
$tbl4->foreign(["group" => ["groupedoo", "group",
|
|
"ON DELETE CASCADE"]]);
|
|
return $tbl4;
|
|
}
|
|
|
|
public function testDropTable()
|
|
{
|
|
$dbconfig = $this->confs["{ENGINE}"];
|
|
$db = new Dblayeroo(
|
|
$dbconfig["dsn"],
|
|
$dbconfig["username"],
|
|
$dbconfig["password"],
|
|
$dbconfig["driver_options"]
|
|
);
|
|
foreach (
|
|
["rightsoo", "usersoo", "groupedoo",
|
|
"multipleoo", "multiple2oo", "users3oo",
|
|
"readORoo"] as $table
|
|
) {
|
|
$db->table($table);
|
|
try {
|
|
$res = $db->dropTable();
|
|
} catch (\Exception $e) {
|
|
}
|
|
}
|
|
$db->disconnect();
|
|
// Never generate an error, just drop the table if it exists, and do noting
|
|
// if it doesn't exists
|
|
}
|
|
|
|
public function testCreateTable1()
|
|
{
|
|
// Create a table named groupedoo
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->createTable();
|
|
$tbl1->disconnect();
|
|
$this->assertSame(0, $res);
|
|
}
|
|
|
|
public function testCreateTable2()
|
|
{
|
|
// Create a table named usersoo
|
|
$tbl2 = $this->tbl2();
|
|
$res = $tbl2->createTable();
|
|
$tbl2->disconnect();
|
|
$this->assertSame(0, $res);
|
|
}
|
|
|
|
public function testCreateTable4()
|
|
{
|
|
// Create a table named rightsoo
|
|
$tbl4 = $this->tbl4();
|
|
$res = $tbl4->createTable();
|
|
$tbl4->disconnect();
|
|
$this->assertSame(0, $res);
|
|
}
|
|
|
|
public function testSelect1()
|
|
{
|
|
// Select all on the table : nothing
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->select()->execute();
|
|
$tbl1->disconnect();
|
|
$this->assertSame([], $res);
|
|
}
|
|
|
|
public function testInsert1()
|
|
{
|
|
// Insert without value : raise an exception
|
|
$this->setExpectedException("Exception");
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->insert()->execute();
|
|
$tbl1->disconnect();
|
|
}
|
|
|
|
public function testInsert2()
|
|
{
|
|
// Insert : missing not null field : exception
|
|
$this->setExpectedException("Exception");
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->insert()
|
|
->setValues(["group" => "group1", "where" => "where"])
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
}
|
|
|
|
public function testInsert3()
|
|
{
|
|
// Insert : first row inserted
|
|
$tbl1 = $this->tbl1();
|
|
// Normalize the value to be inserted too
|
|
$res = $tbl1->insert()->setValues(["group" => " group1 ",
|
|
"where" => "where",
|
|
"object" => "object"])->execute();
|
|
$tbl1->disconnect();
|
|
// As the key is not an autoincrement, the lastInsertID can be 0 or 1
|
|
$this->assertSame($res, "group1");
|
|
}
|
|
|
|
public function testSelect2()
|
|
{
|
|
// Select all on the table : nothing
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->select()->execute();
|
|
$tbl1->disconnect();
|
|
$this->assertSame(
|
|
[["group" => "group1", "object" => "object",
|
|
"where" => "where", "with space" => null]],
|
|
$res
|
|
);
|
|
}
|
|
|
|
public function testUpdate1()
|
|
{
|
|
// update the all the rows of the table (without WHERE)
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->update()->setValues(["group" => "group2",
|
|
"where" => "where",
|
|
"object" => "object"])->execute();
|
|
$tbl1->disconnect();
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
public function testSelect3()
|
|
{
|
|
// Select all on the table after update
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->select()->execute();
|
|
$tbl1->disconnect();
|
|
$this->assertSame(
|
|
[["group" => "group2", "object" => "object",
|
|
"where" => "where", "with space" => null]],
|
|
$res
|
|
);
|
|
}
|
|
|
|
public function testUpdate2()
|
|
{
|
|
// update the all the rows of the table (with inexisting WHERE)
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->update()
|
|
->setValues(["group" => "group2", "where" => "where",
|
|
"object" => "object"])
|
|
->whereAdd("group", "=", "group1")
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$this->assertSame(0, $res);
|
|
}
|
|
|
|
public function testUpdate3()
|
|
{
|
|
// update the all the rows of the table (with existing WHERE)
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->update()
|
|
->setValues(["group" => "group1", "where" => "where",
|
|
"object" => "object"])
|
|
->whereAdd("group", "=", "group2")
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
public function testUpdate4()
|
|
{
|
|
// update the all the rows of the table : NOT NULL value not provided
|
|
// (already existing in the table)
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->update()
|
|
->setValues(["group" => "group1"])
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
public function testDelete1()
|
|
{
|
|
// Delete : WHERE return nothing
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->delete()
|
|
->whereAdd("group", "=", "group2")
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$this->assertSame(0, $res);
|
|
}
|
|
|
|
public function testDelete2()
|
|
{
|
|
// Delete all
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->delete()
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$this->assertSame(1, $res);
|
|
}
|
|
|
|
public function testSelect4()
|
|
{
|
|
// Select all on the table : nothing
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->select()->execute();
|
|
$tbl1->disconnect();
|
|
$this->assertSame([], $res);
|
|
}
|
|
|
|
public function testInsert5()
|
|
{
|
|
// Insert : first row inserted for TABLE 2 tests
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->insert()->setValues(["group" => "group1",
|
|
"where" => "where",
|
|
"object" => "object"])->execute();
|
|
$tbl1->disconnect();
|
|
// As the key is not an autoincrement, the lastInsertID can be 0 or 1
|
|
$this->assertSame($res, "group1");
|
|
}
|
|
|
|
///////////////////
|
|
/// TABLE 2 ///
|
|
///////////////////
|
|
public function testInsertAutoincrement1()
|
|
{
|
|
// Test autoincrement
|
|
$tbl1 = $this->tbl1();
|
|
$tbl2 = $this->tbl2();
|
|
$tbl2->setForeignObj($tbl1);
|
|
$res = $tbl2->insert()->setValues(["gecos" => "name",
|
|
"password" => "toto",
|
|
"group" => "group1"])->execute();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
$this->assertSame("1", $res);
|
|
}
|
|
|
|
public function testInsertAutoincrement2()
|
|
{
|
|
// Test autoincrement
|
|
$tbl1 = $this->tbl1();
|
|
$tbl2 = $this->tbl2();
|
|
$tbl2->setForeignObj($tbl1);
|
|
$res = $tbl2->insert()->setValues(["gecos" => "firstname2",
|
|
"password" => "toto2",
|
|
"group" => "group1"])->execute();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
$this->assertSame("2", $res);
|
|
}
|
|
|
|
public function testInsertAutoincrement3()
|
|
{
|
|
// Test autoincrement
|
|
$tbl1 = $this->tbl1();
|
|
$tbl2 = $this->tbl2();
|
|
$tbl2->setForeignObj($tbl1);
|
|
$res = $tbl2->insert()->setValues(["gecos" => "firstname3",
|
|
"password" => "toto3",
|
|
"group" => "group1"])->execute();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
$this->assertSame("3", $res);
|
|
}
|
|
|
|
public function testDelete3()
|
|
{
|
|
// Delete with WHERE clause
|
|
$tbl1 = $this->tbl1();
|
|
$tbl2 = $this->tbl2();
|
|
$tbl2->setForeignObj($tbl1);
|
|
$res = $tbl2->delete()
|
|
->whereAdd("gecos", "LIKE", "firstname%")
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
$this->assertSame(2, $res);
|
|
}
|
|
|
|
public function testSelect5()
|
|
{
|
|
// Select all on the table : one entry "gecos"=>"name"
|
|
$tbl1 = $this->tbl1();
|
|
$tbl2 = $this->tbl2();
|
|
$tbl2->setForeignObj($tbl1);
|
|
$res = $tbl2->select()->execute();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
$this->assertSame([["uid" => 1,
|
|
"gecos" => "name",
|
|
"password" => "toto",
|
|
"group" => "group1"]], $res);
|
|
}
|
|
|
|
/// SCHEMA MANAGEMENT ///
|
|
public function testGetTableSchema1()
|
|
{
|
|
$tbl3 = $this->tbl3();
|
|
$res = $tbl3->getTableSchema("usersoo");
|
|
$tbl3->disconnect();
|
|
$this->assertSame(
|
|
["table" => "usersoo",
|
|
"fields" => [
|
|
"uid" => ["integer", "not null", "autoincrement"],
|
|
"gecos" => ["varchar(255)", "not null"],
|
|
"password" => ["varchar(255)", "not null"],
|
|
"group" => ["varchar(255)", "not null"],
|
|
],
|
|
"primary" => "uid",
|
|
"unique" => ["gecos","password","uid"],
|
|
"foreign" => [
|
|
"group" => ['groupedoo', 'group', 'ON DELETE CASCADE'],
|
|
],
|
|
"foreignUsed" => [
|
|
],
|
|
],
|
|
$res
|
|
);
|
|
}
|
|
|
|
public function testGetTableSchema2()
|
|
{
|
|
$tbl3 = $this->tbl3();
|
|
$res = $tbl3->getTableSchema("groupedoo");
|
|
$tbl3->disconnect();
|
|
$this->assertSame(
|
|
[
|
|
"table" => "groupedoo",
|
|
"fields" => [
|
|
"group" => ["varchar(255)", "not null"],
|
|
"object" => ["varchar(255)", "not null"],
|
|
"where" => ["varchar(255)", "not null"],
|
|
"with space" => ["varchar(255)"]],
|
|
"primary" => "group",
|
|
"unique" => ["group"],
|
|
"foreign" => [],
|
|
"foreignUsed" => [
|
|
"group" => [
|
|
["rightsoo", "group"],
|
|
["usersoo", "group"],
|
|
],
|
|
],
|
|
],
|
|
$res
|
|
);
|
|
}
|
|
|
|
// JOINS
|
|
public function testInsertJoin1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->insert()
|
|
->setValues(["group" => "group2",
|
|
"object" => "object",
|
|
"where" => "where"])
|
|
->execute();
|
|
$tbl2 = $this->tbl2();
|
|
$tbl2->setForeignObj($tbl1);
|
|
$res = $tbl2->insert()
|
|
->setValues(["gecos" => "name2",
|
|
"password" => "pwd2",
|
|
"group" => "group1"])
|
|
->execute();
|
|
$res = $tbl2->insert()
|
|
->setValues(["gecos" => "name3",
|
|
"password" => "pwd3",
|
|
"group" => "group1"])
|
|
->execute();
|
|
$res = $tbl2->insert()
|
|
->setValues(["gecos" => "name4",
|
|
"password" => "pwd4",
|
|
"group" => "group1"])
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
}
|
|
|
|
public function testInnerJoin1()
|
|
{
|
|
// No filter
|
|
$tbl1 = $this->tbl1();
|
|
$tbl2 = $this->tbl2();
|
|
$res = $tbl2->select()
|
|
->joinInner($tbl1, ["group" => "group"])
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
$this->assertSame([
|
|
[
|
|
'usersoo.uid' => 1,
|
|
'usersoo.gecos' => 'name',
|
|
'usersoo.password' => 'toto',
|
|
'usersoo.group' => 'group1',
|
|
'groupedoo.group' => 'group1',
|
|
'groupedoo.object' => 'object',
|
|
'groupedoo.where' => 'where',
|
|
'groupedoo.with space' => null,
|
|
],
|
|
[
|
|
'usersoo.uid' => 4,
|
|
'usersoo.gecos' => 'name2',
|
|
'usersoo.password' => 'pwd2',
|
|
'usersoo.group' => 'group1',
|
|
'groupedoo.group' => 'group1',
|
|
'groupedoo.object' => 'object',
|
|
'groupedoo.where' => 'where',
|
|
'groupedoo.with space' => null,
|
|
],
|
|
[
|
|
'usersoo.uid' => 5,
|
|
'usersoo.gecos' => 'name3',
|
|
'usersoo.password' => 'pwd3',
|
|
'usersoo.group' => 'group1',
|
|
'groupedoo.group' => 'group1',
|
|
'groupedoo.object' => 'object',
|
|
'groupedoo.where' => 'where',
|
|
'groupedoo.with space' => null,
|
|
],
|
|
[
|
|
'usersoo.uid' => 6,
|
|
'usersoo.gecos' => 'name4',
|
|
'usersoo.password' => 'pwd4',
|
|
'usersoo.group' => 'group1',
|
|
'groupedoo.group' => 'group1',
|
|
'groupedoo.object' => 'object',
|
|
'groupedoo.where' => 'where',
|
|
'groupedoo.with space' => null,
|
|
],
|
|
], $res);
|
|
}
|
|
|
|
public function testInnerJoin2()
|
|
{
|
|
// No filter. Manage the empty displayAdd
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->displayAdd();
|
|
$tbl2 = $this->tbl2();
|
|
$res = $tbl2->select()
|
|
->joinInner($tbl1, ["group" => "group"])
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
$this->assertSame([
|
|
[
|
|
'uid' => 1,
|
|
'gecos' => 'name',
|
|
'password' => 'toto',
|
|
'group' => 'group1',
|
|
],
|
|
[
|
|
'uid' => 4,
|
|
'gecos' => 'name2',
|
|
'password' => 'pwd2',
|
|
'group' => 'group1',
|
|
],
|
|
[
|
|
'uid' => 5,
|
|
'gecos' => 'name3',
|
|
'password' => 'pwd3',
|
|
'group' => 'group1',
|
|
],
|
|
[
|
|
'uid' => 6,
|
|
'gecos' => 'name4',
|
|
'password' => 'pwd4',
|
|
'group' => 'group1',
|
|
],
|
|
], $res);
|
|
}
|
|
|
|
public function testInnerJoin3()
|
|
{
|
|
// No filter. Manage the empty displayAdd
|
|
$tbl1 = $this->tbl1();
|
|
$tbl2 = $this->tbl2();
|
|
$tbl2->displayAdd();
|
|
$res = $tbl2->select()
|
|
->joinInner($tbl1, ["group" => "group"])
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
$this->assertSame([
|
|
[
|
|
'group' => 'group1',
|
|
'object' => 'object',
|
|
'where' => 'where',
|
|
'with space' => null,
|
|
],
|
|
[
|
|
'group' => 'group1',
|
|
'object' => 'object',
|
|
'where' => 'where',
|
|
'with space' => null,
|
|
],
|
|
[
|
|
'group' => 'group1',
|
|
'object' => 'object',
|
|
'where' => 'where',
|
|
'with space' => null,
|
|
],
|
|
[
|
|
'group' => 'group1',
|
|
'object' => 'object',
|
|
'where' => 'where',
|
|
'with space' => null,
|
|
],
|
|
], $res);
|
|
}
|
|
|
|
public function testLeftJoin2()
|
|
{
|
|
// No filter
|
|
$tbl1 = $this->tbl1();
|
|
$tbl2 = $this->tbl2();
|
|
$res = $tbl1->select()
|
|
->joinLeft($tbl2, ["group" => "group"])
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
$this->assertSame([
|
|
[
|
|
'groupedoo.group' => 'group1',
|
|
'groupedoo.object' => 'object',
|
|
'groupedoo.where' => 'where',
|
|
'groupedoo.with space' => null,
|
|
'usersoo.uid' => 1,
|
|
'usersoo.gecos' => 'name',
|
|
'usersoo.password' => 'toto',
|
|
'usersoo.group' => 'group1',
|
|
],
|
|
[
|
|
'groupedoo.group' => 'group1',
|
|
'groupedoo.object' => 'object',
|
|
'groupedoo.where' => 'where',
|
|
'groupedoo.with space' => null,
|
|
'usersoo.uid' => 4,
|
|
'usersoo.gecos' => 'name2',
|
|
'usersoo.password' => 'pwd2',
|
|
'usersoo.group' => 'group1',
|
|
],
|
|
[
|
|
'groupedoo.group' => 'group1',
|
|
'groupedoo.object' => 'object',
|
|
'groupedoo.where' => 'where',
|
|
'groupedoo.with space' => null,
|
|
'usersoo.uid' => 5,
|
|
'usersoo.gecos' => 'name3',
|
|
'usersoo.password' => 'pwd3',
|
|
'usersoo.group' => 'group1',
|
|
],
|
|
[
|
|
'groupedoo.group' => 'group1',
|
|
'groupedoo.object' => 'object',
|
|
'groupedoo.where' => 'where',
|
|
'groupedoo.with space' => null,
|
|
'usersoo.uid' => 6,
|
|
'usersoo.gecos' => 'name4',
|
|
'usersoo.password' => 'pwd4',
|
|
'usersoo.group' => 'group1',
|
|
],
|
|
[
|
|
'groupedoo.group' => 'group2',
|
|
'groupedoo.object' => 'object',
|
|
'groupedoo.where' => 'where',
|
|
'groupedoo.with space' => null,
|
|
'usersoo.uid' => null,
|
|
'usersoo.gecos' => null,
|
|
'usersoo.password' => null,
|
|
'usersoo.group' => null,
|
|
],
|
|
], $res);
|
|
}
|
|
|
|
public function testLeftJoin3()
|
|
{
|
|
// Filter on the tbl1, do not display tbl2
|
|
$tbl1 = $this->tbl1();
|
|
$tbl2 = $this->tbl2();
|
|
$tbl2->displayAdd();
|
|
$res = $tbl1->select()
|
|
->displayAdd("group")
|
|
->joinLeft($tbl2, ["group" => "group"])
|
|
->orderAdd("group", "ASC")
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
$this->assertSame([
|
|
[
|
|
'group' => 'group1',
|
|
],
|
|
[
|
|
'group' => 'group1',
|
|
],
|
|
[
|
|
'group' => 'group1',
|
|
],
|
|
[
|
|
'group' => 'group1',
|
|
],
|
|
[
|
|
'group' => 'group2',
|
|
],
|
|
], $res);
|
|
}
|
|
|
|
public function testLeftJoin4()
|
|
{
|
|
// Filter on the tbl1, display one column in tbl2
|
|
$tbl1 = $this->tbl1();
|
|
$tbl2 = $this->tbl2();
|
|
$tbl2->displayAdd("group");
|
|
$res = $tbl1->select()
|
|
->displayAdd("group")
|
|
->joinLeft($tbl2, ["group" => "group"])
|
|
->orderAdd("group", "DESC")
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
$this->assertSame([
|
|
[
|
|
'usersoo.group' => null,
|
|
'groupedoo.group' => 'group2',
|
|
],
|
|
[
|
|
'usersoo.group' => 'group1',
|
|
'groupedoo.group' => 'group1',
|
|
],
|
|
[
|
|
'usersoo.group' => 'group1',
|
|
'groupedoo.group' => 'group1',
|
|
],
|
|
[
|
|
'usersoo.group' => 'group1',
|
|
'groupedoo.group' => 'group1',
|
|
],
|
|
[
|
|
'usersoo.group' => 'group1',
|
|
'groupedoo.group' => 'group1',
|
|
],
|
|
], $res);
|
|
}
|
|
|
|
public function testLeftJoin5()
|
|
{
|
|
// 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($tbl2, ["group" => "group"])
|
|
->orderAdd("group", "DESC")
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
$this->assertSame([
|
|
[
|
|
'usersoo.group' => null,
|
|
'groupedoo.group' => 'group2',
|
|
],
|
|
[
|
|
'usersoo.group' => 'group1',
|
|
'groupedoo.group' => 'group1',
|
|
],
|
|
[
|
|
'usersoo.group' => 'group1',
|
|
'groupedoo.group' => 'group1',
|
|
],
|
|
[
|
|
'usersoo.group' => 'group1',
|
|
'groupedoo.group' => 'group1',
|
|
],
|
|
[
|
|
'usersoo.group' => 'group1',
|
|
'groupedoo.group' => 'group1',
|
|
],
|
|
], $res);
|
|
}
|
|
|
|
/// THREE TABLES ///
|
|
public function testInsert6()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl4 = $this->tbl4();
|
|
$tbl4->setForeignObj($tbl1);
|
|
$res = $tbl4->insert()
|
|
->setValues(["name" => "RO",
|
|
"group" => "group1"])
|
|
->execute();
|
|
$tbl4->disconnect();
|
|
// As the key is not an autoincrement, the lastInsertID can be 0 or 1
|
|
$this->assertGreaterThanOrEqual($res, "0");
|
|
}
|
|
|
|
public function testLeftJoin6()
|
|
{
|
|
// Two joins tables in left join
|
|
$tbl1 = $this->tbl1(); // Do not display anything from groupedoo
|
|
$tbl1->displayAdd("group")
|
|
->orderAdd("group", "DESC");
|
|
|
|
$tbl2 = $this->tbl2(); // Display the gecos and group from usersoo
|
|
$tbl2->displayAdd("gecos")
|
|
->orderAdd("gecos", "ASC");
|
|
|
|
$tbl4 = $this->tbl4(); // Display the name in rightsoo
|
|
$tbl4->displayAdd("name");
|
|
$tbl1->joinLeft($tbl4, ["group" => "group"]);
|
|
$res = $tbl1->select()
|
|
->joinLeft($tbl2, ["group" => "group"])
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
$tbl4->disconnect();
|
|
$this->assertSame([
|
|
[
|
|
'groupedoo.group' => 'group2',
|
|
'usersoo.gecos' => null,
|
|
'rightsoo.name' => null,
|
|
],
|
|
[
|
|
'groupedoo.group' => 'group1',
|
|
'usersoo.gecos' => 'name',
|
|
'rightsoo.name' => 'RO',
|
|
],
|
|
[
|
|
'groupedoo.group' => 'group1',
|
|
'usersoo.gecos' => 'name2',
|
|
'rightsoo.name' => 'RO',
|
|
],
|
|
[
|
|
'groupedoo.group' => 'group1',
|
|
'usersoo.gecos' => 'name3',
|
|
'rightsoo.name' => 'RO',
|
|
],
|
|
[
|
|
'groupedoo.group' => 'group1',
|
|
'usersoo.gecos' => 'name4',
|
|
'rightsoo.name' => 'RO',
|
|
],
|
|
], $res);
|
|
}
|
|
|
|
public function testSortOrder1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->getSortOrder();
|
|
$tbl1->disconnect();
|
|
$this->assertSame("order1", $res);
|
|
}
|
|
|
|
public function testSortOrder2()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->getSortOrder();
|
|
$res = $tbl1->getSortOrder();
|
|
$tbl1->disconnect();
|
|
$this->assertSame("order2", $res);
|
|
}
|
|
|
|
public function testSortOrder3()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl2 = $this->tbl2();
|
|
$tbl1->getSortOrder();
|
|
$tbl1->getSortOrder();
|
|
$res = $tbl2->getSortOrder();
|
|
$tbl1->disconnect();
|
|
$tbl2->disconnect();
|
|
$this->assertSame("order3", $res);
|
|
}
|
|
|
|
public function testDisplayAddNotFull1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->displayAdd("group");
|
|
$res = $tbl1->displayGet();
|
|
$tbl1->disconnect();
|
|
$this->assertSame(
|
|
["order1" => $tbl1->sep() . "group" . $tbl1->sep()],
|
|
$res
|
|
);
|
|
}
|
|
|
|
public function testDisplayAddNotFull2()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->displayAdd("distinct group");
|
|
$res = $tbl1->displayGet();
|
|
$tbl1->disconnect();
|
|
$this->assertSame([
|
|
"order1" => "DISTINCT " . $tbl1->sep() . "group" . $tbl1->sep()], $res);
|
|
}
|
|
|
|
public function testDisplayAddNotFull3()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->displayAdd("group_concat ( group ) ");
|
|
$res = $tbl1->displayGet();
|
|
$tbl1->disconnect();
|
|
if ($this->engine === "pgsql") {
|
|
$this->assertSame([
|
|
"order1" => "string_agg(" . $tbl1->sep() . "group" . $tbl1->sep() .
|
|
"::character varying, ',' order by \"group\"" .
|
|
")"], $res);
|
|
} else {
|
|
$this->assertSame([
|
|
"order1" => "GROUP_CONCAT(" . $tbl1->sep() . "group" . $tbl1->sep() . ")"], $res);
|
|
}
|
|
}
|
|
|
|
public function testDisplayAddNotFull4()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->displayAdd("group_concat (distinct group ) ");
|
|
$res = $tbl1->displayGet();
|
|
$tbl1->disconnect();
|
|
if ($this->engine === "pgsql") {
|
|
$this->assertSame([
|
|
"order1" => "string_agg(DISTINCT " .
|
|
$tbl1->sep() . "group" . $tbl1->sep() .
|
|
"::character varying, ',' order by \"group\"" .
|
|
")"], $res);
|
|
} else {
|
|
$this->assertSame([
|
|
"order1" => "GROUP_CONCAT(DISTINCT " .
|
|
$tbl1->sep() . "group" . $tbl1->sep() . ")"], $res);
|
|
}
|
|
}
|
|
|
|
public function testDisplayAddNotFull5()
|
|
{
|
|
// With alias
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->displayAdd("group_concat (distinct group ) ", "Group Alias");
|
|
$res = $tbl1->displayGet();
|
|
$tbl1->disconnect();
|
|
if ($this->engine === "pgsql") {
|
|
$this->assertSame([
|
|
"order1" => "string_agg(DISTINCT " .
|
|
$tbl1->sep() . "group" . $tbl1->sep() .
|
|
"::character varying, ',' order by " .
|
|
$tbl1->sep() . "group" . $tbl1->sep() .
|
|
") AS " .
|
|
$tbl1->sep() . "Group Alias" . $tbl1->sep()], $res);
|
|
} else {
|
|
$this->assertSame([
|
|
"order1" => "GROUP_CONCAT(DISTINCT " .
|
|
$tbl1->sep() . "group" . $tbl1->sep() . ") AS " .
|
|
$tbl1->sep() . "Group Alias" . $tbl1->sep()], $res);
|
|
}
|
|
}
|
|
|
|
public function testDisplayAddFull1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->displayAdd("group");
|
|
$res = $tbl1->displayGet(true);
|
|
$tbl1->disconnect();
|
|
$this->assertSame(
|
|
[
|
|
"order1" => $tbl1->sep() . "groupedoo" . $tbl1->sep() . "." .
|
|
$tbl1->sep() . "group" . $tbl1->sep()],
|
|
$res
|
|
);
|
|
}
|
|
|
|
public function testDisplayAddFull2()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->displayAdd("distinct group");
|
|
$res = $tbl1->displayGet(true);
|
|
$tbl1->disconnect();
|
|
$this->assertSame([
|
|
"order1" => "DISTINCT " . $tbl1->sep() . "groupedoo" . $tbl1->sep() . "." .
|
|
$tbl1->sep() . "group" . $tbl1->sep()], $res);
|
|
}
|
|
|
|
public function testDisplayAddFull3()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->displayAdd("group_concat ( group ) ");
|
|
$res = $tbl1->displayGet(true);
|
|
$tbl1->disconnect();
|
|
if ($this->engine === "pgsql") {
|
|
$this->assertSame([
|
|
"order1" => "string_agg(" . $tbl1->sep() . "groupedoo" . $tbl1->sep() . "." .
|
|
$tbl1->sep() . "group" . $tbl1->sep() .
|
|
"::character varying, ',' order by \"group\"" .
|
|
")"], $res);
|
|
} else {
|
|
$this->assertSame([
|
|
"order1" => "GROUP_CONCAT(" . $tbl1->sep() . "groupedoo" . $tbl1->sep() . "." .
|
|
$tbl1->sep() . "group" . $tbl1->sep() . ")"], $res);
|
|
}
|
|
}
|
|
|
|
public function testDisplayAddFull4()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->displayAdd("group_concat (distinct group ) ");
|
|
$res = $tbl1->displayGet(true);
|
|
$tbl1->disconnect();
|
|
if ($this->engine === "pgsql") {
|
|
$this->assertSame([
|
|
"order1" => "string_agg(DISTINCT " .
|
|
$tbl1->sep() . "groupedoo" . $tbl1->sep() . "." .
|
|
$tbl1->sep() . "group" . $tbl1->sep() .
|
|
"::character varying, ',' order by \"group\"" .
|
|
")"], $res);
|
|
} else {
|
|
$this->assertSame([
|
|
"order1" => "GROUP_CONCAT(DISTINCT " .
|
|
$tbl1->sep() . "groupedoo" . $tbl1->sep() . "." .
|
|
$tbl1->sep() . "group" . $tbl1->sep() . ")"], $res);
|
|
}
|
|
}
|
|
|
|
public function testDisplayAddFull5()
|
|
{
|
|
// With alias
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->displayAdd("group_concat (distinct group ) ", "Group Alias");
|
|
$res = $tbl1->displayGet(true);
|
|
$tbl1->disconnect();
|
|
if ($this->engine === "pgsql") {
|
|
$this->assertSame([
|
|
"order1" => "string_agg(DISTINCT " .
|
|
$tbl1->sep() . "groupedoo" . $tbl1->sep() . "." .
|
|
$tbl1->sep() . "group" . $tbl1->sep() .
|
|
"::character varying, ',' order by \"group\"" .
|
|
") AS " .
|
|
$tbl1->sep() . "Group Alias" . $tbl1->sep()], $res);
|
|
} else {
|
|
$this->assertSame([
|
|
"order1" => "GROUP_CONCAT(DISTINCT " .
|
|
$tbl1->sep() . "groupedoo" . $tbl1->sep() . "." .
|
|
$tbl1->sep() . "group" . $tbl1->sep() . ") AS " .
|
|
$tbl1->sep() . "Group Alias" . $tbl1->sep()], $res);
|
|
}
|
|
}
|
|
|
|
public function testDisplayAddMultiple1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->displayAdd("group");
|
|
$tbl1->displayAdd("where");
|
|
$res = $tbl1->displayGet();
|
|
$tbl1->disconnect();
|
|
$this->assertSame(
|
|
["order1" => $tbl1->sep() . "group" . $tbl1->sep(),
|
|
"order2" => $tbl1->sep() . "where" . $tbl1->sep(),],
|
|
$res
|
|
);
|
|
}
|
|
|
|
|
|
public function testUpdate5()
|
|
{
|
|
// Manage to update the non unique fields
|
|
// the "where" column is not unique, so it allow to have twice the same
|
|
// value
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->update()
|
|
->setValues(["where" => "where2"])
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$this->assertSame(2, $res);
|
|
}
|
|
|
|
public function testUpdate6()
|
|
{
|
|
// 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)
|
|
$tbl1 = $this->tbl1();
|
|
$this->setExpectedException("Exception");
|
|
$res = $tbl1->update()
|
|
->setValues(["group" => "group3"])
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
}
|
|
|
|
public function testDisplayAddComaFields1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl1->displayAdd(
|
|
"group_concat (group ),group ",
|
|
"Group Alias,Group2"
|
|
);
|
|
$res = $tbl1->select()
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
if ($this->engine !== "pgsql") {
|
|
$this->assertSame([
|
|
['Group Alias' => 'group1',
|
|
'Group2' => 'group1',],
|
|
['Group Alias' => 'group2',
|
|
'Group2' => 'group2',],
|
|
], $res);
|
|
}
|
|
}
|
|
|
|
public function testDisplayAddDISTINCT1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->select()
|
|
->displayAdd("distinct where", "ALIAS")
|
|
->execute();
|
|
$tbl1->disconnect();
|
|
$this->assertSame(
|
|
[0 => ["ALIAS" => "where2"]],
|
|
$res
|
|
);
|
|
}
|
|
|
|
public function testOrderAddAlias1()
|
|
{
|
|
$tbl2 = $this->tbl2();
|
|
$res = $tbl2->select()
|
|
->displayAdd("uid", "max")
|
|
->orderAdd("max", "ASC")
|
|
->execute();
|
|
$tbl2->disconnect();
|
|
$this->assertSame([
|
|
['max' => 1],
|
|
['max' => 4],
|
|
['max' => 5],
|
|
['max' => 6],
|
|
], $res);
|
|
}
|
|
|
|
public function testDisplayAddMAXGROUPBY1()
|
|
{
|
|
$tbl2 = $this->tbl2();
|
|
$res = $tbl2->select()
|
|
->displayAdd("MAX(uid)", "max")
|
|
->displayAdd("gecos")
|
|
->orderAdd("max", "ASC")
|
|
->execute();
|
|
$tbl2->disconnect();
|
|
$this->assertSame(
|
|
[
|
|
['max' => 1, 'gecos' => 'name'],
|
|
['max' => 4, 'gecos' => 'name2'],
|
|
['max' => 5, 'gecos' => 'name3'],
|
|
['max' => 6, 'gecos' => 'name4']],
|
|
$res
|
|
);
|
|
}
|
|
|
|
public function testDisplayAddMAXGROUPBY2()
|
|
{
|
|
$tbl2 = $this->tbl2();
|
|
$res = $tbl2->select()
|
|
->displayAdd("MAX(uid)")
|
|
->execute();
|
|
$tbl2->disconnect();
|
|
$this->assertSame([['MAX(uid)' => 6]], $res);
|
|
}
|
|
|
|
public function testDisplayAddMAXGROUPBY3()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$tbl2 = $this->tbl2();
|
|
$tbl1->select()
|
|
->displayAdd("group");
|
|
$res = $tbl2->select()
|
|
->displayAdd("MAX(uid)")
|
|
->joinInner($tbl1, ["group" => "group"])
|
|
->execute();
|
|
$tbl2->disconnect();
|
|
$this->assertSame([[
|
|
'groupedoo.group' => 'group1',
|
|
'MAX(usersoo.uid)' => 6,
|
|
]], $res);
|
|
}
|
|
|
|
public function testGROUPCONCATwithAlias1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->select()
|
|
->displayAdd("GROUP_CONCAT(group)", "groups")
|
|
->execute();
|
|
$this->assertSame([[
|
|
'groups' => 'group1,group2'
|
|
]], $res);
|
|
}
|
|
|
|
public function testGROUPCONCATwithAlias2()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->select()
|
|
->displayAdd("GROUP_CONCAT(group,',')", "groups")
|
|
->execute();
|
|
$this->assertSame([[
|
|
'groups' => 'group1,group2'
|
|
]], $res);
|
|
}
|
|
|
|
public function testGROUPCONCATwithAlias3()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->select()
|
|
->displayAdd("GROUP_CONCAT(group,' ')", "groups")
|
|
->execute();
|
|
$this->assertSame([[
|
|
'groups' => 'group1 group2'
|
|
]], $res);
|
|
}
|
|
|
|
public function testListTables1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->listTables();
|
|
if ($this->engine === "sqlite") {
|
|
$this->assertSame([
|
|
0 => 'groupedoo',
|
|
1 => 'rightsoo',
|
|
2 => 'usersoo',
|
|
], $res);
|
|
} else {
|
|
$this->assertSame([
|
|
0 => 'grouped',
|
|
1 => 'groupedoo',
|
|
2 => 'multiple',
|
|
3 => 'multiple2',
|
|
4 => 'readOR',
|
|
5 => 'rightsoo',
|
|
6 => 'users',
|
|
7 => 'users3',
|
|
8 => 'usersoo',
|
|
], $res);
|
|
}
|
|
}
|
|
|
|
//// CHECK REAL TYPES TESTS ////
|
|
public function testCheckRealTypeIntegerPositive1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_integerPositive",
|
|
"1",
|
|
""
|
|
);
|
|
$this->assertSame(null, $res);
|
|
}
|
|
public function testCheckRealTypeIntegerPositive2()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_integerPositive",
|
|
"-1",
|
|
""
|
|
);
|
|
$this->assertSame("Invalid positive integer : " .
|
|
"can not start by minus sign", $res);
|
|
}
|
|
public function testCheckRealTypeIntegerPositive3()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_integerPositive",
|
|
"0777",
|
|
""
|
|
);
|
|
$this->assertSame("Invalid positive integer : " .
|
|
"can not start by Zero", $res);
|
|
}
|
|
public function testCheckRealTypeIntegerPositive4()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_integerPositive",
|
|
"07a7",
|
|
""
|
|
);
|
|
$this->assertSame("Invalid positive integer : " .
|
|
"invalid char", $res);
|
|
}
|
|
|
|
public function testCheckRealTypeAllowedchars1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_allowedchars",
|
|
"1111",
|
|
"allowedchars(123)"
|
|
);
|
|
$this->assertSame(null, $res);
|
|
}
|
|
public function testCheckRealTypeAllowedchars2()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_allowedchars",
|
|
"-1",
|
|
"allowedchars(123)"
|
|
);
|
|
$this->assertSame("Invalid char provided", $res);
|
|
}
|
|
|
|
public function testCheckRealTypeArray1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_array",
|
|
"235",
|
|
"array('123','235','256')"
|
|
);
|
|
$this->assertSame(null, $res);
|
|
}
|
|
public function testCheckRealTypeArray2()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_array",
|
|
"777",
|
|
"array('123','235','256')"
|
|
);
|
|
$this->assertSame("Invalid value provided : not in allowed list", $res);
|
|
}
|
|
|
|
public function testCheckRealTypeRegex1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_regex",
|
|
"235",
|
|
"regex(/^\\d+$/)"
|
|
);
|
|
$this->assertSame(null, $res);
|
|
}
|
|
public function testCheckRealTypeRegex2()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_regex",
|
|
"235",
|
|
"regex(/^\\d{3}$/)"
|
|
);
|
|
$this->assertSame(null, $res);
|
|
}
|
|
public function testCheckRealTypeRegex3()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_regex",
|
|
"235",
|
|
"regex(/^\\d{4}$/)"
|
|
);
|
|
$this->assertSame("Invalid value provided : do not match the regex", $res);
|
|
}
|
|
public function testCheckRealTypeRegex4()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_regex",
|
|
"abcdef",
|
|
"regex(/^[a-z]+$/)"
|
|
);
|
|
$this->assertSame(null, $res);
|
|
}
|
|
public function testCheckRealTypeRegex5()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_regex",
|
|
"Abcdef",
|
|
"regex(/^[a-z]+$/)"
|
|
);
|
|
$this->assertSame("Invalid value provided : do not match the regex", $res);
|
|
}
|
|
|
|
public function testCheckRealTypeMail1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_mail",
|
|
"toto@example.com",
|
|
""
|
|
);
|
|
$this->assertSame(null, $res);
|
|
}
|
|
public function testCheckRealTypeMail2()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_mail",
|
|
"toto@",
|
|
""
|
|
);
|
|
$this->assertSame("Invalid mail provided", $res);
|
|
}
|
|
|
|
public function testCheckRealTypeUuid1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_uuid",
|
|
"4e799e3f-f376-46e5-a5db-85200949987e",
|
|
""
|
|
);
|
|
$this->assertSame(null, $res);
|
|
}
|
|
public function testCheckRealTypeUuid2()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_uuid",
|
|
"4E799E3F-F376-46E5-A5DB-85200949987E",
|
|
""
|
|
);
|
|
$this->assertSame(null, $res);
|
|
}
|
|
public function testCheckRealTypeUuid3()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_uuid",
|
|
"4E799E3F-F376-46E5+A5DB+85200949987E",
|
|
""
|
|
);
|
|
$this->assertSame("Invalid UUID provided : invalid char", $res);
|
|
}
|
|
public function testCheckRealTypeUuid4()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_uuid",
|
|
"4E799E3F5F376546E55A5DB585200949987E",
|
|
""
|
|
);
|
|
$this->assertSame("Invalid UUID provided : missing dash", $res);
|
|
}
|
|
|
|
public function testCheckRealTypeSqldate1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_sqldate",
|
|
"2018-10-24",
|
|
""
|
|
);
|
|
$this->assertSame(null, $res);
|
|
}
|
|
public function testCheckRealTypeSqldate2()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_sqldate",
|
|
"2018/10/24",
|
|
""
|
|
);
|
|
$this->assertSame("Invalid date provided : invalid chars", $res);
|
|
}
|
|
public function testCheckRealTypeSqldate3()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_sqldate",
|
|
"2018-10-32",
|
|
""
|
|
);
|
|
$this->assertSame("Invalid date provided : can not parse the date", $res);
|
|
}
|
|
|
|
public function testCheckRealTypeSqltime1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_sqltime",
|
|
"12:34:56",
|
|
""
|
|
);
|
|
$this->assertSame(null, $res);
|
|
}
|
|
public function testCheckRealTypeSqltime2()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_sqltime",
|
|
"12;22;22",
|
|
""
|
|
);
|
|
$this->assertSame("Invalid time provided : invalid chars", $res);
|
|
}
|
|
public function testCheckRealTypeSqltime3()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_sqltime",
|
|
"32:34:56",
|
|
""
|
|
);
|
|
$this->assertSame("Invalid time provided : can not parse the time", $res);
|
|
}
|
|
|
|
public function testCheckRealTypeSqldatetime1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_sqldatetime",
|
|
"2018-10-24 22:23:24",
|
|
""
|
|
);
|
|
$this->assertSame(null, $res);
|
|
}
|
|
public function testCheckRealTypeSqldatetime2()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_sqldatetime",
|
|
"2018/10/24",
|
|
""
|
|
);
|
|
$this->assertSame("Invalid date and time provided : invalid length", $res);
|
|
}
|
|
public function testCheckRealTypeSqldatetime3()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $this->invokeMethod(
|
|
$tbl1,
|
|
"checkRealType_sqldatetime",
|
|
"2018-10-24 25:12:25",
|
|
""
|
|
);
|
|
$this->assertSame("Invalid date and time provided : " .
|
|
"can not parse the date", $res);
|
|
}
|
|
|
|
//// TEST REAL TYPES ////
|
|
public function testCheckRealTypes1()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->checkRealTypes(["group" => "notempty"]);
|
|
$this->assertSame([
|
|
"object" => "The field can not be empty",
|
|
"where" => "The field can not be empty",
|
|
], $res);
|
|
}
|
|
public function testCheckRealTypes2()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->checkRealTypes(["group" => "not valid"]);
|
|
$this->assertSame([
|
|
"group" => "Invalid value provided : do not match the regex",
|
|
"object" => "The field can not be empty",
|
|
"where" => "The field can not be empty",
|
|
], $res);
|
|
}
|
|
public function testCheckRealTypes3()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->checkRealTypes(["group" => "notempty"], true);
|
|
$this->assertSame([], $res);
|
|
}
|
|
public function testCheckRealTypes4()
|
|
{
|
|
$tbl1 = $this->tbl1();
|
|
$res = $tbl1->checkRealTypes(["group" => "not valid"], true);
|
|
$this->assertSame([
|
|
"group" => "Invalid value provided : do not match the regex",
|
|
], $res);
|
|
}
|
|
}
|