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,9 +18,9 @@
/**
* \file test/phpunit/ContratTest.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;
@@ -29,11 +29,10 @@ global $conf,$user,$langs,$db;
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
require_once dirname(__FILE__).'/../../htdocs/compta/bank/class/account.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;
@@ -49,127 +48,129 @@ $langs->load("main");
*/
class BankAccountTest 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 BankAccountTest
*/
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 BankAccountTest
*/
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";
}
/**
* testBankAccountCreate
*
* @return int
* @return int
*/
public function testBankAccountCreate()
{
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 Account($this->savdb);
$localobject->initAsSpecimen();
$localobject->date_solde=dol_now();
$result=$localobject->create($user);
$localobject=new Account($this->savdb);
$localobject->initAsSpecimen();
$localobject->date_solde=dol_now();
$result=$localobject->create($user);
print __METHOD__." result=".$result."\n";
$this->assertLessThan($result, 0);
print __METHOD__." result=".$result."\n";
$this->assertLessThan($result, 0);
return $result;
return $result;
}
/**
* testBankAccountFetch
*
* @param int $id Id of contract
* @return int
* @param int $id Id of contract
* @return int
*
* @depends testBankAccountCreate
* @depends testBankAccountCreate
* The depends says test is run only if previous is ok
*/
public function testBankAccountFetch($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 Account($this->savdb);
$result=$localobject->fetch($id);
$localobject=new Account($this->savdb);
$result=$localobject->fetch($id);
print __METHOD__." id=".$id." result=".$result."\n";
$this->assertLessThan($result, 0);
print __METHOD__." id=".$id." result=".$result."\n";
$this->assertLessThan($result, 0);
return $localobject;
return $localobject;
}
/**
* testBankAccountOther
*
* @param Object $localobject Object contract
* @return int
* @param Object $localobject Object contract
* @return int
*
* @depends testBankAccountFetch
* The depends says test is run only if previous is ok
@@ -197,27 +198,27 @@ class BankAccountTest extends PHPUnit_Framework_TestCase
/**
* testBankAccountDelete
*
* @param int $id Id of contract
* @return int
* @param int $id Id of contract
* @return int
*
* @depends testBankAccountOther
* @depends testBankAccountOther
* The depends says test is run only if previous is ok
*/
public function testBankAccountDelete($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 Account($this->savdb);
$result=$localobject->fetch($id);
$result=$localobject->delete($id);
$localobject=new Account($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;
}
}