noalyss-commit
[Top][All Lists]
Advanced

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

[Noalyss-commit] [noalyss] 02/02: Improve PHPUNIT and adapt it to PhpSto


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 02/02: Improve PHPUNIT and adapt it to PhpStorm in order to debug or run them from this IDE
Date: Sat, 3 Sep 2022 07:31:09 -0400 (EDT)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 407e056710286c98811bf39ff81b9db7efa04fe7
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Sat Sep 3 13:30:54 2022 +0200

    Improve PHPUNIT and adapt it to PhpStorm in order
    to debug or run them from this IDE
---
 unit-test/include/class/Acc_ReportTest.php         |   2 +-
 unit-test/include/class/acc_ledgerTest.php         |   2 +-
 unit-test/include/class/acc_ledger_sale.Test.php   |   4 +-
 unit-test/include/class/acc_ledger_search.Test.php |   4 +-
 unit-test/include/class/acc_letter.Test.php        |   2 +-
 unit-test/include/class/acc_payment.Test.php       |   2 +-
 unit-test/include/class/anc_group.Test.php         |   2 +-
 unit-test/include/class/contactTest.php            |   2 +-
 unit-test/include/class/document.Test.php          |   2 +-
 unit-test/include/class/ficheTest.php              | 273 +++++++++------------
 unit-test/include/class/followup_detail.Test.php   |   2 +-
 unit-test/include/class/forecast.Test.php          |   2 +-
 unit-test/include/class/letteringTest.php          |   2 +-
 ..._acc_list.Test.php => pdf_anc_acc_listTest.php} |   6 +-
 unit-test/include/class/periode.Test.php           |   2 +-
 .../class/print_ledger_detail.classTest.php        |   2 +-
 unit-test/include/class/todo_list.Test.php         |   2 +-
 unit-test/include/class/userTest.php               |   2 +-
 18 files changed, 143 insertions(+), 172 deletions(-)

diff --git a/unit-test/include/class/Acc_ReportTest.php 
b/unit-test/include/class/Acc_ReportTest.php
index edf3e348a..ba8b627b4 100644
--- a/unit-test/include/class/Acc_ReportTest.php
+++ b/unit-test/include/class/Acc_ReportTest.php
@@ -32,7 +32,7 @@ use PHPUnit\Framework\TestCase;
  * @backupGlobals enabled
  * @coversDefaultClass \Acc_Report
  */
