Add new PHP Unit file

This commit is contained in:
sparkyx 2021-12-06 18:56:16 +01:00
parent fc3c1057e3
commit 613360befe
5 changed files with 662 additions and 0 deletions

View file

@ -0,0 +1,132 @@
<?php
/*
* * Copyright (C) 2021 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
*/
use PHPUnit\Framework\TestCase;
/**
* @backupGlobals enabled
* @coversDefaultClass \Follow_Up_Detail
*/
require 'global.php';
class Follow_Up_DetailTest 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()
{
include 'global.php';
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test method is executed.
*/
protected function tearDown()
{
}
/**
* the setUpBeforeClass() template methods is called before the first test of the test case
* class is run
*/
public static function setUpBeforeClass()
{
global $g_connection;
$g_connection->exec_sql('delete from action_detail');
}
/**
* tearDownAfterClass() template methods is calleafter the last test of the test case class is run,
*
*/
static function tearDownAfterClass()
{
// include 'global.php';
}
private function insert(Follow_Up_Detail $pFollow_Detail)
{
$pFollow_Detail->set_parameter("qcode", 23);
$pFollow_Detail->set_parameter("text" ,"Marchandise 1");
$pFollow_Detail->set_parameter("price_unit",5.30);
$pFollow_Detail->set_parameter("quantity",12);
$pFollow_Detail->set_parameter("tva_id",null);
$pFollow_Detail->set_parameter("tva_amount", 0);
$pFollow_Detail->set_parameter("total", 63.6);
$pFollow_Detail->set_parameter("ag_id", 1);
$pFollow_Detail->insert();
}
/**
* @brief test insert, load , delete
* @testdox insert into action_detail
* @covers ::insert ::delete ::load
*/
public function testSQL_Insert()
{
global $g_connection;
$obj=new Follow_Up_Detail($g_connection);
$this->insert($obj);
$this->assertTrue($obj->get_parameter("id")>0,"Cannot insert");
$obj->delete();
$this->assertFalse($obj->load(),"Cannot delete");
}
/**
* @brief test update, load , insert, delete
* @testdox update into action_detail
* @covers ::insert ::delete ::load
*/
public function testSQL_Update()
{
global $g_connection;
$obj=new Follow_Up_Detail($g_connection);
$this->insert($obj);
$this->assertTrue($obj->get_parameter("id")>0,"Cannot insert");
$obj->set_parameter('text','TEST UPDATE');
$obj->save();
$reload=new Follow_Up_Detail($g_connection,$obj->get_parameter("id"));
$reload->load();
$this->assertTrue($reload->get_parameter("text") == $obj->get_parameter("text"),"cannot update");
$reload->delete();
$this->assertFalse($reload->load(),"Cannot delete");
}
}

View file

@ -0,0 +1,128 @@
<?php
/*
* * Copyright (C) 2021 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
*/
use PHPUnit\Framework\TestCase;
/**
* @backupGlobals enabled
* @coversDefaultClass \Forecast
*/
require 'global.php';
class ForecastTest 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()
{
include 'global.php';
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test method is executed.
*/
protected function tearDown()
{
}
/**
* the setUpBeforeClass() template methods is called before the first test of the test case
* class is run
*/
public static function setUpBeforeClass()
{
include 'global.php';
global $g_connection;
$g_connection->exec_sql('delete from forecast');
}
/**
* tearDownAfterClass() template methods is calleafter the last test of the test case class is run,
*
*/
static function tearDownAfterClass()
{
// include 'global.php';
}
/**
* @brief test insert, load , delete
* @testdox insert into forecast
* @covers ::insert ::delete ::load
*/
public function testSQL_Insert()
{
global $g_connection;
$obj=new Forecast($g_connection);
$obj->set_parameter("start_date", 111);
$obj->set_parameter("end_date", 116);
$obj->set_parameter("name","PhpUNIT 2014");
$obj->insert();
$this->assertTrue($obj->get_parameter("id")>0,"Cannot insert");
$obj->delete();
$this->assertFalse($obj->load(),"Cannot delete");
}
/**
* @brief test update, load , insert, delete
* @testdox update into forecast
* @covers ::insert ::delete ::load
*/
public function testSQL_Update()
{
global $g_connection;
$obj=new Forecast($g_connection);
$obj->set_parameter("start_date", 111);
$obj->set_parameter("end_date", 116);
$obj->set_parameter("name", "PhpUNIT 2014");
$obj->insert();
$this->assertTrue($obj->get_parameter("id")>0,"Cannot insert");
$obj->set_parameter('name','TEST UPDATE');
$obj->save();
$reload=new Forecast($g_connection,$obj->get_parameter("id"));
$reload->load();
$this->assertTrue($reload->get_parameter("name") == $obj->get_parameter("name"),"cannot update");
$reload->delete();
$this->assertFalse($reload->load(),"Cannot delete");
}
}

