code cleaning

rename class Acc_Ledger_Sold to Acc_Ledger_Sale ,
improve doc ,
improve phpunit test
This commit is contained in:
sparkyx 2021-08-05 16:50:29 +02:00
parent 69c8c18dfa
commit 8155f502c3
23 changed files with 210 additions and 110 deletions

View file

@ -2,9 +2,14 @@
export PGCLUSTER=10/main
DOSSIER_TEST=rel70dossier25
FILE_TEST=dossiertest210607-1503.sql
FILE_TEST=dossiertest210620-1111.sql
dropdb $DOSSIER_TEST
if [ $? -ne 0 ] ; then
echo cannot drop $DOSSIER_TEST
exit 1
fi
createdb $DOSSIER_TEST
psql -X $DOSSIER_TEST < db/$FILE_TEST

View file

@ -37,6 +37,7 @@ $_SESSION[SESSION_KEY.'g_pagesize']='50';
$_SESSION[SESSION_KEY.'csv_fieldsep']='0';
$_SESSION[SESSION_KEY.'csv_decimal']='1';
$_SESSION[SESSION_KEY.'csv_encoding']='utf8';
$_SESSION[SESSION_KEY.'access_mode']='PC';
$g_user=new User($g_connection);
require_once __DIR__.'/facility.class.php';

View file

