[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Noalyss-commit] [noalyss] 12/20: Improve Unit Test for Report
From: |
dwm |
Subject: |
[Noalyss-commit] [noalyss] 12/20: Improve Unit Test for Report |
Date: |
Sun, 10 Dec 2023 03:22:24 -0500 (EST) |
sparkyx pushed a commit to branch master
in repository noalyss.
commit 2e294d2f97943335e5cdc80707c3a5d34d3a5468
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Tue Dec 5 15:24:01 2023 +0100
Improve Unit Test for Report
---
html/export.php | 1 +
include/class/acc_bilan.class.php | 8 +-
include/class/lettering.class.php | 2 +-
include/header_print.php | 4 +-
sql/upgrade.sql | 1 +
unit-test/create-dossier-test.sh | 2 +-
unit-test/dossier25.sql.gz | Bin 393280 -> 393280 bytes
unit-test/include/class/NoalyssUserTest.php | 10 +--
.../{acc_bilan.Test.php => acc_bilanTest.php} | 99 ++++++++++++++++++---
9 files changed, 102 insertions(+), 25 deletions(-)
diff --git a/html/export.php b/html/export.php
index dda4479b4..4c4443cca 100644
--- a/html/export.php
+++ b/html/export.php
@@ -35,6 +35,7 @@ require_once NOALYSS_INCLUDE .
'/class/noalyss_user.class.php';
require_once NOALYSS_INCLUDE.'/lib/http_input.class.php';
$gDossier=dossier::id();
$cn=Dossier::connect();
+$g_parameter=new Noalyss_Parameter_Folder($cn);
mb_internal_encoding("UTF-8");
$g_user=new Noalyss_user($cn);
$g_user->Check();
diff --git a/include/class/acc_bilan.class.php
b/include/class/acc_bilan.class.php
index e0b51d7df..d39780f54 100644
--- a/include/class/acc_bilan.class.php
+++ b/include/class/acc_bilan.class.php
@@ -229,7 +229,7 @@ class Acc_Bilan
where pcm_type=$1 or pcm_type=$2";
- $this->db->prepare("sqlAccount",$sqlAccount);
+ if ( ! $this->db->is_prepare("sqlAccount") )
$this->db->prepare("sqlAccount",$sqlAccount);
@@ -298,10 +298,12 @@ class Acc_Bilan
*/
function get_request_get()
{
- $g_parameter=new Noalyss_Parameter_Folder($this->db);
+ // $g_parameter=new Noalyss_Parameter_Folder($this->db);
+ global $g_parameter;
$http=new \HttpInput();
$this->b_id=$http->get("b_id","number","");
if ( $g_parameter->MY_REPORT=="Y") {
+
$this->from=$http->get("from_periode","number",-1);
$this->to=$http->get("to_periode","number",-1);
}else {
@@ -374,7 +376,7 @@ class Acc_Bilan
*/
function compute_formula($p_handle)
{
- $g_parameter=new Noalyss_Parameter_Folder($this->db);
+ global $g_parameter;
while (! feof ($p_handle))
{
$buffer=trim(fgets($p_handle));
diff --git a/include/class/lettering.class.php
b/include/class/lettering.class.php
index 924610eca..63e9a9a5c 100644
--- a/include/class/lettering.class.php
+++ b/include/class/lettering.class.php
@@ -54,7 +54,7 @@ class Lettering
* @param $p_init resource to database
* @note by default start and end are the 1.1.exercice to 31.12.exercice
*/
- function __construct(public $p_init)
+ function __construct( $p_init)
{
$this->db=$p_init;
$a=new Noalyss_user($p_init);
diff --git a/include/header_print.php b/include/header_print.php
index 90fb24b81..f4fe658bb 100644
--- a/include/header_print.php
+++ b/include/header_print.php
@@ -35,9 +35,7 @@ function header_txt($p_cn)
$date=date('d / m / Y H:i ');
$dossier=mb_convert_encoding(" Dossier :
".dossier::name(),'ISO-8859-1','UTF-8');
- // convert to latin1
- $dossier=iconv('UTF-8','ISO-8859-1//IGNORE',$str);
-
+
return $dossier." ".$soc." ".$date;
}
diff --git a/sql/upgrade.sql b/sql/upgrade.sql
index c1b424bb5..7d4f8e9d1 100644
--- a/sql/upgrade.sql
+++ b/sql/upgrade.sql
@@ -36,4 +36,5 @@ public.fiche_detail for each row execute function
comptaproc.fiche_detail_check_
update fiche_detail set ad_value=ad_value where ad_id in (select ad_id from
attr_def where ad_type='card');
+insert into parameter values ('MY_REPORT','N') ON CONFLICT DO NOTHING;
diff --git a/unit-test/create-dossier-test.sh b/unit-test/create-dossier-test.sh
index b7dab135f..a609f783b 100755
--- a/unit-test/create-dossier-test.sh
+++ b/unit-test/create-dossier-test.sh
@@ -11,5 +11,5 @@ if [ $? -ne 0 ] ; then
fi
createdb $DOSSIER_TEST
-psql $DOSSIER_TEST < db/$FILE_TEST
+psql -X $DOSSIER_TEST < db/$FILE_TEST
diff --git a/unit-test/dossier25.sql.gz b/unit-test/dossier25.sql.gz
index 13780fabf..a7b28e950 100644
Binary files a/unit-test/dossier25.sql.gz and b/unit-test/dossier25.sql.gz
differ
diff --git a/unit-test/include/class/NoalyssUserTest.php
b/unit-test/include/class/NoalyssUserTest.php
index 49cdd55ee..290c81677 100644
--- a/unit-test/include/class/NoalyssUserTest.php
+++ b/unit-test/include/class/NoalyssUserTest.php
@@ -6,7 +6,7 @@ define('USE_FIRST_NAME', 'Unit test');
define('USE_NAME', 'UNIT');
define('USE_LOGIN', 'unit-test');
define('USE_ACTIVE', 1);
-define('USE_PASS', md5('password'));
+define('USE_PASS', md5('password+123P'));
define('USE_ADMIN', 0);
define('USE_EMAIL', 'none@dev.null.eu');
@@ -16,7 +16,7 @@ define('USE_EMAIL', 'none@dev.null.eu');
*/
require DIRTEST.'/global.php';
-class UserTest extends TestCase
+class NoalyssUserTest extends TestCase
{
/**
@@ -151,12 +151,12 @@ class UserTest extends TestCase
$old_password=$this->object->getPassword();
$this->assertEquals(USE_PASS,$old_password,"Password mismatch");
-
$this->assertFalse($this->object->save_password("test1","test2"),"Passwords
must be identical");
-
$this->assertTrue($this->object->save_password("test2","test2"),"Identical
passwords seen as different");
+
$this->assertFalse($this->object->save_password("test1+T123","test2+T123"),"Passwords
must be identical");
+
$this->assertTrue($this->object->save_password("test2+T123","test2+T123"),"Identical
passwords seen as different");
$this->object->load();
$new_password = $this->object->getPassword();
$this->assertTrue(($old_password != $new_password),"Password not
changed old=$old_password new=$new_password");
-
$this->assertTrue($new_password=='ad0234829205b9033196ba818f7a872b',"Password
incorrect");
+
$this->assertTrue($new_password=='b37707c6d3d6a702aa7968b5f182772a',"Password
incorrect $new_password");
diff --git a/unit-test/include/class/acc_bilan.Test.php
b/unit-test/include/class/acc_bilanTest.php
similarity index 51%
rename from unit-test/include/class/acc_bilan.Test.php
rename to unit-test/include/class/acc_bilanTest.php
index e6394844a..72bd531b4 100644
--- a/unit-test/include/class/acc_bilan.Test.php
+++ b/unit-test/include/class/acc_bilanTest.php
@@ -41,20 +41,40 @@ class Acc_BilanTest extends TestCase
* @covers Acc_Bilan::display_form
* @todo Implement testDisplay_form().
*/
- public function testDisplay_form()
+ public function testDisplay_formReport()
{
+ global $g_parameter;
+ $g_parameter->MY_REPORT='Y';
$r=$this->object->display_form();
- $this->assertStringStartsWith('<input type="hidden" id="gDossier"
name="gDossier" value=',$r);
- $this->assertStringEndsWith('</TABLE>',$r);
-
+ $this->assertFalse(empty($r), "display_form must return a HTML
string");
+ $this->assertStringStartsWith('<input type="hidden" id="gDossier"
name="gDossier" value=',$r);
+ $this->assertStringEndsWith('</TABLE>',$r);
+
}
+ /**
+ * @covers Acc_Bilan::display_form
+ * @todo Implement testDisplay_form().
+ */
+ public function testDisplay_formNoReport()
+ {
+ global $g_parameter;
+ $g_parameter->MY_REPORT='N';
+ $r=$this->object->display_form();
+ $this->assertFalse(empty($r), "display_form must return a HTML
string");
+ $this->assertStringStartsWith('<input type="hidden" id="gDossier"
name="gDossier" value=',$r);
+ $this->assertStringEndsWith('</SELECT></p>',$r);
+ }
/**
* @covers Acc_Bilan::verify
* @todo Implement testVerify().
*/
- public function testVerify()
+ public function testVerifyNoReport()
{
+ global $g_parameter;
+ $g_parameter->MY_REPORT='N';
+ $this->object->from='01.01.2000';
+ $this->object->to='31.12.2024';
ob_start();
$this->object->verify();
$r=ob_get_contents();
@@ -62,13 +82,30 @@ class Acc_BilanTest extends TestCase
$this->assertStringStartsWith('<h3>',$r);
}
+ /**
+ * @covers Acc_Bilan::verify
+ * @todo Implement testVerify().
+ */
+ public function testVerifyReport()
+ {
+ global $g_parameter;
+ $g_parameter->MY_REPORT='Y';
+ ob_start();
+ $this->object->verify();
+ $r=ob_get_contents();
+ ob_end_clean();
+
+ $this->assertStringStartsWith('<h3>',$r);
+ }
/**
* @covers Acc_Bilan::get_request_get
* @todo Implement testGet_request_get().
*/
- public function testGet_request_get()
+ public function testGet_request_getReport()
{
+ global $g_parameter;
+ $g_parameter->MY_REPORT='Y';
$_GET['b_id']=111;
$_GET['from_periode']=95;
$_GET['to_periode']=100;
@@ -77,7 +114,22 @@ class Acc_BilanTest extends TestCase
$this->assertEquals($this->object->from,95);
$this->assertEquals($this->object->to,100);
}
-
+ /**
+ * @covers Acc_Bilan::get_request_get
+ * @todo Implement testGet_request_get().
+ */
+ public function testGet_request_getNoReport()
+ {
+ global $g_parameter;
+ $g_parameter->MY_REPORT='N';
+ $_GET['b_id']=111;
+ $_GET['from_periode']='01.01.2000';
+ $_GET['to_periode']='31.12.2024';
+ $this->object->get_request_get();
+ $this->assertEquals($this->object->b_id,111);
+ $this->assertEquals($this->object->from,'01.01.2000');
+ $this->assertEquals($this->object->to,'31.12.2024');
+ }
/**
* @covers Acc_Bilan::load
*/
@@ -123,25 +175,48 @@ class Acc_BilanTest extends TestCase
$this->assertTrue(FALSE);
}
}
+ /**
+ * @covers Acc_Bilan::compute_formula
+ */
+ public function testCompute_formulaReport()
+ {
+ global $g_parameter;
+ $g_parameter->MY_REPORT='Y';
+ $this->object->b_id=1;
+ $hFile=fopen("document/fr_be/bnb.form",'r');
+
+ $this->object->from=92;
+ $this->object->to=103;
+ $this->object->compute_formula($hFile);
+ $this->assertTrue(isset($this->object->C70),"Exist C70");
+ $this->assertTrue(isset($this->object->C60),"Exist C60");
+ $this->assertTrue(isset($this->object->C61),"Exist C61");
+ $this->assertEquals($this->object->C70,456.8);
+ $this->assertEquals($this->object->C60,0);
+ $this->assertEquals($this->object->C61,1468.33);
+
+ }
/**
* @covers Acc_Bilan::compute_formula
*/
- public function testCompute_formula()
+ public function testCompute_formulaNoReport()
{
+ global $g_parameter;
+ $g_parameter->MY_REPORT='N';
$this->object->b_id=1;
$hFile=fopen("document/fr_be/bnb.form",'r');
- $this->object->from=92;
- $this->object->to=103;
+ $this->object->from='01.01.2000';
+ $this->object->to='31.12.2024';
$this->object->compute_formula($hFile);
$this->assertTrue(isset($this->object->C70),"Exist C70");
$this->assertTrue(isset($this->object->C60),"Exist C60");
$this->assertTrue(isset($this->object->C61),"Exist C61");
- $this->assertEquals($this->object->C70,456.8);
+ $this->assertEquals($this->object->C70,4948.34);
$this->assertEquals($this->object->C60,0);
- $this->assertEquals($this->object->C61,1468.33);
+ $this->assertEquals($this->object->C61,10498.33);
}
- [Noalyss-commit] [noalyss] 17/20: PRINTGL Main Ledger (GL), (continued)
- [Noalyss-commit] [noalyss] 17/20: PRINTGL Main Ledger (GL), dwm, 2023/12/10
- [Noalyss-commit] [noalyss] 20/20: Fix merge issue, dwm, 2023/12/10
- [Noalyss-commit] [noalyss] 06/20: ergo, dwm, 2023/12/10
- [Noalyss-commit] [noalyss] 15/20: Improve DatabaseCore : fetch_all, dwm, 2023/12/10
- [Noalyss-commit] [noalyss] 10/20: Merge master, dwm, 2023/12/10
- [Noalyss-commit] [noalyss] 07/20: Update link to https://www.noalyss.eu instead of http, dwm, 2023/12/10
- [Noalyss-commit] [noalyss] 03/20: Documentation, dwm, 2023/12/10
- [Noalyss-commit] [noalyss] 09/20: Protect Qcode in fiche_detail, dwm, 2023/12/10
- [Noalyss-commit] [noalyss] 04/20: PHP8.2 deprecated, dwm, 2023/12/10
- [Noalyss-commit] [noalyss] 14/20: Improve DBG , add stopwatch : timer_start and timer_show, dwm, 2023/12/10
- [Noalyss-commit] [noalyss] 12/20: Improve Unit Test for Report,
dwm <=