noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 09/09: Task #0002126: Fiche : amélioration


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 09/09: Task #0002126: Fiche : amélioration
Date: Mon, 17 Jan 2022 14:58:32 -0500 (EST)

sparkyx pushed a commit to branch devel
in repository noalyss.

commit 55f9dd9a738c42fbe4edb8492b8fc89d6504bd97
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sun Jan 16 12:51:42 2022 +0100

    Task #0002126: Fiche : amélioration
---
 include/category_card.inc.php                      |   2 +-
 include/class/contact.class.php                    |  36 +++--
 include/class/fiche.class.php                      |   2 +-
 unit-test/include/class/contactTest.php            | 176 +++++++++++++++++++++
 .../class/{fiche.Test.php => ficheTest.php}        |  32 ++++
 5 files changed, 230 insertions(+), 18 deletions(-)

diff --git a/include/category_card.inc.php b/include/category_card.inc.php
index c09bac17..d91537fc 100644
--- a/include/category_card.inc.php
+++ b/include/category_card.inc.php
@@ -28,7 +28,7 @@
  */
 if (!defined('ALLOWED'))
     die('Appel direct ne sont pas permis');
-
+if ( DEBUGNOALYSS > 1 ) { echo __FILE__;}
 global $http;
 
 $str_dossier=Dossier::get();
diff --git a/include/class/contact.class.php b/include/class/contact.class.php
index 787786a6..94da9dfa 100644
--- a/include/class/contact.class.php
+++ b/include/class/contact.class.php
@@ -37,13 +37,16 @@ class contact extends Fiche
         parent::__construct($p_cn,$p_id) ;
         $this->company="";
     }
-    /*!   Summary
-     **************************************************
-     * \brief  show the default screen
+    /*!   
+     * @brief display a summary of the contact card
+     
      *
-     * \param  p_search (filter)
+     * @param  p_search : filter on card name
+     * @param  p_action : nothing
+     * @param  p_sql : extra SQL command
+     * @param  p_nothing (filter)
      *
-     * \return string to display
+     * @returns string to display
      */
     function Summary($p_search="",$p_action="",$p_sql="",$p_nothing=false)
     {
@@ -52,7 +55,7 @@ class contact extends Fiche
         if ( $this->company != "")
         {
             $extra_sql="and f_id in (select f_id from fiche_detail
-                       where ad_value=upper('".$this->company."') and 
ad_id=".ATTR_DEF_COMPANY.") ";
+                       where 
ad_value='".sql_string(trim(strtoupper($this->company)))."' and 
ad_id=".ATTR_DEF_COMPANY.") ";
         }
         $url=urlencode($_SERVER['REQUEST_URI']);
         $script=$_SERVER['PHP_SELF'];
@@ -75,7 +78,7 @@ class contact extends Fiche
         // Get The result Array
         
$step_contact=$this->get_by_category($offset,$search.$extra_sql.$p_sql);
 
-               if ( $all_contact == 0 ) return "";
+       if ( $all_contact == 0 ) return "";
         $r=$bar;
         $r.='<table id="contact_tb" class="sortable">
             <TR>
@@ -112,24 +115,25 @@ class contact extends Fiche
         {
             $l_company=new Fiche($this->cn);
             
$l_company->get_by_qcode($contact->strAttribut(ATTR_DEF_COMPANY),false);
-            $l_company_name=$l_company->strAttribut(ATTR_DEF_NAME);
-            if ( $l_company_name == NOTFOUND ) $l_company_name="";
-            // add popup for detail
+            $l_company_name=$l_company->strAttribut(ATTR_DEF_NAME,0);
+            
+            // add popup for detail if the company does exist
             if ( $l_company_name !="")
             {
-                               
$l_company_name=HtmlInput::card_detail($contact->strAttribut(ATTR_DEF_COMPANY),$l_company_name,'style="text-decoration:underline;"');
+                $l_company_name=HtmlInput::card_detail($contact->strAttribut
+                        
(ATTR_DEF_COMPANY),$l_company_name,'style="text-decoration:underline;"');
             }
             $tr=($idx%2==0)?' <tr class="odd">':'<tr class="even">';
             $idx++;
             $r.=$tr;
             $qcode=$contact->strAttribut(ATTR_DEF_QUICKCODE);
             $r.='<TD>'.HtmlInput::card_detail($qcode)."</TD>";
-            $r.="<TD>".$contact->strAttribut(ATTR_DEF_NAME)."</TD>";
-            $r.="<TD>".$contact->strAttribut(ATTR_DEF_FIRST_NAME)."</TD>";
+            $r.="<TD>".$contact->strAttribut(ATTR_DEF_NAME,0)."</TD>";
+            $r.="<TD>".$contact->strAttribut(ATTR_DEF_FIRST_NAME,0)."</TD>";
             $r.="<TD>".$l_company_name."</TD>";
-            $r.="<TD>".$contact->strAttribut(ATTR_DEF_TEL)."</TD>";
-            $r.="<TD>".$contact->strAttribut(ATTR_DEF_EMAIL)."</TD>".
-                "<TD> ".$contact->strAttribut(ATTR_DEF_FAX)."</TD>";
+            $r.="<TD>".$contact->strAttribut(ATTR_DEF_TEL,0)."</TD>";
+            $r.="<TD>".$contact->strAttribut(ATTR_DEF_EMAIL,0)."</TD>".
+                "<TD> ".$contact->strAttribut(ATTR_DEF_FAX,0)."</TD>";
 
             $r.="</TR>";
 
diff --git a/include/class/fiche.class.php b/include/class/fiche.class.php
index 5a5558f4..29fb26d6 100644
--- a/include/class/fiche.class.php
+++ b/include/class/fiche.class.php
@@ -289,7 +289,7 @@ class Fiche
         foreach ($this->attribut as $e)
         {
             if ( $e->ad_id == $p_ad_id )
-                return $e->av_text;
+                return trim($e->av_text);
         }
         return $return;
     }
