From 69bbda205c39f2a2cbe7fa14fc8ed919b5b315b8 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Wed, 11 Jan 2023 16:35:14 +0100 Subject: [PATCH] Bug : default accounting override existing one --- include/class/card_property.class.php | 6 +-- unit-test/include/class/card_propertyTest.php | 47 +++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/include/class/card_property.class.php b/include/class/card_property.class.php index b01dc73f6..6ee51211c 100644 --- a/include/class/card_property.class.php +++ b/include/class/card_property.class.php @@ -49,11 +49,11 @@ class Card_Property var $cn; //!< cn database connexion protected $display_mode; - //!< display mode determine if there link + //!< display mode values are large , window , display Property depending of this mode. function __construct($cn, $ad_id=0) { $this->cn=$cn; - $this->ad_id=0; + $this->ad_id=$ad_id; $this->display_mode='window'; } public function __toString(): string @@ -188,7 +188,7 @@ class Card_Property $result['msg'] .= " " . _("Rappel: Poste par défaut sera ") . $p_fiche_def->class_base . " ! "; - $result['input']->value = $p_fiche_def->class_base; + $result['input']->value = (empty ($result['input']->value)) ?$p_fiche_def->class_base:$result['input']->value; } } $result['label']=_("Poste comptable"); diff --git a/unit-test/include/class/card_propertyTest.php b/unit-test/include/class/card_propertyTest.php index 48f82bd20..4e8e89898 100644 --- a/unit-test/include/class/card_propertyTest.php +++ b/unit-test/include/class/card_propertyTest.php @@ -217,4 +217,51 @@ class Card_PropertyTest extends TestCase 'count of card properties must be the same than the card category (fiche_def )'); } + /** + * @testdox Build Input for automatic account , for a new card , the account is null + * @return void + */ + public function testBuildInput1() + { + $g_connection=Dossier::connect(); + + + $property=new \Card_Property($g_connection,ATTR_DEF_ACCOUNT); + $g_connection->exec_sql("update fiche_def set fd_create_account=true where fd_id=25"); + $fiche_def=new \Fiche_Def($g_connection,25); + + $result=$property->build_input($fiche_def); + + /* + $file_result=__CLASS__."-".__FUNCTION__.".txt"; + $file_target='target-'.$file_result; + \Noalyss\Facility::save_file(__DIR__."/file",$file_result,var_export($result,true)); + $this->assertFileEquals(__DIR__."/file/$file_target",__DIR__."/file/$file_result","Card_Property::build_input failed"); + */ + $this->assertEquals("",$result["input"]->value," Accounting incorrect "); + + } + /** + * @testdox Build Input for default account , for a new card , the account is the account of the category + * @return void + */ + + public function testBuildInput2() + { + $g_connection=Dossier::connect(); + $g_connection->exec_sql("update fiche_def set fd_create_account=false where fd_id=25"); + + $property=new \Card_Property($g_connection,ATTR_DEF_ACCOUNT); + $fiche_def=new \Fiche_Def($g_connection,25); + $result=$property->build_input($fiche_def); + $g_connection->exec_sql("update fiche_def set fd_create_account=true where fd_id=25"); + /* + $file_result=__CLASS__."-".__FUNCTION__.".txt"; + $file_target='target-'.$file_result; + \Noalyss\Facility::save_file(__DIR__."/file",$file_result,var_export($result,true)); + $this->assertFileEquals(__DIR__."/file/$file_target",__DIR__."/file/$file_result","Card_Property::build_input failed"); + */ + $this->assertEquals("600",$result["input"]->value," Accounting incorrect "); + } + }