noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 14/27: Facility : new function to help with p


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 14/27: Facility : new function to help with phpunit
Date: Sat, 2 Nov 2019 18:12:18 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 698b24e8afe46ffc9b993973cd6c62f99c99fae6
Author: Dany De Bontridder <address@hidden>
Date:   Sat Nov 2 17:34:12 2019 +0100

    Facility : new function to help with phpunit
---
 unit-test/{global.php => facility.class.php}       |  58 ++++++-----
 unit-test/global.php                               |  24 +----
 .../acc_ledger_history_financialTest.class.php     |   4 +-
 .../class/acc_ledger_history_genericTest.class.php |   8 +-
 .../acc_ledger_history_purchaseTest.class.php      |   8 +-
 .../class/acc_ledger_history_saleTest.class.php    |   8 +-
 .../class/acc_ledger_purchaseTest.class.php        | 107 +++++++++++++++++----
 7 files changed, 138 insertions(+), 79 deletions(-)

diff --git a/unit-test/global.php b/unit-test/facility.class.php
similarity index 61%
copy from unit-test/global.php
copy to unit-test/facility.class.php
index a01c85a..25afcd0 100644
--- a/unit-test/global.php
+++ b/unit-test/facility.class.php
@@ -1,45 +1,40 @@
 <?php
 
+namespace Noalyss;
+
 /*
  *   This file is part of NOALYSS.
  *
- *   NOALYSS is free software; you can redistribute it and/or modify
+ *   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.
  *
- *   NOALYSS is distributed in the hope that it will be useful,
+ *   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 NOALYSS; if not, write to the Free Software
+ *   along with PhpCompta; if not, write to the Free Software
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-// Copyright Author Dany De Bontridder address@hidden
-
-/*
- * Global variables
  */
-global $g_connection,$g_parameter,$g_user;
-if (!defined("DOSSIER"))define ("DOSSIER",25);
-
-$_REQUEST['gDossier'] = DOSSIER;
-$g_connection=new Database(DOSSIER);
-$g_parameter = new Noalyss_Parameter_Folder($g_connection);
-$_SESSION['g_user']='admin';
-$_SESSION['g_pass']='phpcompta';
-$_SESSION['g_pagesize']='50';
-$g_user=new User($g_connection);
+// Copyright (2002-2019) Author Dany De Bontridder <address@hidden>
 
-if ( !function_exists("phpunit_page_start"))
-{
-function phpunit_page_start()
+/**
+ * @file
+ * @brief Set of function to use with phpunit , to save files and to visualize 
them later, to use tracefile...
+ */
+class Facility
 {
-    $noalyss_home=NOALYSS_HOME;
-    echo <<<EOF
+
+    /**
+     * include code for HTML to generate the display
+     */
+    static function page_start()
+    {
+        $noalyss_home=NOALYSS_HOME;
+        echo <<<EOF
     <!doctype html>
 <HTML><HEAD><meta charset="utf-8"><META http-equiv="Content-Type" 
content="text/html; charset=UTF-8">
     <TITLE>PRINTJRN  NOALYSS</TITLE>
@@ -55,5 +50,18 @@ function phpunit_page_start()
     <body>
     <div class="content">
 EOF;
+    }
+    /**
+     * Create a file with the content
+     * @param type $p_dir
+     * @param type $p_file
+     * @param type $p_content
+     */
+    static function save_file($p_dir,$p_file,$p_content)
+    {
+        $hFile=fopen($p_dir."/".$p_name,"w+");
+        fwrite($hFile, $content);
+        fclose($hFile);
+    }
+
 }
-}
\ No newline at end of file
diff --git a/unit-test/global.php b/unit-test/global.php
index a01c85a..e2271a2 100644
--- a/unit-test/global.php
+++ b/unit-test/global.php
@@ -34,26 +34,4 @@ $_SESSION['g_pass']='phpcompta';
 $_SESSION['g_pagesize']='50';
 $g_user=new User($g_connection);
 
