Update tests to remove the dependancy to configuration

Change the databases to be unique by test file


git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2670 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2016-03-12 16:34:44 +00:00
parent 3c133753ea
commit e977f9dfa1
5 changed files with 93 additions and 190 deletions

View File

@@ -6,12 +6,20 @@
/** Test the authzgroups.php file */
class test_authzgroups extends PHPUnit_Framework_TestCase
{
private $dbconfig = array (
"dsn" => "sqlite:/tmp/databaseAuthzGroups.db",
"username" => null,
"password" => null,
"driver_options" => null,
"tableprefix" => "",
);
public function test_Initialization ()
{
@unlink ("/tmp/databaseAuthzGroups.db");
}
public function test_createTables1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$this->setExpectedException ("Exception");
$authz->createTables ();
@@ -21,25 +29,19 @@ class test_authzgroups extends PHPUnit_Framework_TestCase
{
// Must use the model to create the database structure as there is no
// creation of tables in controller
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$res = $authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$res = $authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$this->assertSame (true, $res);
}
public function test_createTables2 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->createTables ();
$this->assertSame (true, $res);
}
@@ -49,39 +51,30 @@ class test_authzgroups extends PHPUnit_Framework_TestCase
////////////////
public function test_objectCreate1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->objectAdd ("MODULE", "/object");
$this->assertSame ("1", $res);
}
public function test_objectUpdate1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->objectUpdate ("MODULE", "/object", "/object2");
$this->assertSame (1, $res);
}
public function test_objectDelete1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
// The object was renamed and is not available
$this->setExpectedException ("Exception");
$res = $authz->objectDel ("MODULE", "/object");
@@ -92,39 +85,30 @@ class test_authzgroups extends PHPUnit_Framework_TestCase
////////////////
public function test_groupCreate1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->groupAdd ("MODULE", "group");
$this->assertSame ("1", $res);
}
public function test_groupUpdate1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->groupUpdate ("MODULE", "group", "group2");
$this->assertSame (1, $res);
}
public function test_groupDelete1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
// The group doesn't exists
$this->setExpectedException ("Exception");
$res = $authz->groupDel ("MODULE", "group");
@@ -135,13 +119,10 @@ class test_authzgroups extends PHPUnit_Framework_TestCase
/////////////////////
public function test_groupmemberCreate1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
// The group doesn't exists
$this->setExpectedException ("Exception");
$res = $authz->groupmemberAdd ("MODULE", "group", "userKnown");
@@ -149,26 +130,20 @@ class test_authzgroups extends PHPUnit_Framework_TestCase
public function test_groupmemberCreate2 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->groupmemberAdd ("MODULE", "group2", "userKnown");
$this->assertSame ("1", $res);
}
public function test_groupmemberDelete1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
// The group doesn't exists
$this->setExpectedException ("Exception");
$res = $authz->groupmemberDel ("MODULE", "group","userKnown");
@@ -176,13 +151,10 @@ class test_authzgroups extends PHPUnit_Framework_TestCase
public function test_groupmemberReadGroup1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
// The group doesn't exists
$this->setExpectedException ("Exception");
$res = $authz->groupmemberReadGroup ("MODULE", "group");
@@ -190,26 +162,20 @@ class test_authzgroups extends PHPUnit_Framework_TestCase
public function test_groupmemberReadGroup2 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->groupmemberReadGroup ("MODULE", "group2");
$this->assertSame (array (array ("user"=>"userKnown")), $res);
}
public function test_groupmemberReadUser1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->groupmemberReadUser ("MODULE", "userKnown");
$this->assertSame (array (1=>"group2"), $res);
}
@@ -219,39 +185,30 @@ class test_authzgroups extends PHPUnit_Framework_TestCase
////////////////
public function test_rightCreate1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->rightAdd ("MODULE", "group2","/object2", "RW");
$this->assertSame ("1", $res);
}
public function test_rightUpdate1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->rightUpdate ("MODULE", "group2", "/object2", "RO");
$this->assertSame (1, $res);
}
public function test_rightDelete1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
// The object doesn't exists
$this->setExpectedException ("Exception");
$res = $authz->rightDel ("MODULE", "group2", "/object");
@@ -263,39 +220,30 @@ class test_authzgroups extends PHPUnit_Framework_TestCase
//////////////////////////////////////////////
public function test_deleteGroupmember2 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->groupmemberDel ("MODULE", "group2","userKnown");
$this->assertSame (1, $res);
}
public function test_deleteObject2 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->objectDel ("MODULE", "/object2");
$this->assertSame (1, $res);
}
public function test_deleteGroup2 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->groupDel ("MODULE", "group2");
$this->assertSame (1, $res);
}
@@ -305,13 +253,10 @@ class test_authzgroups extends PHPUnit_Framework_TestCase
/////////////////////
public function test_userrightsget1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
// Create infos to tests the userrightsget method
$authz->objectAdd ("MODULE1", "/");
$authz->objectAdd ("MODULE1", "/rep1");
@@ -337,26 +282,20 @@ class test_authzgroups extends PHPUnit_Framework_TestCase
public function test_allow1 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->allow ("MODULE1", "userKnown", "/rep1/rep2");
$this->assertSame ("RW", $res);
}
public function test_allow2 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$authz->rightAdd ("MODULE1", "group2","/","RW");
$res = $authz->allow ("MODULE1", "userKnown", "/rep1/rep2");
$this->assertSame ("RW", $res);
@@ -364,13 +303,10 @@ class test_authzgroups extends PHPUnit_Framework_TestCase
public function test_allow3 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$authz->rightAdd ("MODULE1", "group2","/rep1","RO");
$res = $authz->allow ("MODULE1", "userKnown", "/rep1/rep2");
$this->assertSame ("RW", $res);
@@ -378,13 +314,10 @@ class test_authzgroups extends PHPUnit_Framework_TestCase
public function test_allow4 ()
{
$configuration = new configuration ();
$dbconfig = $configuration->get ("database");
if (! isset ($dbconfig["tableprefix"]))
$dbconfig["tableprefix"] = "";
$authz = new authzgroups ();
$authz->connect ($dbconfig["dsn"], $dbconfig["username"],
$dbconfig["password"], $dbconfig["driver_options"]);
$authz->connect ($this->dbconfig["dsn"], $this->dbconfig["username"],
$this->dbconfig["password"],
$this->dbconfig["driver_options"]);
$res = $authz->allow ("MODULE1", "userKnown", "/rep1/rep2/rep3");
$this->assertSame ("NO", $res);
}