-require 'global.php';
+require DIRTEST.'/global.php';
 
 class Acc_ReportTest extends TestCase
 {
diff --git a/unit-test/include/class/acc_ledgerTest.php 
b/unit-test/include/class/acc_ledgerTest.php
index 8a5a953a1..1886b6f9a 100644
--- a/unit-test/include/class/acc_ledgerTest.php
+++ b/unit-test/include/class/acc_ledgerTest.php
@@ -49,7 +49,7 @@ class Acc_LedgerTest extends TestCase
      */
     protected function setUp():void
     {
-        include 'global.php';
+        require DIRTEST.'/global.php';
         $this->object=new Acc_Ledger($g_connection,0);
     }
 
diff --git a/unit-test/include/class/acc_ledger_sale.Test.php 
b/unit-test/include/class/acc_ledger_sale.Test.php
index 029165ede..4b75fe9ae 100644
--- a/unit-test/include/class/acc_ledger_sale.Test.php
+++ b/unit-test/include/class/acc_ledger_sale.Test.php
@@ -26,7 +26,7 @@ class Acc_Ledger_SaleTest extends TestCase
      */
     protected function setUp():void
     {
-        include 'global.php';
+        require DIRTEST.'/global.php';
         $this->object=new Acc_Ledger_Sale($g_connection, 2);
         $this->array=array(
             "ledger_type"=>"VEN",
@@ -221,7 +221,7 @@ class Acc_Ledger_SaleTest extends TestCase
     public function testHeading_detail_sale()
     {
         $a=$this->object->heading_detail_sale();
-        $this->assertEquals(32,count($a));
+        $this->assertEquals(34,count($a));
     }
     /**
      * @covers Acc_Ledger_Sale::get_detail_sale
diff --git a/unit-test/include/class/acc_ledger_search.Test.php 
b/unit-test/include/class/acc_ledger_search.Test.php
index 313c1b4e0..d4a37ed17 100644
--- a/unit-test/include/class/acc_ledger_search.Test.php
+++ b/unit-test/include/class/acc_ledger_search.Test.php
@@ -42,7 +42,7 @@ class Acc_Ledger_Test extends TestCase
      */
     protected function setUp():void
     {
-        include 'global.php';
+        require DIRTEST.'/global.php';
         global $g_user;
         $g_user->set_periode(119);
     }
@@ -88,7 +88,7 @@ class Acc_Ledger_Test extends TestCase
         $ledger=new Acc_Ledger_Search('ALL');
         $r=$ledger->display_search_form();
         \Noalyss\Facility::save_file(__DIR__."/file", 
"acc_ledger_search-test_display_search_form.html", $r);
-        $this->assertEquals(9669,strlen($r),"Size of the html string for 
display_search_form see "
+        $this->assertEquals(9697,strlen($r),"Size of the html string for 
display_search_form see "
                 . 
__DIR__."/file/acc_ledger_search-test_display_search_form.html ");
     }
     /**
diff --git a/unit-test/include/class/acc_letter.Test.php 
b/unit-test/include/class/acc_letter.Test.php
index 9bc18b0fa..677500b0c 100644
--- a/unit-test/include/class/acc_letter.Test.php
+++ b/unit-test/include/class/acc_letter.Test.php
@@ -31,7 +31,7 @@ use PHPUnit\Framework\TestCase;
 /**
  * @backupGlobals enabled
  */
-require 'global.php';
+require DIRTEST.'/global.php';
 
 class Acc_Letter extends TestCase
 {
diff --git a/unit-test/include/class/acc_payment.Test.php 
b/unit-test/include/class/acc_payment.Test.php
index ee201a581..f726ecf17 100644
--- a/unit-test/include/class/acc_payment.Test.php
+++ b/unit-test/include/class/acc_payment.Test.php
@@ -32,7 +32,7 @@ use PHPUnit\Framework\TestCase;
  * @backupGlobals enabled
  * @coversDefaultClass \Acc_Payment
  */
-require 'global.php';
+require DIRTEST.'/global.php';
 
 class AccPaymentTest extends TestCase
 {
diff --git a/unit-test/include/class/anc_group.Test.php 
b/unit-test/include/class/anc_group.Test.php
index 99a7c186c..7807d54db 100644
--- a/unit-test/include/class/anc_group.Test.php
+++ b/unit-test/include/class/anc_group.Test.php
@@ -32,7 +32,7 @@ use PHPUnit\Framework\TestCase;
  * @backupGlobals enabled
  * @coversDefaultClass \Anc_Group
  */
-require 'global.php';
+require DIRTEST.'/global.php';
 
 class Anc_GroupTest extends TestCase
 {
diff --git a/unit-test/include/class/contactTest.php 
b/unit-test/include/class/contactTest.php
index 72160f927..e3e6d4517 100644
--- a/unit-test/include/class/contactTest.php
+++ b/unit-test/include/class/contactTest.php
@@ -32,7 +32,7 @@ use PHPUnit\Framework\TestCase;
  * @backupGlobals enabled
  * @coversDefaultClass \Contact
  */
-require 'global.php';
+require DIRTEST.'/global.php';
 
 class ContactTest extends TestCase
 {
diff --git a/unit-test/include/class/document.Test.php 
b/unit-test/include/class/document.Test.php
index 4f684caf2..36248f277 100644
--- a/unit-test/include/class/document.Test.php
+++ b/unit-test/include/class/document.Test.php
@@ -25,7 +25,7 @@ use PHPUnit\Framework\TestCase;
  * @file
  * @brief  test \Document
  */
-require_once 'global.php';
+require DIRTEST.'/global.php';
 
 class DocumentTest extends TestCase
 {
diff --git a/unit-test/include/class/ficheTest.php 
b/unit-test/include/class/ficheTest.php
index 7ab5d4f79..d39c7445c 100644
--- a/unit-test/include/class/ficheTest.php
+++ b/unit-test/include/class/ficheTest.php
@@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase;
  * Generated by PHPUnit_SkeletonGenerator on 2014-11-07 at 23:05:36.
  * @backupGlobals enabled
  */
-require 'global.php';
+require DIRTEST.'/global.php';
 
 class FicheTest extends TestCase
 {
@@ -15,7 +15,13 @@ class FicheTest extends TestCase
      * @var Fiche
      */
     protected $object;
-    private $connection;
+    private $g_connection;
+    function __construct($name = null, array $data = [], $dataName = '')
+    {
+
+        parent::__construct($name, $data, $dataName);
+
+    }
 
     /**
      * Sets up the fixture, for example, opens a network connection.
@@ -23,9 +29,14 @@ class FicheTest extends TestCase
      */
     protected function setUp():void
     {
-        include 'global.php';
+        $g_connection=Dossier::connect();
         $this->object = new Fiche($g_connection);
-        $this->connection=$g_connection;
+        $this->g_connection=$g_connection;
+        $this->g_connection->exec_sql("delete from tmp_pcmn where  id > 1194");
+        $this->g_connection->exec_sql("delete from fiche_detail where f_id > 
47  ");
+        $this->g_connection->exec_sql("delete from fiche where f_id > 47  ");
+        $this->g_connection->exec_sql("update public.parameter set pr_value = 
$1 where pr_id=$2",
+            array('N','MY_ALPHANUM'));
     }
 
     /**
@@ -39,10 +50,15 @@ class FicheTest extends TestCase
 
     static function tearDownAfterClass():void
     {
-        include 'global.php';
-        $fiche_def = new Fiche_Def($g_connection, 5);
+        $g_connection=Dossier::connect();
+          $fiche_def = new Fiche_Def($g_connection, 5);
         // prepare test , clean 
         $fiche_def->RemoveAttribut([20, 21, 22, 51, 52, 53]);
+        $g_connection->exec_sql("delete from tmp_pcmn  where  id > 1194");
+        $g_connection->exec_sql("delete from fiche_detail where f_id > 47  ");
+        $g_connection->exec_sql("delete from fiche where f_id > 47  ");
+        $g_connection->exec_sql("update public.parameter set pr_value = $1 
where pr_id=$2",
+            array('N','MY_ALPHANUM'));
     }
 
     /**
@@ -50,23 +66,23 @@ class FicheTest extends TestCase
      */
     public function testCmp_name()
     {
-        global $g_connection;
-        $fiche = new \Fiche($g_connection, 21);
-        $fiche_2 = new \Fiche($g_connection, 25);
+
+        $fiche = new \Fiche($this->g_connection, 21);
+        $fiche_2 = new \Fiche($this->g_connection, 25);
         $this->assertGreaterThan(\Fiche::cmp_name($fiche, $fiche_2), 0);
     }
 
     /**
      * @covers Fiche::get_bk_account
+     * @backupGlobals enabled
      */
     public function testGet_bk_account()
     {
-        include 'global.php';
-        $this->object = new Fiche($g_connection);
+        require DIRTEST.'/global.php';
         $result = $this->object->get_bk_account();
         $this->assertEquals(gettype($result), 'array');
         $count = count($result);
-        $this->assertGreaterThan(0, $count);
+        $this->assertEquals(3, $count,'number of FIN ledgers');
     }
 
     /**
@@ -74,13 +90,13 @@ class FicheTest extends TestCase
      */
     public function testGet_row()
     {
-        include 'global.php';
-        $card_count = $g_connection->get_array("select count(*),f_id " .
+
+        $card_count = $this->g_connection->get_array("select count(*),f_id " .
             " from jrnx " .
             " where " .
             " f_id is not null " .
             "group by f_id order by count(*) desc");
-        $a = new Fiche($g_connection, $card_count[0]['f_id']);
+        $a = new Fiche($this->g_connection, $card_count[0]['f_id']);
         try {
             $a->get_row(235, 238);
             $this->assertFalse(TRUE, "Exception periode invalide");
@@ -129,6 +145,7 @@ class FicheTest extends TestCase
      */
     public function testSummary()
     {
+        require DIRTEST.'/global.php';
         $_REQUEST['ac'] = "CARD";
         $this->object->fiche_def_ref = -1;
         $r = $this->object->summary();
@@ -144,12 +161,12 @@ class FicheTest extends TestCase
      */
     function testFicheDefInsertAttribut()
     {
-        global $g_connection;
-        $fiche_def = new Fiche_Def($g_connection, 5);
+
+        $fiche_def = new Fiche_Def($this->g_connection, 5);
         // prepare test , clean 
         $fiche_def->RemoveAttribut([20, 21, 22, 51, 52, 53]);
         $this->assertEquals(35,
-            $g_connection->get_value("select count(*) from fiche_detail join 
fiche using (f_id)
+            $this->g_connection->get_value("select count(*) from fiche_detail 
join fiche using (f_id)
                 where fd_id=5"), "Efface 6 attributs");
 
         // percent deductible
@@ -164,7 +181,7 @@ class FicheTest extends TestCase
 
         // check that all card has these attributes
         $this->assertEquals(77,
-            $g_connection->get_value("select count(*) from fiche_detail join 
fiche using (f_id)
+            $this->g_connection->get_value("select count(*) from fiche_detail 
join fiche using (f_id)
                 where fd_id=5"), "Ajout 6 attributs");
     }
 
@@ -174,14 +191,13 @@ class FicheTest extends TestCase
      */
     function testFicheDefRemoveAttribut()
     {
-        global $g_connection;
-        $fiche_def = new Fiche_Def($g_connection, 5);
+        $fiche_def = new Fiche_Def($this->g_connection, 5);
 
         // prepare test , clean 
         $fiche_def->RemoveAttribut([20, 21, 22, 51, 52, 53]);
 
         $this->assertEquals(35,
-            $g_connection->get_value("select count(*) from fiche_detail join 
fiche using (f_id)
+            $this->g_connection->get_value("select count(*) from fiche_detail 
join fiche using (f_id)
                 where fd_id=5"), "Efface 6 attributs");
     }
 
@@ -194,12 +210,10 @@ class FicheTest extends TestCase
         $this->testFicheDefRemoveAttribut();
         $this->testFicheDefInsertAttribut();
 
-        global $g_connection;
-
         // modify attribute for card category , add VAT non ded, Tax non ded , 
VAT completely non ded 0%
         // category Misc Services & goods (5)
         //-- modify card 29 : ELECTR
-        $fiche = new Fiche($g_connection, 29);
+        $fiche = new Fiche($this->g_connection, 29);
         $fiche->set_f_enable("1");
         $fiche->setAttribut(20, "33.33");
         $a_attribut = $fiche->to_array();
@@ -208,23 +222,23 @@ class FicheTest extends TestCase
         $fiche->update($a_attribut);
 
         $this->assertEquals("33.33",
-            $g_connection->get_value("select ad_value from fiche_detail where 
f_id=$1 and ad_id=$2", [29, 20]),
+            $this->g_connection->get_value("select ad_value from fiche_detail 
where f_id=$1 and ad_id=$2", [29, 20]),
             "Attribut ad_id 20 inserted");
 
         $this->assertEquals("33.33", $fiche->strAttribut(20), "retrieve 
attribute 20");
         $fiche->setAttribut(20, "0.05");
         Card_Property::update($fiche);
         $this->assertEquals("0.05",
-            $g_connection->get_value("select ad_value from fiche_detail where 
f_id=$1 and ad_id=$2", [29, 20]),
+            $this->g_connection->get_value("select ad_value from fiche_detail 
where f_id=$1 and ad_id=$2", [29, 20]),
             "Attribut ad_id 20 updated");
     }
 
     function testInexistantCard()
     {
-        global $g_connection;
-        $last_card = $g_connection->get_next_seq('s_fiche');
-        $last_card = $g_connection->get_next_seq('s_fiche');
-        $inexistant_fiche = new Fiche($g_connection, $last_card + 2000);
+
+        $last_card = $this->g_connection->get_next_seq('s_fiche');
+        $last_card = $this->g_connection->get_next_seq('s_fiche');
+        $inexistant_fiche = new Fiche($this->g_connection, $last_card + 2000);
         $_POST['av_text1'] = 'not exist';
         try {
             $inexistant_fiche->update();
@@ -239,14 +253,12 @@ class FicheTest extends TestCase
      */
     public function testQueryAttribute()
     {
-        global $g_connection;
-
-        $fiche_goods = new Fiche($g_connection);
+        $fiche_goods = new Fiche($this->g_connection);
         $fiche_goods->get_by_qcode("MARCHA");
         $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 = new Fiche($this->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");
@@ -258,20 +270,19 @@ class FicheTest extends TestCase
      */
     public function testInsertAndRemoveCard()
     {
-        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);
+        $last_card = $this->g_connection->get_next_seq('s_fiche');
+        $nb_fiche = $this->g_connection->get_value("select count(*) from 
fiche");
+        $new_fiche = new Fiche($this->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");
+        $nb_fiche_after = $this->g_connection->get_value("select count(*) from 
fiche");
         $this->assertGreaterThan($nb_fiche, $nb_fiche_after, 'card created');
         $this->assertEquals("1", $new_fiche->get_f_enable(), "By default 
enable");
         $new_fiche->remove();
-        $nb_fiche_after = $g_connection->get_value("select count(*) from 
fiche");
+        $nb_fiche_after = $this->g_connection->get_value("select count(*) from 
fiche");
         $this->assertEquals($nb_fiche, $nb_fiche_after, 'card removed');
     }
 
@@ -280,11 +291,10 @@ class FicheTest extends TestCase
      */
     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");
+        $last_card = $this->g_connection->get_next_seq('s_fiche');
+        $nb_fiche = $this->g_connection->get_value("select count(*) from 
fiche");
 
-        $new_fiche = new Fiche($g_connection);
+        $new_fiche = new Fiche($this->g_connection);
         $aProperty = array('av_text1' => 'Nom', 'av_text23' => 'ZZZTEST2');
         $new_fiche->insert(5, $aProperty);
 
@@ -297,7 +307,7 @@ class FicheTest extends TestCase
 
         $new_fiche->remove();
 
-        $nb_fiche_after = $g_connection->get_value("select count(*) from 
fiche");
+        $nb_fiche_after = $this->g_connection->get_value("select count(*) from 
fiche");
         $this->assertEquals($nb_fiche, $nb_fiche_after, 'card not removed');
     }
 
@@ -320,9 +330,8 @@ class FicheTest extends TestCase
      */
     public function testInsertEmptyQuickCode($name, $quick_code)
     {
-        global $g_connection;
         //insert
-        $fiche = new Fiche($g_connection);
+        $fiche = new Fiche($this->g_connection);
         $fiche->insert(2, ['av_text13' => $quick_code, "av_text1" => $name]);
         $fiche->load();
         $this->assertTrue($fiche->id > 0 && 
!empty(trim($fiche->strAttribut(23))), 'error : card created with empty 
quickcode');
@@ -340,8 +349,8 @@ class FicheTest extends TestCase
             array('ÀÉ@Ê', 'AE@E'),
             array('ça&"', 'CA'),
             array("", "QC"),
-            array(",,,,", "QC0"),
-            array("####", "QC0")
+            array(",,,,", "QC"),
+            array("####", "QC")
         );
     }
 
@@ -351,18 +360,17 @@ class FicheTest extends TestCase
      */
     public function testUpdateEmptyQuickCode($name, $quick_code)
     {
-        global $g_connection;
-
+        $aCardId=[];
         //insert
-        $fiche = new Fiche($g_connection);
+        $fiche = new Fiche($this->g_connection);
         $fiche->insert(2, ['av_text23' => 'QC', "av_text1" => $name]);
         $this->assertTrue($fiche->id > 0 && !empty($fiche->strAttribut(23)), 
'error : card created with empty quickcode');
-
+        $aCardId[]=$fiche->get_id();
 
         // add attributes of type card , and for another card, set it to this 
quickcode
-        $fiche_def_id=$g_connection->get_value("select fd_id from fiche where 
f_id=$1 ",[$fiche->id]);
-        $fiche_def=new Fiche_Def($g_connection,$fiche_def_id);
-        $aAttribute=$g_connection->get_array("
+        $fiche_def_id=$this->g_connection->get_value("select fd_id from fiche 
where f_id=$1 ",[$fiche->id]);
+        $fiche_def=new Fiche_Def($this->g_connection,$fiche_def_id);
+        $aAttribute=$this->g_connection->get_array("
 select ad_id from attr_def a1
 where 
       a1.ad_id not 
@@ -372,7 +380,7 @@ where
             $fiche_def->insertAttribut($nAttribute['ad_id']);
         }
         // related cards
-        $fiche_related1=new Fiche($g_connection);
+        $fiche_related1=new Fiche($this->g_connection);
         $aAttributeRelated=array(
             "av_text23"=>"FR1",
             'av_text1'=>'Fiche reliée'
@@ -383,8 +391,10 @@ where
         $fiche_related1->insert(2,$aAttributeRelated);
         $aAttributeRelated['av_text1']='Fiche reliée 2';
         $aAttributeRelated['av_text23']='FR2';
-        $fiche_related2=new Fiche($g_connection);
+        $fiche_related2=new Fiche($this->g_connection);
         $fiche_related2->insert(2,$aAttributeRelated);
+        $aCardId[]=$fiche_related1->get_id();
+        $aCardId[]=$fiche_related2->get_id();
 
         // ----
         // check that related cards are properly created
@@ -407,7 +417,7 @@ where
 
 
         $fiche->update($fiche->to_array());
-        $compare = new Fiche($g_connection, $fiche->id);
+        $compare = new Fiche($this->g_connection, $fiche->id);
         $this->assertEquals($quick_code, $compare->get_quick_code(), 'Error : 
quickcode not correct');
 
         // check that the other attributes of type card have been updated
@@ -415,10 +425,10 @@ where
             
$this->assertEquals($fiche->get_quick_code(),$fiche_related1->strAttribut($nAttribute['ad_id']),'Attribute
 QC is not set');
             
$this->assertEquals($fiche->get_quick_code(),$fiche_related2->strAttribut($nAttribute['ad_id']),'Attribute
 QC is not set');
         }
-        if ( $fiche->id == 872 || $fiche->id == 871 ) {
-            //$this->assertEquals($fiche->remove(),1,"Removed used card not 
allowed {$fiche->id}");
-            // @todo : skip because these cards changed in another test
-            
+
+        if ($fiche->is_used()) {
+            $this->assertEquals($fiche->remove(),1,"Cannot remove 
{$fiche->id}");
+            $aCardId[]=$fiche->get_id();
         } else {
             $this->assertEquals($fiche->remove(),0,"Cannot remove 
{$fiche->id}");
         }
@@ -427,9 +437,8 @@ where
         foreach ($aAttribute as $nAttribute) {
             $fiche_def->removeAttribut($nAttribute['ad_id']);
         }
-
-
     }
+
     function dataFormat_QuickCode()
     {
         return array(
@@ -451,8 +460,7 @@ where
      */
     public function testFormat_QuickCode($p_qcode,$p_result)
     {
-        global $g_connection;
-        $this->assertEquals($p_result,$g_connection->get_value( "select 
comptaproc.format_quickcode($1)",
+        $this->assertEquals($p_result,$this->g_connection->get_value( "select 
comptaproc.format_quickcode($1)",
         [$p_result]),'quickcode is not transformed correctly');
     }
     function dataInsertName()
@@ -469,10 +477,9 @@ where
      */
     public function testInsertName($p_name,$p_result)
     {
-        global $g_connection;
 
         //insert
-        $fiche = new Fiche($g_connection);
+        $fiche = new Fiche($this->g_connection);
         $fiche->insert(2, ['av_text23' => 'QC', "av_text1" => $p_name]);
         $fiche->load();
         
$this->assertEquals($p_result,$fiche->strAttribut(ATTR_DEF_NAME),'incorrect 
name');
@@ -485,10 +492,9 @@ where
      */
     public function testUpdateName($p_name,$p_result)
     {
-        global $g_connection;
 
         //insert
-        $fiche = new Fiche($g_connection);
+        $fiche = new Fiche($this->g_connection);
         $fiche->insert(2, ['av_text23' => 'QC', "av_text1" => $p_name]);
         $fiche->load();
         
$this->assertEquals($p_result,$fiche->strAttribut(ATTR_DEF_NAME),'incorrect 
name');
@@ -499,46 +505,42 @@ where
      */
     public function testQuickCodeNumbering()
     {
-        global $g_connection;
-        $fiche=new Fiche($g_connection);
+        $fiche=new Fiche($this->g_connection);
         $fiche->insert(2,array("av_text1"=>'Card for 
PHPUNIT','av_text23'=>'DUP'));
         $this->assertTrue($fiche->id > 0 && 'DUP'==$fiche->strAttribut(23),
             'error : card created with wrong 
quickcode'.$fiche->strAttribut(23));
         for ($i=0;$i<100;$i++) {
-            $fiche_duplicate = new Fiche($g_connection);
+            $fiche_duplicate = new Fiche($this->g_connection);
             $fiche_duplicate->insert(2, array("av_text1" => 'Base Card' . $i, 
'av_text23' => 'DUP'));
             
             $this->assertTrue($fiche_duplicate->id > $fiche->id && 'DUP' . $i 
== $fiche_duplicate->strAttribut(23),
                 " error : card created with  quickcode 
{$fiche_duplicate->strAttribut(23)} expected DUP{$i}");
          
         }
-        $a_fiche_clean=$g_connection->get_array("select f_id from fiche where 
f_id >= $1",
+        $a_fiche_clean=$this->g_connection->get_array("select f_id from fiche 
where f_id >= $1",
                     [$fiche->id]);
         foreach($a_fiche_clean as $fiche_clean) {
-            $fiche=new Fiche($g_connection,$fiche_clean['f_id']);
+            $fiche=new Fiche($this->g_connection,$fiche_clean['f_id']);
             $fiche->remove();
             $this->assertEquals(0,
-                $g_connection->get_value("select count(*) from fiche where 
f_id=$1",
+                $this->g_connection->get_value("select count(*) from fiche 
where f_id=$1",
                     array($fiche_clean['f_id']))
                 ,"Card not removed");
         }
     }
     /**
      * Create a card
-     * @global type $g_connection
      * @param type $p_qcode
      * @returns \Fiche
      */
     public function build_fiche($p_category,$p_qcode)
     {
                 // insert a card in category 2 with automatic set 
-        global $g_connection;
-        $fiche=new Fiche($g_connection);
+        $fiche=new Fiche($this->g_connection);
         if ( $fiche->get_by_qcode($p_qcode) == 0 ) 
         {
             $fiche->remove();
         }
-        
         $fiche->insert($p_category,array("av_text1"=>'Card for 
PHPUNIT','av_text23'=>$p_qcode));
         $this->assertTrue($fiche->id > 0 && $p_qcode==$fiche->strAttribut(23),
             'error : card created with wrong 
quickcode'.$fiche->strAttribut(23));
@@ -549,59 +551,43 @@ where
      */
     public function testAutomaticAccountingUpdate()
     {
-        global $g_connection;
-        $g_connection->exec_sql("delete from tmp_pcmn where pcm_val like 
'6000%'");
-        
-        $fiche_def=new Fiche_Def($g_connection,2);
+        $this->g_connection->exec_sql("update public.parameter set pr_value = 
$1 where pr_id=$2",
+            array('N','MY_ALPHANUM'));
+        $fiche_def=new Fiche_Def($this->g_connection,2);
         $fiche_def->set_autocreate(true);
         $fiche_def->save_class_base('600');
         $fiche=$this->build_fiche(2,'TESTACCOUNT');
         $start=$fiche->id;
         
$this->assertEquals('600001',$fiche->strAttribut(ATTR_DEF_ACCOUNT),'Account not 
properly created');
-        $aAccount=array();
         for ( $i=600002; $i < 600999;$i++) {
            $fiche->setAttribut(ATTR_DEF_ACCOUNT, "");
            Card_Property::update($fiche);
            $fiche->load();
            
$this->assertEquals($i,$fiche->strAttribut(ATTR_DEF_ACCOUNT),'Account not 
properly created');
-           $aAccount[]="'$i'";
-            
+
         }
-        $sAccount=join(",",$aAccount);
-       $g_connection->exec_sql("delete from tmp_pcmn where pcm_val in 
($sAccount)");
-       $g_connection->exec_sql("delete from fiche_detail where f_id >= 
$1",[$start]);
-       $g_connection->exec_sql("delete from fiche where f_id >= $1",[$start]);
+
     }
     /**
      * @testdox testAutomaticAccountingInsert test accounting automatic 
compute (insert)
      */
     public function testAutomaticAccountingInsert()
     {
-
-        global $g_connection;
-        $g_connection->exec_sql("delete from tmp_pcmn where pcm_val like 
'6000%'");
-          
-        $fiche_def=new Fiche_Def($g_connection,2);
+        $this->g_connection->exec_sql("update public.parameter set pr_value = 
$1 where pr_id=$2",
+            array('N','MY_ALPHANUM'));
+        $fiche_def=new Fiche_Def($this->g_connection,2);
         $fiche_def->set_autocreate(true);
         $fiche_def->save_class_base('600');
         $first=true;
-        $aAccount=array();
         for ( $i=600001; $i <  601000;$i++) {
-            $fiche=new Fiche($g_connection);
+            $fiche=new Fiche($this->g_connection);
             $fiche->insert(2,['av_text1'=>'PHPUNIT '.__FUNCTION__]);
             if ( $first ) { 
                 $first=false;
-                $start=$fiche->id;
             }
            $fiche->load();
            
$this->assertEquals($i,$fiche->strAttribut(ATTR_DEF_ACCOUNT),'Account not 
properly created');
-            $aAccount[]="'$i'";
         }
-          $sAccount=join(",",$aAccount);
-       $g_connection->exec_sql("delete from tmp_pcmn where pcm_val in 
($sAccount)");
-       $g_connection->exec_sql("delete from fiche_detail where f_id >= 
$1",[$start]);
-       $g_connection->exec_sql("delete from fiche where f_id >= $1",[$start]);
-
     }
     public function dataAccount()
     {
@@ -618,14 +604,13 @@ where
      */
     public function testAccountInsert($p_value,$p_expected)
     {
-        global $g_connection;
-        $fiche=$this->build_fiche(2, 'PHPUNIT.ACCOUNT.INSERT');
+      $fiche=$this->build_fiche(2, 'PHPUNIT.ACCOUNT.INSERT');
         $fiche->setAttribut(ATTR_DEF_ACCOUNT, $p_value);
         Card_Property::update($fiche);
         
$this->assertEquals($p_expected,$fiche->strAttribut(ATTR_DEF_ACCOUNT)," cannot 
SET accounting");
-        $this->assertTrue($g_connection->get_value("select count(*) from 
tmp_pcmn where pcm_val = $1",[$p_expected])==1
+        $this->assertTrue($this->g_connection->get_value("select count(*) from 
tmp_pcmn where pcm_val = $1",[$p_expected])==1
                 ," accounting not created in TMP_PCMN");
-        $g_connection->exec_sql("delete from tmp_pcmn where 
pcm_val=$1",[$p_expected]);
+        $this->g_connection->exec_sql("delete from tmp_pcmn where 
pcm_val=$1",[$p_expected]);
         $fiche->remove();
     }
 
@@ -634,15 +619,16 @@ where
      */
     public function testAutomaticAccountingUpdateAlpha()
     {
-        global $g_connection;
-        $g_connection->exec_sql("delete from tmp_pcmn where pcm_val like 
'600%'");
-        $g_connection->exec_sql("update public.parameter set pr_value = $1 
where pr_id=$2",
+     
+        $this->g_connection->exec_sql("update public.parameter set pr_value = 
$1 where pr_id=$2",
             array('Y','MY_ALPHANUM'));
-        $fiche_def=new Fiche_Def($g_connection,2);
+        $fiche_def=new Fiche_Def($this->g_connection,2);
         $fiche_def->set_autocreate(true);
         $fiche_def->save_class_base('600');
         $fiche=$this->build_fiche(2,'TESTACCOUNT');
-        $start=$fiche->id;
+        $fiche->setAttribut(ATTR_DEF_ACCOUNT, "");
+        Card_Property::update($fiche);
+        $fiche->load();
         
$this->assertEquals('600CARDFORPHPUNIT',$fiche->strAttribut(ATTR_DEF_ACCOUNT),'Account
 not properly created');
 
         for ( $i=600002; $i < 600999;$i++) {
@@ -655,29 +641,22 @@ where
 
         }
 
-        $g_connection->exec_sql("delete from tmp_pcmn where pcm_val like 
'600%'");
-        $g_connection->exec_sql("delete from fiche_detail where f_id >= 
$1",[$start]);
-        $g_connection->exec_sql("delete from fiche where f_id >= $1",[$start]);
-        $g_connection->exec_sql("update public.parameter set pr_value = $1 
where pr_id=$2",
-            array('N','MY_ALPHANUM'));
-    }
+       }
     /**
      * @testdox testAutomaticAccountingInsertAlpha test accounting automatic 
compute (insert) with alphanumeric enable
      */
     public function testAutomaticAccountingInsertAlpha()
     {
 
-        global $g_connection;
-        $g_connection->exec_sql("delete from tmp_pcmn where pcm_val like 
'600%'");
-        $g_connection->exec_sql("update public.parameter set pr_value = $1 
where pr_id=$2",
+        $this->g_connection->exec_sql("update public.parameter set pr_value = 
$1 where pr_id=$2",
             array('Y','MY_ALPHANUM'));
-        $fiche_def=new Fiche_Def($g_connection,2);
+        $fiche_def=new Fiche_Def($this->g_connection,2);
         $fiche_def->set_autocreate(true);
         $fiche_def->save_class_base('600');
         $first=true;
 
         for ( $i=1; $i <  1000;$i++) {
-            $fiche=new Fiche($g_connection);
+            $fiche=new Fiche($this->g_connection);
             $fiche->insert(2,['av_text1'=>substr($i.' PHPUNIT 
'.__FUNCTION__,0,35)],);
             if ( $first ) {
                 $first=false;
@@ -688,13 +667,7 @@ where
 
         }
 
-        $g_connection->exec_sql("delete from tmp_pcmn where pcm_val like 
'600%'");
-        $g_connection->exec_sql("delete from fiche_detail where f_id >= 
$1",[$start]);
-        $g_connection->exec_sql("delete from fiche where f_id >= $1",[$start]);
-        $g_connection->exec_sql("update public.parameter set pr_value = $1 
where pr_id=$2",
-            array('N','MY_ALPHANUM'));
-
-    }
+     }
      /**
      * @brief test update of the accounting
      * @testdox testAccountUpdate et  of the accounting while updating
@@ -702,14 +675,15 @@ where
      */
     public function testAccountUpdate($p_value,$p_expected)
     {
-        global $g_connection;
+        $this->g_connection->exec_sql("update public.parameter set pr_value = 
$1 where pr_id=$2",
+            array('N','MY_ALPHANUM'));
         $fiche=$this->build_fiche(2, 'PHPUNIT.ACCOUNT.UPDATE');
         $fiche->setAttribut(ATTR_DEF_ACCOUNT, $p_value);
         $fiche->update($fiche->to_array());
         
$this->assertEquals($p_expected,$fiche->strAttribut(ATTR_DEF_ACCOUNT)," cannot 
SET accounting");
-        $this->assertTrue($g_connection->get_value("select count(*) from 
tmp_pcmn where pcm_val = $1",[$p_expected])==1
+        $this->assertTrue($this->g_connection->get_value("select count(*) from 
tmp_pcmn where pcm_val = $1",[$p_expected])==1
                 ," accounting not created in TMP_PCMN");
-        $g_connection->exec_sql("delete from tmp_pcmn where 
pcm_val=$1",[$p_expected]);
+        $this->g_connection->exec_sql("delete from tmp_pcmn where 
pcm_val=$1",[$p_expected]);
         $fiche->remove();
     }
     /**
@@ -717,9 +691,10 @@ where
      */
     public function testSameAccountingUpdate()
     {
+        $this->g_connection->exec_sql("update public.parameter set pr_value = 
$1 where pr_id=$2",
+            array('N','MY_ALPHANUM'));
         // insert a card in category 2 with always the same account
-        global $g_connection;
-        $fiche_def=new Fiche_Def($g_connection,2);
+        $fiche_def=new Fiche_Def($this->g_connection,2);
         $fiche_def->set_autocreate(false);
         $fiche_def->save_class_base('600');
         $fiche=$this->build_fiche(2,'TESTACCOUNT');
@@ -739,13 +714,12 @@ where
     public function testSameAccountingInsert()
     {
         // insert a card in category 2 with always the same account
-        global $g_connection;
-        $fiche_def=new Fiche_Def($g_connection,2);
+        $fiche_def=new Fiche_Def($this->g_connection,2);
         $fiche_def->set_autocreate(false);
         $fiche_def->save_class_base('600');
         
         for ( $i=600002; $i < 600025;$i++) {
-            $fiche=new Fiche($g_connection);
+            $fiche=new Fiche($this->g_connection);
             $fiche->insert(2,['av_text1'=>'PHPUNIT test Same 
accounting','av_text5'=>""]);
             $fiche->load();
             
$this->assertEquals(600,$fiche->strAttribut(ATTR_DEF_ACCOUNT),'Account not 
properly created');
@@ -758,38 +732,35 @@ where
      */
     public function testUpdateEnable()
     {
-        global $g_connection;
         $fiche= $fiche=$this->build_fiche(2,'PHPUNIT-ENABLE');
         $fiche->update($fiche->to_array());
-        $this->assertEquals(1,$g_connection->get_value("select f_enable from 
fiche where f_id=$1",[$fiche->id])," Fiche::update card is not enabled" );
+        $this->assertEquals(1,$this->g_connection->get_value("select f_enable 
from fiche where f_id=$1",[$fiche->id])," Fiche::update card is not enabled" );
         $fiche->set_f_enable(0);
         $fiche->update($fiche->to_array());
-        $this->assertEquals(0,$g_connection->get_value("select f_enable from 
fiche where f_id=$1",[$fiche->id])," Fiche::update  card is not disabled" );
+        $this->assertEquals(0,$this->g_connection->get_value("select f_enable 
from fiche where f_id=$1",[$fiche->id])," Fiche::update  card is not disabled" 
);
         $fiche->set_f_enable(1);
         Card_Property::update($fiche);
-        $this->assertEquals(1,$g_connection->get_value("select f_enable from 
fiche where f_id=$1",[$fiche->id]),"Card_Property:update card is not enabled" );
+        $this->assertEquals(1,$this->g_connection->get_value("select f_enable 
from fiche where f_id=$1",[$fiche->id]),"Card_Property:update card is not 
enabled" );
         $fiche->set_f_enable(0);
         Card_Property::update($fiche);
-        $this->assertEquals(0,$g_connection->get_value("select f_enable from 
fiche where f_id=$1",[$fiche->id]),"Card_Property:update card is not disabled" 
);
+        $this->assertEquals(0,$this->g_connection->get_value("select f_enable 
from fiche where f_id=$1",[$fiche->id]),"Card_Property:update card is not 
disabled" );
         $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=new Fiche($this->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);
+        $fiche_target=new Fiche($this->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());
diff --git a/unit-test/include/class/followup_detail.Test.php 
b/unit-test/include/class/followup_detail.Test.php
index 355876cfb..da99d80b6 100644
--- a/unit-test/include/class/followup_detail.Test.php
+++ b/unit-test/include/class/followup_detail.Test.php
@@ -32,7 +32,7 @@ use PHPUnit\Framework\TestCase;
  * @backupGlobals enabled
  * @coversDefaultClass \Follow_Up_Detail
  */
-require 'global.php';
+require DIRTEST.'/global.php';
 
 class Follow_Up_DetailTest extends TestCase
 {
diff --git a/unit-test/include/class/forecast.Test.php 
b/unit-test/include/class/forecast.Test.php
index 9b49dbafd..d05cc6777 100644
--- a/unit-test/include/class/forecast.Test.php
+++ b/unit-test/include/class/forecast.Test.php
@@ -32,7 +32,7 @@ use PHPUnit\Framework\TestCase;
  * @backupGlobals enabled
  * @coversDefaultClass \Forecast
  */
-require 'global.php';
+require DIRTEST.'/global.php';
 
 class ForecastTest extends TestCase
 {
diff --git a/unit-test/include/class/letteringTest.php 
b/unit-test/include/class/letteringTest.php
index 6b7eb3b36..cbde43752 100644
--- a/unit-test/include/class/letteringTest.php
+++ b/unit-test/include/class/letteringTest.php
@@ -32,7 +32,7 @@ use PHPUnit\Framework\TestCase;
  * @backupGlobals enabled
  * @coversDefaultClass \Lettering
  */
-require 'global.php';
+require DIRTEST.'/global.php';
 
 class LetteringTest extends TestCase
 {
diff --git a/unit-test/include/class/pdf_anc_acc_list.Test.php 
b/unit-test/include/class/pdf_anc_acc_listTest.php
similarity index 98%
rename from unit-test/include/class/pdf_anc_acc_list.Test.php
rename to unit-test/include/class/pdf_anc_acc_listTest.php
index f73f17b84..1bcf914be 100644
--- a/unit-test/include/class/pdf_anc_acc_list.Test.php
+++ b/unit-test/include/class/pdf_anc_acc_listTest.php
@@ -31,7 +31,7 @@ use PHPUnit\Framework\TestCase;
 /**
  * @backupGlobals enabled
  */
-require 'global.php';
+require DIRTEST.'/global.php';
 
 class PDF_Anc_Acc_ListTest extends TestCase
 {
@@ -134,7 +134,7 @@ EOF;
         $anc_acc_list->card_poste=2;
         $pdf_anc_acc=new PDF_Anc_Acc_List($anc_acc_list);
         
$pdf_anc_acc->export_pdf()->Output(__DIR__."/file/pdf_anc_acc_list-account-activity.pdf","F");
-        
$this->assertEquals(77151,filesize(__DIR__."/file/pdf_anc_acc_list-account-activity.pdf"),
+        
$this->assertEquals(77150,filesize(__DIR__."/file/pdf_anc_acc_list-account-activity.pdf"),
                __DIR__."/file/pdf_anc_acc_list-account-activity.pdf incorrect 
");
         
         // By Activity / Card
@@ -156,7 +156,7 @@ EOF;
         $anc_acc_list->card_poste=4;
         $pdf_anc_acc=new PDF_Anc_Acc_List($anc_acc_list);
         
$pdf_anc_acc->export_pdf()->Output(__DIR__."/file/pdf_anc_acc_list-activity-account.pdf","F");
-        
$this->assertEquals(76410,filesize(__DIR__."/file/pdf_anc_acc_list-activity-account.pdf"),
+        
$this->assertEquals(76411,filesize(__DIR__."/file/pdf_anc_acc_list-activity-account.pdf"),
                 __DIR__."/file/pdf_anc_acc_list-activity-account.pdf 
incorrect");
     }
 
diff --git a/unit-test/include/class/periode.Test.php 
b/unit-test/include/class/periode.Test.php
index 1b9cd1f67..93b839293 100644
--- a/unit-test/include/class/periode.Test.php
+++ b/unit-test/include/class/periode.Test.php
@@ -31,7 +31,7 @@ use PHPUnit\Framework\TestCase;
 /**
  * @backupGlobals enabled
  */
-require 'global.php';
+require DIRTEST.'/global.php';
 
 class PeriodeTest extends TestCase
 {
diff --git a/unit-test/include/class/print_ledger_detail.classTest.php 
b/unit-test/include/class/print_ledger_detail.classTest.php
index 39d14da9b..055549b0b 100644
--- a/unit-test/include/class/print_ledger_detail.classTest.php
+++ b/unit-test/include/class/print_ledger_detail.classTest.php
@@ -26,7 +26,7 @@ use PHPUnit\Framework\TestCase;
  * @brief concerne print_ledger_detail
  * @coversDefaultClass Print_Ledger_Detail
  */
-include_once 'global.php';
+require DIRTEST.'/global.php';
 
 class Print_Ledger_DetailTest extends TestCase
 {
diff --git a/unit-test/include/class/todo_list.Test.php 
b/unit-test/include/class/todo_list.Test.php
index 73afe3218..a170d5bfb 100644
--- a/unit-test/include/class/todo_list.Test.php
+++ b/unit-test/include/class/todo_list.Test.php
@@ -32,7 +32,7 @@ use PHPUnit\Framework\TestCase;
  * @backupGlobals enabled
  * @coversDefaultClass \Todo_List
  */
-require 'global.php';
+require DIRTEST.'/global.php';
 
 class Todo_ListTest extends TestCase
 {
diff --git a/unit-test/include/class/userTest.php 
b/unit-test/include/class/userTest.php
index 6f07ccd1d..9f175ec03 100644
--- a/unit-test/include/class/userTest.php
+++ b/unit-test/include/class/userTest.php
@@ -14,7 +14,7 @@ define('USE_EMAIL', 'none@dev.null.eu');
  * @backupGlobals enabled
  * @coversDefaultClass \User
  */
-require 'global.php';
+require DIRTEST.'/global.php';
 
 class UserTest extends TestCase
 {



reply via email to

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