-if ( !function_exists("phpunit_page_start"))
-{
-function phpunit_page_start()
-{
-    $noalyss_home=NOALYSS_HOME;
-    echo <<<EOF
-    <!doctype html>
-<HTML><HEAD><meta charset="utf-8"><META http-equiv="Content-Type" 
content="text/html; charset=UTF-8">
-    <TITLE>PRINTJRN  NOALYSS</TITLE>
-       <link rel="icon" type="image/ico" href="favicon.ico" />
-    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-    <LINK id="pagestyle" REL="stylesheet" type="text/css" 
href="{$noalyss_home}/style-classic7.css?version=7105" media="screen"/>
-    <link rel="stylesheet" type="text/css" 
href="./style-print.css?version=7105" media="print"/>
-    <script language="javascript" src="js/calendar.js"></script>
-    <script type="text/javascript" src="js/lang/calendar-en.js"></script>
-    <script language="javascript" src="js/calendar-setup.js"></script>
-    <LINK REL="stylesheet" type="text/css" href="calendar-blue.css" 
media="screen">
-    </HEAD>
-    <body>
-    <div class="content">
-EOF;
-}
-}
\ No newline at end of file
+require_once __DIR__.'/facility.class.php';
\ No newline at end of file
diff --git a/unit-test/include/class/acc_ledger_history_financialTest.class.php 
b/unit-test/include/class/acc_ledger_history_financialTest.class.php
index 1d7d754..67e6ac5 100644
--- a/unit-test/include/class/acc_ledger_history_financialTest.class.php
+++ b/unit-test/include/class/acc_ledger_history_financialTest.class.php
@@ -74,7 +74,7 @@ class Acc_Ledger_History_FinancialTest extends TestCase
         $name="acc_ledger_history_export_listing.html";
         $this->object->set_m_mode("L");
         ob_start();
-        phpunit_page_start();
+        \Noalyss\Facility::page_start();
         $this->object->export_html();
         $content=ob_get_contents();
         
@@ -85,7 +85,7 @@ class Acc_Ledger_History_FinancialTest extends TestCase
         $name="acc_ledger_history_export_accounting.html";
         $this->object->set_m_mode("E");
         ob_start();
-        phpunit_page_start();
+        \Noalyss\Facility::page_start();
         $this->object->export_html();
         $content=ob_get_contents();
         
diff --git a/unit-test/include/class/acc_ledger_history_genericTest.class.php 
b/unit-test/include/class/acc_ledger_history_genericTest.class.php
index fa84e9e..b412cc4 100644
--- a/unit-test/include/class/acc_ledger_history_genericTest.class.php
+++ b/unit-test/include/class/acc_ledger_history_genericTest.class.php
@@ -73,7 +73,7 @@ class Acc_Ledger_History_GenericTest extends TestCase
         $name="acc_ledger_history_Generic_export_listing.html";
         $this->object->set_m_mode("L");
         ob_start();
-        phpunit_page_start();
+        \Noalyss\Facility::page_start();
         $this->object->export_html();
         $content=ob_get_contents();
 
@@ -84,7 +84,7 @@ class Acc_Ledger_History_GenericTest extends TestCase
         $name="acc_ledger_history_Generic_export_extended.html";
         $this->object->set_m_mode("E");
         ob_start();
-        phpunit_page_start();
+        \Noalyss\Facility::page_start();
         $this->object->export_html();
         $content=ob_get_contents();
 
@@ -95,7 +95,7 @@ class Acc_Ledger_History_GenericTest extends TestCase
         $name="acc_ledger_history_Generic_export_detail.html";
         $this->object->set_m_mode("D");
         ob_start();
-        phpunit_page_start();
+        \Noalyss\Facility::page_start();
         $this->object->export_html();
         $content=ob_get_contents();
 
@@ -106,7 +106,7 @@ class Acc_Ledger_History_GenericTest extends TestCase
         $name="acc_ledger_history_Generic_export_accounting.html";
         $this->object->set_m_mode("D");
         ob_start();
-        phpunit_page_start();
+        \Noalyss\Facility::page_start();
         $this->object->export_html();
         $content=ob_get_contents();
 
diff --git a/unit-test/include/class/acc_ledger_history_purchaseTest.class.php 
b/unit-test/include/class/acc_ledger_history_purchaseTest.class.php
index 2ec6cad..b6dd9ed 100644
--- a/unit-test/include/class/acc_ledger_history_purchaseTest.class.php
+++ b/unit-test/include/class/acc_ledger_history_purchaseTest.class.php
@@ -72,7 +72,7 @@ class Acc_Ledger_History_PurchaseTest extends TestCase
         $name="acc_ledger_history_purchase_export_listing.html";
         $this->object->set_m_mode("L");
         ob_start();