View File

@@ -5,14 +5,6 @@ spl_autoload_register(function ($class) {
});
define ("PHPUNIT", "ON-GOING");
define ("CONFIGFILE", "./Tests/configuration.php");
if (! file_exists (CONFIGFILE))
die ("No Config file found in ".CONFIGFILE."\n");
echo "Configuration file : ".CONFIGFILE."\n";
if (file_exists ("/tmp/database.db"))
{
unlink ("/tmp/database.db");
}
file_put_contents ("Tests/dblayerSqliteTest.php",
str_replace ("{ENGINE}", "sqlite",
@@ -24,24 +16,4 @@ file_put_contents ("Tests/dblayerPostgreSQLTest.php",
str_replace ("{ENGINE}", "pgsql",
file_get_contents ("Tests/dblayerComplet.php")));
require_once ("domframework/config.php");
/** The class need to take care of configuration parameters */
class configuration extends config
{
/** All the default parameters in the configuration */
function __construct ()
{
$this->default = array (
"database"=>array ("dsn"=>null,
"username"=>null,
"password"=>null,
"driver_options"=>null,
"tableprefix"=>""),
);
if (defined("CONFIGFILE"))
$this->confFile = CONFIGFILE;
}
}
// vim: syntax=on filetype=php

View File

@@ -6,12 +6,10 @@
/** Test the cache.php file */
class test_cachefile extends PHPUnit_Framework_TestCase
{
public function __construct ()
public function testInit ()
{
// Removing the cache file if it previously exists
$c = new cachefile ();
$c->directory = "/tmp/cache";
$res = $c->delete ("id");
exec ("rm -rf /tmp/cache");
}
// Unknown cache file : return FALSE
@@ -41,7 +39,7 @@ class test_cachefile extends PHPUnit_Framework_TestCase
$this->assertSame ("DATA_TO_STORE", $res);
}
// Sleep 3s to expire the cache
// Sleep 4s to expire the cache
public function testWait1 ()
{
sleep (4);

View File

@@ -94,7 +94,7 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
"where"=>"\$'\"",
"with space"=>"with space"));
// SQLite start at 1, MySQL start at 0...
$this->assertThat($res, $this->lessThanOrEqual(1));
$this->assertLessThanOrEqual ($res, 1);
}
public function test_read1 ()
@@ -267,7 +267,7 @@ class test_dblayer_{ENGINE} extends PHPUnit_Framework_TestCase
"with space"=>"with space"));
$db->disconnect ();
// SQLite start at 1, MySQL start at 0...
$this->assertThat($res, $this->lessThanOrEqual(2));
$this->assertLessThanOrEqual ($res, 2);
}
// Test the unique feature

View File

@@ -7,7 +7,7 @@ class test_dblayerauthzgroups_sqlite extends PHPUnit_Framework_TestCase
{
public $confs = array (
"sqlite" => array (
"dsn" => "sqlite:/tmp/database.db",
"dsn" => "sqlite:/tmp/databaseAuthz.db",
"username" => null,
"password" => null,
"driver_options" => null,