diff --git a/unit-test/include/class/contactTest.php 
b/unit-test/include/class/contactTest.php
new file mode 100644
index 00000000..34b64f3c
--- /dev/null
+++ b/unit-test/include/class/contactTest.php
@@ -0,0 +1,176 @@
+<?php
+
+/*
+ * * Copyright (C) 2022 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 the class Contact
+ */
+use PHPUnit\Framework\TestCase;
+
+/**
+ * @backupGlobals enabled
+ * @coversDefaultClass \Contact
+ */
+require 'global.php';
+
+class ContactTest 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():void
+    {
+        include 'global.php';
+        $this->object = new stdClass();
+        $this->object->fiche_def=0;
+        $this->object->card_to_clean=array();
+    }
+
+    /**
+     * Tears down the fixture, for example, closes a network connection.
+     * This method is called after a test method is executed.
+     */
+    protected function tearDown():void
+    {
+        include 'global.php';
+        $sql=new ArrayObject();
+        $sql->append("delete from fiche_detail where f_id in (select f_id from 
fiche where fd_id = $1 )");
+        $sql->append("delete from fiche where f_id not in (select f_id from 
fiche_detail where $1=$1)");
+        $sql->append("delete from jnt_fic_attr where fd_id  = $1 ");
+        $sql->append("delete from fiche_def where fd_id = $1");
+        foreach ($sql as $s) {
+            $g_connection->exec_sql($s,[$this->object->fiche_def->id]);
+        }
+
+    }
+
+    /**
+     * the setUpBeforeClass() template methods is called before the first test 
of the test case
+     *  class is run 
+     */
+    public static function setUpBeforeClass():void
+    {
+        //        include 'global.php';
+    }
+
+    /**
+     *  tearDownAfterClass() template methods is calleafter the last test of 
the test case class is run,
+     *
+     */
+    static function tearDownAfterClass():void
+    {
+        //        include 'global.php';
+    }
+//
+//    public function dataExample()
+//    {
+//        return array([1], [2], [3]);
+//    }
+
+    /**
+     * a. create contact category
+     */
+    public function createContact()
+    {
+        include_once 'global.php';
+
+        global $g_connection;
+        // create a category of card, type Charges
+        $fiche_def=new Fiche_Def($g_connection);
+        $aParam=["nom_mod"=>"Test.Contact", 
+            "fd_description"=>'PHPUNIT test', 'class_base'=>'', 
'FICHE_REF'=>16,
+            'create'=>'off'];
+        $this->assertEquals($fiche_def->id, 0, 'Before created');
+
+        $fiche_def->add($aParam);
+        $this->assertLessThan($fiche_def->id, 0, 'After created');
+
+        $this->assertEquals($g_connection->get_value("select count(*) 
+                from fiche_def where fd_id=$1", [$fiche_def->id]),
+                1, "Category not created");
+        $this->object->fiche_def=$fiche_def;
+        
+    }
+    /**
+     *
+     * @dataProvider dataContactCard
+     * @param array $p_param
+     */
+    public function createContactCard()
+    {
+        global $g_connection;
+        if ( $this->object->fiche_def == 0) {
+            $this->createContact();
+        }
+        $aName=array();
+        // Available fd_id for supplier or customer = 25 21 22 31 32
+        $aName[]=['name'=>'Chantal','company'=>'CLIENT'];
+        $aName[]=['name'=>'Pierre','company'=>'CLIENT'];
+        $aName[]=['name'=>'William','company'=>'FOURNI'];
+        $aName[]=['name'=>'Daniel','company'=>'FOURNI'];
+        $aName[]=['name'=>'Geert','company'=>'FOURNI'];
+        foreach ($aName as $param  ) {
+            $fiche=new Fiche($g_connection);
+            $fiche->fiche_def=$this->object->fiche_def->id;
+            $fiche->load();
+            $fiche->setAttribut(ATTR_DEF_NAME, $param['name']);
+            $fiche->setAttribut(ATTR_DEF_COMPANY, $param['company']);
+            $fiche->insert($fiche->fiche_def,$fiche->to_array());
+            $this->object->card_to_clean[]=$fiche->id;
+            printf("Card to clean %s ",$fiche->id);
+        }
+        $this->assertTrue(count($aName) == 
count($this->object->card_to_clean),"Not all contact created");
+    }
+
+    /**
+     * @brief 
+     * @testdox Contact Summary
+     */
+    public function testSummary()
+    {
+        global $g_connection;
+        if ( $this->object->fiche_def == 0) {
+            $this->createContactCard();
+          }
+        $contact=new Contact($g_connection);
+        $_SERVER['REQUEST_URI']="?";
+        $_SERVER['PHP_SELF']=__FILE__;
+        $r=$contact->summary();
+        $this->assertEquals(count($this->object->card_to_clean)*2 , 
substr_count($r,'fill_ipopcard')," 1. Missing card");
+        $contact->company=' fourni ';
+        $r=$contact->summary();
+        $this->assertEquals(6, substr_count($r,'fill_ipopcard') , 'not found 
all the contacts from FOURNI');
+        $r=$contact->summary('william');
+        $this->assertEquals(2, substr_count($r,'fill_ipopcard') , 'Search does 
not filter');
+        
+    }
+
+}
diff --git a/unit-test/include/class/fiche.Test.php 
b/unit-test/include/class/ficheTest.php
similarity index 94%
rename from unit-test/include/class/fiche.Test.php
rename to unit-test/include/class/ficheTest.php
index 2821e4e8..a27ca3d4 100644
--- a/unit-test/include/class/fiche.Test.php
+++ b/unit-test/include/class/ficheTest.php
@@ -244,6 +244,11 @@ class FicheTest extends TestCase
         $this->assertEquals($fiche_goods->id, 23, "retrieve card by qcode");
         $this->assertEquals($fiche_goods->strAttribut(ATTR_DEF_NAME), 
"Marchandise1", "Retrieve name");
         $this->assertEquals($fiche_goods->getName(), "Marchandise1", "Retrieve 
name from db");
+        $fiche_2 = new Fiche($g_connection);
+        $fiche_2->get_by_qcode("marcha ");
+        $this->assertEquals($fiche_2->id, 23, "retrieve card by qcode");
+        $this->assertEquals($fiche_2->strAttribut(ATTR_DEF_NAME), 
"Marchandise1", "Retrieve name");
+        $this->assertEquals($fiche_2->getName(), "Marchandise1", "Retrieve 
name from db");
     }
 
     /**
@@ -700,4 +705,31 @@ where
         $fiche->remove();
            
     }
+    /**
+     * @testdox test the formating of quick-code : upper-case and some 
charater removed
+     * @global type $g_connection
+     */
+    public function testQuickCodeFormat()
+    {
+        global $g_connection;
+        // create a new card
+        $fiche=new Fiche($g_connection);
+        $fiche->set_fiche_def(5);
+        Card_Property::load($fiche);
+        $fiche->setAttribut(1, "Inserted by PHPUNIT");
+        $fiche->setAttribut(23, " a a a a");
+        $fiche->insert("5", $fiche->to_array());
+        $this->assertGreaterThan (0,$fiche->id, "Card no created");
+        $fiche_target=new Fiche($g_connection,$fiche->id);
+        $this->assertTrue("AAAA"==$fiche_target->strAttribut(23),"Insert Quick 
code format not correct");
+        $fiche_target->setAttribut(ATTR_DEF_QUICKCODE, " a a a a a a ");
+        $fiche_target->update($fiche_target->to_array());
+        
+        // reload the card !!
+        $fiche_target->load();
+        
+        $this->assertTrue("AAAAAA"==$fiche_target->strAttribut(23),"Update 
Quick code format not correct");
+        
+        $fiche->delete();
+    }
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]