This commit is contained in:
frederic34
2015-01-06 17:54:36 +01:00
parent f7dd4a1357
commit 73fda2cb86
70 changed files with 3612 additions and 3523 deletions

View File

@@ -18,22 +18,21 @@
/**
* \file test/phpunit/UserGroupTest.php
* \ingroup test
* \ingroup test
* \brief PHPUnit test
* \remarks To run this script as CLI: phpunit filename.php
* \remarks To run this script as CLI: phpunit filename.php
*/
global $conf,$user,$langs,$db;
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
//require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
require_once dirname(__FILE__).'/../../htdocs/user/class/usergroup.class.php';
if (empty($user->id))
{
print "Load permissions for admin user nb 1\n";
$user->fetch(1);
$user->getrights();
if (empty($user->id)) {
print "Load permissions for admin user nb 1\n";
$user->fetch(1);
$user->getrights();
}
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
@@ -47,71 +46,73 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
*/
class UserGroupTest extends PHPUnit_Framework_TestCase
{
protected $savconf;
protected $savuser;
protected $savlangs;
protected $savdb;
protected $savconf;
protected $savuser;
protected $savlangs;
protected $savdb;
/**
* Constructor
* We save global variables into local variables
*
* @return UserGroupTest
*/
function __construct()
{
//$this->sharedFixture
global $conf,$user,$langs,$db;
$this->savconf=$conf;
$this->savuser=$user;
$this->savlangs=$langs;
$this->savdb=$db;
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
//print " - db ".$db->db;
print "\n";
}
// Static methods
public static function setUpBeforeClass()
/**
* Constructor
* We save global variables into local variables
*
* @return UserGroupTest
*/
function __construct()
{
global $conf,$user,$langs,$db;
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
//$this->sharedFixture
global $conf,$user,$langs,$db;
$this->savconf=$conf;
$this->savuser=$user;
$this->savlangs=$langs;
$this->savdb=$db;
print __METHOD__."\n";
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
//print " - db ".$db->db;
print "\n";
}
// Static methods
public static function setUpBeforeClass()
{
global $conf,$user,$langs,$db;
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
print __METHOD__."\n";
}
// tear down after class
public static function tearDownAfterClass()
{
global $conf,$user,$langs,$db;
$db->rollback();
global $conf,$user,$langs,$db;
$db->rollback();
print __METHOD__."\n";
print __METHOD__."\n";
}
/**
* Init phpunit tests
*
* @return void
*/
/**
* Init phpunit tests
*
* @return void
*/
protected function setUp()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
print __METHOD__."\n";
print __METHOD__."\n";
}
/**
* End phpunit tests
*
* @return void
*/
/**
* End phpunit tests
*
* @return void
*/
protected function tearDown()
{
print __METHOD__."\n";
print __METHOD__."\n";
}
/**
@@ -121,120 +122,120 @@ class UserGroupTest extends PHPUnit_Framework_TestCase
*/
public function testUserGroupCreate()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new UserGroup($this->savdb);
$localobject->initAsSpecimen();
$result=$localobject->create($user);
$localobject=new UserGroup($this->savdb);
$localobject->initAsSpecimen();
$result=$localobject->create($user);
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
return $result;
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
return $result;
}
/**
* testUserGroupFetch
*
* @param int $id Id of group
* @return void
* @depends testUserGroupCreate
* @param int $id Id of group
* @return void
* @depends testUserGroupCreate
* The depends says test is run only if previous is ok
*/
public function testUserGroupFetch($id)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new UserGroup($this->savdb);
$result=$localobject->fetch($id);
$localobject=new UserGroup($this->savdb);
$result=$localobject->fetch($id);
$this->assertLessThan($result, 0);
print __METHOD__." id=".$id." result=".$result."\n";
return $localobject;
$this->assertLessThan($result, 0);
print __METHOD__." id=".$id." result=".$result."\n";
return $localobject;
}
/**
* testUserGroupUpdate
*
* @param Object $localobject Group
* @return void
* @depends testUserGroupFetch
* @param Object $localobject Group
* @return void
* @depends testUserGroupFetch
* The depends says test is run only if previous is ok
*/
public function testUserGroupUpdate($localobject)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject->note='New note after update';
$result=$localobject->update($user);
$localobject->note='New note after update';
$result=$localobject->update($user);
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertLessThan($result, 0);
return $localobject;
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertLessThan($result, 0);
return $localobject;
}
/**
* testUserGroupAddRight
*
* @param Object $localobject Object to show
* @return void
* @depends testUserGroupUpdate
* @param Object $localobject Object to show
* @return void
* @depends testUserGroupUpdate
* The depends says test is run only if previous is ok
*/
public function testUserGroupAddRight($localobject)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$result=$localobject->addrights(1,'bookmarks');
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$result=$localobject->addrights(1,'bookmarks');
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertLessThan($result, 0);
return $localobject;
$this->assertLessThan($result, 0);
return $localobject;
}
/**
* testUserGroupDelRight
*
* @param Object $localobject Object
* @return void
* @depends testUserGroupAddRight
* @param Object $localobject Object
* @return void
* @depends testUserGroupAddRight
* The depends says test is run only if previous is ok
*/
public function testUserGroupDelRight($localobject)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$result=$localobject->delrights(1,'bookmarks');
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$result=$localobject->delrights(1,'bookmarks');
print __METHOD__." id=".$localobject->id." result=".$result."\n";
$this->assertLessThan($result, 0);
return $localobject;
$this->assertLessThan($result, 0);
return $localobject;
}
/**
* testUserGroupOther
*
* @param Object $localobject Object
* @return void
* @param Object $localobject Object
* @return void
* @depends testUserGroupDelRight
* The depends says test is run only if previous is ok
*/
@@ -261,26 +262,26 @@ class UserGroupTest extends PHPUnit_Framework_TestCase
/**
* testUserGroupDelete
*
* @param int $id Id of object
* @return void
* @depends testUserGroupOther
* @param int $id Id of object
* @return void
* @depends testUserGroupOther
* The depends says test is run only if previous is ok
*/
public function testUserGroupDelete($id)
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$localobject=new UserGroup($this->savdb);
$result=$localobject->fetch($id);
$result=$localobject->delete($id);
$localobject=new UserGroup($this->savdb);
$result=$localobject->fetch($id);
$result=$localobject->delete($id);
print __METHOD__." id=".$id." result=".$result."\n";
$this->assertLessThan($result, 0);
return $result;
print __METHOD__." id=".$id." result=".$result."\n";
$this->assertLessThan($result, 0);
return $result;
}
}