View file

@ -0,0 +1,187 @@
<?php
/*
* * Copyright (C) 2021 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
*/
use PHPUnit\Framework\TestCase;
/**
* @backupGlobals enabled
*/
require 'global.php';
class PeriodeTest 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()
{
include 'global.php';
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test method is executed.
*/
protected function tearDown()
{
}
/**
* the setUpBeforeClass() template methods is called before the first test of the test case
* class is run
*/
public static function setUpBeforeClass()
{
// include 'global.php';
}
/**
* tearDownAfterClass() template methods is calleafter the last test of the test case class is run,
*
*/
static function tearDownAfterClass()
{
// include 'global.php';
}
public function dataInsert()
{
return array(
[ '01.01.2023' , '31.01.2023','2020','2020.2023','NOK'],
[ '01.01.2023' , '31.01.2023','2023','2020.2023','OK'],
[ '01.02.2023' , '28.02.2023','2020','2020.2023','NOK'],
[ '01.02.2023' , '28.02.2023','2023','2020.2023','OK'],
[ '01.02.2023' , '28.01.2023','2023','2020.2023','NOK']
);
}
/**
* @brief test the trigger comptaproc.check_periode()
* @testdox insert - comptaproc.check_periode
* @dataProvider dataInsert
* @param type $p_param
* @covers
*/
public function testInsert($p_start,$p_end,$p_exercice,$p_exercice_label,$p_status)
{
global $g_connection;
$g_connection->exec_sql("delete from parm_periode where p_id > 144");
$obj=new Parm_periode_SQL($g_connection);
$obj->set('p_start',$p_start);
$obj->set('p_end',$p_end);
$obj->set('p_closed',false);
$obj->set('p_central',false);
$obj->set('p_exercice',$p_exercice);
$obj->set('p_exercice_label',$p_exercice_label);
try {
$obj->insert();
if ($p_status== 'OK') {
$this->assertTrue(True,"Expected");
} else {
$this->assertTrue(FALSE,"Error");
}
} catch(Exception $e) {
if ($p_status == 'NOK') {
$this->assertTrue(True,"Expected");
} else {
$this->assertTrue(FALSE,"Error");
printf("message : %s",$e->getMessage());
}
}
$g_connection->exec_sql("delete from parm_periode where p_id > 144");
}
public function dataUpdate()
{
return array(
[ '01.01.2023' , '31.01.2023','2020','2020.2023','NOK'],
[ '01.01.2023' , '31.01.2023','2023','2020.2023','OK'],
[ '01.02.2023' , '28.02.2023','2020','2020.2023','NOK'],
[ '01.02.2023' , '28.02.2023','2023','2020.2023','OK'],
[ '01.02.2023' , '28.01.2023','2023','2020.2023','NOK']
);
}
/**
* @brief test the trigger comptaproc.check_periode()
* @testdox update - comptaproc.check_periode
* @dataProvider dataInsert
*
*
*/
public function testUpdate($p_start,$p_end,$p_exercice,$p_exercice_label,$p_status)
{
global $g_connection;
/* insert the record to update */
$g_connection->exec_sql("delete from parm_periode where p_exercice =$1",["2024-PHPUNIT"]);
$obj=new Parm_periode_SQL($g_connection);
$obj->set('p_start','01.01.2024');
$obj->set('p_end','31.01.2024');
$obj->set('p_closed',false);
$obj->set('p_central',false);
$obj->set('p_exercice','2024');
$obj->set('p_exercice_label',"2024-PHPUNIT");
try {
$obj->insert();
$obj->set('p_start',$p_start);
$obj->set('p_end',$p_end);
$obj->set('p_closed',false);
$obj->set('p_central',false);
$obj->set('p_exercice',$p_exercice);
$obj->set('p_exercice_label',$p_exercice_label);
$obj->update();
if ($p_status== 'OK') {
$this->assertTrue(True,"Expected");
} else {
$this->assertTrue(FALSE,"Error");
}
} catch(Exception $e) {
if ($p_status == 'NOK') {
$this->assertTrue(True,"Expected");
} else {
$this->assertTrue(FALSE,"Error");
printf("message : %s",$e->getMessage());
}
}
$g_connection->exec_sql("delete from parm_periode where p_exercice =$1",["2024-PHPUNIT"]);
}
}

