Code improved : test and fix load functions
This commit is contained in:
parent
0068caaf89
commit
fc3c1057e3
16 changed files with 453 additions and 80 deletions
|
|
@ -80,7 +80,6 @@ class Acc_BilanTest extends TestCase
|
|||
|
||||
/**
|
||||
* @covers Acc_Bilan::load
|
||||
* @todo Implement testLoad().
|
||||
*/
|
||||
public function testLoad()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -59,11 +59,12 @@ class Acc_Ledger_InfoTest extends TestCase
|
|||
$this->object->id_type='BON_COMMANDE';
|
||||
$this->object->ji_value='BON';
|
||||
|
||||
$cnt=$g_connection->get_array("select * from jrn_info where jr_id=$1",[$this->object->jr_id]);
|
||||
$this->assertSame(count($cnt),0);
|
||||
$g_connection->exec_sql("delete from jrn_info where jr_id=$1",[$this->object->jr_id]);
|
||||
$cnt=$g_connection->get_value("select count(*) from jrn_info where jr_id=$1",[$this->object->jr_id]);
|
||||
$this->assertEquals($cnt,0,"Error : bon_commande already exist");
|
||||
$this->object->insert();
|
||||
$cnt=$g_connection->get_array("select * from jrn_info where jr_id=$1",[$this->object->jr_id]);
|
||||
$this->assertSame(count($cnt),1);
|
||||
$cnt=$g_connection->get_value("select count(*) from jrn_info where jr_id=$1",[$this->object->jr_id]);
|
||||
$this->assertEquals($cnt,1,'Error : not inserted');
|
||||
$g_connection->exec_sql("delete from jrn_info where jr_id=$1",[$this->object->jr_id]);
|
||||
|
||||
}
|
||||
|
|
@ -81,5 +82,28 @@ class Acc_Ledger_InfoTest extends TestCase
|
|||
$this->assertSame(count($cnt),1);
|
||||
$g_connection->exec_sql("delete from jrn_info where jr_id=$1",[$this->object->jr_id]);
|
||||
}
|
||||
/**
|
||||
* @testdox test loading
|
||||
*/
|
||||
function test_load()
|
||||
{
|
||||
global $g_connection;
|
||||
$this->object->jr_id=3;
|
||||
$this->object->id_type='BON_COMMANDE';
|
||||
$this->object->ji_value='BONi 11111111';
|
||||
|
||||
$cnt=$g_connection->get_array("select * from jrn_info where jr_id=$1",[$this->object->jr_id]);
|
||||
$this->assertSame(count($cnt),0);
|
||||
$this->object->insert();
|
||||
$cnt=$g_connection->get_array("select * from jrn_info where jr_id=$1",[$this->object->jr_id]);
|
||||
$this->assertSame(count($cnt),1);
|
||||
$reload_id=$g_connection->get_value("select ji_id from jrn_info where jr_id=$1",[$this->object->jr_id]);
|
||||
$reload=new Acc_Ledger_Info($g_connection,$reload_id);
|
||||
$reload->load();
|
||||
$this->assertSame($reload->ji_value,$this->object->ji_value,"Error cannot load");
|
||||
|
||||
$g_connection->exec_sql("delete from jrn_info where jr_id=$1",[$this->object->jr_id]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ class Acc_Ledger_Test extends TestCase
|
|||
$ledger=new Acc_Ledger_Search('ALL');
|
||||
$r=$ledger->display_search_form();
|
||||
\Noalyss\Facility::save_file(__DIR__."/file", "acc_ledger_search-test_display_search_form.html", $r);
|
||||
$this->assertEquals(9665,strlen($r),"Size of the html string for display_search_form see "
|
||||
$this->assertEquals(9669,strlen($r),"Size of the html string for display_search_form see "
|
||||
. __DIR__."/file/acc_ledger_search-test_display_search_form.html ");
|
||||
}
|
||||
/**
|
||||
|
|
@ -98,35 +98,34 @@ class Acc_Ledger_Test extends TestCase
|
|||
{
|
||||
$ledger=new Acc_Ledger_Search('ALL');
|
||||
$ret = $ledger->build_search_filter();
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'ALL','all_type':1,'dossier':%d})"
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'ALL','all_type':1,'dossier':'%d'})"
|
||||
,Dossier::id());
|
||||
$this->assertEquals($ret,$result,"Build filter for ALL");
|
||||
|
||||
$this->assertEquals($ret,$result,"Build filter for ALL");
|
||||
$ledger=new Acc_Ledger_Search('FIN');
|
||||
$this->assertEquals($ret,$result);
|
||||
$ret = $ledger->build_search_filter();
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'FIN','all_type':1,'dossier':%d})"
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'FIN','all_type':1,'dossier':'%d'})"
|
||||
,Dossier::id());
|
||||
$this->assertEquals($ret,$result,"Build filter for FIN");
|
||||
|
||||
$ledger=new Acc_Ledger_Search('VEN');
|
||||
$this->assertEquals($ret,$result);
|
||||
$ret = $ledger->build_search_filter();
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'VEN','all_type':1,'dossier':%d})"
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'VEN','all_type':1,'dossier':'%d'})"
|
||||
,Dossier::id());
|
||||
$this->assertEquals($ret,$result,"Build filter for VEN");
|
||||
|
||||
$ledger=new Acc_Ledger_Search('ACH');
|
||||
$this->assertEquals($ret,$result);
|
||||
$ret = $ledger->build_search_filter();
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'ACH','all_type':1,'dossier':%d})"
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'ACH','all_type':1,'dossier':'%d'})"
|
||||
,Dossier::id());
|
||||
$this->assertEquals($ret,$result,"Build filter for ACH");
|
||||
|
||||
$ledger=new Acc_Ledger_Search('ODS');
|
||||
$this->assertEquals($ret,$result);
|
||||
$ret = $ledger->build_search_filter();
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'ODS','all_type':1,'dossier':%d})"
|
||||
$result=sprintf("manage_search_filter({'div':'','ledger_type':'ODS','all_type':1,'dossier':'%d'})"
|
||||
,Dossier::id());
|
||||
|
||||
$this->assertEquals($ret,$result,"Build filter for ODS");
|
||||
|
|
|
|||
180
unit-test/include/class/acc_payment.Test.php
Normal file
180
unit-test/include/class/acc_payment.Test.php
Normal file
|
|
@ -0,0 +1,180 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* * Copyright (C) 2021 Dany De Bontridder <dany@alchimerys.be>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*
|
||||
* Author : Dany De Bontridder danydb@noalyss.eu
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief
|
||||
*/
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @backupGlobals enabled
|
||||
* @coversDefaultClass \Acc_Payment
|
||||
*/
|
||||
require 'global.php';
|
||||
|
||||
class AccPaymentTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Fiche
|
||||
*/
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test method is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
include 'global.php';
|
||||
}
|
||||
|
||||
public function dataLoad()
|
||||
{
|
||||
$a_json=array();
|
||||
$a_json[0]=['{
|
||||
"mp_id" : 4,
|
||||
"mp_lib" : "Caisse",
|
||||
"mp_jrn_def_id" : 1,
|
||||
"mp_fd_id" : null,
|
||||
"mp_qcode" : null,
|
||||
"jrn_def_id" : 3
|
||||
}'];
|
||||
|
||||
$a_json[1]=['{
|
||||
"mp_id" : 3,
|
||||
"mp_lib" : "Par gérant ou administrateur",
|
||||
"mp_jrn_def_id" : 2,
|
||||
"mp_fd_id" : null,
|
||||
"mp_qcode" : null,
|
||||
"jrn_def_id" : 3
|
||||
}'];
|
||||
$a_json[2]=['{
|
||||
"mp_id" : 1,
|
||||
"mp_lib" : "Paiement électronique",
|
||||
"mp_jrn_def_id" : 1,
|
||||
"mp_fd_id" : 3,
|
||||
"mp_qcode" : "COMPTE",
|
||||
"jrn_def_id" : 2
|
||||
}'];
|
||||
$a_json[3]=[' {
|
||||
"mp_id" : 2,
|
||||
"mp_lib" : "Caisse",
|
||||
"mp_jrn_def_id" : 4,
|
||||
"mp_fd_id" : 2,
|
||||
"mp_qcode" : null,
|
||||
"jrn_def_id" : 2
|
||||
}'];
|
||||
$a_json[4]=['{
|
||||
"mp_id" : 11,
|
||||
"mp_lib" : "Caisse",
|
||||
"mp_jrn_def_id" : 1,
|
||||
"mp_fd_id" : 3,
|
||||
"mp_qcode" : "COMPTE",
|
||||
"jrn_def_id" : 35
|
||||
}'];
|
||||
return $a_json;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @testdox load record
|
||||
* @dataProvider dataLoad
|
||||
* @param json $json
|
||||
* @covers ::load ::get_parameter
|
||||
*/
|
||||
public function testLoad($json)
|
||||
{
|
||||
global $g_connection;
|
||||
$acc_pay=json_decode($json, true);
|
||||
$object=new Acc_Payment($g_connection, $acc_pay['mp_id']);
|
||||
$object->load();
|
||||
$this->assertEquals($acc_pay['mp_id'], $object->get_parameter('id'), "Error for column mp_id");
|
||||
$this->assertEquals($acc_pay['mp_lib'], $object->get_parameter('lib'), "Error for column mp_lib");
|
||||
$this->assertEquals($acc_pay['mp_qcode'], $object->get_parameter('qcode'), "Error for column mp_qcode");
|
||||
$this->assertEquals($acc_pay['mp_jrn_def_id'], $object->get_parameter('ledger_target'),
|
||||
"Error for column mp_jrn_def_id");
|
||||
$this->assertEquals($acc_pay['jrn_def_id'], $object->get_parameter('ledger_source'),
|
||||
"Error for column jrn_def_id");
|
||||
$this->assertEquals($acc_pay['mp_fd_id'], $object->get_parameter('fiche_def'), "Error for column mp_fd_id");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @testdox Test from array
|
||||
* @dataProvider dataLoad
|
||||
* @param json $json
|
||||
* @covers ::from_array ::get_parameter
|
||||
*/
|
||||
public function testFromArray($json)
|
||||
{
|
||||
global $g_connection;
|
||||
$acc_pay=json_decode($json, true);
|
||||
$object=new Acc_Payment($g_connection);
|
||||
$object->from_array($acc_pay);
|
||||
$this->assertEquals($acc_pay['mp_id'], $object->get_parameter('id'), "Error for column mp_id");
|
||||
$this->assertEquals($acc_pay['mp_lib'], $object->get_parameter('lib'), "Error for column mp_lib");
|
||||
$this->assertEquals($acc_pay['mp_qcode'], $object->get_parameter('qcode'), "Error for column mp_qcode");
|
||||
$this->assertEquals($acc_pay['mp_jrn_def_id'], $object->get_parameter('ledger_target'),
|
||||
"Error for column mp_jrn_def_id");
|
||||
$this->assertEquals($acc_pay['jrn_def_id'], $object->get_parameter('ledger_source'),
|
||||
"Error for column jrn_def_id");
|
||||
$this->assertEquals($acc_pay['mp_fd_id'], $object->get_parameter('fiche_def'), "Error for column mp_fd_id");
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @testdox function get_valide
|
||||
* @covers ::set_parameter ::get_valide
|
||||
*/
|
||||
public function testGet_Valide()
|
||||
{
|
||||
global $g_connection;
|
||||
$object=new Acc_Payment($g_connection);
|
||||
$object->set_parameter("ledger_source", 2);
|
||||
$valid_payment=$object->get_valide();
|
||||
$this->assertEquals(2, count($valid_payment), 'Error different payment method');
|
||||
$this->assertEquals($valid_payment[0]->get_parameter('qcode'), 'COMPTE',
|
||||
'Propose method no correct ['.$valid_payment[0]->get_parameter('qcode').']');
|
||||
$this->assertEquals($valid_payment[1]->get_parameter('lib'), 'Caisse',
|
||||
'label no correct ['.$valid_payment[0]->get_parameter('lib').']');
|
||||
}
|
||||
/**
|
||||
* @brief
|
||||
* @testdox function get_all
|
||||
* @covers ::set_parameter ::get_all
|
||||
*/
|
||||
public function testGet_All()
|
||||
{
|
||||
global $g_connection;
|
||||
$object=new Acc_Payment($g_connection);
|
||||
$valid_payment=$object->get_all();
|
||||
$this->assertEquals(5, count($valid_payment), 'Error different payment method');
|
||||
$this->assertEquals($valid_payment[0]->get_parameter('qcode'), null,
|
||||
'Propose method no correct ['.$valid_payment[0]->get_parameter('qcode').']');
|
||||
$this->assertEquals($valid_payment[1]->get_parameter('lib'), 'Caisse',
|
||||
'label no correct ['.$valid_payment[0]->get_parameter('lib').']');
|
||||
}
|
||||
|
||||
}
|
||||
126
unit-test/include/class/anc_group.Test.php
Normal file
126
unit-test/include/class/anc_group.Test.php
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* * Copyright (C) 2021 Dany De Bontridder <dany@alchimerys.be>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*
|
||||
* Author : Dany De Bontridder danydb@noalyss.eu
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Test Anc_Group
|
||||
*/
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @backupGlobals enabled
|
||||
* @coversDefaultClass \Anc_Group
|
||||
*/
|
||||
require 'global.php';
|
||||
|
||||
class Anc_GroupTest extends TestCase
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test method is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
include 'global.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test method is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* the setUpBeforeClass() template methods is called before the first test of the test case
|
||||
* class is run
|
||||
*/
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
include 'global.php';
|
||||
global $g_connection;
|
||||
$g_connection->exec_sql("delete from plan_analytique where pa_id>1");
|
||||
$g_connection->exec_sql("INSERT INTO plan_analytique (pa_id,pa_name,pa_description) VALUES
|
||||
(2,'AXE2','Axe 2'),
|
||||
(3,'AXE3','Axe 3')");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDownAfterClass() template methods is calleafter the last test of the test case class is run,
|
||||
*
|
||||
*/
|
||||
static function tearDownAfterClass()
|
||||
{
|
||||
include 'global.php';
|
||||
global $g_connection;
|
||||
$g_connection->exec_sql("delete from plan_analytique where pa_id>1");
|
||||
}
|
||||
|
||||
public function datasqlStmt()
|
||||
{
|
||||
return array([1,"Group 1",1],
|
||||
[2,"Group 2",1],
|
||||
[3,"Group 3",1],
|
||||
[4,"Group 4",null]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @testdox insert, load and remove
|
||||
* @dataProvider datasqlStmt
|
||||
* @param type $p_param
|
||||
* @covers
|
||||
*/
|
||||
public function test_sqlStmt($p_ga_id,$pga_description,$ppa_id)
|
||||
{
|
||||
global $g_connection;
|
||||
// check group empty
|
||||
$this->assertEquals(0,$g_connection->get_value("select count(*) from groupe_analytique"),
|
||||
"Table not empty");
|
||||
$obj=new Anc_Group($g_connection);
|
||||
$obj->ga_id=$p_ga_id;
|
||||
$obj->ga_description=$pga_description;
|
||||
$obj->pa_id=$ppa_id;
|
||||
$obj->insert();
|
||||
$this->assertEquals(1,$g_connection->get_value("select count(*) from groupe_analytique"),
|
||||
"record not inserted");
|
||||
// load it
|
||||
$reload=new Anc_Group($g_connection);
|
||||
$reload->ga_id=$obj->ga_id;
|
||||
$reload->load();
|
||||
$this->assertEquals($reload->ga_description,$obj->ga_description,"Cannot load from db");
|
||||
|
||||
// remove it
|
||||
$reload->remove();
|
||||
$this->assertEquals(0,$g_connection->get_value("select count(*) from groupe_analytique"),
|
||||
"Cannot remove");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
use PHPUnit\Framework\TestCase;
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator on 2016-02-11 at 15:39:21.
|
||||
* @coversDefaultClass \Dossier
|
||||
* @backupGlobals enable
|
||||
*/
|
||||
class DossierTest extends TestCase
|
||||
{
|
||||
|
|
@ -17,6 +19,7 @@ class DossierTest extends TestCase
|
|||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
require_once 'global.php';
|
||||
$this->object=new Dossier(DOSSIER);
|
||||
}
|
||||
|
||||
|
|
@ -35,6 +38,25 @@ class DossierTest extends TestCase
|
|||
public function testSynchro_admin()
|
||||
{
|
||||
Dossier::synchro_admin(DOSSIER);
|
||||
// nothing to test
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
/**
|
||||
* @testdox Test Dossier::id()
|
||||
* @covers ::id
|
||||
*/
|
||||
public function testID()
|
||||
{
|
||||
$this->assertEquals(DOSSIER,Dossier::id(),"Id() doesn't work");
|
||||
}
|
||||
/**
|
||||
* @testdox Load
|
||||
*/
|
||||
public function testLoad()
|
||||
{
|
||||
global $g_connection;
|
||||
$obj=new Dossier(DOSSIER);
|
||||
$obj->load();
|
||||
$this->assertEquals(DOSSIER,$obj->get_parameter("id"),"Not the right folder");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ EOF;
|
|||
$anc_acc_list->card_poste=3;
|
||||
$pdf_anc_acc=new PDF_Anc_Acc_List($anc_acc_list);
|
||||
$pdf_anc_acc->export_pdf()->Output(__DIR__."/file/pdf_anc_acc_list-activity-card.pdf","F");
|
||||
$this->assertEquals(77690,filesize(__DIR__."/file/pdf_anc_acc_list-activity-card.pdf"),
|
||||
$this->assertEquals(77689,filesize(__DIR__."/file/pdf_anc_acc_list-activity-card.pdf"),
|
||||
__DIR__."/file/pdf_anc_acc_list-activity-card.pdf incorrect");
|
||||
|
||||
// By Activity / Account
|
||||
|
|
@ -156,7 +156,7 @@ EOF;
|
|||
$anc_acc_list->card_poste=4;
|
||||
$pdf_anc_acc=new PDF_Anc_Acc_List($anc_acc_list);
|
||||
$pdf_anc_acc->export_pdf()->Output(__DIR__."/file/pdf_anc_acc_list-activity-account.pdf","F");
|
||||
$this->assertEquals(76411,filesize(__DIR__."/file/pdf_anc_acc_list-activity-account.pdf"),
|
||||
$this->assertEquals(76410,filesize(__DIR__."/file/pdf_anc_acc_list-activity-account.pdf"),
|
||||
__DIR__."/file/pdf_anc_acc_list-activity-account.pdf incorrect");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,11 @@ define('USE_ADMIN', 0);
|
|||
define('USE_EMAIL', 'none@dev.null.eu');
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator on 2016-02-10 at 22:48:23.
|
||||
* @backupGlobals enabled
|
||||
* @coversDefaultClass \User
|
||||
*/
|
||||
require 'global.php';
|
||||
|
||||
class UserTest extends TestCase
|
||||
{
|
||||
|
||||
|
|
@ -132,8 +135,8 @@ class UserTest extends TestCase
|
|||
*/
|
||||
public function testPeriode($p_id)
|
||||
{
|
||||
global $g_connection;
|
||||
$this->object->db=$g_connection;
|
||||
$this->object=new User(Dossier::connect(), USE_ID);
|
||||
|
||||
$restore=$this->object->get_periode();
|
||||
$this->assertTrue(is_numeric($restore),"Old periode id is not an integer");
|
||||
$this->object->set_periode($p_id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue