noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 25/28: Acc_Ledger_Search , fix small bug + Te


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 25/28: Acc_Ledger_Search , fix small bug + Test file
Date: Sat, 30 Nov 2019 07:51:26 -0500 (EST)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 5715a582f86c2d97a166b24e575f8f8876707907
Author: Dany De Bontridder <address@hidden>
Date:   Wed Nov 27 22:19:57 2019 +0100

    Acc_Ledger_Search , fix small bug + Test file
---
 include/class/acc_ledger_search.class.php          |  30 +++--
 include/export/export_histo_csv.php                |   5 +-
 include/template/ledger_search.php                 |   2 +-
 unit-test/include/class/acc_ledger_search.Test.php | 133 +++++++++++++++++++++
 4 files changed, 156 insertions(+), 14 deletions(-)

diff --git a/include/class/acc_ledger_search.class.php 
b/include/class/acc_ledger_search.class.php
index 9ffc292..12ba84e 100644
--- a/include/class/acc_ledger_search.class.php
+++ b/include/class/acc_ledger_search.class.php
@@ -19,8 +19,7 @@
  */
 // Copyright (2016) Author Dany De Bontridder <address@hidden>
 
-if (!defined('ALLOWED'))
-    die('Appel direct ne sont pas permis');
+// if (!defined('ALLOWED'))     die('Appel direct ne sont pas permis');
 
 /**
  * @file
@@ -36,8 +35,8 @@ class Acc_Ledger_Search
 
     /**
      * @brief return a HTML string with the form for the search
-     * @param  $p_type if the type of ledger possible 
values=ALL,VEN,ACH,ODS,FIN
-     * @param  $all_type_ledger
+     * @param  $p_type if the type of ledger possible 
values=ALL,VEN,ACH,ODS,FIN: uppercase !
+     * @param  $all_type_ledger 
      *       values :
      *         - 1 means all the ledger of this type
      *         - 0 No have the "Tous les journaux" availables
@@ -50,7 +49,7 @@ class Acc_Ledger_Search
     function __construct($p_type, $p_all=1, $p_div="")
     {
         $this->cn=Dossier::connect();
-        $this->type=$p_type;
+        $this->set_type($p_type);
         $this->all=$p_all;
         $this->div=$p_div;
     }
@@ -72,6 +71,10 @@ class Acc_Ledger_Search
 
     public function set_type($type)
     {
+        if (! in_array($type, ["ALL","VEN","ACH","ODS","FIN"]))
+        {
+            throw new Exception ("ALS02 : type invalide 
$type",EXC_PARAM_VALUE);
+        }
         $this->type=$type;
     }
 
@@ -265,7 +268,7 @@ class Acc_Ledger_Search
      * @brief this function will create a sql stmt to use to create the list 
for
      * the ledger,
      * @param  $p_array is usually the $_GET,
-     * @param  $p_order the order of the row
+     * @param  $p_order the order of the row --> not used
      * @param  $p_where is the sql condition if not null then the $p_array 
will not be used
      * \note the p_action will be used to filter the ledger but gl means ALL
      * struct array $p_array
@@ -407,7 +410,7 @@ class Acc_Ledger_Search
 
         $and='';
         $g_user=new User($this->cn);
-        $p_action=$ledger_type;
+        $p_action=(isset ($ledger_type)) ? $ledger_type:$this->type;
         if ($p_action=='')
             $p_action='ALL';
         if ($r_jrn==-1)
@@ -571,6 +574,8 @@ class Acc_Ledger_Search
         
$where=$fil_ledger.$fil_amount.$fil_date.$fil_desc.$fil_sec.$fil_amount.
             
$fil_qcode.$fil_paid.$fil_account.$fil_date_paid.$fil_hide_operation;
         $sql.=" where ".$where;
+        
+        // Q?? Why do we return where if it is included in SQL ?
         return array($sql, $where);
     }
 
@@ -583,6 +588,7 @@ class Acc_Ledger_Search
      */
     function display_search_form()
     {
+        $http=new HttpInput();
         $r='';
         $r.='<div id="search_form" style="display:none">';
         $r.=HtmlInput::title_box(_('Recherche'), "search_form", "hide", "", 
"n");
@@ -597,18 +603,18 @@ class Acc_Ledger_Search
         
         
 
-        $r.=HtmlInput::hidden('ac', $_REQUEST['ac']);
+        $r.=HtmlInput::hidden('ac', $http->request('ac'));
 
 
         /*  when called from commercial.php some hidden values are needed */
         if (isset($_REQUEST['sa']))
-            $r.=HtmlInput::hidden("sa", $_REQUEST['sa']);
+            $r.=HtmlInput::hidden("sa", $http->request('sa'));
         if (isset($_REQUEST['sb']))
-            $r.=HtmlInput::hidden("sb", $_REQUEST['sb']);
+            $r.=HtmlInput::hidden("sb", $http->request('sb'));
         if (isset($_REQUEST['sc']))
-            $r.=HtmlInput::hidden("sc", $_REQUEST['sc']);
+            $r.=HtmlInput::hidden("sc", $http->request('sc'));
         if (isset($_REQUEST['f_id']))
-            $r.=HtmlInput::hidden("f_id", $_REQUEST['f_id']);
+            $r.=HtmlInput::hidden("f_id", $http->request('f_id'));
 
 
 
diff --git a/include/export/export_histo_csv.php 
b/include/export/export_histo_csv.php
index 847ceae..251fe0f 100644
--- a/include/export/export_histo_csv.php
+++ b/include/export/export_histo_csv.php
@@ -26,7 +26,10 @@ if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas 
permis');
 require_once NOALYSS_INCLUDE.'/lib/noalyss_csv.class.php';
 require_once NOALYSS_INCLUDE.'/class/acc_ledger_search.class.php';
 
-$ledger=new Acc_Ledger_Search($cn,0);
+$http=new HttpInput();
+
+$ledger=new Acc_Ledger_Search($http->get("ledger_type"),0);
+
 list($sql,$where)=$ledger->build_search_sql($_GET);
 
 $order=" order by jr_date_order asc,substring(jr_pj_number,'[0-9]+$')::numeric 
asc ";
diff --git a/include/template/ledger_search.php 
b/include/template/ledger_search.php
index c22dd20..a6a1e00 100644
--- a/include/template/ledger_search.php
+++ b/include/template/ledger_search.php
@@ -80,7 +80,7 @@ echo $f_accounting->input();  ?>
 
 <tr>
 <td style="text-align:right;width:30em">
-       <?php echo _('Statut')?>
+       <?php echo _('Etat')?>
 </td>
 
 <td>
diff --git a/unit-test/include/class/acc_ledger_search.Test.php 
b/unit-test/include/class/acc_ledger_search.Test.php
new file mode 100644
index 0000000..a0e672e
--- /dev/null
+++ b/unit-test/include/class/acc_ledger_search.Test.php
@@ -0,0 +1,133 @@
+<?php
+
+use PHPUnit\Framework\TestCase;
+
+/*
+ *   This file is part of NOALYSS.
+ *
+ *   PhpCompta 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.
+ *
+ *   PhpCompta 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 PhpCompta; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+// Copyright (2002-2019) Author Dany De Bontridder <address@hidden>
+if ( ! defined("ALLOWED"))  {
+    define('ALLOWED',1);
+}
+/**
+ * @file
+ * @brief concern acc_ledger_search
+ * @coversDefaultClass  acc_ledger_search
+ */
+class Acc_Ledger_Test extends TestCase
+{
+
+    /**
+     * @var 
+     */
+    protected $object;
+
+    /**
+     * Sets up the fixture, for example, opens a network connection.
+     * This method is called before a test is executed.
+     */
+    protected function setUp()
+    {
+        include 'global.php';
+        global $g_user;
+        $g_user->set_periode(119);
+    }
+
+    /**
+     * Tears down the fixture, for example, closes a network connection.
+     * This method is called after a test is executed.
+     */
+    protected function tearDown()
+    {
+        
+    }
+
+    /**
+     * @covers ::build_search_sql
+     */
+    function test_all_ledger()
+    {
+        global $g_connection;
+        // all legder
+        $ledger=new Acc_Ledger_Search('ALL');
+        $result=$ledger->build_search_sql(NULL);
+        $a_result=$g_connection->get_array($result[0]);
+        $this->assertEquals(4,count($a_result));
+        $this->assertEquals(" jrn_def_id in (3,83,1,35,4,2,36,-1) and  jr_date 
>= to_date('02.01.2019','DD.MM.YYYY')".
+                " and  jr_date <= 
to_date('31.01.2019','DD.MM.YYYY')",$result[1]);
+        
+        // Expect exception
+        try {
+            $ledger=new Acc_Ledger_Search('ALL1');
+            $this->assertTrue(FALSE,"Exception not thrown with invalide type");
+        } catch (Exception $e) {
+            $this->assertEquals($e->getCode(),1005,"Exception is type 
invalide");
+        }
+        
+    }
+    /**
+     * @covers ::display_search_form
+     */
+    function test_display_search_form()
+    {
+         put_global(array(["key"=>"ac","value"=>"phpunit"]));
+        $ledger=new Acc_Ledger_Search('ALL');
+        $r=$ledger->display_search_form();
+        $this->assertEquals(9068,strlen($r),"Size of the html string for 
display_search_form");
+    }
+    /**
+     * @covers ::build_search_filter
+     */
+    function test_build_search_filter()
+    {
+         $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})"
+                 ,Dossier::id());
+         $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})"
+                 ,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})"
+                 ,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})"
+                 ,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})"
+                 ,Dossier::id());
+         
+         $this->assertEquals($ret,$result,"Build filter for ODS");
+         
+    }
+}



reply via email to

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