@ -5,6 +5,7 @@ use PHPUnit\Framework\TestCase;
/**
* @backupGlobals enabled
* @coversDefaultClass Acc_Ledger_Purchase
* @covers Fiche
*
*/
class Acc_Ledger_PurchaseTest extends TestCase
@ -120,11 +121,13 @@ class Acc_Ledger_PurchaseTest extends TestCase
$this->clean_operation();
$this->assertEquals(0,
$g_connection->get_value ("select count(*) from jrn where jr_mt=$1",["1572704002.1732"]));
$g_connection->get_value ("select count(*) from jrn where jr_mt=$1",["1572704002.1732"]),
"avant les test verifie operation n'existe pas");
$this->object->insert($array);
$this->assertEquals(1,
$g_connection->get_value ("select count(*) from jrn where jr_mt=$1",["1572704002.1732"]));
$g_connection->get_value ("select count(*) from jrn where jr_mt=$1",["1572704002.1732"]),
"Operation Achat sauvée");
$this->clean_operation();
// If some data are corruptes
@ -155,7 +158,7 @@ class Acc_Ledger_PurchaseTest extends TestCase
"tvac_march1"=>22.08));
$this->object->insert($array);
$this->assertEquals(0,$g_connection->get_value("select count(*) ".$sql));
$this->assertEquals(0,$g_connection->get_value("select count(*) ".$sql),"Quantite == 0 pas d'enregistrement");
$this->clean_operation();
// Test space in e_march0_price instead of zero must be
@ -178,7 +181,7 @@ class Acc_Ledger_PurchaseTest extends TestCase
"tva_march1"=>3.83,
"tvac_march1"=>22.08));
$this->object->insert($array);
$this->assertEquals(3.83,$g_connection->get_value("select qp_vat ".$sql));
$this->assertEquals(3.83,$g_connection->get_value("select qp_vat ".$sql),"Calcul TVA en EUR");
$this->clean_operation();
// Test space in e_march0_tva_amount instead of zero must be calculated
@ -201,13 +204,85 @@ class Acc_Ledger_PurchaseTest extends TestCase
$this->object->insert($array);
// en USD , 22.08 = 20.26€ * 1.09
$this->assertEquals(20.26,$g_connection->get_value("select qp_vat ".$sql));
$this->assertEquals(20.26,$g_connection->get_value("select qp_vat ".$sql),"Calcul TVA en USD");
$this->clean_operation();
}
/**
* @covers Acc_Ledger_Purchase::insert
* @covers Fiche_Def::insertAttribut
* @covers Fiche_Def::removeAttribut
*/
public function testInsertPurchase_No_Ded()
{
global $g_connection;
// modify attribute for card category , add VAT non ded, Tax non ded , VAT completely non ded 0%
// category Misc Services & goods (5)
$fiche_def=new Fiche_Def($g_connection,5);
// prepare test , clean
$fiche_def->RemoveAttribut([20,21,22,51,52,53]);
$this->assertEquals(35,$g_connection->get_value("select count(*) from fiche_detail join fiche using (f_id)
where fd_id=5"),"Efface 6 attributs");
// percent deductible
$fiche_def->InsertAttribut(20);
$fiche_def->InsertAttribut(21);
$fiche_def->InsertAttribut(22);
// accouting for not deductible
$fiche_def->InsertAttribut(51);
$fiche_def->InsertAttribut(52);
$fiche_def->InsertAttribut(53);
// check that all card has these attributes
$this->assertEquals(77,$g_connection->get_value("select count(*) from fiche_detail join fiche using (f_id)
where fd_id=5"),"Ajout 6 attributs");
//-- modify card 29 : ELECTR
$fiche=new Fiche($g_connection,29);
$fiche->set_f_enable("1");
$a_attribut=$fiche->to_array();
$a_attribut['av_text20']= "33.33";
$this->assertEquals($a_attribut['av_text20'],33.33,"Attribut 20 set to 33%");
$fiche->update($a_attribut);
$this->assertEquals("33.33",$g_connection->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=$2",[29,20]),"Attribut ad_id 20 inserted");
$array=$this->array;
$array['e_march0']='ELECTR';
$array['e_march0_tva_id']='1';
$array['tva_march0']=bcmul($array['e_march0_tva_amount'],0.21,2);
$array['tvac_march0']=bcmul ($array['htva_march0'],1.21,2);
$array['mt']='no-ded-33';
$this->clean_operation($array['mt']);
$this->object->insert($array);
$row_quant=$g_connection->get_row("select * from quant_purchase where qp_internal in
( select jr_internal from jrn where jr_mt=$1)",[$array["mt"]]);
$this->assertFalse(empty($row_quant)," row inserted in quant_fin");
// unit price not rounded
$this->assertEquals(603.8990,$row_quant['qp_unit']);
// rounded to 2 decimal
$this->assertEquals(603.9000,$row_quant['qp_price']);
$this->assertEquals(201.2800,$row_quant['qp_nd_amount']);
$this->clean_operation($array['mt']);
// end test clean
// $fiche_def->RemoveAttribut([20,21,22,51,52,53]);
}
/**
* @covers Acc_Ledger_Purchase::input
* @covers Acc_Ledger_Purchase::input
*/
public function testInput()
{
@ -240,13 +315,13 @@ class Acc_Ledger_PurchaseTest extends TestCase
$this->assertContains('NAME="e_quant0" VALUE="1">',$ret);
}
private function clean_operation()
private function clean_operation($p_internal='1572704002.1732')
{
global $g_connection;
$g_connection->exec_sql("delete from quant_purchase where j_id in ("
. " select j_id from jrnx join jrn on (jr_grpt_id = j_grpt) where "
. " jr_mt=$1 ) ", ["1572704002.1732"]);
$g_connection->exec_sql("delete from jrn where jr_mt=$1", ["1572704002.1732"]);
. " jr_mt=$1 ) ", [$p_internal]);
$g_connection->exec_sql("delete from jrn where jr_mt=$1", [$p_internal]);
$g_connection->exec_sql("delete from jrnx where j_grpt not in (select jr_grpt_id from jrn)");
$g_connection->exec_sql("alter sequence s_jrn_pj3 restart with 52");

View file

@ -4,13 +4,13 @@ use PHPUnit\Framework\TestCase;
/**
* @backupGlobals enabled
* @coversDefaultClass Acc_Ledger_Sold
* @coversDefaultClass Acc_Ledger_Sale
*/
class Acc_Ledger_SoldTest extends TestCase
class Acc_Ledger_SaleTest extends TestCase
{
/**
* @var Acc_Ledger_Sold
* @var Acc_Ledger_Sale
*/
protected $object;
@ -27,7 +27,7 @@ class Acc_Ledger_SoldTest extends TestCase
protected function setUp()
{
include 'global.php';
$this->object=new Acc_Ledger_Sold($g_connection, 2);
$this->object=new Acc_Ledger_Sale($g_connection, 2);
$this->array=array(
"ledger_type"=>"VEN",
"ac"=>"COMPTA/VENMENU/VEN",
@ -88,7 +88,7 @@ class Acc_Ledger_SoldTest extends TestCase
$g_connection->exec_sql("alter sequence s_jrn_pj2 restart with 40");
}
/**
* @covers Acc_Ledger_Sold::verify
* @covers Acc_Ledger_Sale::verify
*/
public function testVerify()
{
@ -97,7 +97,7 @@ class Acc_Ledger_SoldTest extends TestCase
}
/**
* @covers Acc_Ledger_Sold::insert
* @covers Acc_Ledger_Sale::insert
*/
public function testInsert()
{
@ -169,14 +169,14 @@ class Acc_Ledger_SoldTest extends TestCase
}
/**
* @covers Acc_Ledger_Sold::confirm
* @covers Acc_Ledger_Sale::confirm
*/
public function testConfirm()
{
$array=$this->array;
$res=$this->object->confirm($array);
\Noalyss\Facility::save_file(__DIR__."/file"
, "acc_ledger_sold_confirm.html"
, "Acc_Ledger_Sale_confirm.html"
, \Noalyss\Facility::page_start().$res);
$this->assertContains(
'<input type="button" class="button" value="Vérifiez Imputation Analytique" onClick="verify_ca(\'\');">',
@ -188,14 +188,14 @@ class Acc_Ledger_SoldTest extends TestCase
/**
* @covers Acc_Ledger_Sold::input
* @covers Acc_Ledger_Sale::input
* @todo Implement testInput().
*/
public function testInput()
{
global $g_connection;
$_REQUEST['ac']='VEN';
$object=new Acc_Ledger_Sold($g_connection, 2);
$object=new Acc_Ledger_Sale($g_connection, 2);
$info=$object->input($this->array);
// var_dump($info);
@ -203,7 +203,7 @@ class Acc_Ledger_SoldTest extends TestCase
{
$this->assertTrue(FALSE);
}
\Noalyss\Facility::save_file(__DIR__."/file", "acc_ledger_sold_input.html",
\Noalyss\Facility::save_file(__DIR__."/file", "Acc_Ledger_Sale_input.html",
\Noalyss\Facility::page_start().
$info);
$this->assertContains(
@ -216,7 +216,7 @@ class Acc_Ledger_SoldTest extends TestCase
/**
* @covers Acc_Ledger_Sold::heading_detail_sale
* @covers Acc_Ledger_Sale::heading_detail_sale
* @todo Implement testHeading_detail_sale().
*/
public function testHeading_detail_sale()
@ -225,7 +225,7 @@ class Acc_Ledger_SoldTest extends TestCase
$this->assertEquals(32,count($a));
}
/**
* @covers Acc_Ledger_Sold::get_detail_sale
* @covers Acc_Ledger_Sale::get_detail_sale
*/
public function testget_detail_sale()
{

View file

@ -61,7 +61,7 @@ class print_LedgerTest extends TestCase
function testFactory()
{
global $g_connection;
$ledger_sale=new Acc_Ledger_Sold($g_connection,2);
$ledger_sale=new Acc_Ledger_Sale($g_connection,2);
$p_from=$this->from;
$p_to=$this->to;

View file

@ -112,7 +112,7 @@ class Print_Ledger_Detail_ItemTest extends TestCase
//-------------------------------------------------------------------------------------------------------------
// Sale
//-------------------------------------------------------------------------------------------------------------
$ledger_sale=new Acc_Ledger_Sold($g_connection,2);
$ledger_sale=new Acc_Ledger_Sale($g_connection,2);
// Paid
//-----------------

View file

@ -116,7 +116,7 @@ class print_ledger_simpleTest extends TestCase
//-------------------------------------------------------------------------------------------------------------
// Sale
//-------------------------------------------------------------------------------------------------------------
$ledger_sale=new Acc_Ledger_Sold($g_connection, 2);
$ledger_sale=new Acc_Ledger_Sale($g_connection, 2);
// Paid
//-----------------

View file

@ -114,7 +114,7 @@ class Print_Ledger_Simple_Without_VatTest extends TestCase
//-------------------------------------------------------------------------------------------------------------
// Sale
//-------------------------------------------------------------------------------------------------------------
$ledger_sale=new Acc_Ledger_Sold($g_connection, 2);
$ledger_sale=new Acc_Ledger_Sale($g_connection, 2);
// Paid
//-----------------

View file

@ -43,6 +43,6 @@ else
# $PHPUNIT --bootstrap bootstrap.php --whitelist $FILETOTEST --coverage-text=${FILETOTEST%.php}.txt --color $FILETOTEST
# $PHPUNIT --bootstrap $CUR_DIR/bootstrap.php --whitelist=$CUR_DIR/../include/class --coverage-html=coverage --color $FILETOTEST
$PHPUNIT --bootstrap bootstrap.php $FILETOTEST --testdox-html ${FILETOTEST%.php}-testdox.html --color $FILETOTEST
$PHPUNIT --bootstrap bootstrap.php --whitelist=../include --coverage-html=coverage $FILETOTEST --testdox-html ${FILETOTEST%.php}-testdox.html --color $FILETOTEST
fi