-        phpunit_page_start();
+        \Noalyss\Facility::page_start();
         $this->object->export_html();
         $content=ob_get_contents();
         
@@ -83,7 +83,7 @@ class Acc_Ledger_History_PurchaseTest extends TestCase
         $name="acc_ledger_history_purchase_export_extended.html";
         $this->object->set_m_mode("E");
         ob_start();
-        phpunit_page_start();
+        \Noalyss\Facility::page_start();
         $this->object->export_html();
         $content=ob_get_contents();
         
@@ -94,7 +94,7 @@ class Acc_Ledger_History_PurchaseTest extends TestCase
         $name="acc_ledger_history_purchase_export_detail.html";
         $this->object->set_m_mode("D");
         ob_start();
-        phpunit_page_start();
+        \Noalyss\Facility::page_start();
         $this->object->export_html();
         $content=ob_get_contents();
         
@@ -105,7 +105,7 @@ class Acc_Ledger_History_PurchaseTest extends TestCase
         $name="acc_ledger_history_purchase_export_accounting.html";
         $this->object->set_m_mode("D");
         ob_start();
-        phpunit_page_start();
+        \Noalyss\Facility::page_start();
         $this->object->export_html();
         $content=ob_get_contents();
         
diff --git a/unit-test/include/class/acc_ledger_history_saleTest.class.php 
b/unit-test/include/class/acc_ledger_history_saleTest.class.php
index 468731d..d76263b 100644
--- a/unit-test/include/class/acc_ledger_history_saleTest.class.php
+++ b/unit-test/include/class/acc_ledger_history_saleTest.class.php
@@ -70,7 +70,7 @@ class Acc_Ledger_History_SaleTest extends TestCase
         $name="acc_ledger_history_sale_export_listing.html";
         $this->object->set_m_mode("L");
         ob_start();
-        phpunit_page_start();
+        \Noalyss\Facility::page_start();
         $this->object->export_html();
         $content=ob_get_contents();
         
@@ -81,7 +81,7 @@ class Acc_Ledger_History_SaleTest extends TestCase
         $name="acc_ledger_history_sale_export_extended.html";
         $this->object->set_m_mode("E");
         ob_start();
-        phpunit_page_start();
+        \Noalyss\Facility::page_start();
         $this->object->export_html();
         $content=ob_get_contents();
         
@@ -92,7 +92,7 @@ class Acc_Ledger_History_SaleTest extends TestCase
         $name="acc_ledger_history_sale_export_detail.html";
         $this->object->set_m_mode("D");
         ob_start();
-        phpunit_page_start();
+        \Noalyss\Facility::page_start();
         $this->object->export_html();
         $content=ob_get_contents();
         
@@ -103,7 +103,7 @@ class Acc_Ledger_History_SaleTest extends TestCase
         $name="acc_ledger_history_sale_export_accounting.html";
         $this->object->set_m_mode("D");
         ob_start();
-        phpunit_page_start();
+        \Noalyss\Facility::page_start();
         $this->object->export_html();
         $content=ob_get_contents();
         
diff --git a/unit-test/include/class/acc_ledger_purchaseTest.class.php 
b/unit-test/include/class/acc_ledger_purchaseTest.class.php
index 543e88a..723bba4 100644
--- a/unit-test/include/class/acc_ledger_purchaseTest.class.php
+++ b/unit-test/include/class/acc_ledger_purchaseTest.class.php
@@ -1,4 +1,5 @@
 <?php
