Qual: Add new PHPUnit test and fix bugs the test show me
This commit is contained in:
parent
fc18414228
commit
ab6c1a5160
@ -1,36 +1,34 @@
|
||||
<?php
|
||||
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
|
||||
* Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
|
||||
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
* Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
|
||||
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/compta/bank/class/account.class.php
|
||||
* \ingroup banque
|
||||
* \brief File of class to manage bank accounts
|
||||
*/
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php");
|
||||
|
||||
|
||||
/**
|
||||
* \class Account
|
||||
* \brief Class to manage bank accounts
|
||||
* Class to manage bank accounts
|
||||
*/
|
||||
class Account extends CommonObject
|
||||
{
|
||||
@ -46,7 +44,7 @@ class Account extends CommonObject
|
||||
//! Name
|
||||
var $bank;
|
||||
var $clos;
|
||||
var $rappro; // If bank need to be conciliated
|
||||
var $rappro=1; // If bank need to be conciliated
|
||||
var $url;
|
||||
//! BBAN field for French Code banque
|
||||
var $code_banque;
|
||||
@ -266,12 +264,12 @@ class Account extends CommonObject
|
||||
// Check parameters
|
||||
if (! $oper)
|
||||
{
|
||||
$this->error="Account::addline oper not defined";
|
||||
$this->error="oper not defined";
|
||||
return -1;
|
||||
}
|
||||
if (! $this->rowid)
|
||||
{
|
||||
$this->error="Account::addline this->rowid not defined";
|
||||
$this->error="this->rowid not defined";
|
||||
return -2;
|
||||
}
|
||||
if ($this->courant == 2 && $oper != 'LIQ')
|
||||
@ -309,7 +307,7 @@ class Account extends CommonObject
|
||||
$sql.= ", ".($banque?"'".$this->db->escape($banque)."'":"null");
|
||||
$sql.= ")";
|
||||
|
||||
dol_syslog("Account::addline sql=".$sql);
|
||||
dol_syslog(get_class($this)."::addline sql=".$sql);
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
$rowid = $this->db->last_insert_id(MAIN_DB_PREFIX."bank");
|
||||
@ -337,7 +335,7 @@ class Account extends CommonObject
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("Account::addline ".$this->error, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::addline ".$this->error, LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
@ -353,19 +351,29 @@ class Account extends CommonObject
|
||||
{
|
||||
global $langs,$conf;
|
||||
|
||||
// Check parameters
|
||||
// Clean parameters
|
||||
if (! $this->min_allowed) $this->min_allowed=0;
|
||||
if (! $this->min_desired) $this->min_desired=0;
|
||||
if (empty($this->fk_pays))
|
||||
$this->state_id = ($this->state_id?$this->state_id:$this->fk_departement);
|
||||
$this->country_id = ($this->country_id?$this->country_id:$this->fk_pays);
|
||||
|
||||
// Check parameters
|
||||
if (empty($this->country_id))
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Country"));
|
||||
dol_syslog("Account::update ".$this->error, LOG_ERR);
|
||||
$this->error=$langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Country"));
|
||||
dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
if (empty($this->ref))
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref"));
|
||||
dol_syslog("Account::update ".$this->error, LOG_ERR);
|
||||
$this->error=$langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref"));
|
||||
dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
if (empty($this->date_solde))
|
||||
{
|
||||
$this->error=$langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("DateInitialBalance"));
|
||||
dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -398,43 +406,48 @@ class Account extends CommonObject
|
||||
$sql.= ", ".price2num($this->min_allowed);
|
||||
$sql.= ", ".price2num($this->min_desired);
|
||||
$sql.= ", '".$this->db->escape($this->comment)."'";
|
||||
$sql.= ", ".($this->fk_departement>0?"'".$this->fk_departement."'":"null");
|
||||
$sql.= ", ".$this->fk_pays;
|
||||
$sql.= ", ".($this->state_id>0?"'".$this->state_id."'":"null");
|
||||
$sql.= ", ".$this->country_id;
|
||||
$sql.= ")";
|
||||
|
||||
dol_syslog("Account::create sql=".$sql);
|
||||
dol_syslog(get_class($this)."::create sql=".$sql);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($this->db->affected_rows($resql))
|
||||
{
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_account");
|
||||
if ( $this->update() )
|
||||
{
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (";
|
||||
$sql.= "datec";
|
||||
$sql.= ", label";
|
||||
$sql.= ", amount";
|
||||
$sql.= ", fk_account";
|
||||
$sql.= ", datev";
|
||||
$sql.= ", dateo";
|
||||
$sql.= ", fk_type";
|
||||
$sql.= ", rappro";
|
||||
$sql.= ") VALUES (";
|
||||
$sql.= $this->db->idate($now);
|
||||
$sql.= ", '(".$langs->trans("InitialBankBalance").")'";
|
||||
$sql.= ", ".price2num($this->solde);
|
||||
$sql.= ", '".$this->id."'";
|
||||
$sql.= ", '".$this->db->idate($this->date_solde)."'";
|
||||
$sql.= ", '".$this->db->idate($this->date_solde)."'";
|
||||
$sql.= ", 'SOLD'";
|
||||
$sql.= ", 0"; // Not conciliated by default
|
||||
$sql.= ")";
|
||||
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_account");
|
||||
|
||||
$this->db->query($sql);
|
||||
$result=$this->update();
|
||||
if ($result > 0)
|
||||
{
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (";
|
||||
$sql.= "datec";
|
||||
$sql.= ", label";
|
||||
$sql.= ", amount";
|
||||
$sql.= ", fk_account";
|
||||
$sql.= ", datev";
|
||||
$sql.= ", dateo";
|
||||
$sql.= ", fk_type";
|
||||
$sql.= ", rappro";
|
||||
$sql.= ") VALUES (";
|
||||
$sql.= "'".$this->db->idate($now)."'";
|
||||
$sql.= ", '(".$langs->trans("InitialBankBalance").")'";
|
||||
$sql.= ", ".price2num($this->solde);
|
||||
$sql.= ", '".$this->id."'";
|
||||
$sql.= ", '".$this->db->idate($this->date_solde)."'";
|
||||
$sql.= ", '".$this->db->idate($this->date_solde)."'";
|
||||
$sql.= ", 'SOLD'";
|
||||
$sql.= ", 0"; // Not conciliated by default
|
||||
$sql.= ")";
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
if (! $resql)
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog($this->error, LOG_ERR);
|
||||
return -3;
|
||||
}
|
||||
return $this->id;
|
||||
}
|
||||
return $this->id;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -462,19 +475,23 @@ class Account extends CommonObject
|
||||
{
|
||||
global $langs,$conf;
|
||||
|
||||
// Check parameters
|
||||
// Clean parameters
|
||||
if (! $this->min_allowed) $this->min_allowed=0;
|
||||
if (! $this->min_desired) $this->min_desired=0;
|
||||
if (empty($this->fk_pays))
|
||||
$this->state_id = ($this->state_id?$this->state_id:$this->fk_departement);
|
||||
$this->country_id = ($this->country_id?$this->country_id:$this->fk_pays);
|
||||
|
||||
// Check parameters
|
||||
if (empty($this->country_id))
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Country"));
|
||||
dol_syslog("Account::update ".$this->error, LOG_ERR);
|
||||
$this->error=$langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Country"));
|
||||
dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
if (empty($this->ref))
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref"));
|
||||
dol_syslog("Account::update ".$this->error, LOG_ERR);
|
||||
$this->error=$langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->transnoentitiesnoconv("Ref"));
|
||||
dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
if (! $this->label) $this->label = "???";
|
||||
@ -496,13 +513,13 @@ class Account extends CommonObject
|
||||
$sql.= ",min_desired = '".price2num($this->min_desired)."'";
|
||||
$sql.= ",comment = '".$this->db->escape($this->comment)."'";
|
||||
|
||||
$sql.= ",fk_departement = ".($this->fk_departement>0?"'".$this->fk_departement."'":"null");
|
||||
$sql.= ",fk_pays = ".$this->fk_pays;
|
||||
$sql.= ",fk_departement = ".($this->state_id>0?"'".$this->state_id."'":"null");
|
||||
$sql.= ",fk_pays = ".$this->country_id;
|
||||
|
||||
$sql.= " WHERE rowid = ".$this->id;
|
||||
$sql.= " AND entity = ".$conf->entity;
|
||||
|
||||
dol_syslog("Account::update sql=".$sql);
|
||||
dol_syslog(get_class($this)."::update sql=".$sql);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
@ -527,15 +544,19 @@ class Account extends CommonObject
|
||||
{
|
||||
global $conf,$langs;
|
||||
|
||||
// Clean parameters
|
||||
$this->state_id = ($this->state_id?$this->state_id:$this->fk_departement);
|
||||
$this->country_id = ($this->country_id?$this->country_id:$this->fk_pays);
|
||||
|
||||
// Chargement librairie pour acces fonction controle RIB
|
||||
require_once(DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php');
|
||||
|
||||
dol_syslog("Account::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
|
||||
dol_syslog(get_class($this)."::update_bban $this->code_banque,$this->code_guichet,$this->number,$this->cle_rib,$this->iban");
|
||||
|
||||
// Check parameters
|
||||
if (! $this->ref)
|
||||
{
|
||||
$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("Ref"));
|
||||
$this->error=$langs->transnoentitiesnoconv("ErrorFieldRequired",$langs->trans("Ref"));
|
||||
return -2;
|
||||
}
|
||||
|
||||
@ -550,12 +571,12 @@ class Account extends CommonObject
|
||||
$sql.= ",domiciliation='".$this->db->escape($this->domiciliation)."'";
|
||||
$sql.= ",proprio = '".$this->db->escape($this->proprio)."'";
|
||||
$sql.= ",adresse_proprio = '".$this->db->escape($this->adresse_proprio)."'";
|
||||
$sql.= ",fk_departement = ".($this->fk_departement>0?"'".$this->fk_departement."'":"null");
|
||||
$sql.= ",fk_pays = ".$this->fk_pays;
|
||||
$sql.= ",fk_departement = ".($this->state_id>0?"'".$this->state_id."'":"null");
|
||||
$sql.= ",fk_pays = ".$this->country_id;
|
||||
$sql.= " WHERE rowid = ".$this->id;
|
||||
$sql.= " AND entity = ".$conf->entity;
|
||||
|
||||
dol_syslog("Account::update_bban sql=$sql");
|
||||
dol_syslog(get_class($this)."::update_bban sql=$sql");
|
||||
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
@ -603,7 +624,7 @@ class Account extends CommonObject
|
||||
if ($id) $sql.= " AND ba.rowid = ".$id;
|
||||
if ($ref) $sql.= " AND ba.ref = '".$this->db->escape($ref)."'";
|
||||
|
||||
dol_syslog("Account::fetch sql=".$sql);
|
||||
dol_syslog(get_class($this)."::fetch sql=".$sql);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
@ -979,6 +1000,8 @@ class Account extends CommonObject
|
||||
*/
|
||||
function initAsSpecimen()
|
||||
{
|
||||
$this->ref = 'MBA';
|
||||
$this->label = 'My Bank account';
|
||||
$this->bank = 'MyBank';
|
||||
$this->courant = 1;
|
||||
$this->clos = 0;
|
||||
@ -992,6 +1015,7 @@ class Account extends CommonObject
|
||||
$this->domiciliation = 'The bank addresse';
|
||||
$this->proprio = 'Owner';
|
||||
$this->adresse_proprio = 'Owner address';
|
||||
$this->country_id = 1;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1067,7 +1091,7 @@ class AccountLine extends CommonObject
|
||||
else if ($ref) $sql.= " AND b.rowid='".$ref."'";
|
||||
else $sql.= " AND b.rowid=".$rowid;
|
||||
|
||||
dol_syslog("AccountLine::fetch sql=".$sql);
|
||||
dol_syslog(get_class($this)."::fetch sql=".$sql);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
{
|
||||
@ -1137,12 +1161,12 @@ class AccountLine extends CommonObject
|
||||
}
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid=".$this->rowid;
|
||||
dol_syslog("AccountLine::delete sql=".$sql);
|
||||
dol_syslog(get_class($this)."::delete sql=".$sql);
|
||||
$result = $this->db->query($sql);
|
||||
if (! $result) $nbko++;
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank WHERE rowid=".$this->rowid;
|
||||
dol_syslog("AccountLine::delete sql=".$sql);
|
||||
dol_syslog(get_class($this)."::delete sql=".$sql);
|
||||
$result = $this->db->query($sql);
|
||||
if (! $result) $nbko++;
|
||||
|
||||
@ -1179,7 +1203,7 @@ class AccountLine extends CommonObject
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url WHERE fk_bank=".$this->rowid;
|
||||
dol_syslog("AccountLine::delete_urls sql=".$sql);
|
||||
dol_syslog(get_class($this)."::delete_urls sql=".$sql);
|
||||
$result = $this->db->query($sql);
|
||||
if (! $result) $nbko++;
|
||||
|
||||
@ -1213,7 +1237,7 @@ class AccountLine extends CommonObject
|
||||
$sql.= " dateo='".$this->db->idate($this->dateo)."'";
|
||||
$sql.= " WHERE rowid = ".$this->rowid;
|
||||
|
||||
dol_syslog("AccountLine::update sql=".$sql);
|
||||
dol_syslog(get_class($this)."::update sql=".$sql);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
@ -1224,7 +1248,7 @@ class AccountLine extends CommonObject
|
||||
{
|
||||
$this->db->rollback();
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("AccountLine::update ".$this->error, LOG_ERR);
|
||||
dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -1247,7 +1271,7 @@ class AccountLine extends CommonObject
|
||||
$sql.= ", fk_user_rappro = ".$user->id;
|
||||
$sql.= " WHERE rowid = ".$this->id;
|
||||
|
||||
dol_syslog("AccountLine::update_conciliation sql=".$sql, LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::update_conciliation sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
@ -1261,7 +1285,7 @@ class AccountLine extends CommonObject
|
||||
$sql.= ", ".$cat;
|
||||
$sql.= ")";
|
||||
|
||||
dol_syslog("AccountLine::update_conciliation sql=".$sql, LOG_DEBUG);
|
||||
dol_syslog(get_class($this)."::update_conciliation sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
// No error check. Can fail if category already affected
|
||||
|
||||
@ -263,19 +263,19 @@ class Facture extends CommonObject
|
||||
// On recupere les differents contact interne et externe
|
||||
$order = new Commande($this->db);
|
||||
$order->id = $origin_id;
|
||||
|
||||
|
||||
// On recupere le commercial suivi propale
|
||||
$this->userid = $order->getIdcontact('internal', 'SALESREPFOLL');
|
||||
|
||||
|
||||
if ($this->userid)
|
||||
{
|
||||
//On passe le commercial suivi commande en commercial suivi paiement
|
||||
$this->add_contact($this->userid[0], 'SALESREPFOLL', 'internal');
|
||||
}
|
||||
|
||||
|
||||
// On recupere le contact client facturation commande
|
||||
$this->contactid = $order->getIdcontact('external', 'BILLING');
|
||||
|
||||
|
||||
if ($this->contactid)
|
||||
{
|
||||
//On passe le contact client facturation commande en contact client facturation
|
||||
@ -674,7 +674,7 @@ class Facture extends CommonObject
|
||||
|
||||
$this->origin = $object->element;
|
||||
$this->origin_id = $object->id;
|
||||
|
||||
|
||||
// Possibility to add external linked objects with hooks
|
||||
$this->linked_objects[$this->origin] = $this->origin_id;
|
||||
if (is_array($object->other_linked_objects) && ! empty($object->other_linked_objects))
|
||||
@ -827,7 +827,7 @@ class Facture extends CommonObject
|
||||
$this->user_author = $obj->fk_user_author;
|
||||
$this->user_valid = $obj->fk_user_valid;
|
||||
$this->modelpdf = $obj->model_pdf;
|
||||
|
||||
|
||||
$this->extraparams = (array) json_decode($obj->extraparams, true);
|
||||
|
||||
if ($this->statut == 0) $this->brouillon = 1;
|
||||
@ -3073,6 +3073,7 @@ class Facture extends CommonObject
|
||||
$this->specimen=1;
|
||||
$this->socid = 1;
|
||||
$this->date = $nownotime;
|
||||
$this->date_lim_reglement = $nownotime + 3600 * 24 *30;
|
||||
$this->cond_reglement_id = 1;
|
||||
$this->cond_reglement_code = 'RECEP';
|
||||
$this->date_lim_reglement=$this->calculate_date_lim_reglement();
|
||||
|
||||
@ -723,29 +723,6 @@ class Project extends CommonObject
|
||||
|
||||
$now = mktime();
|
||||
|
||||
// Charge tableau des id de societe socids
|
||||
$socids = array();
|
||||
|
||||
$sql = "SELECT rowid";
|
||||
$sql.= " FROM " . MAIN_DB_PREFIX . "societe";
|
||||
$sql.= " WHERE client IN (1, 3)";
|
||||
$sql.= " AND entity = " . $conf->entity;
|
||||
$sql.= " LIMIT 10";
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num_socs = $this->db->num_rows($resql);
|
||||
$i = 0;
|
||||
while ($i < $num_socs)
|
||||
{
|
||||
$i++;
|
||||
|
||||
$row = $this->db->fetch_row($resql);
|
||||
$socids[$i] = $row[0];
|
||||
}
|
||||
}
|
||||
|
||||
// Charge tableau des produits prodids
|
||||
$prodids = array();
|
||||
|
||||
@ -772,7 +749,7 @@ class Project extends CommonObject
|
||||
$this->ref = 'SPECIMEN';
|
||||
$this->specimen = 1;
|
||||
$socid = rand(1, $num_socs);
|
||||
$this->socid = $socids[$socid];
|
||||
$this->socid = 1;
|
||||
$this->date_c = $now;
|
||||
$this->date_m = $now;
|
||||
$this->date_start = $now;
|
||||
|
||||
224
test/phpunit/BankAccount.php
Normal file
224
test/phpunit/BankAccount.php
Normal file
@ -0,0 +1,224 @@
|
||||
<?php
|
||||
/* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
*
|
||||
* 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, see <http://www.gnu.org/licenses/>.
|
||||
* or see http://www.gnu.org/
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file test/phpunit/ContratTest.php
|
||||
* \ingroup test
|
||||
* \brief PHPUnit test
|
||||
* \remarks To run this script as CLI: phpunit filename.php
|
||||
*/
|
||||
|
||||
global $conf,$user,$langs,$db;
|
||||
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
|
||||
require_once 'PHPUnit/Autoload.php';
|
||||
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
|
||||
require_once dirname(__FILE__).'/../../htdocs/compta/bank/class/account.class.php';
|
||||
|
||||
if (empty($user->id))
|
||||
{
|
||||
print "Load permissions for admin user nb 1\n";
|
||||
$user->fetch(1);
|
||||
$user->getrights();
|
||||
}
|
||||
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
|
||||
|
||||
$langs->load("main");
|
||||
|
||||
|
||||
/**
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
* @backupGlobals disabled
|
||||
* @backupStaticAttributes enabled
|
||||
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
|
||||
*/
|
||||
class BankAccountTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $savconf;
|
||||
protected $savuser;
|
||||
protected $savlangs;
|
||||
protected $savdb;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* We save global variables into local variables
|
||||
*
|
||||
* @return BankAccountTest
|
||||
*/
|
||||
function BankAccountTest()
|
||||
{
|
||||
//$this->sharedFixture
|
||||
global $conf,$user,$langs,$db;
|
||||
$this->savconf=$conf;
|
||||
$this->savuser=$user;
|
||||
$this->savlangs=$langs;
|
||||
$this->savdb=$db;
|
||||
|
||||
print __METHOD__." db->type=".$db->type." user->id=".$user->id;
|
||||
//print " - db ".$db->db;
|
||||
print "\n";
|
||||
}
|
||||
|
||||
// Static methods
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
|
||||
|
||||
print __METHOD__."\n";
|
||||
}
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$db->rollback();
|
||||
|
||||
print __METHOD__."\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Init phpunit tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
print __METHOD__."\n";
|
||||
}
|
||||
/**
|
||||
* End phpunit tests
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
print __METHOD__."\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* testContratCreate
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function testBankAccountCreate()
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$localobject=new Account($this->savdb);
|
||||
$localobject->initAsSpecimen();
|
||||
$localobject->date_solde=dol_now();
|
||||
$result=$localobject->create($user);
|
||||
|
||||
print __METHOD__." result=".$result."\n";
|
||||
$this->assertLessThan($result, 0);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* testContratFetch
|
||||
*
|
||||
* @param int $id Id of contract
|
||||
* @return int
|
||||
*
|
||||
* @depends testContratCreate
|
||||
* The depends says test is run only if previous is ok
|
||||
*/
|
||||
public function testBankAccountFetch($id)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$localobject=new Account($this->savdb);
|
||||
$result=$localobject->fetch($id);
|
||||
|
||||
print __METHOD__." id=".$id." result=".$result."\n";
|
||||
$this->assertLessThan($result, 0);
|
||||
|
||||
return $localobject;
|
||||
}
|
||||
|
||||
/**
|
||||
* testBankAccountFetch
|
||||
*
|
||||
* @param Object $localobject Object contract
|
||||
* @return int
|
||||
*
|
||||
* @depends testBankAccountOther
|
||||
* The depends says test is run only if previous is ok
|
||||
*/
|
||||
public function testBankAccountOther($localobject)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
/*$result=$localobject->setstatus(0);
|
||||
print __METHOD__." id=".$localobject->id." result=".$result."\n";
|
||||
$this->assertLessThan($result, 0);
|
||||
*/
|
||||
|
||||
$localobject->info($localobject->id);
|
||||
print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n";
|
||||
$this->assertNotEquals($localobject->date_creation, '');
|
||||
|
||||
return $localobject->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* testBankAccountDelete
|
||||
*
|
||||
* @param int $id Id of contract
|
||||
* @return int
|
||||
*
|
||||
* @depends testBankAccountOther
|
||||
* The depends says test is run only if previous is ok
|
||||
*/
|
||||
public function testBankAccountDelete($id)
|
||||
{
|
||||
global $conf,$user,$langs,$db;
|
||||
$conf=$this->savconf;
|
||||
$user=$this->savuser;
|
||||
$langs=$this->savlangs;
|
||||
$db=$this->savdb;
|
||||
|
||||
$localobject=new Account($this->savdb);
|
||||
$result=$localobject->fetch($id);
|
||||
$result=$localobject->delete($id);
|
||||
|
||||
print __METHOD__." id=".$id." result=".$result."\n";
|
||||
$this->assertLessThan($result, 0);
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@ -164,15 +164,22 @@ class BuildDocTest extends PHPUnit_Framework_TestCase
|
||||
$db=$this->savdb;
|
||||
|
||||
$conf->facture->dir_output.='/temp';
|
||||
|
||||
$localobjectcom=new Commande($this->savdb);
|
||||
$localobjectcom->initAsSpecimen();
|
||||
|
||||
$localobject=new Facture($this->savdb);
|
||||
$localobject->initAsSpecimen();
|
||||
$localobject->socid=1;
|
||||
$localobject->createFromOrder($localobjectcom);
|
||||
$localobject->date_lim_reglement = dol_now() + 3600 * 24 *30;
|
||||
|
||||
// Crabe
|
||||
$localobject->modelpdf='crabe';
|
||||
$result=facture_pdf_create($db, $localobject, $localobject->modelpdf, $langs);
|
||||
|
||||
$this->assertLessThan($result, 0);
|
||||
$localobject=new Facture($this->savdb);
|
||||
$localobject->initAsSpecimen();
|
||||
|
||||
$this->assertLessThan($result, 0);
|
||||
print __METHOD__." result=".$result."\n";
|
||||
|
||||
// Oursin
|
||||
@ -201,7 +208,6 @@ class BuildDocTest extends PHPUnit_Framework_TestCase
|
||||
$conf->fournisseur->facture->dir_output.='/temp';
|
||||
$localobject=new FactureFournisseur($this->savdb);
|
||||
$localobject->initAsSpecimen();
|
||||
$localobject->socid=1;
|
||||
|
||||
// Canelle
|
||||
$localobject->modelpdf='canelle';
|
||||
@ -229,7 +235,6 @@ class BuildDocTest extends PHPUnit_Framework_TestCase
|
||||
$conf->commande->dir_output.='/temp';
|
||||
$localobject=new Commande($this->savdb);
|
||||
$localobject->initAsSpecimen();
|
||||
$localobject->socid=1;
|
||||
|
||||
// Einstein
|
||||
$localobject->modelpdf='einstein';
|
||||
@ -265,7 +270,6 @@ class BuildDocTest extends PHPUnit_Framework_TestCase
|
||||
$conf->fournisseur->commande->dir_output.='/temp';
|
||||
$localobject=new CommandeFournisseur($this->savdb);
|
||||
$localobject->initAsSpecimen();
|
||||
$localobject->socid=1;
|
||||
|
||||
// Muscadet
|
||||
$localobject->modelpdf='muscadet';
|
||||
@ -293,7 +297,6 @@ class BuildDocTest extends PHPUnit_Framework_TestCase
|
||||
$conf->propale->dir_output.='/temp';
|
||||
$localobject=new Propal($this->savdb);
|
||||
$localobject->initAsSpecimen();
|
||||
$localobject->socid=1;
|
||||
|
||||
// Einstein
|
||||
$localobject->modelpdf='azur';
|
||||
@ -328,7 +331,6 @@ class BuildDocTest extends PHPUnit_Framework_TestCase
|
||||
$conf->project->dir_output.='/temp';
|
||||
$localobject=new Project($this->savdb);
|
||||
$localobject->initAsSpecimen();
|
||||
$localobject->socid=1;
|
||||
|
||||
// Soleil
|
||||
$localobject->modelpdf='baleine';
|
||||
@ -356,7 +358,6 @@ class BuildDocTest extends PHPUnit_Framework_TestCase
|
||||
$conf->fichinter->dir_output.='/temp';
|
||||
$localobject=new Fichinter($this->savdb);
|
||||
$localobject->initAsSpecimen();
|
||||
$localobject->socid=1;
|
||||
|
||||
// Soleil
|
||||
$localobject->modelpdf='soleil';
|
||||
@ -384,7 +385,6 @@ class BuildDocTest extends PHPUnit_Framework_TestCase
|
||||
$conf->expedition->dir_output.='/temp';
|
||||
$localobject=new Expedition($this->savdb);
|
||||
$localobject->initAsSpecimen();
|
||||
$localobject->socid=1;
|
||||
|
||||
// Soleil
|
||||
$localobject->modelpdf='merou';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user