diff --git a/include/class/acc_bilan.class.php b/include/class/acc_bilan.class.php index dcae0b861..85c8dda69 100644 --- a/include/class/acc_bilan.class.php +++ b/include/class/acc_bilan.class.php @@ -273,8 +273,10 @@ class Acc_Bilan if ( Database::num_row($res)==0) throw new Exception (_('Aucun enregistrement trouve')); $array=Database::fetch_array($res,0); - foreach ($array as $name=>$value) - $this->$name=$value; + $this->b_name=$array['b_name']; + $this->b_file_template=$array['b_file_template']; + $this->b_file_form=$array['b_file_form']; + $this->b_type=$array['b_type']; } catch(Exception $Ex) diff --git a/include/class/acc_ledger_info.class.php b/include/class/acc_ledger_info.class.php index b67b97163..376c99334 100644 --- a/include/class/acc_ledger_info.class.php +++ b/include/class/acc_ledger_info.class.php @@ -90,26 +90,30 @@ class Acc_Ledger_Info throw $e; } } + /** + * @brief load the todo_list row thanks it's ID + * @return boolean true if found else false + */ function load() { - $sql="select jr_id,id_type,ji_value from jrn_info where ji_id=".$this->ji_id; - $r=$this->cn->exec_sql($sql); + $sql="select jr_id,id_type,ji_value from jrn_info where ji_id=$1"; + $r=$this->cn->exec_sql($sql,[$this->ji_id]); if (Database::num_row ($r) > 0 ) { $this->from_array(Database::fetch_array($r,0)); - return 0; + return true; } else { - return 1; + return false; } } function from_array($p_array) { - foreach ($p_array as $col=>$value) + foreach (array("jr_id","id_type","ji_value") as $col) { - $this->$col=$value; + $this->$col=$p_array[$col]; } } function set_id($p_ji_id) diff --git a/include/class/acc_payment.class.php b/include/class/acc_payment.class.php index a35f2b8b0..4358b36a9 100644 --- a/include/class/acc_payment.class.php +++ b/include/class/acc_payment.class.php @@ -93,13 +93,15 @@ class Acc_Payment array($this->mp_id) ); - if ( Database::num_row($res) == 0 ) return; + if ( Database::num_row($res) == 0 ) return false; + $row=Database::fetch_array($res,0); - foreach ($row as $idx=>$value) + $a_index=array_values(self::$variable); + foreach ($a_index as $idx) { - $this->$idx=$value; + $this->$idx=$row[$idx]; } - + return true; } /*!\brief retrieve all the data for all ledgers @@ -289,9 +291,11 @@ class Acc_Payment */ public function from_array($p_array) { - $idx=array('mp_id','mp_lib','mp_fd_id','mp_jrn_def_id','mp_qcode','jrn_def_id'); - foreach ($idx as $l) - if (isset($p_array[$l])) $this->$l=$p_array[$l]; + $a_index=array_values(self::$variable); + // $idx=array('mp_id','mp_lib','mp_fd_id','mp_jrn_def_id','mp_qcode','jrn_def_id'); + foreach ($a_index as $l) { + if (isset($p_array[$l])) $this->$l=$p_array[$l]; + } } /** *@brief return an html with a form to add a new middle of payment @@ -333,13 +337,6 @@ class Acc_Payment ob_end_clean(); return $r; } - /*!\brief test function - */ - static function test_me() - { - - } - } diff --git a/include/class/anc_group.class.php b/include/class/anc_group.class.php index 599156867..50ffb94ac 100644 --- a/include/class/anc_group.class.php +++ b/include/class/anc_group.class.php @@ -52,19 +52,19 @@ class Anc_Group extends Anc_Print { if (strlen ($this->ga_id) > 10 ) return ''. _('Taille de la code trop long maximum 10 caractères').''; - $sql=" insert into groupe_analytique (ga_id,ga_description,pa_id) values ('%s','%s',%d)"; - $sql=sprintf($sql,Database::escape_string($this->ga_id), - Database::escape_string($this->ga_description), - $this->pa_id); + $sql=" insert into groupe_analytique (ga_id,ga_description,pa_id) values ($1,$2,$3)"; try { - $this->db->exec_sql($sql); + $this->db->exec_sql($sql,[$this->ga_id, + $this->ga_description, + $this->pa_id]); + return true; } catch (Exception $a) { return 'Doublon !!'; + return false; } - return ""; } /*! * \brief remove from the database @@ -74,26 +74,29 @@ class Anc_Group extends Anc_Print { $this->ga_id=str_replace(' ','',$this->ga_id); $this->ga_id=strtoupper($this->ga_id); - $sql=" delete from groupe_analytique where ga_id='".Database::escape_string($this->ga_id)."'"; + $sql=" delete from groupe_analytique where ga_id=$1"; - $this->db->exec_sql($sql); + $this->db->exec_sql($sql,array($this->ga_id)); } - /*! - * \brief load from the database and make an object + /** + * @brief load the todo_list row thanks it's ID + * @return boolean true if found else false */ function load() { $sql="select ga_id, ga_description,pa_id from groupe_analytique where". - " ga_id = ".$this->ga_id; - $res=$this->db->exec_sql($sql); - $array=Database::fetch_all($res); + " ga_id = $1"; + $res=$this->db->exec_sql($sql,[$this->ga_id]); + $array=Database::fetch_array($res); if ( ! empty($array) ) { $this->ga_id=$array['ga_id']; $this->ga_description=$array['ga_description']; $this->pa_id=$array['pa_id']; + return true; } + return false; } /*! diff --git a/include/class/dossier.class.php b/include/class/dossier.class.php index 1eaa0a13f..d666a0a0b 100644 --- a/include/class/dossier.class.php +++ b/include/class/dossier.class.php @@ -55,7 +55,9 @@ class Dossier static function id() { self::check(); - return $_REQUEST['gDossier']; + $http=new HttpInput(); + + return $http->request('gDossier','number'); } /** @@ -259,7 +261,7 @@ class Dossier public function load() { - $sql="select dos_name,dos_description,dos_email from ac_dossier where dos_id=$1"; + $sql="select * from ac_dossier where dos_id=$1"; $res=$this->cn->exec_sql( $sql, array($this->dos_id) @@ -268,9 +270,9 @@ class Dossier if (Database::num_row($res)==0) return; $row=Database::fetch_array($res, 0); - foreach ($row as $idx=> $value) + foreach ( self::$variable as $idx) { - $this->$idx=$value; + $this->$idx=$row[$idx]; } } diff --git a/include/class/follow_up_detail.class.php b/include/class/follow_up_detail.class.php index 9b5b0ee7a..dccfc0763 100644 --- a/include/class/follow_up_detail.class.php +++ b/include/class/follow_up_detail.class.php @@ -22,7 +22,8 @@ * \brief Follow_Up details are the details for a actions */ -/*!\brief Follow_Up Details are the details for an actions, it means +/*! + * \brief Follow_Up Details are the details for an actions, it means * the details of an order, delivery order, submit a quote... * this class is linked to the table action_detail * - "id"=>"ad_id", primary key @@ -164,24 +165,27 @@ class Follow_Up_Detail } return $aRet; } - + /** + * @brief load the todo_list row thanks it's ID + * @return boolean true if found else false + */ public function load() { $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount, ad_total_amount, ag_id FROM action_detail". " where ad_id=$1"; - $res=$this->db->get_array($this->db, + $res=$this->db->get_array( $sql, array($this->ad_id) ); - if ( $this->db->count() == 0 ) return; + if ( $this->db->count() == 0 ) return false; $row=$res[0]; - foreach ($row as $idx=>$value) + foreach (self::$variable as $idx) { - $this->$idx=$value; + $this->$idx=$row[$idx]; } - + return true; } public function delete() { diff --git a/include/class/forecast.class.php b/include/class/forecast.class.php index 166dac161..49fd909cd 100644 --- a/include/class/forecast.class.php +++ b/include/class/forecast.class.php @@ -27,7 +27,9 @@ */ class Forecast { - private static $variable=array ("id"=>"f_id","name"=>"f_name","start_date"=>"f_start_date","end_date"=>"f_end_date"); + private static $variable=array ("id"=>"f_id", + "name"=>"f_name","start_date"=>"f_start_date","end_date"=>"f_end_date" + ); private $cn; /** * @brief constructor @@ -118,20 +120,25 @@ class Forecast $ret=$p_cn->get_array($sql); return $ret; } + /** + * @brief load from db + * @return boolean true if found else false + */ public function load() { - $sql="select f_name,f_start_date ,f_end_date from forecast where f_id=$1"; + $sql="select f_id, f_name,f_start_date ,f_end_date from forecast where f_id=$1"; $res=$this->cn->exec_sql( $sql, array($this->f_id) ); - if ( Database::num_row($res) == 0 ) return -1; + if ( Database::num_row($res) == 0 ) return false; $row=Database::fetch_array($res,0); - foreach ($row as $idx=>$value) + $a_index=array_values(self::$variable); + foreach ( $a_index as $idx) { - $this->$idx=$value; + $this->$idx=$row[$idx]; } - + return true; } public function delete() { @@ -158,11 +165,7 @@ class Forecast " from forecast_item where fc_id=$2",array($array[$i]['fc_id'],$old[$i]['fc_id'])); } } - /** - * @brief unit test - */ - static function test_me() - {} + } ?> diff --git a/include/class/todo_list.class.php b/include/class/todo_list.class.php index d42747ea7..d0bec9da2 100644 --- a/include/class/todo_list.class.php +++ b/include/class/todo_list.class.php @@ -206,6 +206,10 @@ class Todo_List return $array; } + /** + * @brief load the todo_list row thanks it's ID + * @return boolean true if found else false + */ public function load() { @@ -217,13 +221,14 @@ class Todo_List array($this->tl_id) ); - if ( Database::num_row($res) == 0 ) return; + if ( Database::num_row($res) == 0 ) return false; $row=Database::fetch_array($res,0); - foreach ($row as $idx=>$value) + $aIndex=array_values(self::$variable); + foreach ($aIndex as $idx) { - $this->$idx=$value; + $this->$idx=$row[$idx]; } - + return true; } public function delete() { diff --git a/unit-test/include/class/acc_bilan.Test.php b/unit-test/include/class/acc_bilan.Test.php index 90637dd01..217b1780c 100644 --- a/unit-test/include/class/acc_bilan.Test.php +++ b/unit-test/include/class/acc_bilan.Test.php @@ -80,7 +80,6 @@ class Acc_BilanTest extends TestCase /** * @covers Acc_Bilan::load - * @todo Implement testLoad(). */ public function testLoad() { diff --git a/unit-test/include/class/acc_ledger_info.Test.php b/unit-test/include/class/acc_ledger_info.Test.php index a9185981e..ad06660b2 100644 --- a/unit-test/include/class/acc_ledger_info.Test.php +++ b/unit-test/include/class/acc_ledger_info.Test.php @@ -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]); + + } } diff --git a/unit-test/include/class/acc_ledger_search.Test.php b/unit-test/include/class/acc_ledger_search.Test.php index f3f0b0374..cb4e28e43 100644 --- a/unit-test/include/class/acc_ledger_search.Test.php +++ b/unit-test/include/class/acc_ledger_search.Test.php @@ -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"); diff --git a/unit-test/include/class/acc_payment.Test.php b/unit-test/include/class/acc_payment.Test.php new file mode 100644 index 000000000..dfbc81a79 --- /dev/null +++ b/unit-test/include/class/acc_payment.Test.php @@ -0,0 +1,180 @@ + + * + * 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').']'); + } + +} diff --git a/unit-test/include/class/anc_group.Test.php b/unit-test/include/class/anc_group.Test.php new file mode 100644 index 000000000..4d50ba576 --- /dev/null +++ b/unit-test/include/class/anc_group.Test.php @@ -0,0 +1,126 @@ + + * + * 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"); + } + +} diff --git a/unit-test/include/class/dossier.Test.php b/unit-test/include/class/dossier.Test.php index afba77c93..f0d627317 100644 --- a/unit-test/include/class/dossier.Test.php +++ b/unit-test/include/class/dossier.Test.php @@ -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"); } - } diff --git a/unit-test/include/class/pdf_anc_acc_list.Test.php b/unit-test/include/class/pdf_anc_acc_list.Test.php index fbbfd3bf2..1bd806753 100644 --- a/unit-test/include/class/pdf_anc_acc_list.Test.php +++ b/unit-test/include/class/pdf_anc_acc_list.Test.php @@ -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"); } diff --git a/unit-test/include/class/user.Test.php b/unit-test/include/class/user.Test.php index 68836b6b7..0e98279c3 100644 --- a/unit-test/include/class/user.Test.php +++ b/unit-test/include/class/user.Test.php @@ -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);