+
 use PHPUnit\Framework\TestCase;
 
 /**
@@ -14,13 +15,46 @@ class Acc_Ledger_PurchaseTest extends TestCase
     protected $object;
 
     /**
+     * @var array transmitted by _POST
+     */
+    private $array;
+
+    /**
      * 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';
-        $this->object=new Acc_Ledger_Purchase($g_connection,3);
+        $this->object=new Acc_Ledger_Purchase($g_connection, 3);
+        $this->array=array
+            (
+            "gDossier"=>25,
+            "nb_item"=>1,
+            "p_jrn"=>3,
+            "p_jrn_predef"=>3,
+            "action"=>"use_opd",
+            "jrn_type"=>"ACH",
+            "filter"=>"",
+            "e_date"=>"24.02.2018",
+            "e_ech"=>"",
+            "e_client"=>"FOURNI",
+            "e_pj"=>"ACH6",
+            "e_pj_suggest"=>"ACH6",
+            "e_comm"=>"Loyer Appartement",
+            "e_march0"=>"LOYER",
+            "e_march0_price"=>658.25,
+            "e_quant0"=>1,
+            "htva_march0"=>658.25,
+            "e_march0_tva_id"=>4,
+            "e_march0_tva_amount"=>0,
+            "tva_march0"=>0,
+            "tvac_march0"=>658.25,
+            "p_action"=>"ach",
+            "sa"=>"p",
+            "e_mp"=>0,
+            "view_invoice"=>"Enregistrer",
+        );
     }
 
     /**
@@ -34,12 +68,35 @@ class Acc_Ledger_PurchaseTest extends TestCase
 
     /**
      * @covers Acc_Ledger_Purchase::verify
-     * @todo   Implement testVerify().
-     * @expectedException Exception
      */
     public function testVerify()
     {
-        $this->object->verify_operation(array());
+
+        $this->object->verify_operation($this->array);
+        $this->assertTrue(TRUE);
+
+        // Test date
+        try
+        {
+            $array=$this->array;
+            $array['e_date']="g";
+            $this->object->verify_operation($array);
+        }
+        catch (Exception $e)
+        {
+            $this->assertEquals(2, $e->getCode());
+        }
+        // Test Strict
+        try
+        {
+            $array=$this->array;
+            $array['e_date']="01.01.2018";
+            $this->object->verify_operation($array);
+        }
+        catch (Exception $e)
+        {
+            $this->assertEquals(13, $e->getCode());
+        }
     }
 
     /**
@@ -48,10 +105,24 @@ class Acc_Ledger_PurchaseTest extends TestCase
      */
     public function testInsert()
     {
-        // Remove the following lines when you implement this test.
-        $this->markTestIncomplete(
-                'This test has not been implemented yet.'
-        );
+        global $g_connection;
+        $array=$this->array;
+        $array["mt"]="1572704002.1732";
+        $array["pa_id"]=array(2);
+        $array["op"]=array(0);
+        $array["amount_t0"]=658.25;
+        $array['hplan']=array(array(-1));
+        $array["val"]=array(array(658.25));
+        $this->clean_operation();
+        
+        $this->assertEquals(0,
+                $g_connection->get_value ("select count(*) from jrn where 
jr_mt=$1",["1572704002.1732"]));
+        
+        $this->object->insert($array);
+        $this->assertEquals(1,
+                $g_connection->get_value ("select count(*) from jrn where 
jr_mt=$1",["1572704002.1732"]));
+        $this->clean_operation();
+                
     }
 
     /**
@@ -60,10 +131,8 @@ class Acc_Ledger_PurchaseTest extends TestCase
      */
     public function testInput()
     {
-        // Remove the following lines when you implement this test.
-        $this->markTestIncomplete(
-                'This test has not been implemented yet.'
-        );
+        $res=$this->object->input();
+        
     }
 
     /**
@@ -72,10 +141,15 @@ class Acc_Ledger_PurchaseTest extends TestCase
      */
     public function testConfirm()
     {
-        // Remove the following lines when you implement this test.
-        $this->markTestIncomplete(
-                'This test has not been implemented yet.'
-        );
+        $array=$this->array;
+        $this->object->confirm($array);
+    }
+
+    private function clean_operation()
+    {
+        global $g_connection;
+        $g_connection->exec_sql("delete from jrn where jr_mt=$1", 
["1572704002.1732"]);
+        $g_connection->exec_sql("delete from jrnx where j_grpt not in (select 
jr_grpt_id from jrn)");
     }
 
     /**
@@ -90,7 +164,6 @@ class Acc_Ledger_PurchaseTest extends TestCase
         );
     }
 
-
     /**
      * @covers Acc_Ledger_Purchase::get_detail_purchase
      * @todo   Implement testGet_detail_purchase().



reply via email to

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