View file

@ -0,0 +1,141 @@
<?php
/*
* * Copyright (C) 2021 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
*/
use PHPUnit\Framework\TestCase;
/**
* @backupGlobals enabled
* @coversDefaultClass \Todo_List
*/
require 'global.php';
class Todo_ListTest 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()
{
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test method is executed.
*/
protected function tearDown()
{
}
/**
* the setUpBeforeClass() template methods is called before the first test of the test case
* class is run
*/
public static function setUpBeforeClass()
{
require 'global.php';
global $g_connection;
$g_connection->exec_sql("delete from todo_list");
$g_connection->exec_sql("alter sequence todo_list_tl_id_seq restart with 1000");
$g_connection->exec_sql("INSERT INTO todo_list (tl_id,tl_date,tl_title,tl_desc,use_login,is_public)
VALUES
(1,'2018-02-24','TVA','Déclaration TVA',$1,'N'),
(2,'2019-02-28','Test PHPUNIT','Test PHPUNIST',$1,'Y'),
(3,'2014-03-14','PhpUNit 2','Second test',$1,'N'),
(4,'2017-06-24','PhpUnit 3','Déclaration TVA',$1,'N'),
(5,'2016-06-18','PhpUNit 4','4 test',$1,'N');",array($_SESSION[SESSION_KEY.'g_user'] ));
}
/**
* @brief
* @testdox Test load, load_all , delete, insert , update
* @param type $p_param
*s @covers
*/
public function test_SQLStmt()
{
global $g_connection;
$obj=new Todo_List($g_connection);
$obj->set_parameter("id", 3);
$obj->load();
$this->assertEquals('14.03.2014',$obj->get_parameter("date"),"Wrong record");
$obj->set_parameter("id", 5);
$obj->load();
$this->assertEquals('18.06.2016',$obj->get_parameter("date"),"Wrong record");
$a_todo_list=$obj->load_all();
$this->assertEquals(5,count($a_todo_list),"Wrong number of rows");
foreach ($a_todo_list as $todo_list) {
$idx=$todo_list["tl_id"];
$date=$todo_list["tl_date"];
if ( $idx==1) {
$this->assertEquals('24.02.2018',$date,"Wrong date [$date]" );
}elseif ($idx==2)
{
$this->assertEquals('28.02.2019',$date,"Wrong date [$date]" );
}
}
$obj->delete();
$this->assertEquals(false,$obj->load(),"Not deleted");
$obj=new Todo_List($g_connection);
$obj->set_parameter("id", 1);
$obj->load();
$obj2=clone $obj;
$obj2->set_parameter("id",0);
$obj2->insert();
$obj3=new Todo_List($g_connection);
$obj3->set_parameter("id", $obj2->get_parameter("id"));
$this->assertEquals(true,$obj3->load(),"Not inserted");
$obj3->set_parameter("title","PHPUNIT-TITLE");
$obj3->save();
$obj4=new Todo_List($g_connection);
$obj4->set_parameter("id", $obj2->get_parameter("id"));
$obj4->load();
$this->assertEquals("PHPUNIT-TITLE",$obj4->get_parameter("title"),"not Updated");
$g_connection->exec_sql("delete from todo_list");
}
}

View file

@ -0,0 +1,74 @@
<?php
/*
* 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-2021) Author Dany De Bontridder <danydb@noalyss.eu>
/**
* @file
* @brief Test DabaseCore
*/
use PHPUnit\Framework\TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator on 2016-02-11 at 15:41:40.
*/
class DatabaseCoreTest extends TestCase
{
/**
* @var Database
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$noalyss_user = (defined("noalyss_user")) ? noalyss_user : phpcompta_user;
$password = (defined("noalyss_password")) ? noalyss_password : phpcompta_password;
$port = (defined("noalyss_psql_port")) ? noalyss_psql_port : phpcompta_psql_port;
$host = (!defined("noalyss_psql_host")) ? '127.0.0.1' : noalyss_psql_host;
$this->object=new DatabaseCore($noalyss_user, $password, sprintf("%sdossier%s",domaine,DOSSIER), $host, $port);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
*
*/
public function testExec_SQL()
{
$this->assertEquals(DBVERSION,$this->object->get_value("select max(val) from version"),"check Version");
$this->assertTrue(true,$this->object->get_is_open(),"Database open");
}
}