Task #0002126: Fiche : amélioration
This commit is contained in:
parent
ad125d0321
commit
55f9dd9a73
5 changed files with 230 additions and 18 deletions
176
unit-test/include/class/contactTest.php
Normal file
176
unit-test/include/class/contactTest.php
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* * Copyright (C) 2022 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 test the class Contact
|
||||
*/
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @backupGlobals enabled
|
||||
* @coversDefaultClass \Contact
|
||||
*/
|
||||
require 'global.php';
|
||||
|
||||
class ContactTest 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():void
|
||||
{
|
||||
include 'global.php';
|
||||
$this->object = new stdClass();
|
||||
$this->object->fiche_def=0;
|
||||
$this->object->card_to_clean=array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test method is executed.
|
||||
*/
|
||||
protected function tearDown():void
|
||||
{
|
||||
include 'global.php';
|
||||
$sql=new ArrayObject();
|
||||
$sql->append("delete from fiche_detail where f_id in (select f_id from fiche where fd_id = $1 )");
|
||||
$sql->append("delete from fiche where f_id not in (select f_id from fiche_detail where $1=$1)");
|
||||
$sql->append("delete from jnt_fic_attr where fd_id = $1 ");
|
||||
$sql->append("delete from fiche_def where fd_id = $1");
|
||||
foreach ($sql as $s) {
|
||||
$g_connection->exec_sql($s,[$this->object->fiche_def->id]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* the setUpBeforeClass() template methods is called before the first test of the test case
|
||||
* class is run
|
||||
*/
|
||||
public static function setUpBeforeClass():void
|
||||
{
|
||||
// include 'global.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* tearDownAfterClass() template methods is calleafter the last test of the test case class is run,
|
||||
*
|
||||
*/
|
||||
static function tearDownAfterClass():void
|
||||
{
|
||||
// include 'global.php';
|
||||
}
|
||||
//
|
||||
// public function dataExample()
|
||||
// {
|
||||
// return array([1], [2], [3]);
|
||||
// }
|
||||
|
||||
/**
|
||||
* a. create contact category
|
||||
*/
|
||||
public function createContact()
|
||||
{
|
||||
include_once 'global.php';
|
||||
|
||||
global $g_connection;
|
||||
// create a category of card, type Charges
|
||||
$fiche_def=new Fiche_Def($g_connection);
|
||||
$aParam=["nom_mod"=>"Test.Contact",
|
||||
"fd_description"=>'PHPUNIT test', 'class_base'=>'', 'FICHE_REF'=>16,
|
||||
'create'=>'off'];
|
||||
$this->assertEquals($fiche_def->id, 0, 'Before created');
|
||||
|
||||
$fiche_def->add($aParam);
|
||||
$this->assertLessThan($fiche_def->id, 0, 'After created');
|
||||
|
||||
$this->assertEquals($g_connection->get_value("select count(*)
|
||||
from fiche_def where fd_id=$1", [$fiche_def->id]),
|
||||
1, "Category not created");
|
||||
$this->object->fiche_def=$fiche_def;
|
||||
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @dataProvider dataContactCard
|
||||
* @param array $p_param
|
||||
*/
|
||||
public function createContactCard()
|
||||
{
|
||||
global $g_connection;
|
||||
if ( $this->object->fiche_def == 0) {
|
||||
$this->createContact();
|
||||
}
|
||||
$aName=array();
|
||||
// Available fd_id for supplier or customer = 25 21 22 31 32
|
||||
$aName[]=['name'=>'Chantal','company'=>'CLIENT'];
|
||||
$aName[]=['name'=>'Pierre','company'=>'CLIENT'];
|
||||
$aName[]=['name'=>'William','company'=>'FOURNI'];
|
||||
$aName[]=['name'=>'Daniel','company'=>'FOURNI'];
|
||||
$aName[]=['name'=>'Geert','company'=>'FOURNI'];
|
||||
foreach ($aName as $param ) {
|
||||
$fiche=new Fiche($g_connection);
|
||||
$fiche->fiche_def=$this->object->fiche_def->id;
|
||||
$fiche->load();
|
||||
$fiche->setAttribut(ATTR_DEF_NAME, $param['name']);
|
||||
$fiche->setAttribut(ATTR_DEF_COMPANY, $param['company']);
|
||||
$fiche->insert($fiche->fiche_def,$fiche->to_array());
|
||||
$this->object->card_to_clean[]=$fiche->id;
|
||||
printf("Card to clean %s ",$fiche->id);
|
||||
}
|
||||
$this->assertTrue(count($aName) == count($this->object->card_to_clean),"Not all contact created");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* @testdox Contact Summary
|
||||
*/
|
||||
public function testSummary()
|
||||
{
|
||||
global $g_connection;
|
||||
if ( $this->object->fiche_def == 0) {
|
||||
$this->createContactCard();
|
||||
}
|
||||
$contact=new Contact($g_connection);
|
||||
$_SERVER['REQUEST_URI']="?";
|
||||
$_SERVER['PHP_SELF']=__FILE__;
|
||||
$r=$contact->summary();
|
||||
$this->assertEquals(count($this->object->card_to_clean)*2 , substr_count($r,'fill_ipopcard')," 1. Missing card");
|
||||
$contact->company=' fourni ';
|
||||
$r=$contact->summary();
|
||||
$this->assertEquals(6, substr_count($r,'fill_ipopcard') , 'not found all the contacts from FOURNI');
|
||||
$r=$contact->summary('william');
|
||||
$this->assertEquals(2, substr_count($r,'fill_ipopcard') , 'Search does not filter');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -244,6 +244,11 @@ class FicheTest extends TestCase
|
|||
$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->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");
|
||||
$this->assertEquals($fiche_2->getName(), "Marchandise1", "Retrieve name from db");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -700,4 +705,31 @@ where
|
|||
$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->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);
|
||||
$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());
|
||||
|
||||
// reload the card !!
|
||||
$fiche_target->load();
|
||||
|
||||
$this->assertTrue("AAAAAA"==$fiche_target->strAttribut(23),"Update Quick code format not correct");
|
||||
|
||||
$fiche->delete();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue