[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 02/05: Bug : cannot add card , improve test
From: |
Dany De Bontridder |
Subject: |
[Noalyss-commit] [noalyss] 02/05: Bug : cannot add card , improve test |
Date: |
Thu, 12 Aug 2021 17:11:21 -0400 (EDT) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 0e43f60267e90d44ba832a7a239fcb1253b1a7db
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Thu Aug 12 12:18:48 2021 +0200
Bug : cannot add card , improve test
---
include/class/card_property.class.php | 4 +--
include/class/fiche.class.php | 43 +++++++++++++++++++++-----
unit-test/include/class/card_property.Test.php | 9 ++++++
unit-test/include/class/fiche.Test.php | 28 ++++++++++++++++-
4 files changed, 74 insertions(+), 10 deletions(-)
diff --git a/include/class/card_property.class.php
b/include/class/card_property.class.php
index 8f481b7..ae37d74 100644
--- a/include/class/card_property.class.php
+++ b/include/class/card_property.class.php
@@ -140,7 +140,7 @@ class Card_Property
// if card is not yet saved then we don't load it from database but
all the properties are set to empty
if ($fiche->id==0 && $fiche->fiche_def !=0 )
{
- $fiche_def=new Fiche_Def($this->cn,$fiche->fiche_def);
+ $fiche_def=new Fiche_Def($fiche->cn,$fiche->fiche_def);
$aProperty=$fiche_def->getAttribut();
$fiche->attribut=$aProperty;
return;
@@ -301,7 +301,7 @@ class Card_Property
$w=new ISelect("av_text".$this->ad_id);
$w->value=$this->cn->make_array($this->ad_extra);
$w->style='style="width:100%"';
- $w->value=$this->av_text;
+ $w->selected=$this->av_text;
break;
case 'card':
$w=new ICard("av_text".$this->ad_id);
diff --git a/include/class/fiche.class.php b/include/class/fiche.class.php
index c947256..d5b177d 100644
--- a/include/class/fiche.class.php
+++ b/include/class/fiche.class.php
@@ -53,10 +53,17 @@ class Fiche
$this->f_enable='1';
if ($p_id != 0 ) { $this->load();} else {
$this->fiche_def=0;
+ $this->fiche_def_ref=0;
}
}
+ public function set_fiche_def($p_fiche_def)
+ {
+ $this->fiche_def=$p_fiche_def;
+ return $this;
+ }
+
public function get_id()
{
return $this->id;
@@ -418,7 +425,7 @@ class Fiche
av_text1=>'name'
\endverb
*/
- function insert($p_fiche_def,$p_array=null,$transaction=true)
+ function insert($p_fiche_def, $p_array=null, $transaction=true)
{
if ($p_array==null)
$p_array=$_POST;
@@ -430,19 +437,40 @@ class Fiche
{
// by default the card is available
- if ( !isset ($p_array['f_enable'])) {
+ if (!isset($p_array['f_enable']))
+ {
$p_array['f_enable']=1;
}
$Ret=$this->cn->exec_sql("insert into fiche(f_id,f_enable,fd_id)
values ($1,$2,$3)",
- array($fiche_id, $p_array['f_enable'],$p_fiche_def));
+ array($fiche_id, $p_array['f_enable'], $p_fiche_def));
// compute a quick_code
- if ( ! isset ($p_array["av_text".ATTR_DEF_QUICKCODE] )) {
+ if (!isset($p_array["av_text".ATTR_DEF_QUICKCODE]))
+ {
$p_array["av_text".ATTR_DEF_QUICKCODE]="";
}
$sql=sprintf("select insert_quick_code(%d,'%s')", $fiche_id,
-
sql_string($p_array['av_text'.ATTR_DEF_QUICKCODE]));
- $this->getAttribut();
+ sql_string($p_array['av_text'.ATTR_DEF_QUICKCODE]));
+
+ // get the card properties for this card category
+ $fiche_def=new Fiche_Def($this->cn, $p_fiche_def);
+
+ $this->attribut=$fiche_def->getAttribut();
+
+ if (empty($this->attribut))
+ {
+ throw new Exception("FICHE.UPDATE02"._("Aucun attribut
")."($p_fiche_def)", EXC_INVALID);
+ }
+ // for each property set the attribut on the card
+ foreach ($this->attribut as $property)
+ {
+ $key='av_text'.$property->ad_id;
+ if (isset($p_array[$key]))
+ {
+ $this->setAttribut($property->ad_id, $p_array[$key]);
+ }
+ }
Card_Property::update($this);
+ $this->quick_code=$this->strAttribut(ATTR_DEF_QUICKCODE);
}
catch (Exception $e)
{
@@ -493,6 +521,7 @@ class Fiche
}
// save all
Card_Property::update($this);
+ $this->quick_code=$this->strAttribut(ATTR_DEF_QUICKCODE);
}
/*!\brief remove a card
@@ -1514,7 +1543,7 @@ class Fiche
/*\brief remove a card without verification */
function delete()
{
- $this->cn->start();
+ $this->cn->start();
// Remove from attr_value
$Res=$this->cn->exec_sql("delete from fiche_detail
diff --git a/unit-test/include/class/card_property.Test.php
b/unit-test/include/class/card_property.Test.php
index 449fffd..0085cc2 100644
--- a/unit-test/include/class/card_property.Test.php
+++ b/unit-test/include/class/card_property.Test.php
@@ -177,9 +177,18 @@ class Card_PropertyTest extends TestCase
*/
public function testLoad()
{
+ global $g_connection;
$fiche=$this->getFiche();
Card_Property::load($fiche);
$this->assertEquals(count($fiche->attribut), 35, 'there are not 35
attributes');
+ $fiche=new Fiche($g_connection);
+ Card_Property::load($fiche);
+ $this->assertTrue(empty($fiche->attribut),'Card property must be
equals to 0 (unknown category ');
+ $fiche->set_fiche_def(5);
+ Card_Property::load($fiche);
+ $nb_attribut=$g_connection->get_value("select count(*) from
jnt_fic_attr where fd_id=$1",[5]);
+ $this->assertTrue(count($fiche->attribut)==$nb_attribut,
+ 'count of card properties must be the same than the card
category (fiche_def )');
}
}
diff --git a/unit-test/include/class/fiche.Test.php
b/unit-test/include/class/fiche.Test.php
index 74054d1..cabd2d0 100644
--- a/unit-test/include/class/fiche.Test.php
+++ b/unit-test/include/class/fiche.Test.php
@@ -265,6 +265,8 @@ class FicheTest extends TestCase
$new_fiche=new Fiche($g_connection);
$aProperty=array('av_text1'=>'Nom', 'av_text23'=>'ZZZTEST');
$new_fiche->insert(5, $aProperty);
+ $this->assertFalse(empty($new_fiche->attribut)," attributes array is
empty");
+
$this->assertGreaterThan($last_card, $new_fiche->id, 'card created');
$nb_fiche_after=$g_connection->get_value("select count(*) from fiche");
$this->assertGreaterThan($nb_fiche, $nb_fiche_after, 'card created');
@@ -273,5 +275,29 @@ class FicheTest extends TestCase
$nb_fiche_after=$g_connection->get_value("select count(*) from fiche");
$this->assertEquals($nb_fiche, $nb_fiche_after, 'card removed');
}
-
+ /**
+ * @testdox fiche->display
+ */
+ public function testDisplay()
+ {
+ global $g_connection;
+ $last_card=$g_connection->get_next_seq('s_fiche');
+ $nb_fiche=$g_connection->get_value("select count(*) from fiche");
+
+ $new_fiche=new Fiche($g_connection);
+ $aProperty=array('av_text1'=>'Nom', 'av_text23'=>'ZZZTEST2');
+ $new_fiche->insert(5, $aProperty);
+
+ $this->assertFalse(empty($new_fiche->attribut)," attributes array is
empty");
+ $this->assertGreaterThan($last_card, $new_fiche->id, 'card not
created');
+ $result = $new_fiche->display(true);
+
+ \Noalyss\Facility::save_file(__DIR__.'/file', 'testDisplay.txt',
$result);
+ $this->assertNotEquals('FNT',$result,'card not found
'.print_r($new_fiche,true));
+
+ $new_fiche->remove();
+
+ $nb_fiche_after=$g_connection->get_value("select count(*) from fiche");
+ $this->assertEquals($nb_fiche, $nb_fiche_after, 'card not removed');
+ }
}
- [Noalyss-commit] [noalyss] branch master updated (07fedf5 -> c7bf320), Dany De Bontridder, 2021/08/12
- [Noalyss-commit] [noalyss] 03/05: Cosmetic and Ergonomy, Dany De Bontridder, 2021/08/12
- [Noalyss-commit] [noalyss] 01/05: Documentation, Dany De Bontridder, 2021/08/12
- [Noalyss-commit] [noalyss] 05/05: Purchase & Sale : check the payment date and improve tests for not deductible fee or VAT, Dany De Bontridder, 2021/08/12
- [Noalyss-commit] [noalyss] 04/05: Fix bug when searching for an accounting in a card, Dany De Bontridder, 2021/08/12
- [Noalyss-commit] [noalyss] 02/05: Bug : cannot add card , improve test,
Dany De Bontridder <=