|
|
|
|
@ -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());
|
|
|
|
|
|