Qual: Add phpunit test before working on different rounding modes

This commit is contained in:
Laurent Destailleur 2012-01-11 16:35:12 +01:00
parent c773e25c21
commit a57295cc73
2 changed files with 127 additions and 75 deletions

View File

@ -3070,9 +3070,10 @@ class Facture extends CommonObject
* Used to build previews or test instances. * Used to build previews or test instances.
* id must be 0 if object instance is a specimen. * id must be 0 if object instance is a specimen.
* *
* @param string $option ''=Create a specimen invoice with lines, 'nolines'=No lines
* @return void * @return void
*/ */
function initAsSpecimen() function initAsSpecimen($option='')
{ {
global $user,$langs,$conf; global $user,$langs,$conf;
@ -3110,6 +3111,9 @@ class Facture extends CommonObject
$this->mode_reglement_code = 'CHQ'; $this->mode_reglement_code = 'CHQ';
$this->note_public='This is a comment (public)'; $this->note_public='This is a comment (public)';
$this->note='This is a comment (private)'; $this->note='This is a comment (private)';
if (empty($option) || $option != 'nolines')
{
// Lines // Lines
$nbp = 5; $nbp = 5;
$xnbp = 0; $xnbp = 0;
@ -3187,6 +3191,7 @@ class Facture extends CommonObject
$this->lines[$xnbp]=$line; $this->lines[$xnbp]=$line;
$xnbp++; $xnbp++;
} }
}
/** /**
* Load indicators for dashboard (this->nbtodo and this->nbtodolate) * Load indicators for dashboard (this->nbtodo and this->nbtodolate)

View File

@ -28,17 +28,15 @@ global $conf,$user,$langs,$db;
require_once 'PHPUnit/Autoload.php'; require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
require_once dirname(__FILE__).'/../../htdocs/core/lib/price.lib.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/price.lib.php';
require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture.class.php';
if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); if (empty($user->id))
if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); {
if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); print "Load permissions for admin user nb 1\n";
if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); $user->fetch(1);
if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); $user->getrights();
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); }
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); // If there is no menu to show $conf->global->MAIN_DISABLE_ALL_MAILS=1;
if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); // If we don't need to load the html.form.class.php
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session)
/** /**
@ -139,5 +137,54 @@ class PricesTest extends PHPUnit_Framework_TestCase
return true; return true;
} }
/**
* Test function addline and update_price
*
* @return boolean
* @see http://wiki.dolibarr.org/index.php/Draft:VAT_calculation_and_rounding#Standard_usage
*/
public function testUpdatePrice()
{
//$this->sharedFixture
global $conf,$user,$langs,$db;
$this->savconf=$conf;
$this->savuser=$user;
$this->savlangs=$langs;
$this->savdb=$db;
// Two lines of 1.24 give 2.48 HT and 2.72 TTC with standard vat rounding mode
$localobject=new Facture($this->savdb);
$localobject->initAsSpecimen('nolines');
$invoiceid=$localobject->create($user);
$localobject->addline($invoiceid,'Desc',1.24,1,10,0,0,0,0,'','',0,0,0,'HT');
$localobject->addline($invoiceid,'Desc',1.24,1,10,0,0,0,0,'','',0,0,0,'HT');
$newlocalobject=new Facture($this->savdb);
$newlocalobject->fetch($invoiceid);
$this->assertEquals(2.48,$newlocalobject->total_ht);
$this->assertEquals(0.24,$newlocalobject->total_tva);
$this->assertEquals(2.72,$newlocalobject->total_ttc);
// Two lines of 1.24 give 2.48 HT and 2.73 TTC with global vat rounding mode
$localobject=new Facture($this->savdb);
$localobject->initAsSpecimen('nolines');
$invoiceid=$localobject->create($user);
$localobject->addline($invoiceid,'Desc',1.24,1,10,0,0,0,0,'','',0,0,0,'HT');
$localobject->addline($invoiceid,'Desc',1.24,1,10,0,0,0,0,'','',0,0,0,'HT');
$newlocalobject=new Facture($this->savdb);
$newlocalobject->fetch($invoiceid);
$this->assertEquals(2.48,$newlocalobject->total_ht);
//$this->assertEquals(0.25,$newlocalobject->total_tva);
//$this->assertEquals(2.73,$newlocalobject->total_ttc);
}
} }
?> ?>