From 6b5125fed08651b29894b6497af414d97b508156 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Tue, 1 Dec 2020 14:50:12 +0100 Subject: [PATCH 001/149] dev widget state_board, add in user class and clean index --- .../core/boxes/box_dolibarr_state_board.php | 337 ++++++++++++++++++ htdocs/core/modules/modUser.class.php | 3 +- htdocs/index.php | 259 -------------- 3 files changed, 339 insertions(+), 260 deletions(-) create mode 100644 htdocs/core/boxes/box_dolibarr_state_board.php diff --git a/htdocs/core/boxes/box_dolibarr_state_board.php b/htdocs/core/boxes/box_dolibarr_state_board.php new file mode 100644 index 00000000000..e96dc795581 --- /dev/null +++ b/htdocs/core/boxes/box_dolibarr_state_board.php @@ -0,0 +1,337 @@ + + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2015 Frederic France + * + * 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 3 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 . + */ + +/** + * \file htdocs/core/boxes/box_dolibarr_state_board.php + * \ingroup + * \brief Module Dolibarr state base + */ + +use Symfony\Component\VarDumper\VarDumper; + +include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php'; +include_once(DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'); + + +/** + * Class to manage the box to show last thirdparties + */ +class box_dolibarr_state_board extends ModeleBoxes +{ + public $boxcode = "dolibarrstatebox"; + public $boximg = "box_user"; + public $boxlabel = "BoxDolibarrStateBoard"; + public $depends = array("user"); + + /** + * @var DoliDB Database handler. + */ + public $db; + + public $enabled = 1; + + public $info_box_head = array(); + public $info_box_contents = array(); + + + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + public function __construct($db, $param = '') + { + global $conf, $user; + + $this->db = $db; + + // disable box for such cases + if (!empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $this->enabled = 0; // disabled by this option + + $this->hidden = !($user->rights->societe->lire && empty($user->socid)); + } + + /** + * Load data for box to show them later + * + * @param int $max Maximum number of records to load + * @return void + */ + public function loadBox($max = 5) + { + global $user, $langs, $conf; + $langs->load("boxes"); + + $this->max = $max; + $this->info_box_head = array('text' => $langs->trans("DolibarrStateBoard")); + + if (empty($user->socid) && empty($conf->global->MAIN_DISABLE_GLOBAL_BOXSTATS)) + { + $hookmanager = new HookManager($this->db); + $hookmanager->initHooks(array('index')); + $boxstatItems = array(); + $boxstatFromHook = ''; + $boxstatFromHook = $hookmanager->resPrint; + $boxstat = ''; + + $keys = array( + 'users', + 'members', + 'expensereports', + 'holidays', + 'customers', + 'prospects', + 'suppliers', + 'contacts', + 'products', + 'services', + 'projects', + 'proposals', + 'orders', + 'invoices', + 'donations', + 'supplier_proposals', + 'supplier_orders', + 'supplier_invoices', + 'contracts', + 'interventions', + 'ticket' + ); + $conditions = array( + 'users' => $user->rights->user->user->lire, + 'members' => !empty($conf->adherent->enabled) && $user->rights->adherent->lire, + 'customers' => !empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS), + 'prospects' => !empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS), + 'suppliers' => !empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS), + 'contacts' => !empty($conf->societe->enabled) && $user->rights->societe->contact->lire, + 'products' => !empty($conf->product->enabled) && $user->rights->produit->lire, + 'services' => !empty($conf->service->enabled) && $user->rights->service->lire, + 'proposals' => !empty($conf->propal->enabled) && $user->rights->propale->lire, + 'orders' => !empty($conf->commande->enabled) && $user->rights->commande->lire, + 'invoices' => !empty($conf->facture->enabled) && $user->rights->facture->lire, + 'donations' => !empty($conf->don->enabled) && $user->rights->don->lire, + 'contracts' => !empty($conf->contrat->enabled) && $user->rights->contrat->lire, + 'interventions' => !empty($conf->ficheinter->enabled) && $user->rights->ficheinter->lire, + 'supplier_orders' => !empty($conf->supplier_order->enabled) && $user->rights->fournisseur->commande->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_ORDERS_STATS), + 'supplier_invoices' => !empty($conf->supplier_invoice->enabled) && $user->rights->fournisseur->facture->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_INVOICES_STATS), + 'supplier_proposals' => !empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_PROPOSAL_STATS), + 'projects' => !empty($conf->projet->enabled) && $user->rights->projet->lire, + 'expensereports' => !empty($conf->expensereport->enabled) && $user->rights->expensereport->lire, + 'holidays' => !empty($conf->holiday->enabled) && $user->rights->holiday->read, + 'ticket' => !empty($conf->ticket->enabled) && $user->rights->ticket->read + ); + $classes = array( + 'users' => 'User', + 'members' => 'Adherent', + 'customers' => 'Client', + 'prospects' => 'Client', + 'suppliers' => 'Fournisseur', + 'contacts' => 'Contact', + 'products' => 'Product', + 'services' => 'ProductService', + 'proposals' => 'Propal', + 'orders' => 'Commande', + 'invoices' => 'Facture', + 'donations' => 'Don', + 'contracts' => 'Contrat', + 'interventions' => 'Fichinter', + 'supplier_orders' => 'CommandeFournisseur', + 'supplier_invoices' => 'FactureFournisseur', + 'supplier_proposals' => 'SupplierProposal', + 'projects' => 'Project', + 'expensereports' => 'ExpenseReport', + 'holidays' => 'Holiday', + 'ticket' => 'Ticket', + ); + $includes = array( + 'users' => DOL_DOCUMENT_ROOT . "/user/class/user.class.php", + 'members' => DOL_DOCUMENT_ROOT . "/adherents/class/adherent.class.php", + 'customers' => DOL_DOCUMENT_ROOT . "/societe/class/client.class.php", + 'prospects' => DOL_DOCUMENT_ROOT . "/societe/class/client.class.php", + 'suppliers' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.class.php", + 'contacts' => DOL_DOCUMENT_ROOT . "/contact/class/contact.class.php", + 'products' => DOL_DOCUMENT_ROOT . "/product/class/product.class.php", + 'services' => DOL_DOCUMENT_ROOT . "/product/class/product.class.php", + 'proposals' => DOL_DOCUMENT_ROOT . "/comm/propal/class/propal.class.php", + 'orders' => DOL_DOCUMENT_ROOT . "/commande/class/commande.class.php", + 'invoices' => DOL_DOCUMENT_ROOT . "/compta/facture/class/facture.class.php", + 'donations' => DOL_DOCUMENT_ROOT . "/don/class/don.class.php", + 'contracts' => DOL_DOCUMENT_ROOT . "/contrat/class/contrat.class.php", + 'interventions' => DOL_DOCUMENT_ROOT . "/fichinter/class/fichinter.class.php", + 'supplier_orders' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.commande.class.php", + 'supplier_invoices' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.facture.class.php", + 'supplier_proposals' => DOL_DOCUMENT_ROOT . "/supplier_proposal/class/supplier_proposal.class.php", + 'projects' => DOL_DOCUMENT_ROOT . "/projet/class/project.class.php", + 'expensereports' => DOL_DOCUMENT_ROOT . "/expensereport/class/expensereport.class.php", + 'holidays' => DOL_DOCUMENT_ROOT . "/holiday/class/holiday.class.php", + 'ticket' => DOL_DOCUMENT_ROOT . "/ticket/class/ticket.class.php" + ); + $links = array( + 'users' => DOL_URL_ROOT . '/user/list.php', + 'members' => DOL_URL_ROOT . '/adherents/list.php?statut=1&mainmenu=members', + 'customers' => DOL_URL_ROOT . '/societe/list.php?type=c&mainmenu=companies', + 'prospects' => DOL_URL_ROOT . '/societe/list.php?type=p&mainmenu=companies', + 'suppliers' => DOL_URL_ROOT . '/societe/list.php?type=f&mainmenu=companies', + 'contacts' => DOL_URL_ROOT . '/contact/list.php?mainmenu=companies', + 'products' => DOL_URL_ROOT . '/product/list.php?type=0&mainmenu=products', + 'services' => DOL_URL_ROOT . '/product/list.php?type=1&mainmenu=products', + 'proposals' => DOL_URL_ROOT . '/comm/propal/list.php?mainmenu=commercial&leftmenu=propals', + 'orders' => DOL_URL_ROOT . '/commande/list.php?mainmenu=commercial&leftmenu=orders', + 'invoices' => DOL_URL_ROOT . '/compta/facture/list.php?mainmenu=billing&leftmenu=customers_bills', + 'donations' => DOL_URL_ROOT . '/don/list.php?leftmenu=donations', + 'contracts' => DOL_URL_ROOT . '/contrat/list.php?mainmenu=commercial&leftmenu=contracts', + 'interventions' => DOL_URL_ROOT . '/fichinter/list.php?mainmenu=commercial&leftmenu=ficheinter', + 'supplier_orders' => DOL_URL_ROOT . '/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers', + 'supplier_invoices' => DOL_URL_ROOT . '/fourn/facture/list.php?mainmenu=billing&leftmenu=suppliers_bills', + 'supplier_proposals' => DOL_URL_ROOT . '/supplier_proposal/list.php?mainmenu=commercial&leftmenu=', + 'projects' => DOL_URL_ROOT . '/projet/list.php?mainmenu=project', + 'expensereports' => DOL_URL_ROOT . '/expensereport/list.php?mainmenu=hrm&leftmenu=expensereport', + 'holidays' => DOL_URL_ROOT . '/holiday/list.php?mainmenu=hrm&leftmenu=holiday', + 'ticket' => DOL_URL_ROOT . '/ticket/list.php?leftmenu=ticket' + ); + $titres = array( + 'users' => "Users", + 'members' => "Members", + 'customers' => "ThirdPartyCustomersStats", + 'prospects' => "ThirdPartyProspectsStats", + 'suppliers' => "Suppliers", + 'contacts' => "Contacts", + 'products' => "Products", + 'services' => "Services", + 'proposals' => "CommercialProposalsShort", + 'orders' => "CustomersOrders", + 'invoices' => "BillsCustomers", + 'donations' => "Donations", + 'contracts' => "Contracts", + 'interventions' => "Interventions", + 'supplier_orders' => "SuppliersOrders", + 'supplier_invoices' => "SuppliersInvoices", + 'supplier_proposals' => "SupplierProposalShort", + 'projects' => "Projects", + 'expensereports' => "ExpenseReports", + 'holidays' => "Holidays", + 'ticket' => "Ticket", + ); + $langfile = array( + 'customers' => "companies", + 'contacts' => "companies", + 'services' => "products", + 'proposals' => "propal", + 'invoices' => "bills", + 'supplier_orders' => "orders", + 'supplier_invoices' => "bills", + 'supplier_proposals' => 'supplier_proposal', + 'expensereports' => "trips", + 'holidays' => "holiday", + ); + $boardloaded = array(); + + foreach ($keys as $val) + { + if ($conditions[$val]) + { + $boxstatItem = ''; + $class = $classes[$val]; + // Search in cache if load_state_board is already realized + $classkeyforcache = $class; + if ($classkeyforcache == 'ProductService') $classkeyforcache = 'Product'; // ProductService use same load_state_board than Product + + if (!isset($boardloaded[$classkeyforcache]) || !is_object($boardloaded[$classkeyforcache])) + { + include_once $includes[$val]; // Loading a class cost around 1Mb + + $board = new $class($this->db); + $board->load_state_board(); + $boardloaded[$class] = $board; + } else { + $board = $boardloaded[$classkeyforcache]; + } + + $langs->load(empty($langfile[$val]) ? $val : $langfile[$val]); + + $text = $langs->trans($titres[$val]); + $boxstatItem .= ''; + $boxstatItem .= '
'; + $boxstatItem .= '' . $text . '
'; + $boxstatItem .= '' . img_object("", $board->picto, 'class="inline-block"') . ' ' . ($board->nb[$val] ? $board->nb[$val] : 0) . ''; + $boxstatItem .= '
'; + $boxstatItem .= '
'; + + $boxstatItems[$val] = $boxstatItem; + } + } + + if (!empty($boxstatFromHook) || !empty($boxstatItems)) + { + $boxstat .= $boxstatFromHook; + + if (is_array($boxstatItems) && count($boxstatItems) > 0) + { + $boxstat .= implode('', $boxstatItems); + } + + $boxstat .= '
'; + $boxstat .= '
'; + $boxstat .= '
'; + $boxstat .= '
'; + $boxstat .= '
'; + $boxstat .= '
'; + $boxstat .= '
'; + $boxstat .= '
'; + + $boxstat .= ''; + $boxstat .= ''; + $boxstat .= ''; + + $this->info_box_contents[0][0] = array( + 'td' => '', + 'textnoformat' => $boxstat + ); + + } else { + $this->info_box_contents[0][0] = array( + 'td' => 'class="nohover center"', + 'maxlength' => 500, + 'text' => ($this->db->error() . ' sql=' . $sql) + ); + } + } else { + $this->info_box_contents[0][0] = array( + 'td' => '', + 'text' => $langs->trans("ReadPermissionNotAllowed") + ); + } + } + + + /** + * Method to show box + * + * @param array $head Array with properties of box title + * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string + * @return string + */ + public function showBox($head = null, $contents = null, $nooutput = 0) + { + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + } +} diff --git a/htdocs/core/modules/modUser.class.php b/htdocs/core/modules/modUser.class.php index 4b397df65e4..dba5f864e8f 100644 --- a/htdocs/core/modules/modUser.class.php +++ b/htdocs/core/modules/modUser.class.php @@ -78,7 +78,8 @@ class modUser extends DolibarrModules // Boxes $this->boxes = array( 0=>array('file'=>'box_lastlogin.php', 'enabledbydefaulton'=>'Home'), - 1=>array('file'=>'box_birthdays.php', 'enabledbydefaulton'=>'Home') + 1=>array('file'=>'box_birthdays.php', 'enabledbydefaulton'=>'Home'), + 2=>array('file'=>'box_dolibarr_state_board.php', 'enabledbydefaulton'=>'Home') ); // Permissions diff --git a/htdocs/index.php b/htdocs/index.php index 887baa04e78..0347a793d42 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -114,219 +114,6 @@ $boxstatFromHook = ''; // Load translation files required by page $langs->loadLangs(array('commercial', 'bills', 'orders', 'contracts')); -// Load global statistics of objects -if (empty($user->socid) && empty($conf->global->MAIN_DISABLE_GLOBAL_BOXSTATS)) -{ - $object = new stdClass(); - $parameters = array(); - $action = ''; - $reshook = $hookmanager->executeHooks('addStatisticLine', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks - $boxstatFromHook = $hookmanager->resPrint; - - if (empty($reshook)) - { - // Cle array returned by the method load_state_board for each line - $keys = array( - 'users', - 'members', - 'expensereports', - 'holidays', - 'customers', - 'prospects', - 'suppliers', - 'contacts', - 'products', - 'services', - 'projects', - 'proposals', - 'orders', - 'invoices', - 'donations', - 'supplier_proposals', - 'supplier_orders', - 'supplier_invoices', - 'contracts', - 'interventions', - 'ticket' - ); - - // Condition to be checked for each display line dashboard - $conditions = array( - 'users' => $user->rights->user->user->lire, - 'members' => !empty($conf->adherent->enabled) && $user->rights->adherent->lire, - 'customers' => !empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS), - 'prospects' => !empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS), - 'suppliers' => !empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS), - 'contacts' => !empty($conf->societe->enabled) && $user->rights->societe->contact->lire, - 'products' => !empty($conf->product->enabled) && $user->rights->produit->lire, - 'services' => !empty($conf->service->enabled) && $user->rights->service->lire, - 'proposals' => !empty($conf->propal->enabled) && $user->rights->propale->lire, - 'orders' => !empty($conf->commande->enabled) && $user->rights->commande->lire, - 'invoices' => !empty($conf->facture->enabled) && $user->rights->facture->lire, - 'donations' => !empty($conf->don->enabled) && $user->rights->don->lire, - 'contracts' => !empty($conf->contrat->enabled) && $user->rights->contrat->lire, - 'interventions' => !empty($conf->ficheinter->enabled) && $user->rights->ficheinter->lire, - 'supplier_orders' => !empty($conf->supplier_order->enabled) && $user->rights->fournisseur->commande->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_ORDERS_STATS), - 'supplier_invoices' => !empty($conf->supplier_invoice->enabled) && $user->rights->fournisseur->facture->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_INVOICES_STATS), - 'supplier_proposals' => !empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_PROPOSAL_STATS), - 'projects' => !empty($conf->projet->enabled) && $user->rights->projet->lire, - 'expensereports' => !empty($conf->expensereport->enabled) && $user->rights->expensereport->lire, - 'holidays' => !empty($conf->holiday->enabled) && $user->rights->holiday->read, - 'ticket' => !empty($conf->ticket->enabled) && $user->rights->ticket->read - ); - // Class file containing the method load_state_board for each line - $includes = array( - 'users' => DOL_DOCUMENT_ROOT."/user/class/user.class.php", - 'members' => DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php", - 'customers' => DOL_DOCUMENT_ROOT."/societe/class/client.class.php", - 'prospects' => DOL_DOCUMENT_ROOT."/societe/class/client.class.php", - 'suppliers' => DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.class.php", - 'contacts' => DOL_DOCUMENT_ROOT."/contact/class/contact.class.php", - 'products' => DOL_DOCUMENT_ROOT."/product/class/product.class.php", - 'services' => DOL_DOCUMENT_ROOT."/product/class/product.class.php", - 'proposals' => DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php", - 'orders' => DOL_DOCUMENT_ROOT."/commande/class/commande.class.php", - 'invoices' => DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php", - 'donations' => DOL_DOCUMENT_ROOT."/don/class/don.class.php", - 'contracts' => DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php", - 'interventions' => DOL_DOCUMENT_ROOT."/fichinter/class/fichinter.class.php", - 'supplier_orders' => DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.commande.class.php", - 'supplier_invoices' => DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.facture.class.php", - 'supplier_proposals' => DOL_DOCUMENT_ROOT."/supplier_proposal/class/supplier_proposal.class.php", - 'projects' => DOL_DOCUMENT_ROOT."/projet/class/project.class.php", - 'expensereports' => DOL_DOCUMENT_ROOT."/expensereport/class/expensereport.class.php", - 'holidays' => DOL_DOCUMENT_ROOT."/holiday/class/holiday.class.php", - 'ticket' => DOL_DOCUMENT_ROOT."/ticket/class/ticket.class.php" - ); - // Name class containing the method load_state_board for each line - $classes = array( - 'users' => 'User', - 'members' => 'Adherent', - 'customers' => 'Client', - 'prospects' => 'Client', - 'suppliers' => 'Fournisseur', - 'contacts' => 'Contact', - 'products' => 'Product', - 'services' => 'ProductService', - 'proposals' => 'Propal', - 'orders' => 'Commande', - 'invoices' => 'Facture', - 'donations' => 'Don', - 'contracts' => 'Contrat', - 'interventions' => 'Fichinter', - 'supplier_orders' => 'CommandeFournisseur', - 'supplier_invoices' => 'FactureFournisseur', - 'supplier_proposals' => 'SupplierProposal', - 'projects' => 'Project', - 'expensereports' => 'ExpenseReport', - 'holidays' => 'Holiday', - 'ticket' => 'Ticket', - ); - // Translation keyword - $titres = array( - 'users' => "Users", - 'members' => "Members", - 'customers' => "ThirdPartyCustomersStats", - 'prospects' => "ThirdPartyProspectsStats", - 'suppliers' => "Suppliers", - 'contacts' => "Contacts", - 'products' => "Products", - 'services' => "Services", - 'proposals' => "CommercialProposalsShort", - 'orders' => "CustomersOrders", - 'invoices' => "BillsCustomers", - 'donations' => "Donations", - 'contracts' => "Contracts", - 'interventions' => "Interventions", - 'supplier_orders' => "SuppliersOrders", - 'supplier_invoices' => "SuppliersInvoices", - 'supplier_proposals' => "SupplierProposalShort", - 'projects' => "Projects", - 'expensereports' => "ExpenseReports", - 'holidays' => "Holidays", - 'ticket' => "Ticket", - ); - // Dashboard Link lines - $links = array( - 'users' => DOL_URL_ROOT.'/user/list.php', - 'members' => DOL_URL_ROOT.'/adherents/list.php?statut=1&mainmenu=members', - 'customers' => DOL_URL_ROOT.'/societe/list.php?type=c&mainmenu=companies', - 'prospects' => DOL_URL_ROOT.'/societe/list.php?type=p&mainmenu=companies', - 'suppliers' => DOL_URL_ROOT.'/societe/list.php?type=f&mainmenu=companies', - 'contacts' => DOL_URL_ROOT.'/contact/list.php?mainmenu=companies', - 'products' => DOL_URL_ROOT.'/product/list.php?type=0&mainmenu=products', - 'services' => DOL_URL_ROOT.'/product/list.php?type=1&mainmenu=products', - 'proposals' => DOL_URL_ROOT.'/comm/propal/list.php?mainmenu=commercial&leftmenu=propals', - 'orders' => DOL_URL_ROOT.'/commande/list.php?mainmenu=commercial&leftmenu=orders', - 'invoices' => DOL_URL_ROOT.'/compta/facture/list.php?mainmenu=billing&leftmenu=customers_bills', - 'donations' => DOL_URL_ROOT.'/don/list.php?leftmenu=donations', - 'contracts' => DOL_URL_ROOT.'/contrat/list.php?mainmenu=commercial&leftmenu=contracts', - 'interventions' => DOL_URL_ROOT.'/fichinter/list.php?mainmenu=commercial&leftmenu=ficheinter', - 'supplier_orders' => DOL_URL_ROOT.'/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers', - 'supplier_invoices' => DOL_URL_ROOT.'/fourn/facture/list.php?mainmenu=billing&leftmenu=suppliers_bills', - 'supplier_proposals' => DOL_URL_ROOT.'/supplier_proposal/list.php?mainmenu=commercial&leftmenu=', - 'projects' => DOL_URL_ROOT.'/projet/list.php?mainmenu=project', - 'expensereports' => DOL_URL_ROOT.'/expensereport/list.php?mainmenu=hrm&leftmenu=expensereport', - 'holidays' => DOL_URL_ROOT.'/holiday/list.php?mainmenu=hrm&leftmenu=holiday', - 'ticket' => DOL_URL_ROOT.'/ticket/list.php?leftmenu=ticket' - ); - // Translation lang files - $langfile = array( - 'customers' => "companies", - 'contacts' => "companies", - 'services' => "products", - 'proposals' => "propal", - 'invoices' => "bills", - 'supplier_orders' => "orders", - 'supplier_invoices' => "bills", - 'supplier_proposals' => 'supplier_proposal', - 'expensereports' => "trips", - 'holidays' => "holiday", - ); - - - // Loop and displays each line of table - $boardloaded = array(); - foreach ($keys as $val) - { - if ($conditions[$val]) - { - $boxstatItem = ''; - $class = $classes[$val]; - // Search in cache if load_state_board is already realized - $classkeyforcache = $class; - if ($classkeyforcache == 'ProductService') $classkeyforcache = 'Product'; // ProductService use same load_state_board than Product - - if (!isset($boardloaded[$classkeyforcache]) || !is_object($boardloaded[$classkeyforcache])) - { - include_once $includes[$val]; // Loading a class cost around 1Mb - - $board = new $class($db); - $board->load_state_board(); - $boardloaded[$class] = $board; - } else { - $board = $boardloaded[$classkeyforcache]; - } - - $langs->load(empty($langfile[$val]) ? $val : $langfile[$val]); - - $text = $langs->trans($titres[$val]); - $boxstatItem .= ''; - $boxstatItem .= '
'; - $boxstatItem .= ''.$text.'
'; - $boxstatItem .= ''.img_object("", $board->picto, 'class="inline-block"').' '.($board->nb[$val] ? $board->nb[$val] : 0).''; - $boxstatItem .= '
'; - $boxstatItem .= '
'; - - $boxstatItems[$val] = $boxstatItem; - } - } - } -} - - - - // Dolibarr Working Board with weather if (empty($conf->global->MAIN_DISABLE_GLOBAL_WORKBOARD)) { @@ -903,54 +690,8 @@ $boxlist .= $resultboxes['boxlista']; $boxlist .= ''; - -if (empty($user->socid) && empty($conf->global->MAIN_DISABLE_GLOBAL_BOXSTATS)) -{ - // Remove allready present info in new dash board - if (!empty($conf->global->MAIN_INCLUDE_GLOBAL_STATS_IN_OPENED_DASHBOARD) && is_array($boxstatItems) && count($boxstatItems) > 0) { - foreach ($boxstatItems as $boxstatItemKey => $boxstatItemHtml) { - if (in_array($boxstatItemKey, $globalStatInTopOpenedDashBoard)) { - unset($boxstatItems[$boxstatItemKey]); - } - } - } - - if (!empty($boxstatFromHook) || !empty($boxstatItems)) { - $boxstat .= ''."\n"; - $boxstat .= '
'; - $boxstat .= ''; - $boxstat .= ''; - $boxstat .= ''; - $boxstat .= ''; - $boxstat .= ''; - $boxstat .= '
'; - $boxstat .= '
'.$langs->trans("DolibarrStateBoard").'
'; - $boxstat .= '
'; - - $boxstat .= $boxstatFromHook; - - if (is_array($boxstatItems) && count($boxstatItems) > 0) - { - $boxstat .= implode('', $boxstatItems); - } - - $boxstat .= '
'; - $boxstat .= '
'; - $boxstat .= '
'; - $boxstat .= '
'; - $boxstat .= '
'; - $boxstat .= '
'; - $boxstat .= '
'; - $boxstat .= '
'; - - $boxstat .= '
'; - $boxstat .= '
'; - } -} - $boxlist .= '
'; -$boxlist .= $boxstat; $boxlist .= $resultboxes['boxlistb']; $boxlist .= '
'; From bca89fc204adc8238776ea2cc109df3a39a2aee2 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Tue, 1 Dec 2020 15:57:15 +0100 Subject: [PATCH 002/149] add dolibarr_state_board in migration --- htdocs/install/mysql/migration/12.0.0-13.0.0.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index 18802301e5a..960dee1eb56 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -439,7 +439,8 @@ INSERT INTO llx_c_product_nature (code, label, active) VALUES (1, 'Finished', 1) ALTER TABLE llx_product MODIFY COLUMN finished tinyint DEFAULT NULL; ALTER TABLE llx_product ADD CONSTRAINT fk_product_finished FOREIGN KEY (finished) REFERENCES llx_c_product_nature (code); - +INSERT INTO llx_boxes_def (file) VALUES ('box_dolibarr_state_board.php'); +INSERT INTO llx_boxes (box_id, position, box_order, maxline, params) VALUES ((SELECT b.rowid FROM llx_boxes_def as b WHERE file = 'box_dolibarr_state_board.php'), 0, 0, NULL, NULL); -- MIGRATION TO DO AFTER RENAMING AN OBJECT -- drop constraint From 95bc0ff54db8df7529f01df4747b0ca71ddb321b Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Tue, 1 Dec 2020 15:59:55 +0100 Subject: [PATCH 003/149] update dolibarr_state_board bug fix --- htdocs/core/boxes/box_dolibarr_state_board.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/boxes/box_dolibarr_state_board.php b/htdocs/core/boxes/box_dolibarr_state_board.php index e96dc795581..463af26c88e 100644 --- a/htdocs/core/boxes/box_dolibarr_state_board.php +++ b/htdocs/core/boxes/box_dolibarr_state_board.php @@ -299,7 +299,6 @@ class box_dolibarr_state_board extends ModeleBoxes $boxstat .= ''; $boxstat .= ''; - $boxstat .= ''; $this->info_box_contents[0][0] = array( 'td' => '', From 5c3c3d760858ca27bb3edef7402ac64a3906d9bf Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Tue, 1 Dec 2020 15:05:11 +0000 Subject: [PATCH 004/149] Fixing style errors. --- htdocs/core/boxes/box_dolibarr_state_board.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/htdocs/core/boxes/box_dolibarr_state_board.php b/htdocs/core/boxes/box_dolibarr_state_board.php index 463af26c88e..6f9190dda1e 100644 --- a/htdocs/core/boxes/box_dolibarr_state_board.php +++ b/htdocs/core/boxes/box_dolibarr_state_board.php @@ -20,14 +20,14 @@ /** * \file htdocs/core/boxes/box_dolibarr_state_board.php - * \ingroup + * \ingroup * \brief Module Dolibarr state base */ use Symfony\Component\VarDumper\VarDumper; include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php'; -include_once(DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'); +include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; /** @@ -304,7 +304,6 @@ class box_dolibarr_state_board extends ModeleBoxes 'td' => '', 'textnoformat' => $boxstat ); - } else { $this->info_box_contents[0][0] = array( 'td' => 'class="nohover center"', From 647294e88e5203c00da072e61d1dba812214b4bd Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Thu, 3 Dec 2020 11:04:24 +0100 Subject: [PATCH 005/149] fix #15384 migration --- htdocs/install/mysql/migration/12.0.0-13.0.0.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index 960dee1eb56..541bb6f58be 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -439,8 +439,6 @@ INSERT INTO llx_c_product_nature (code, label, active) VALUES (1, 'Finished', 1) ALTER TABLE llx_product MODIFY COLUMN finished tinyint DEFAULT NULL; ALTER TABLE llx_product ADD CONSTRAINT fk_product_finished FOREIGN KEY (finished) REFERENCES llx_c_product_nature (code); -INSERT INTO llx_boxes_def (file) VALUES ('box_dolibarr_state_board.php'); -INSERT INTO llx_boxes (box_id, position, box_order, maxline, params) VALUES ((SELECT b.rowid FROM llx_boxes_def as b WHERE file = 'box_dolibarr_state_board.php'), 0, 0, NULL, NULL); -- MIGRATION TO DO AFTER RENAMING AN OBJECT -- drop constraint @@ -543,3 +541,4 @@ CREATE TABLE llx_session( user_agent varchar(128) NULL )ENGINE=innodb; +INSERT INTO llx_boxes_def (file) VALUES ('box_dolibarr_state_board.php'); From 401d61dd91984cb4120b5ad33b1127bc8633189e Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Tue, 8 Dec 2020 09:05:31 +0100 Subject: [PATCH 006/149] resolve auto import by IDE --- htdocs/core/boxes/box_dolibarr_state_board.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/htdocs/core/boxes/box_dolibarr_state_board.php b/htdocs/core/boxes/box_dolibarr_state_board.php index 6f9190dda1e..a8e00eef5eb 100644 --- a/htdocs/core/boxes/box_dolibarr_state_board.php +++ b/htdocs/core/boxes/box_dolibarr_state_board.php @@ -24,8 +24,6 @@ * \brief Module Dolibarr state base */ -use Symfony\Component\VarDumper\VarDumper; - include_once DOL_DOCUMENT_ROOT . '/core/boxes/modules_boxes.php'; include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; From d88adb3d47907ef595cbb7694d3811a41031b2c9 Mon Sep 17 00:00:00 2001 From: lmarcouiller Date: Tue, 5 Jan 2021 18:10:57 +0100 Subject: [PATCH 007/149] move line 553 of 12 to 13 migration to 13 to 14 --- htdocs/install/mysql/migration/12.0.0-13.0.0.sql | 1 - htdocs/install/mysql/migration/13.0.0-14.0.0.sql | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql index f017eb10939..26ec6377cc3 100644 --- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql +++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql @@ -554,7 +554,6 @@ INSERT INTO llx_c_socialnetworks (entity, code, label, url, icon, active) VALUES -- VMYSQL4.1 INSERT INTO llx_boxes_def (file, entity) SELECT 'box_funnel_of_prospection.php', 1 FROM DUAL WHERE NOT EXISTS (SELECT * FROM llx_boxes_def WHERE file = 'box_funnel_of_prospection.php' AND entity = 1); -- VMYSQL4.1 INSERT INTO llx_boxes_def (file, entity) SELECT 'box_customers_outstanding_bill_reached.php', 1 FROM DUAL WHERE NOT EXISTS (SELECT * FROM llx_boxes_def WHERE file = 'box_customers_outstanding_bill_reached.php' AND entity = 1); -- VMYSQL4.1 INSERT INTO llx_boxes_def (file, entity) SELECT 'box_scheduled_jobs.php', 1 FROM DUAL WHERE NOT EXISTS (SELECT * FROM llx_boxes_def WHERE file = 'box_scheduled_jobs.php' AND entity = 1); --- VMYSQL4.1 INSERT INTO llx_boxes_def (file, entity) SELECT 'box_dolibarr_state_board.php', 1 FROM DUAL WHERE NOT EXISTS (SELECT * FROM llx_boxes_def WHERE file = 'box_dolibarr_state_board.php' AND entity = 1); ALTER TABLE llx_product_fournisseur_price ADD COLUMN packaging varchar(64); diff --git a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql index 7b9cb8c9ef8..7ac924dbf2d 100644 --- a/htdocs/install/mysql/migration/13.0.0-14.0.0.sql +++ b/htdocs/install/mysql/migration/13.0.0-14.0.0.sql @@ -43,3 +43,4 @@ ALTER TABLE llx_bank_account ADD COLUMN ics varchar(32) NULL; ALTER TABLE llx_bank_account ADD COLUMN ics_transfer varchar(32) NULL; ALTER TABLE llx_facture MODIFY COLUMN date_valid DATETIME NULL DEFAULT NULL; +-- VMYSQL4.1 INSERT INTO llx_boxes_def (file, entity) SELECT 'box_dolibarr_state_board.php', 1 FROM DUAL WHERE NOT EXISTS (SELECT * FROM llx_boxes_def WHERE file = 'box_dolibarr_state_board.php' AND entity = 1); From e5ef45562883733fcb7ae5c65533c310105eb73f Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 11 Jan 2021 19:46:08 +0100 Subject: [PATCH 008/149] fix: date auto fill date paiement tax --- htdocs/compta/paiement_charge.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index 509e20f3613..a1c3a246829 100644 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -224,8 +224,8 @@ if ($action == 'create') print ''.$langs->trans("Date").''; $datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); - $datepayment = empty($conf->global->MAIN_AUTOFILL_DATE) ? (empty($_POST["remonth"]) ?-1 : $datepaye) : 0; - print $form->selectDate($datepayment, '', '', '', '', "add_payment", 1, 1); + $datepaye = ($datepaye == '' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '') : $datepaye); + print $form->selectDate($datepaye, '', '', '', '', "add_payment", 1, 1); print ""; print ''; From 33d7998a9682fecabd94f9f0e61a50a56ff9b0ce Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Mon, 11 Jan 2021 19:47:20 +0100 Subject: [PATCH 009/149] fix: date auto fill date paiement tax --- htdocs/compta/paiement_charge.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index a1c3a246829..37301908693 100644 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -223,9 +223,9 @@ if ($action == 'create') print ''.$langs->trans("RemainderToPay").''.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'';*/ print ''.$langs->trans("Date").''; - $datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); - $datepaye = ($datepaye == '' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '') : $datepaye); - print $form->selectDate($datepaye, '', '', '', '', "add_payment", 1, 1); + $datepayment = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); + $datepayment = ($datepayment == '' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '') : $datepayment); + print $form->selectDate($datepayment, '', '', '', '', "add_payment", 1, 1); print ""; print ''; From b1a78c6c18829e63eeb3c1c0e9b62481c3b7c03a Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 12 Jan 2021 17:18:41 +0100 Subject: [PATCH 010/149] fix thirdparty list filter type_ent empty --- htdocs/societe/list.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index 2e24f355b37..a4ad5ec590e 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -816,7 +816,7 @@ if (!empty($arrayfields['country.code_iso']['checked'])) if (!empty($arrayfields['typent.code']['checked'])) { print ''; - print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), 'maxwidth75', 1); + print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), 'maxwidth75', 1); print ''; } // Staff From 5b21702508323dbed660fb57d320c2b3fc4fa116 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 12 Jan 2021 17:44:22 +0100 Subject: [PATCH 011/149] extrafeild selllist can be use with string fk --- htdocs/core/tpl/extrafields_list_search_sql.tpl.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/core/tpl/extrafields_list_search_sql.tpl.php b/htdocs/core/tpl/extrafields_list_search_sql.tpl.php index 03d487ee0c0..316899ee472 100644 --- a/htdocs/core/tpl/extrafields_list_search_sql.tpl.php +++ b/htdocs/core/tpl/extrafields_list_search_sql.tpl.php @@ -37,7 +37,8 @@ if (!empty($extrafieldsobjectkey) && !empty($search_array_options) && is_array($ { $mode_search = 0; if (in_array($typ, array('int', 'double', 'real', 'price'))) $mode_search = 1; // Search on a numeric - if (in_array($typ, array('sellist', 'link')) && $crit != '0' && $crit != '-1') $mode_search = 2; // Search on a foreign key int + if (in_array($typ, array('sellist', 'link')) && $crit != '0' && $crit != '-1' && !is_string($crit)) $mode_search = 2; // Search on a foreign key int + if (in_array($typ, array('sellist')) && is_string($crit)) $mode_search = 0;// Search on a foreign key string if (in_array($typ, array('chkbxlst', 'checkbox'))) $mode_search = 4; // Search on a multiselect field with sql type = text if (is_array($crit)) $crit = implode(' ', $crit); // natural_search() expects a string elseif ($typ === 'select' and is_string($crit) and strpos($crit, ' ') === false) { From 34b792e9a22738a6210cfd98a89ff7c61e9e23b5 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 12 Jan 2021 21:44:18 +0100 Subject: [PATCH 012/149] betterfix --- htdocs/core/tpl/extrafields_list_search_sql.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/extrafields_list_search_sql.tpl.php b/htdocs/core/tpl/extrafields_list_search_sql.tpl.php index 316899ee472..296dfec52a0 100644 --- a/htdocs/core/tpl/extrafields_list_search_sql.tpl.php +++ b/htdocs/core/tpl/extrafields_list_search_sql.tpl.php @@ -37,7 +37,7 @@ if (!empty($extrafieldsobjectkey) && !empty($search_array_options) && is_array($ { $mode_search = 0; if (in_array($typ, array('int', 'double', 'real', 'price'))) $mode_search = 1; // Search on a numeric - if (in_array($typ, array('sellist', 'link')) && $crit != '0' && $crit != '-1' && !is_string($crit)) $mode_search = 2; // Search on a foreign key int + if (in_array($typ, array('sellist', 'link')) && $crit != '0' && $crit != '-1' && is_numeric($crit)) $mode_search = 2; // Search on a foreign key int if (in_array($typ, array('sellist')) && is_string($crit)) $mode_search = 0;// Search on a foreign key string if (in_array($typ, array('chkbxlst', 'checkbox'))) $mode_search = 4; // Search on a multiselect field with sql type = text if (is_array($crit)) $crit = implode(' ', $crit); // natural_search() expects a string From 3ddcc0efd3ace9abda53417811554d191d1220db Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 12 Jan 2021 21:50:02 +0100 Subject: [PATCH 013/149] revert stuff from 12.0 --- htdocs/user/class/usergroup.class.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index ad26e3e9b6d..5ba6b5553af 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -660,12 +660,6 @@ class UserGroup extends CommonObject $this->nom = $this->name; // Field for 'name' is called 'nom' in database } - $entity = $conf->entity; - if (!empty($conf->multicompany->enabled) && $conf->entity == 1) - { - $entity = $this->entity; - } - return $this->updateCommon($user, $notrigger); } From 7e30812529d6b68e4838d246686a02cd07216a06 Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Tue, 12 Jan 2021 22:01:53 +0100 Subject: [PATCH 014/149] fix review --- htdocs/compta/paiement_charge.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index 37301908693..ac89cfef0b6 100644 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -223,8 +223,13 @@ if ($action == 'create') print ''.$langs->trans("RemainderToPay").''.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'';*/ print ''.$langs->trans("Date").''; - $datepayment = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); - $datepayment = ($datepayment == '' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '') : $datepayment); + if (GETPOSTISSET('remonth')) { + $datepayment = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); + } elseif (!empty($conf->global->MAIN_AUTOFILL_DATE)) { + $datepayment = dol_mktime(12, 0, 0, dol_print_date(dol_now(), '%m'), dol_print_date(dol_now(), '%d'), dol_print_date(dol_now(), '%Y')); + } else { + $datepayment = '' ; + } print $form->selectDate($datepayment, '', '', '', '', "add_payment", 1, 1); print ""; print ''; From 11100b3017a8ff9c3ab3ddbaae8d4ab71290eeaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 13 Jan 2021 15:16:43 +0100 Subject: [PATCH 015/149] missing default value --- htdocs/product/card.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index d6f62b34769..d74cab0ada4 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -16,7 +16,7 @@ * Copyright (C) 2016 Charlie Benke * Copyright (C) 2016 Meziane Sof * Copyright (C) 2017 Josep Lluís Amador - * Copyright (C) 2019 Frédéric France + * Copyright (C) 2019-2021 Frédéric France * Copyright (C) 2019-2020 Thibault FOUCART * * This program is free software; you can redistribute it and/or modify @@ -1297,11 +1297,10 @@ else // Accountancy_code_buy print ''.$langs->trans("ProductAccountancyBuyCode").''; print ''; - if ($type == 0) - { + if ($type == 0) { $accountancy_code_buy = (GETPOST('accountancy_code_buy', 'alpha') ? (GETPOST('accountancy_code_buy', 'alpha')) : $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT); } else { - $accountancy_code_buy = GETPOST('accountancy_code_buy', 'alpha'); + $accountancy_code_buy = (GETPOST('accountancy_code_buy', 'alpha') ? (GETPOST('accountancy_code_buy', 'alpha')) : $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT); } print $formaccounting->select_account($accountancy_code_buy, 'accountancy_code_buy', 1, null, 1, 1, ''); print ''; From cb7266d26106d16a4dfd34a95f4cf0dc17e9f623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 13 Jan 2021 16:18:23 +0100 Subject: [PATCH 016/149] fix trans --- htdocs/admin/dav.php | 4 ++-- htdocs/core/class/commonobject.class.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/admin/dav.php b/htdocs/admin/dav.php index 8f005c0f0d7..4008a3cd7be 100644 --- a/htdocs/admin/dav.php +++ b/htdocs/admin/dav.php @@ -172,13 +172,13 @@ $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domai // Show message $message = ''; $url = ''.$urlwithroot.'/dav/fileserver.php'; -$message .= img_picto('', 'globe').' '.$langs->trans("WebDavServer", 'WebDAV', $url); +$message .= img_picto('', 'globe').' '.str_replace('{url}', $url, $langs->trans("WebDavServer", 'WebDAV', '{url}')); $message .= '
'; if (!empty($conf->global->DAV_ALLOW_PUBLIC_DIR)) { $urlEntity = (!empty($conf->multicompany->enabled) ? '?entity='.$conf->entity : ''); $url = ''.$urlwithroot.'/dav/fileserver.php/public/'.$urlEntity.''; - $message .= img_picto('', 'globe').' '.$langs->trans("WebDavServer", 'WebDAV public', $url); + $message .= img_picto('', 'globe').' '.str_replace('{url}', $url, $langs->trans("WebDavServer", 'WebDAV public', '{url}')); $message .= '
'; } print $message; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index d701da55d8f..bdca5f74d0a 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3671,7 +3671,9 @@ abstract class CommonObject */ static public function getAllItemsLinkedByObjectID($fk_object_where, $field_select, $field_where, $table_element) { - if(empty($fk_object_where) || empty($field_where) || empty($table_element)) return -1; + if (empty($fk_object_where) || empty($field_where) || empty($table_element)) { + return -1; + } global $db; @@ -3686,7 +3688,6 @@ abstract class CommonObject } return $TRes; - } /** @@ -3698,7 +3699,7 @@ abstract class CommonObject */ static public function deleteAllItemsLinkedByObjectID($fk_object_where, $field_where, $table_element) { - if(empty($fk_object_where) || empty($field_where) || empty($table_element)) return -1; + if (empty($fk_object_where) || empty($field_where) || empty($table_element)) return -1; global $db; @@ -3708,7 +3709,6 @@ abstract class CommonObject if (empty($resql)) return 0; return 1; - } /** From 40a45efb63d9a5294a5da9da46beca6fa632b9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 13 Jan 2021 16:23:54 +0100 Subject: [PATCH 017/149] fix code --- htdocs/core/class/commonobject.class.php | 8 ++++++-- htdocs/core/class/html.formmail.class.php | 12 +++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index bdca5f74d0a..2d0dc6b4090 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3699,14 +3699,18 @@ abstract class CommonObject */ static public function deleteAllItemsLinkedByObjectID($fk_object_where, $field_where, $table_element) { - if (empty($fk_object_where) || empty($field_where) || empty($table_element)) return -1; + if (empty($fk_object_where) || empty($field_where) || empty($table_element)) { + return -1; + } global $db; $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$table_element.' WHERE '.$field_where.' = '.$fk_object_where; $resql = $db->query($sql); - if (empty($resql)) return 0; + if (empty($resql)) { + return 0; + } return 1; } diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 1b29af772a7..d3147eafa6f 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1509,9 +1509,15 @@ class FormMail extends Form //,'__PERSONALIZED__' => 'Personalized' // Hidden because not used yet in mass emailing $onlinepaymentenabled = 0; - if (!empty($conf->paypal->enabled)) $onlinepaymentenabled++; - if (!empty($conf->paybox->enabled)) $onlinepaymentenabled++; - if (!empty($conf->stripe->enabled)) $onlinepaymentenabled++; + if (!empty($conf->paypal->enabled)) { + $onlinepaymentenabled++; + } + if (!empty($conf->paybox->enabled)) { + $onlinepaymentenabled++; + } + if (!empty($conf->stripe->enabled)) { + $onlinepaymentenabled++; + } if ($onlinepaymentenabled && !empty($conf->global->PAYMENT_SECURITY_TOKEN)) { $tmparray['__SECUREKEYPAYMENT__'] = $conf->global->PAYMENT_SECURITY_TOKEN; if (!empty($conf->global->PAYMENT_SECURITY_TOKEN_UNIQUE)) { From a5678147dd92f566a09d358f9a9bce61fb3ef03c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 13 Jan 2021 16:52:32 +0100 Subject: [PATCH 018/149] add missing translation --- htdocs/compta/prelevement/card.php | 15 +++++++-------- htdocs/langs/en_US/withdrawals.lang | 5 +++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/htdocs/compta/prelevement/card.php b/htdocs/compta/prelevement/card.php index 5d87303236a..90d5e1e8fe6 100644 --- a/htdocs/compta/prelevement/card.php +++ b/htdocs/compta/prelevement/card.php @@ -2,7 +2,7 @@ /* Copyright (C) 2005 Rodolphe Quiedeville * Copyright (C) 2005-2010 Laurent Destailleur * Copyright (C) 2010-2016 Juanjo Menent - * Copyright (C) 2018 Frédéric France + * Copyright (C) 2018-2021 Frédéric France * * 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 @@ -354,8 +354,8 @@ if ($id > 0 || $ref) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { + // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } @@ -445,15 +445,14 @@ if ($id > 0 || $ref) $i++; } - if ($num > 0) - { + if ($num > 0) { print ''; print ''.$langs->trans("Total").''; print ' '; print ''; - if (empty($offset) && $num <= $limit) // If we have all record on same page, then the following test/warning can be done - { - if ($total != $object->amount) print img_warning("TotalAmountOfdirectDebitOrderDiffersFromSumOfLines"); + if (empty($offset) && $num <= $limit) { + // If we have all record on same page, then the following test/warning can be done + if ($total != $object->amount) print img_warning($langs->trans("TotalAmountOfdirectDebitOrderDiffersFromSumOfLines")); } print price($total); print "\n"; diff --git a/htdocs/langs/en_US/withdrawals.lang b/htdocs/langs/en_US/withdrawals.lang index debfeaa9d27..059b3451c11 100644 --- a/htdocs/langs/en_US/withdrawals.lang +++ b/htdocs/langs/en_US/withdrawals.lang @@ -26,7 +26,7 @@ NotPossibleForThisStatusOfWithdrawReceiptORLine=Not yet possible. Withdraw statu NbOfInvoiceToWithdraw=No. of qualified customer invoices with waiting direct debit order NbOfInvoiceToWithdrawWithInfo=No. of customer invoice with direct debit payment orders having defined bank account information NbOfInvoiceToPayByBankTransfer=No. of qualified supplier invoices waiting for a payment by credit transfer -SupplierInvoiceWaitingWithdraw=Vendor invoice waiting for payment by credit transfer +SupplierInvoiceWaitingWithdraw=Vendor invoice waiting for payment by credit transfer InvoiceWaitingWithdraw=Invoice waiting for direct debit InvoiceWaitingPaymentByBankTransfer=Invoice waiting for credit transfer AmountToWithdraw=Amount to withdraw @@ -148,4 +148,5 @@ InfoRejectSubject=Direct debit payment order refused InfoRejectMessage=Hello,

the direct debit payment order of invoice %s related to the company %s, with an amount of %s has been refused by the bank.

--
%s ModeWarning=Option for real mode was not set, we stop after this simulation ErrorCompanyHasDuplicateDefaultBAN=Company with id %s has more than one default bank account. No way to know wich one to use. -ErrorICSmissing=Missing ICS in Bank account %s +ErrorICSmissing=Missing ICS in Bank account %s +TotalAmountOfdirectDebitOrderDiffersFromSumOfLines=Total amount of direct debit order differs from sum of lines From 271378fb87e46855710f1e2191f44e8242a043e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 13 Jan 2021 18:09:57 +0100 Subject: [PATCH 019/149] add translation --- htdocs/compta/prelevement/create.php | 36 +++++++++++----------------- htdocs/langs/en_US/banks.lang | 1 + 2 files changed, 15 insertions(+), 22 deletions(-) diff --git a/htdocs/compta/prelevement/create.php b/htdocs/compta/prelevement/create.php index 26b91a1e100..db751735bb0 100644 --- a/htdocs/compta/prelevement/create.php +++ b/htdocs/compta/prelevement/create.php @@ -66,18 +66,14 @@ $parameters = array('mode' => $mode, 'format' => $format, 'limit' => $limit, 'pa $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -if (empty($reshook)) -{ +if (empty($reshook)) { // Change customer bank information to withdraw - if ($action == 'modify') - { - for ($i = 1; $i < 9; $i++) - { + if ($action == 'modify') { + for ($i = 1; $i < 9; $i++) { dolibarr_set_const($db, GETPOST("nom$i"), GETPOST("value$i"), 'chaine', 0, '', $conf->entity); } } - if ($action == 'create') - { + if ($action == 'create') { $default_account=($type == 'bank-transfer' ? 'PAYMENTBYBANKTRANSFER_ID_BANKACCOUNT' : 'PRELEVEMENT_ID_BANKACCOUNT'); if ($id_bankaccount != $conf->global->{$default_account}){ @@ -88,7 +84,8 @@ if (empty($reshook)) $bank = new Account($db); $bank->fetch($conf->global->{$default_account}); if (empty($bank->ics) || empty($bank->ics_transfer)){ - setEventMessages($langs->trans("ErrorICSmissing", $bank->getNomUrl(1)), null, 'errors'); + $errormessage = str_replace('{url}', $bank->getNomUrl(1), $langs->trans("ErrorICSmissing", '{url}')); + setEventMessages($errormessage, null, 'errors'); header("Location: ".DOL_URL_ROOT.'/compta/prelevement/create.php'); exit; } @@ -111,8 +108,7 @@ if (empty($reshook)) $mesg = $langs->trans("NoInvoiceCouldBeWithdrawed", $format); setEventMessages($mesg, null, 'errors'); $mesg .= '
'."\n"; - foreach ($bprev->invoice_in_error as $key => $val) - { + foreach ($bprev->invoice_in_error as $key => $val) { $mesg .= ''.$val."
\n"; } } else { @@ -145,8 +141,7 @@ $bprev = new BonPrelevement($db); llxHeader('', $langs->trans("NewStandingOrder")); -if (prelevement_check_config($type) < 0) -{ +if (prelevement_check_config($type) < 0) { $langs->load("errors"); setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("Withdraw")), null, 'errors'); } @@ -237,8 +232,7 @@ if ($nb) { print ''.$title."\n"; } } else { - if ($mysoc->isInEEC()) - { + if ($mysoc->isInEEC()) { $title = $langs->trans("CreateForSepaFRST"); if ($type == 'bank-transfer') { $title = $langs->trans("CreateSepaFileForPaymentByBankTransfer"); @@ -289,8 +283,7 @@ $sql .= " ".MAIN_DB_PREFIX."societe as s,"; $sql .= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; $sql .= " WHERE s.rowid = f.fk_soc"; $sql .= " AND f.entity IN (".getEntity('invoice').")"; -if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) -{ +if (empty($conf->global->WITHDRAWAL_ALLOW_ANY_INVOICE_STATUS)) { $sql .= " AND f.fk_statut = ".Facture::STATUS_VALIDATED; } //$sql .= " AND pfd.amount > 0"; @@ -305,12 +298,11 @@ if ($type == 'bank-transfer') { if ($socid > 0) $sql .= " AND f.fk_soc = ".$socid; $nbtotalofrecords = ''; -if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) -{ +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 - { + if (($page * $limit) > $nbtotalofrecords) { + // if total resultset is smaller then paging size (filtering), goto and load page 0 $page = 0; $offset = 0; } @@ -399,7 +391,7 @@ if ($resql) if ($format) print ' ('.$format.')'; } } else { - print img_warning($langs->trans("NoBankAccount")); + print img_warning($langs->trans("NoBankAccountDefined")); } print ''; // Amount diff --git a/htdocs/langs/en_US/banks.lang b/htdocs/langs/en_US/banks.lang index a0dc27f86c4..81a23238550 100644 --- a/htdocs/langs/en_US/banks.lang +++ b/htdocs/langs/en_US/banks.lang @@ -180,3 +180,4 @@ BankColorizeMovementDesc=If this function is enable, you can choose specific bac BankColorizeMovementName1=Background color for debit movement BankColorizeMovementName2=Background color for credit movement IfYouDontReconcileDisableProperty=If you don't make the bank reconciliations on some bank accounts, disable the property "%s" on them to remove this warning. +NoBankAccountDefined=No bank account defined From b143fb6b9e90d08be01abdacbcf5ed8e95024819 Mon Sep 17 00:00:00 2001 From: Anthony Berton <34568357+bb2a@users.noreply.github.com> Date: Wed, 13 Jan 2021 18:52:27 +0100 Subject: [PATCH 020/149] Update list.php --- htdocs/user/list.php | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/htdocs/user/list.php b/htdocs/user/list.php index 3b21e19f349..4c2380d4ec5 100644 --- a/htdocs/user/list.php +++ b/htdocs/user/list.php @@ -99,6 +99,8 @@ $fieldstosearchall = array( 'u.lastname'=>"Lastname", 'u.firstname'=>"Firstname", 'u.accountancy_code'=>"AccountancyCode", + 'u.office_phone'=>"PhonePro", + 'u.user_mobile'=>"PhoneMobile", 'u.email'=>"EMail", 'u.note'=>"Note", ); @@ -117,6 +119,8 @@ $arrayfields = array( 'u.employee'=>array('label'=>"Employee", 'checked'=>($mode == 'employee' ? 1 : 0), 'position'=>25), 'u.fk_user'=>array('label'=>"HierarchicalResponsible", 'checked'=>1, 'position'=>27), 'u.accountancy_code'=>array('label'=>"AccountancyCode", 'checked'=>0, 'position'=>30), + 'u.office_phone'=>array('label'=>"PhonePro", 'checked'=>1, 'position'=>31), + 'u.user_mobile'=>array('label'=>"PhoneMobile", 'checked'=>1, 'position'=>32), 'u.email'=>array('label'=>"EMail", 'checked'=>1, 'position'=>35), 'u.api_key'=>array('label'=>"ApiKey", 'checked'=>0, 'position'=>40, "enabled"=>($conf->api->enabled && $user->admin)), 'u.fk_soc'=>array('label'=>"Company", 'checked'=>($contextpage == 'employeelist' ? 0 : 1), 'position'=>45), @@ -142,6 +146,8 @@ $search_firstname = GETPOST('search_firstname', 'alpha'); $search_gender = GETPOST('search_gender', 'alpha'); $search_employee = GETPOST('search_employee', 'alpha'); $search_accountancy_code = GETPOST('search_accountancy_code', 'alpha'); +$search_phonepro = GETPOST('search_phonepro', 'alpha'); +$search_phonemobile = GETPOST('search_phonemobile', 'alpha'); $search_email = GETPOST('search_email', 'alpha'); $search_api_key = GETPOST('search_api_key', 'alphanohtml'); $search_statut = GETPOST('search_statut', 'intcomma'); @@ -199,6 +205,8 @@ if (empty($reshook)) $search_gender = ""; $search_employee = ""; $search_accountancy_code = ""; + $search_phonepro = ""; + $search_phonemobile = ""; $search_email = ""; $search_statut = ""; $search_thirdparty = ""; @@ -296,11 +304,11 @@ if ($contextpage == 'employeelist' && $search_employee == 1) { $user2 = new User($db); -$sql = "SELECT DISTINCT u.rowid, u.lastname, u.firstname, u.admin, u.fk_soc, u.login, u.email, u.api_key, u.accountancy_code, u.gender, u.employee, u.photo,"; +$sql = "SELECT DISTINCT u.rowid, u.lastname, u.firstname, u.admin, u.fk_soc, u.login, u.office_phone, u.user_mobile, u.email, u.api_key, u.accountancy_code, u.gender, u.employee, u.photo,"; $sql .= " u.salary, u.datelastlogin, u.datepreviouslogin,"; $sql .= " u.ldap_sid, u.statut, u.entity,"; $sql .= " u.tms as date_update, u.datec as date_creation,"; -$sql .= " u2.rowid as id2, u2.login as login2, u2.firstname as firstname2, u2.lastname as lastname2, u2.admin as admin2, u2.fk_soc as fk_soc2, u2.email as email2, u2.gender as gender2, u2.photo as photo2, u2.entity as entity2, u2.statut as statut2,"; +$sql .= " u2.rowid as id2, u2.login as login2, u2.firstname as firstname2, u2.lastname as lastname2, u2.admin as admin2, u2.fk_soc as fk_soc2, u2.office_phone as ofice_phone2, u2.user_mobile as user_mobile2, u2.email as email2, u2.gender as gender2, u2.photo as photo2, u2.entity as entity2, u2.statut as statut2,"; $sql .= " s.nom as name, s.canvas"; // Add fields from extrafields if (!empty($extrafields->attributes[$object->table_element]['label'])) { @@ -337,6 +345,8 @@ if (is_numeric($search_employee) && $search_employee >= 0) { $sql .= ' AND u.employee = '.(int) $search_employee; } if ($search_accountancy_code != '') $sql .= natural_search("u.accountancy_code", $search_accountancy_code); +if ($search_phonepro != '') $sql .= natural_search("u.office_phone", $search_phonepro); +if ($search_phonemobile != '') $sql .= natural_search("u.user_mobile", $search_phonemobile); if ($search_email != '') $sql .= natural_search("u.email", $search_email); if ($search_api_key != '') $sql .= natural_search("u.api_key", $search_api_key); if ($search_statut != '' && $search_statut >= 0) $sql .= " AND u.statut IN (".$db->sanitize($db->escape($search_statut)).")"; @@ -408,6 +418,8 @@ if ($search_firstname != '') $param .= "&search_firstname=".urlencode($searc if ($search_gender != '') $param .= "&search_gender=".urlencode($search_gender); if ($search_employee != '') $param .= "&search_employee=".urlencode($search_employee); if ($search_accountancy_code != '') $param .= "&search_accountancy_code=".urlencode($search_accountancy_code); +if ($search_phonepro != '') $param .= "&search_phonepro=".urlencode($search_phonepro); +if ($search_phonemobile != '') $param .= "&search_phonemobile=".urlencode($search_phonemobile); if ($search_email != '') $param .= "&search_email=".urlencode($search_email); if ($search_api_key != '') $param .= "&search_api_key=".urlencode($search_api_key); if ($search_supervisor > 0) $param .= "&search_supervisor=".urlencode($search_supervisor); @@ -543,6 +555,14 @@ if (!empty($arrayfields['u.accountancy_code']['checked'])) { print ''; } +if (!empty($arrayfields['u.office_phone']['checked'])) +{ + print ''; +} +if (!empty($arrayfields['u.user_mobile']['checked'])) +{ + print ''; +} if (!empty($arrayfields['u.email']['checked'])) { print ''; @@ -612,6 +632,8 @@ if (!empty($arrayfields['u.gender']['checked'])) print_liste_field_titre if (!empty($arrayfields['u.employee']['checked'])) print_liste_field_titre("Employee", $_SERVER['PHP_SELF'], "u.employee", $param, "", "", $sortfield, $sortorder); if (!empty($arrayfields['u.fk_user']['checked'])) print_liste_field_titre("HierarchicalResponsible", $_SERVER['PHP_SELF'], "u.fk_user", $param, "", "", $sortfield, $sortorder); if (!empty($arrayfields['u.accountancy_code']['checked'])) print_liste_field_titre("AccountancyCode", $_SERVER['PHP_SELF'], "u.accountancy_code", $param, "", "", $sortfield, $sortorder); +if (!empty($arrayfields['u.office_phone']['checked'])) print_liste_field_titre("PhonePro", $_SERVER['PHP_SELF'], "u.office_phone", $param, "", "", $sortfield, $sortorder); +if (!empty($arrayfields['u.user_mobile']['checked'])) print_liste_field_titre("PhoneMobile", $_SERVER['PHP_SELF'], "u.user_mobile", $param, "", "", $sortfield, $sortorder); if (!empty($arrayfields['u.email']['checked'])) print_liste_field_titre("EMail", $_SERVER['PHP_SELF'], "u.email", $param, "", "", $sortfield, $sortorder); if (!empty($arrayfields['u.api_key']['checked'])) print_liste_field_titre("ApiKey", $_SERVER['PHP_SELF'], "u.api_key", $param, "", "", $sortfield, $sortorder); if (!empty($arrayfields['u.fk_soc']['checked'])) print_liste_field_titre("Company", $_SERVER['PHP_SELF'], "u.fk_soc", $param, "", "", $sortfield, $sortorder); @@ -662,6 +684,8 @@ while ($i < ($limit ? min($num, $limit) : $num)) $userstatic->ref = $obj->label; $userstatic->login = $obj->login; $userstatic->statut = $obj->statut; + $userstatic->office_phone = $obj->office_phone; + $userstatic->user_mobile = $obj->user_mobile; $userstatic->email = $obj->email; $userstatic->gender = $obj->gender; $userstatic->socid = $obj->fk_soc; @@ -724,6 +748,8 @@ while ($i < ($limit ? min($num, $limit) : $num)) $user2->gender = $obj->gender2; $user2->photo = $obj->photo2; $user2->admin = $obj->admin2; + $user2->office_phone = $obj->office_phone; + $user2->user_mobile = $obj->user_mobile; $user2->email = $obj->email2; $user2->socid = $obj->fk_soc2; $user2->statut = $obj->statut2; @@ -745,6 +771,16 @@ while ($i < ($limit ? min($num, $limit) : $num)) print ''.$obj->accountancy_code.''; if (!$i) $totalarray['nbfield']++; } + if (!empty($arrayfields['u.office_phone']['checked'])) + { + print ''.$obj->office_phone.''; + if (!$i) $totalarray['nbfield']++; + } + if (!empty($arrayfields['u.user_mobile']['checked'])) + { + print ''.$obj->user_mobile.''; + if (!$i) $totalarray['nbfield']++; + } if (!empty($arrayfields['u.email']['checked'])) { print ''.$obj->email.''; From ceff964ad50e106511998bd44179c2af229fea29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 13 Jan 2021 21:56:51 +0100 Subject: [PATCH 021/149] member has ref now --- htdocs/adherents/index.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/htdocs/adherents/index.php b/htdocs/adherents/index.php index b2ef8e8854b..44e0e4177b8 100644 --- a/htdocs/adherents/index.php +++ b/htdocs/adherents/index.php @@ -85,9 +85,15 @@ if ($result) { $adhtype->label = $objp->label; $AdherentType[$objp->rowid] = $adhtype; - if ($objp->statut == -1) { $MemberToValidate[$objp->rowid] = $objp->somme; } - if ($objp->statut == 1) { $MembersValidated[$objp->rowid] = $objp->somme; } - if ($objp->statut == 0) { $MembersResiliated[$objp->rowid] = $objp->somme; } + if ($objp->statut == -1) { + $MemberToValidate[$objp->rowid] = $objp->somme; + } + if ($objp->statut == 1) { + $MembersValidated[$objp->rowid] = $objp->somme; + } + if ($objp->statut == 0) { + $MembersResiliated[$objp->rowid] = $objp->somme; + } $i++; } @@ -136,10 +142,14 @@ if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) { // This is usel print ''; $i = 0; foreach ($listofsearchfields as $key => $value) { - if ($i == 0) print ''; + if ($i == 0) { + print ''; + } print ''; print ''; - if ($i == 0) print ''; + if ($i == 0) { + print ''; + } print ''; $i++; } @@ -284,7 +294,7 @@ print '
'; */ $max = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT; -$sql = "SELECT a.rowid, a.statut as status, a.lastname, a.firstname, a.societe as company, a.fk_soc,"; +$sql = "SELECT a.rowid, a.ref, a.statut as status, a.lastname, a.firstname, a.societe as company, a.fk_soc,"; $sql .= " a.gender, a.email, a.photo, a.morphy,"; $sql .= " a.tms as datem, a.datefin as date_end_subscription,"; $sql .= " ta.rowid as typeid, ta.libelle as label, ta.subscription as need_subscription"; @@ -308,7 +318,7 @@ if ($resql) { $obj = $db->fetch_object($resql); $staticmember->id = $obj->rowid; - $staticmember->ref = $obj->rowid; + $staticmember->ref = $obj->ref; $staticmember->lastname = $obj->lastname; $staticmember->firstname = $obj->firstname; $staticmember->gender = $obj->gender; From 225c68d5e65253eba614e08107597f06a5c7a35f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 13 Jan 2021 22:00:40 +0100 Subject: [PATCH 022/149] Update box_members.php --- htdocs/core/boxes/box_members.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/htdocs/core/boxes/box_members.php b/htdocs/core/boxes/box_members.php index 2d0ad45a266..2a69c7b3a21 100644 --- a/htdocs/core/boxes/box_members.php +++ b/htdocs/core/boxes/box_members.php @@ -63,7 +63,9 @@ class box_members extends ModeleBoxes // disable module for such cases $listofmodulesforexternal = explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL); - if (!in_array('adherent', $listofmodulesforexternal) && !empty($user->socid)) $this->enabled = 0; // disabled for external users + if (!in_array('adherent', $listofmodulesforexternal) && !empty($user->socid)) { + $this->enabled = 0; // disabled for external users + } $this->hidden = !($user->rights->adherent->lire); } @@ -87,7 +89,7 @@ class box_members extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedMembers", $max)); if ($user->rights->adherent->lire) { - $sql = "SELECT a.rowid, a.lastname, a.firstname, a.societe as company, a.fk_soc,"; + $sql = "SELECT a.rowid, a.ref, a.lastname, a.firstname, a.societe as company, a.fk_soc,"; $sql .= " a.datec, a.tms, a.statut as status, a.datefin as date_end_subscription,"; $sql .= ' a.photo, a.email, a.gender, a.morphy,'; $sql .= " t.subscription"; @@ -110,14 +112,15 @@ class box_members extends ModeleBoxes $memberstatic->lastname = $objp->lastname; $memberstatic->firstname = $objp->firstname; $memberstatic->id = $objp->rowid; - $memberstatic->ref = $objp->rowid; + $memberstatic->ref = $objp->ref; $memberstatic->photo = $objp->photo; $memberstatic->gender = $objp->gender; $memberstatic->email = $objp->email; $memberstatic->morphy = $objp->morphy; $memberstatic->company = $objp->company; $memberstatic->statut = $objp->status; - + $memberstatic->need_subscription = $objp->subscription; + $memberstatic->datefin = $this->db->jdate($objp->date_end_subscription); if (!empty($objp->fk_soc)) { $memberstatic->socid = $objp->fk_soc; $memberstatic->fetch_thirdparty(); @@ -151,11 +154,12 @@ class box_members extends ModeleBoxes $line++; } - if ($num == 0) + if ($num == 0) { $this->info_box_contents[$line][0] = array( 'td' => 'class="center"', 'text'=>$langs->trans("NoRecordedCustomers"), ); + } $this->db->free($result); } else { From 2c31e0989d623b89d29450a9c2c5890b234ef3ed Mon Sep 17 00:00:00 2001 From: Anthony Berton <34568357+bb2a@users.noreply.github.com> Date: Thu, 14 Jan 2021 08:25:57 +0100 Subject: [PATCH 023/149] Update list.php --- htdocs/user/list.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/user/list.php b/htdocs/user/list.php index 4c2380d4ec5..c8951176354 100644 --- a/htdocs/user/list.php +++ b/htdocs/user/list.php @@ -773,17 +773,17 @@ while ($i < ($limit ? min($num, $limit) : $num)) } if (!empty($arrayfields['u.office_phone']['checked'])) { - print '
'; + print "\n"; if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['u.user_mobile']['checked'])) { - print ''; + print "\n"; if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['u.email']['checked'])) { - print ''; + print '\n"; if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['u.api_key']['checked'])) From 6726d5781d08be4eab5b6e68dcdcef56661967ca Mon Sep 17 00:00:00 2001 From: Anthony Berton <34568357+bb2a@users.noreply.github.com> Date: Thu, 14 Jan 2021 08:41:04 +0100 Subject: [PATCH 024/149] Update list.php --- htdocs/user/list.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/user/list.php b/htdocs/user/list.php index c8951176354..04921893b6f 100644 --- a/htdocs/user/list.php +++ b/htdocs/user/list.php @@ -773,12 +773,12 @@ while ($i < ($limit ? min($num, $limit) : $num)) } if (!empty($arrayfields['u.office_phone']['checked'])) { - print "\n"; + print "\n"; if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['u.user_mobile']['checked'])) { - print "\n"; + print "\n"; if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['u.email']['checked'])) From df5e6a2519288d6c1243cccb6bea4e0e4a47f310 Mon Sep 17 00:00:00 2001 From: Anthony Berton <34568357+bb2a@users.noreply.github.com> Date: Thu, 14 Jan 2021 08:56:38 +0100 Subject: [PATCH 025/149] picto --- htdocs/contact/list.php | 10 +++++----- htdocs/societe/list.php | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 8d6b11e19f0..c33867fed7f 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -933,31 +933,31 @@ while ($i < min($num, $limit)) // Phone if (!empty($arrayfields['p.phone']['checked'])) { - print ''; + print ''; if (!$i) $totalarray['nbfield']++; } // Phone perso if (!empty($arrayfields['p.phone_perso']['checked'])) { - print ''; + print ''; if (!$i) $totalarray['nbfield']++; } // Phone mobile if (!empty($arrayfields['p.phone_mobile']['checked'])) { - print ''; + print ''; if (!$i) $totalarray['nbfield']++; } // Fax if (!empty($arrayfields['p.fax']['checked'])) { - print ''; + print ''; if (!$i) $totalarray['nbfield']++; } // EMail if (!empty($arrayfields['p.email']['checked'])) { - print ''; + print ''; if (!$i) $totalarray['nbfield']++; } // No EMail diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index f4ddb7e571f..ec748d95e94 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -1181,17 +1181,17 @@ while ($i < min($num, $limit)) } if (!empty($arrayfields['s.phone']['checked'])) { - print "\n"; + print "\n"; if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['s.fax']['checked'])) { - print "\n"; + print "\n"; if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['s.url']['checked'])) { - print "\n"; + print "\n"; if (!$i) $totalarray['nbfield']++; } if (!empty($arrayfields['s.siren']['checked'])) From 0fa7134bd11559e51ea019dddd06ca15cb25f19b Mon Sep 17 00:00:00 2001 From: Florian HENRY Date: Thu, 14 Jan 2021 13:04:02 +0100 Subject: [PATCH 026/149] better fix --- htdocs/compta/paiement_charge.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index ac89cfef0b6..f67bed0ec63 100644 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -223,14 +223,16 @@ if ($action == 'create') print '';*/ print '"; print ''; From 727751e0c1512d2621d7def8c07e41f9f5c645d8 Mon Sep 17 00:00:00 2001 From: zuiko Date: Thu, 14 Jan 2021 14:44:32 +0100 Subject: [PATCH 027/149] Update functions.lib.php Fix #15820 function price2num add underscore in the pattern in instruction $amount = preg_replace('/[a-zA-Z\/\\\*\(\)\<\>]/', '', $amount); as this: $amount = preg_replace('/[a-zA-Z\/\\\*\(\)\<\>\_]/', '', $amount); in order to cover some constantes cases as 20% (TX_NORMAL) or 10% (TX_REDUIT) where underscore is used. I don't know if other characters have to be added to this pattern. --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 023ade28052..6921f9f967a 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4725,7 +4725,7 @@ function price2num($amount, $rounding = '', $option = 0) if ($option != 1) { // If not a PHP number or unknown, we change or clean format //print 'PP'.$amount.' - '.$dec.' - '.$thousand.' - '.intval($amount).'
'; if (!is_numeric($amount)) { - $amount = preg_replace('/[a-zA-Z\/\\\*\(\)\<\>]/', '', $amount); + $amount = preg_replace('/[a-zA-Z\/\\\*\(\)\<\>\_]/', '', $amount); } if ($option == 2 && $thousand == '.' && preg_match('/\.(\d\d\d)$/', (string) $amount)) { // It means the . is used as a thousand separator and string come frominput data, so 1.123 is 1123 From 4f67f840bf271305591ee451d83167dad9ac8711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 14 Jan 2021 14:48:41 +0100 Subject: [PATCH 028/149] fix merge --- .../bookkeeping/listbysubaccount.php | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/listbysubaccount.php b/htdocs/accountancy/bookkeeping/listbysubaccount.php index 4800fb779c6..b7ef25fd821 100644 --- a/htdocs/accountancy/bookkeeping/listbysubaccount.php +++ b/htdocs/accountancy/bookkeeping/listbysubaccount.php @@ -695,14 +695,15 @@ while ($i < min($num, $limit)) { print '
'; // Piece number - if (!empty($arrayfields['t.piece_num']['checked'])) - { + if (!empty($arrayfields['t.piece_num']['checked'])) { print ''; - if (!$i) $totalarray['nbfield']++; + if (!$i) { + $totalarray['nbfield']++; + } } // Journal code @@ -724,21 +725,6 @@ while ($i < min($num, $limit)) { } } -<<<<<<< HEAD - // Piece number - if (!empty($arrayfields['t.piece_num']['checked'])) { - print ''; - if (!$i) { - $totalarray['nbfield']++; - } - } - -======= ->>>>>>> branch '13.0' of git@github.com:Dolibarr/dolibarr.git // Document ref if (!empty($arrayfields['t.doc_ref']['checked'])) { if ($line->doc_type == 'customer_invoice') { From fd5948f71637815bd0cc0a988d41961c8f538c32 Mon Sep 17 00:00:00 2001 From: zuiko Date: Thu, 14 Jan 2021 15:00:53 +0100 Subject: [PATCH 029/149] Update functions.lib.php Fix #15820 Fix #15820 function price2num add underscore in the pattern in instruction $amount = preg_replace('/[a-zA-Z\/\\\*\(\)\<\>]/', '', $amount); as this: $amount = preg_replace('/[a-zA-Z\/\\\*\(\)\<\>\_\-]/', '', $amount); in order to cover some constantes cases as 20% (TX_NORMAL) or 10% (TX_REDUIT) where underscore is used. it seems that some constantes use also "-" so I added it in the pattern. I don't know if other characters have to be added to this pattern. --- htdocs/core/lib/functions.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 6921f9f967a..7c562357d9a 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4725,7 +4725,7 @@ function price2num($amount, $rounding = '', $option = 0) if ($option != 1) { // If not a PHP number or unknown, we change or clean format //print 'PP'.$amount.' - '.$dec.' - '.$thousand.' - '.intval($amount).'
'; if (!is_numeric($amount)) { - $amount = preg_replace('/[a-zA-Z\/\\\*\(\)\<\>\_]/', '', $amount); + $amount = preg_replace('/[a-zA-Z\/\\\*\(\)\<\>\_\-]/', '', $amount); } if ($option == 2 && $thousand == '.' && preg_match('/\.(\d\d\d)$/', (string) $amount)) { // It means the . is used as a thousand separator and string come frominput data, so 1.123 is 1123 From b1a1cd4be6bd9dc324bf8b1b110476412289aacc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 14 Jan 2021 15:09:08 +0100 Subject: [PATCH 030/149] code syntax --- dev/examples/code/create_invoice.php | 20 +- dev/examples/code/create_order.php | 20 +- dev/examples/code/create_product.php | 15 +- dev/examples/code/create_user.php | 25 +- dev/examples/code/get_contracts.php | 13 +- test/phpunit/AccountingAccountTest.php | 334 +- test/phpunit/ActionCommTest.php | 368 +-- test/phpunit/AdherentTest.php | 928 +++--- test/phpunit/AdminLibTest.php | 212 +- test/phpunit/AllTests.php | 357 +- test/phpunit/BOMTest.php | 20 +- test/phpunit/BankAccountTest.php | 324 +- test/phpunit/BonPrelevementTest.php | 121 +- test/phpunit/BuildDocTest.php | 622 ++-- test/phpunit/CMailFileTest.php | 274 +- test/phpunit/CategorieTest.php | 520 +-- test/phpunit/ChargeSocialesTest.php | 363 +- test/phpunit/CodingPhpTest.php | 596 ++-- test/phpunit/CodingSqlTest.php | 383 +-- test/phpunit/CommandeFournisseurTest.php | 606 ++-- test/phpunit/CommandeTest.php | 454 +-- test/phpunit/CommonInvoiceTest.php | 186 +- test/phpunit/CommonObjectTest.php | 256 +- test/phpunit/CompanyBankAccountTest.php | 239 +- test/phpunit/CompanyLibTest.php | 186 +- test/phpunit/ContactTest.php | 424 ++- test/phpunit/ContratTest.php | 323 +- test/phpunit/CoreTest.php | 371 ++- test/phpunit/DateLibTest.php | 533 ++- test/phpunit/DateLibTzFranceTest.php | 195 +- test/phpunit/DiscountTest.php | 149 +- test/phpunit/EntrepotTest.php | 221 +- test/phpunit/ExpenseReportTest.php | 468 +-- test/phpunit/ExportTest.php | 512 +-- test/phpunit/FactureFournisseurTest.php | 265 +- test/phpunit/FactureRecTest.php | 167 +- test/phpunit/FactureTest.php | 562 ++-- test/phpunit/FactureTestRounding.php | 425 ++- test/phpunit/FichinterTest.php | 233 +- test/phpunit/FilesLibTest.php | 639 ++-- test/phpunit/FormAdminTest.php | 85 +- test/phpunit/FormTest.php | 87 +- test/phpunit/Functions2LibTest.php | 374 ++- test/phpunit/FunctionsLibTest.php | 2924 +++++++++-------- test/phpunit/GetUrlLibTest.php | 337 +- test/phpunit/HolidayTest.php | 551 ++-- test/phpunit/ImagesLibTest.php | 77 +- test/phpunit/ImportTest.php | 118 +- test/phpunit/JsonLibTest.php | 264 +- test/phpunit/LangTest.php | 174 +- test/phpunit/LesscTest.php | 147 +- test/phpunit/LoanTest.php | 227 +- test/phpunit/MarginsLibTest.php | 77 +- test/phpunit/ModulesTest.php | 99 +- test/phpunit/MouvementStockTest.php | 197 +- test/phpunit/NumberingModulesTest.php | 621 ++-- test/phpunit/PaypalTest.php | 87 +- test/phpunit/PdfDocTest.php | 123 +- test/phpunit/PgsqlTest.php | 137 +- test/phpunit/PricesTest.php | 532 ++- test/phpunit/ProductTest.php | 361 +- test/phpunit/ProjectTest.php | 279 +- test/phpunit/PropalTest.php | 337 +- test/phpunit/RestAPIDocumentTest.php | 336 +- test/phpunit/RestAPIUserTest.php | 336 +- test/phpunit/ScriptsTest.php | 287 +- test/phpunit/SecurityTest.php | 755 ++--- test/phpunit/SocieteTest.php | 684 ++-- test/phpunit/StripeTest.php | 87 +- test/phpunit/SupplierProposalTest.php | 281 +- test/phpunit/TicketTest.php | 20 +- test/phpunit/UserGroupTest.php | 428 +-- test/phpunit/UserTest.php | 536 +-- test/phpunit/UtilsTest.php | 192 +- test/phpunit/WebservicesInvoicesTest.php | 356 +- test/phpunit/WebservicesOrdersTest.php | 246 +- test/phpunit/WebservicesOtherTest.php | 300 +- test/phpunit/WebservicesProductsTest.php | 503 ++- test/phpunit/WebservicesThirdpartyTest.php | 642 ++-- test/phpunit/WebservicesUserTest.php | 300 +- test/phpunit/XCalLibTest.php | 182 +- test/phpunit/functional/InstallTest.php | 150 +- .../functional/TakePosFunctionalTest.php | 19 +- 83 files changed, 14010 insertions(+), 13774 deletions(-) diff --git a/dev/examples/code/create_invoice.php b/dev/examples/code/create_invoice.php index 1acf181a4ba..1d231a7fd7a 100755 --- a/dev/examples/code/create_invoice.php +++ b/dev/examples/code/create_invoice.php @@ -29,8 +29,8 @@ $path=dirname(__FILE__).'/'; // Test if batch mode if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; - exit; + echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; + exit; } // Global variables @@ -49,7 +49,10 @@ $langs->load("main"); // To load language file for default language // Load user and its permissions $result=$user->fetch('', 'admin'); // Load user for login 'admin'. Comment line to run as anonymous user. -if (! $result > 0) { dol_print_error('', $user->error); exit; } +if (! $result > 0) { + dol_print_error('', $user->error); + exit; +} $user->getrights(); @@ -82,12 +85,12 @@ $obj->lines[]=$line1; // Create invoice $idobject=$obj->create($user); -if ($idobject > 0) -{ +if ($idobject > 0) { // Change status to validated $result=$obj->validate($user); - if ($result > 0) print "OK Object created with id ".$idobject."\n"; - else { + if ($result > 0) { + print "OK Object created with id ".$idobject."\n"; + } else { $error++; dol_print_error($db, $obj->error); } @@ -99,8 +102,7 @@ if ($idobject > 0) // -------------------- END OF YOUR CODE -------------------- -if (! $error) -{ +if (! $error) { $db->commit(); print '--- end ok'."\n"; } else { diff --git a/dev/examples/code/create_order.php b/dev/examples/code/create_order.php index 7fe1a82251a..a851ac3cbc5 100755 --- a/dev/examples/code/create_order.php +++ b/dev/examples/code/create_order.php @@ -29,8 +29,8 @@ $path=dirname(__FILE__).'/'; // Test if batch mode if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; - exit; + echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; + exit; } // Global variables @@ -49,7 +49,10 @@ $langs->load("main"); // To load language file for default language // Load user and its permissions $result=$user->fetch('', 'admin'); // Load user for login 'admin'. Comment line to run as anonymous user. -if (! $result > 0) { dol_print_error('', $user->error); exit; } +if (! $result > 0) { + dol_print_error('', $user->error); + exit; +} $user->getrights(); @@ -80,12 +83,12 @@ $com->lines[]=$orderline1; // Create order $idobject=$com->create($user); -if ($idobject > 0) -{ +if ($idobject > 0) { // Change status to validated $result=$com->valid($user); - if ($result > 0) print "OK Object created with id ".$idobject."\n"; - else { + if ($result > 0) { + print "OK Object created with id ".$idobject."\n"; + } else { $error++; dol_print_error($db, $com->error); } @@ -97,8 +100,7 @@ if ($idobject > 0) // -------------------- END OF YOUR CODE -------------------- -if (! $error) -{ +if (! $error) { $db->commit(); print '--- end ok'."\n"; } else { diff --git a/dev/examples/code/create_product.php b/dev/examples/code/create_product.php index 20b898a92aa..8f742065f2f 100755 --- a/dev/examples/code/create_product.php +++ b/dev/examples/code/create_product.php @@ -29,8 +29,8 @@ $path=dirname(__FILE__).'/'; // Test if batch mode if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; - exit; + echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; + exit; } // Global variables @@ -49,7 +49,10 @@ $langs->load("main"); // To load language file for default language // Load user and its permissions $result=$user->fetch('', 'admin'); // Load user for login 'admin'. Comment line to run as anonymous user. -if (! $result > 0) { dol_print_error('', $user->error); exit; } +if (! $result > 0) { + dol_print_error('', $user->error); + exit; +} $user->getrights(); @@ -79,8 +82,7 @@ $myproduct->weight_units = 0; // Create product in database $idobject = $myproduct->create($user); -if ($idobject > 0) -{ +if ($idobject > 0) { print "OK Object created with id ".$idobject."\n"; } else { $error++; @@ -89,8 +91,7 @@ if ($idobject > 0) // -------------------- END OF YOUR CODE -------------------- -if (! $error) -{ +if (! $error) { $db->commit(); print '--- end ok'."\n"; } else { diff --git a/dev/examples/code/create_user.php b/dev/examples/code/create_user.php index d585b490a9c..e374fec531d 100755 --- a/dev/examples/code/create_user.php +++ b/dev/examples/code/create_user.php @@ -29,8 +29,8 @@ $path=dirname(__FILE__).'/'; // Test if batch mode if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; - exit; + echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; + exit; } // Global variables @@ -49,7 +49,10 @@ $langs->load("main"); // To load language file for default language // Load user and its permissions $result=$user->fetch('', 'admin'); // Load user for login 'admin'. Comment line to run as anonymous user. -if (! $result > 0) { dol_print_error('', $user->error); exit; } +if (! $result > 0) { + dol_print_error('', $user->error); + exit; +} $user->getrights(); @@ -69,18 +72,17 @@ $obj->nom = 'ABCDEF'; // Create user $idobject=$obj->create($user); -if ($idobject > 0) -{ +if ($idobject > 0) { // Change status to validated $result=$obj->setStatut(1); - if ($result > 0) print "OK Object created with id ".$idobject."\n"; - else { + if ($result > 0) { + print "OK Object created with id ".$idobject."\n"; + } else { $error++; dol_print_error($db, $obj->error); } -} elseif ($obj->error == 'ErrorLoginAlreadyExists') -{ - print "User with login ".$obj->login." already exists\n"; +} elseif ($obj->error == 'ErrorLoginAlreadyExists') { + print "User with login ".$obj->login." already exists\n"; } else { $error++; dol_print_error($db, $obj->error); @@ -89,8 +91,7 @@ if ($idobject > 0) // -------------------- END OF YOUR CODE -------------------- -if (! $error) -{ +if (! $error) { $db->commit(); print '--- end ok'."\n"; } else { diff --git a/dev/examples/code/get_contracts.php b/dev/examples/code/get_contracts.php index aec246e9480..40bee133d11 100755 --- a/dev/examples/code/get_contracts.php +++ b/dev/examples/code/get_contracts.php @@ -29,8 +29,8 @@ $path=dirname(__FILE__).'/'; // Test if batch mode if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; - exit; + echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; + exit; } // Global variables @@ -49,14 +49,17 @@ $langs->load("main"); // To load language file for default language // Load user and its permissions $result=$user->fetch('', 'admin'); // Load user for login 'admin'. Comment line to run as anonymous user. -if (! $result > 0) { dol_print_error('', $user->error); exit; } +if (! $result > 0) { + dol_print_error('', $user->error); + exit; +} $user->getrights(); print "***** ".$script_file." (".$version.") *****\n"; if (! isset($argv[1])) { // Check parameters - print "Usage: ".$script_file." id_thirdparty ...\n"; - exit; + print "Usage: ".$script_file." id_thirdparty ...\n"; + exit; } print '--- start'."\n"; print 'Argument id_thirdparty='.$argv[1]."\n"; diff --git a/test/phpunit/AccountingAccountTest.php b/test/phpunit/AccountingAccountTest.php index 622bd346872..ce67dc0b839 100644 --- a/test/phpunit/AccountingAccountTest.php +++ b/test/phpunit/AccountingAccountTest.php @@ -30,9 +30,9 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/accountancy/class/accountingaccount.class.php'; if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -46,194 +46,196 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class AccountingAccountTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return AccountingAccountTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return AccountingAccountTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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. - if (empty($conf->accounting->enabled)) { print __METHOD__." module accouting must be enabled.\n"; exit(-1); } + if (empty($conf->accounting->enabled)) { + print __METHOD__." module accouting must be enabled.\n"; exit(-1); + } - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - //print $db->getVersion()."\n"; - } + print __METHOD__."\n"; + //print $db->getVersion()."\n"; + } - /** - * End phpunit tests - * - * @return void - */ - protected function tearDown() - { - print __METHOD__."\n"; - } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testAccountingAccountCreate - * - * @return int Id of created object - */ - public function testAccountingAccountCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAccountingAccountCreate + * + * @return int Id of created object + */ + public function testAccountingAccountCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new AccountingAccount($this->savdb); - $localobject->fk_pcg_version = 'PCG99-ABREGE'; - $localobject->account_category = 0; - $localobject->pcg_type = 'XXXXX'; - $localobject->pcg_subtype = 'XXXXX'; - $localobject->account_number = '411123456'; - $localobject->account_parent = 0; - $localobject->label = 'Account specimen'; - $localobject->active = 0; - $result=$localobject->create($user); + $localobject=new AccountingAccount($this->savdb); + $localobject->fk_pcg_version = 'PCG99-ABREGE'; + $localobject->account_category = 0; + $localobject->pcg_type = 'XXXXX'; + $localobject->pcg_subtype = 'XXXXX'; + $localobject->account_number = '411123456'; + $localobject->account_parent = 0; + $localobject->label = 'Account specimen'; + $localobject->active = 0; + $result=$localobject->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $result; - } + return $result; + } - /** - * testAccountingAccountFetch - * - * @param int $id Id accounting account - * @return AccountingAccount - * - * @depends testAccountingAccountCreate - * The depends says test is run only if previous is ok - */ - public function testAccountingAccountFetch($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAccountingAccountFetch + * + * @param int $id Id accounting account + * @return AccountingAccount + * + * @depends testAccountingAccountCreate + * The depends says test is run only if previous is ok + */ + public function testAccountingAccountFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new AccountingAccount($this->savdb); - $result=$localobject->fetch($id); + $localobject=new AccountingAccount($this->savdb); + $result=$localobject->fetch($id); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject; - } + return $localobject; + } - /** - * testAccountingAccountUpdate - * - * @param Object $localobject AccountingAccount - * @return int ID accounting account - * - * @depends testAccountingAccountFetch - * The depends says test is run only if previous is ok - */ - public function testAccountingAccountUpdate($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAccountingAccountUpdate + * + * @param Object $localobject AccountingAccount + * @return int ID accounting account + * + * @depends testAccountingAccountFetch + * The depends says test is run only if previous is ok + */ + public function testAccountingAccountUpdate($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject->label='New label'; - $result=$localobject->update($user); + $localobject->label='New label'; + $result=$localobject->update($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject->id; - } + return $localobject->id; + } - /** - * testAccountingAccountDelete - * - * @param int $id Id of accounting account - * @return int Result of delete - * - * @depends testAccountingAccountUpdate - * The depends says test is run only if previous is ok - */ - public function testAccountingAccountDelete($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAccountingAccountDelete + * + * @param int $id Id of accounting account + * @return int Result of delete + * + * @depends testAccountingAccountUpdate + * The depends says test is run only if previous is ok + */ + public function testAccountingAccountDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new AccountingAccount($this->savdb); - $result=$localobject->fetch($id); - $result=$localobject->delete($user); + $localobject=new AccountingAccount($this->savdb); + $result=$localobject->fetch($id); + $result=$localobject->delete($user); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $result; - } + return $result; + } } diff --git a/test/phpunit/ActionCommTest.php b/test/phpunit/ActionCommTest.php index abebfd728bf..db1ff5667ef 100644 --- a/test/phpunit/ActionCommTest.php +++ b/test/phpunit/ActionCommTest.php @@ -30,9 +30,9 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/comm/action/class/actioncomm.class.php'; if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -46,210 +46,212 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class ActionCommTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return ActionCommTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return ActionCommTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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. - if (empty($conf->agenda->enabled)) { print __METHOD__." module agenda must be enabled.\n"; die(); } + if (empty($conf->agenda->enabled)) { + print __METHOD__." module agenda must be enabled.\n"; die(); + } - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - //print $db->getVersion()."\n"; - } + print __METHOD__."\n"; + //print $db->getVersion()."\n"; + } - /** - * End phpunit tests - * - * @return void - */ - protected function tearDown() - { - print __METHOD__."\n"; - } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testActionCommCreate - * - * @return int Id of created object - */ - public function testActionCommCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testActionCommCreate + * + * @return int Id of created object + */ + public function testActionCommCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $now = dol_now(); + $now = dol_now(); - $localobject=new ActionComm($this->savdb); + $localobject=new ActionComm($this->savdb); - $localobject->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...) - $localobject->code = 'AC_PHPUNITTEST'; - $localobject->label = 'This is a description'; - $localobject->note_private = 'This is note'; - $localobject->fk_project = 0; - $localobject->datep = $now; - $localobject->datef = $now; - $localobject->percentage = -1; // Not applicable - $localobject->socid = 0; - $localobject->contactid = 0; - $localobject->authorid = $user->id; // User saving action - $localobject->userownerid = $user->id; // Owner of action - // Fields when action is en email (content should be added into note) - /*$localobject->email_msgid = $object->email_msgid; - $localobject->email_from = $object->email_from; - $localobject->email_sender= $object->email_sender; - $localobject->email_to = $object->email_to; - $localobject->email_tocc = $object->email_tocc; - $localobject->email_tobcc = $object->email_tobcc; - $localobject->email_subject = $object->email_subject; - $localobject->errors_to = $object->errors_to;*/ - //$localobject->fk_element = $invoice->id; - //$localobject->elementtype = $invoice->element; - $localobject->extraparams = 'Extra params'; + $localobject->type_code = 'AC_OTH_AUTO'; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...) + $localobject->code = 'AC_PHPUNITTEST'; + $localobject->label = 'This is a description'; + $localobject->note_private = 'This is note'; + $localobject->fk_project = 0; + $localobject->datep = $now; + $localobject->datef = $now; + $localobject->percentage = -1; // Not applicable + $localobject->socid = 0; + $localobject->contactid = 0; + $localobject->authorid = $user->id; // User saving action + $localobject->userownerid = $user->id; // Owner of action + // Fields when action is en email (content should be added into note) + /*$localobject->email_msgid = $object->email_msgid; + $localobject->email_from = $object->email_from; + $localobject->email_sender= $object->email_sender; + $localobject->email_to = $object->email_to; + $localobject->email_tocc = $object->email_tocc; + $localobject->email_tobcc = $object->email_tobcc; + $localobject->email_subject = $object->email_subject; + $localobject->errors_to = $object->errors_to;*/ + //$localobject->fk_element = $invoice->id; + //$localobject->elementtype = $invoice->element; + $localobject->extraparams = 'Extra params'; - $result = $localobject->create($user); + $result = $localobject->create($user); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; - return $result; - } + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + return $result; + } - /** - * testActionCommFetch - * - * @param int $id Id action comm - * @return ActionComm - * - * @depends testActionCommCreate - * The depends says test is run only if previous is ok - */ - public function testActionCommFetch($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testActionCommFetch + * + * @param int $id Id action comm + * @return ActionComm + * + * @depends testActionCommCreate + * The depends says test is run only if previous is ok + */ + public function testActionCommFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new ActionComm($this->savdb); - $result=$localobject->fetch($id); + $localobject=new ActionComm($this->savdb); + $result=$localobject->fetch($id); - $this->assertLessThan($result, 0); - print __METHOD__." id=".$id." result=".$result."\n"; - return $localobject; - } + $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + return $localobject; + } - /** - * testActionCommUpdate - * - * @param Object $localobject ActionComm - * @return int Id action comm updated - * - * @depends testActionCommFetch - * The depends says test is run only if previous is ok - */ - public function testActionCommUpdate($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testActionCommUpdate + * + * @param Object $localobject ActionComm + * @return int Id action comm updated + * + * @depends testActionCommFetch + * The depends says test is run only if previous is ok + */ + public function testActionCommUpdate($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject->label='New label'; - $result=$localobject->update($user); + $localobject->label='New label'; + $result=$localobject->update($user); - $this->assertLessThan($result, 0); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - return $localobject->id; - } + $this->assertLessThan($result, 0); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + return $localobject->id; + } - /** - * testActionCommDelete - * - * @param int $id Id of action comm - * @return int Result of delete - * - * @depends testActionCommUpdate - * The depends says test is run only if previous is ok - */ - public function testActionCommDelete($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testActionCommDelete + * + * @param int $id Id of action comm + * @return int Result of delete + * + * @depends testActionCommUpdate + * The depends says test is run only if previous is ok + */ + public function testActionCommDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new ActionComm($this->savdb); - $result=$localobject->fetch($id); - $result=$localobject->delete($user); + $localobject=new ActionComm($this->savdb); + $result=$localobject->fetch($id); + $result=$localobject->delete($user); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $result; - } + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $result; + } } diff --git a/test/phpunit/AdherentTest.php b/test/phpunit/AdherentTest.php index 384ce5fe6c6..d9ba2e267e9 100644 --- a/test/phpunit/AdherentTest.php +++ b/test/phpunit/AdherentTest.php @@ -32,9 +32,9 @@ require_once dirname(__FILE__).'/../../htdocs/adherents/class/adherent.class.php require_once dirname(__FILE__).'/../../htdocs/adherents/class/adherent_type.class.php'; if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -48,538 +48,542 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class AdherentTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return AdherentTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return AdherentTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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. - if (! empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) { - print "\n".__METHOD__." Company must be setup to have name-firstname in order 'Firstname Lastname'\n"; - die(); - } - if (! empty($conf->global->MAIN_MODULE_LDAP)) { print "\n".__METHOD__." module LDAP must be disabled.\n"; die(); } - if (! empty($conf->global->MAIN_MODULE_MAILMANSPIP)) { print "\n".__METHOD__." module MailmanSpip must be disabled.\n"; die(); } + if (! empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)) { + print "\n".__METHOD__." Company must be setup to have name-firstname in order 'Firstname Lastname'\n"; + die(); + } + if (! empty($conf->global->MAIN_MODULE_LDAP)) { + print "\n".__METHOD__." module LDAP must be disabled.\n"; die(); + } + if (! empty($conf->global->MAIN_MODULE_MAILMANSPIP)) { + print "\n".__METHOD__." module MailmanSpip must be disabled.\n"; die(); + } - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testAdherentTypeCreate - * - * @return void - */ - public function testAdherentTypeCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAdherentTypeCreate + * + * @return void + */ + public function testAdherentTypeCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new AdherentType($this->savdb); - $localobject->statut=1; - $localobject->label='Adherent type test'; - $localobject->subscription=1; - $localobject->vote=1; - $localobject->company='Old company label'; - $result=$localobject->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertLessThan($result, 0); + $localobject=new AdherentType($this->savdb); + $localobject->statut=1; + $localobject->label='Adherent type test'; + $localobject->subscription=1; + $localobject->vote=1; + $localobject->company='Old company label'; + $result=$localobject->create($user); + print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject->id; - } + return $localobject->id; + } - /** - * testAdherentCreate - * - * @param int $fk_adherent_type Id type of member - * @return int - * - * @depends testAdherentTypeCreate - * The depends says test is run only if previous is ok - */ - public function testAdherentCreate($fk_adherent_type) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAdherentCreate + * + * @param int $fk_adherent_type Id type of member + * @return int + * + * @depends testAdherentTypeCreate + * The depends says test is run only if previous is ok + */ + public function testAdherentCreate($fk_adherent_type) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Adherent($this->savdb); - $localobject->initAsSpecimen(); - $localobject->typeid=$fk_adherent_type; - $result=$localobject->create($user); + $localobject=new Adherent($this->savdb); + $localobject->initAsSpecimen(); + $localobject->typeid=$fk_adherent_type; + $result=$localobject->create($user); print __METHOD__." result=".$result."\n"; if ($result < 0) { print $localobject->error; } - $this->assertLessThan($result, 0); + $this->assertLessThan($result, 0); - return $result; - } + return $result; + } - /** - * testAdherentFetch - * - * @param int $id Id of object to fetch - * @return object Fetched object - * - * @depends testAdherentCreate - * The depends says test is run only if previous is ok - */ - public function testAdherentFetch($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAdherentFetch + * + * @param int $id Id of object to fetch + * @return object Fetched object + * + * @depends testAdherentCreate + * The depends says test is run only if previous is ok + */ + public function testAdherentFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Adherent($this->savdb); - $result=$localobject->fetch($id); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + $localobject=new Adherent($this->savdb); + $result=$localobject->fetch($id); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testAdherentFetchLogin - * - * @param Adherent $localobject Member instance - * @return Adherent - * - * @depends testAdherentFetch - * The depends says test is run only if previous is ok - */ - public function testAdherentFetchLogin(Adherent $localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAdherentFetchLogin + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentFetch + * The depends says test is run only if previous is ok + */ + public function testAdherentFetchLogin(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $newobject = new Adherent($this->savdb); - $result = $newobject->fetch_login($localobject->login); + $newobject = new Adherent($this->savdb); + $result = $newobject->fetch_login($localobject->login); - $this->assertEquals($newobject, $localobject); + $this->assertEquals($newobject, $localobject); - return $localobject; - } + return $localobject; + } - /** - * testAdherentUpdate - * - * @param Adherent $localobject Member instance - * @return Adherent - * - * @depends testAdherentFetchLogin - * The depends says test is run only if previous is ok - */ - public function testAdherentUpdate(Adherent $localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAdherentUpdate + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentFetchLogin + * The depends says test is run only if previous is ok + */ + public function testAdherentUpdate(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $timestamp = dol_now(); + $timestamp = dol_now(); - $localobject->civility_id = 0; - $localobject->login='newlogin'; - $localobject->company='New company label'; - $localobject->note_public='New note public after update'; - $localobject->note_private='New note private after update'; - $localobject->lastname='New name'; - $localobject->firstname='New firstname'; - $localobject->gender='man'; - $localobject->address='New address'; - $localobject->zip='New zip'; - $localobject->town='New town'; - $localobject->country_id=2; - $localobject->statut=0; - $localobject->morphy=0; - $localobject->phone='New tel pro'; - $localobject->phone_perso='New tel perso'; - $localobject->phone_mobile='New tel mobile'; - $localobject->email='newemail@newemail.com'; - $localobject->birth=$timestamp; - $result=$localobject->update($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - $result=$localobject->update_note($localobject->note_private, '_private'); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $localobject->civility_id = 0; + $localobject->login='newlogin'; + $localobject->company='New company label'; + $localobject->note_public='New note public after update'; + $localobject->note_private='New note private after update'; + $localobject->lastname='New name'; + $localobject->firstname='New firstname'; + $localobject->gender='man'; + $localobject->address='New address'; + $localobject->zip='New zip'; + $localobject->town='New town'; + $localobject->country_id=2; + $localobject->statut=0; + $localobject->morphy=0; + $localobject->phone='New tel pro'; + $localobject->phone_perso='New tel perso'; + $localobject->phone_mobile='New tel mobile'; + $localobject->email='newemail@newemail.com'; + $localobject->birth=$timestamp; + $result=$localobject->update($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + $result=$localobject->update_note($localobject->note_private, '_private'); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); $result=$localobject->update_note($localobject->note_public, '_public'); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); - $newobject=new Adherent($this->savdb); - $result=$newobject->fetch($localobject->id); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $newobject=new Adherent($this->savdb); + $result=$newobject->fetch($localobject->id); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); - $this->assertEquals($localobject->civility_id, $newobject->civility_id); - $this->assertEquals($localobject->login, $newobject->login); - $this->assertEquals($localobject->company, $newobject->company); - $this->assertEquals($localobject->note_public, $newobject->note_public); - $this->assertEquals($localobject->note_private, $newobject->note_private); - $this->assertEquals($localobject->lastname, $newobject->lastname); - $this->assertEquals($localobject->firstname, $newobject->firstname); - $this->assertEquals($localobject->gender, $newobject->gender); - $this->assertEquals($localobject->address, $newobject->address); - $this->assertEquals($localobject->zip, $newobject->zip); - $this->assertEquals($localobject->town, $newobject->town); - $this->assertEquals($localobject->country_id, $newobject->country_id); - $this->assertEquals('BE', $newobject->country_code); - $this->assertEquals('Belgium', $newobject->country); - $this->assertEquals($localobject->statut, $newobject->statut); - $this->assertEquals($localobject->phone, $newobject->phone); - $this->assertEquals($localobject->phone_perso, $newobject->phone_perso); - $this->assertEquals($localobject->phone_mobile, $newobject->phone_mobile); - $this->assertEquals($localobject->email, $newobject->email); - $this->assertEquals($localobject->birth, $timestamp); - $this->assertEquals($localobject->morphy, $newobject->morphy); + $this->assertEquals($localobject->civility_id, $newobject->civility_id); + $this->assertEquals($localobject->login, $newobject->login); + $this->assertEquals($localobject->company, $newobject->company); + $this->assertEquals($localobject->note_public, $newobject->note_public); + $this->assertEquals($localobject->note_private, $newobject->note_private); + $this->assertEquals($localobject->lastname, $newobject->lastname); + $this->assertEquals($localobject->firstname, $newobject->firstname); + $this->assertEquals($localobject->gender, $newobject->gender); + $this->assertEquals($localobject->address, $newobject->address); + $this->assertEquals($localobject->zip, $newobject->zip); + $this->assertEquals($localobject->town, $newobject->town); + $this->assertEquals($localobject->country_id, $newobject->country_id); + $this->assertEquals('BE', $newobject->country_code); + $this->assertEquals('Belgium', $newobject->country); + $this->assertEquals($localobject->statut, $newobject->statut); + $this->assertEquals($localobject->phone, $newobject->phone); + $this->assertEquals($localobject->phone_perso, $newobject->phone_perso); + $this->assertEquals($localobject->phone_mobile, $newobject->phone_mobile); + $this->assertEquals($localobject->email, $newobject->email); + $this->assertEquals($localobject->birth, $timestamp); + $this->assertEquals($localobject->morphy, $newobject->morphy); - //We return newobject because of new values - return $newobject; - } + //We return newobject because of new values + return $newobject; + } - /** - * testAdherentMakeSubstitution - * - * @param Adherent $localobject Member instance - * @return Adherent - * - * @depends testAdherentUpdate - * The depends says test is run only if previous is ok - */ - public function testAdherentMakeSubstitution(Adherent $localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAdherentMakeSubstitution + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentUpdate + * The depends says test is run only if previous is ok + */ + public function testAdherentMakeSubstitution(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $conf->global->MAIN_FIRSTNAME_NAME_POSITION = 0; // Force setup for firstname+lastname + $conf->global->MAIN_FIRSTNAME_NAME_POSITION = 0; // Force setup for firstname+lastname - $template = '__CIVILITY__,__FIRSTNAME__,__LASTNAME__,__FULLNAME__,__COMPANY__,'; - $template .= '__ADDRESS__,__ZIP__,__TOWN__,__COUNTRY__,__EMAIL__,__BIRTH__,__PHOTO__,__LOGIN__'; + $template = '__CIVILITY__,__FIRSTNAME__,__LASTNAME__,__FULLNAME__,__COMPANY__,'; + $template .= '__ADDRESS__,__ZIP__,__TOWN__,__COUNTRY__,__EMAIL__,__BIRTH__,__PHOTO__,__LOGIN__'; - // If option to store clear password has been set, we get 'dolibspec' into PASSWORD field. - $expected = ',New firstname,New name,New firstname New name,'; - $expected .= 'New company label,New address,New zip,New town,Belgium,newemail@newemail.com,'.dol_print_date($localobject->birth, 'day').',,'; - $expected .= 'newlogin'; + // If option to store clear password has been set, we get 'dolibspec' into PASSWORD field. + $expected = ',New firstname,New name,New firstname New name,'; + $expected .= 'New company label,New address,New zip,New town,Belgium,newemail@newemail.com,'.dol_print_date($localobject->birth, 'day').',,'; + $expected .= 'newlogin'; - $result = $localobject->makeSubstitution($template); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($expected, $result); + $result = $localobject->makeSubstitution($template); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($expected, $result); - return $localobject; - } + return $localobject; + } - /** - * testAdherentSetUserId - * - * @param Adherent $localobject Member instance - * @return Adherent - * - * @depends testAdherentMakeSubstitution - * The depends says test is run only if previous is ok - */ - public function testAdherentSetUserId(Adherent $localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAdherentSetUserId + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentMakeSubstitution + * The depends says test is run only if previous is ok + */ + public function testAdherentSetUserId(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - //We associate member with user - $result = $localobject->setUserId($user->id); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertEquals($result, 1); + //We associate member with user + $result = $localobject->setUserId($user->id); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertEquals($result, 1); - //We update user object - $user->fetch($user->id); - print __METHOD__." user id=".$user->id." fk_member=".$user->fk_member."\n"; + //We update user object + $user->fetch($user->id); + print __METHOD__." user id=".$user->id." fk_member=".$user->fk_member."\n"; - $this->assertEquals($user->fk_member, $localobject->id); + $this->assertEquals($user->fk_member, $localobject->id); - //We remove association with user - $result = $localobject->setUserId(0); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertEquals($result, 1); + //We remove association with user + $result = $localobject->setUserId(0); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertEquals($result, 1); - //We update user object - $user->fetch($user->id); - print __METHOD__." user id=".$user->id." fk_member=".$user->fk_member."\n"; + //We update user object + $user->fetch($user->id); + print __METHOD__." user id=".$user->id." fk_member=".$user->fk_member."\n"; - $this->assertNull($user->fk_member); + $this->assertNull($user->fk_member); - return $localobject; - } + return $localobject; + } - /** - * testAdherentSetThirdPartyId - * - * @param Adherent $localobject Member instance - * @return Adherent - * - * @depends testAdherentSetUserId - * The depends says test is run only if previous is ok - */ - public function testAdherentSetThirdPartyId(Adherent $localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAdherentSetThirdPartyId + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentSetUserId + * The depends says test is run only if previous is ok + */ + public function testAdherentSetThirdPartyId(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - //Create a Third Party - $thirdparty = new Societe($db); - $thirdparty->initAsSpecimen(); - $result = $thirdparty->create($user); - print __METHOD__." third party id=".$thirdparty->id." result=".$result."\n"; - $this->assertTrue($result > 0, 'Test to create a thirdparty specimen to use it to set as thirdparty of a member'); + //Create a Third Party + $thirdparty = new Societe($db); + $thirdparty->initAsSpecimen(); + $result = $thirdparty->create($user); + print __METHOD__." third party id=".$thirdparty->id." result=".$result."\n"; + $this->assertTrue($result > 0, 'Test to create a thirdparty specimen to use it to set as thirdparty of a member'); - //Set Third Party ID - $result = $localobject->setThirdPartyId($thirdparty->id); - $this->assertEquals($result, 1, 'Set thirdparty'); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; + //Set Third Party ID + $result = $localobject->setThirdPartyId($thirdparty->id); + $this->assertEquals($result, 1, 'Set thirdparty'); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; - //Adherent is updated with new data - $localobject->fetch($localobject->id); - $this->assertEquals($localobject->fk_soc, $thirdparty->id, 'Fetch member'); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; + //Adherent is updated with new data + $localobject->fetch($localobject->id); + $this->assertEquals($localobject->fk_soc, $thirdparty->id, 'Fetch member'); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; - //We remove the third party association - $result = $localobject->setThirdPartyId(0); - $this->assertEquals($result, 1, 'Removed the link with thirdparty'); + //We remove the third party association + $result = $localobject->setThirdPartyId(0); + $this->assertEquals($result, 1, 'Removed the link with thirdparty'); - //And check if it has been updated - $localobject->fetch($localobject->id); - $this->assertNull($localobject->fk_soc, 'Check field is null'); + //And check if it has been updated + $localobject->fetch($localobject->id); + $this->assertNull($localobject->fk_soc, 'Check field is null'); - //Now we remove the third party - $result = $thirdparty->delete($thirdparty->id, $user); - $this->assertEquals($result, 1, 'Delete thirdparty'); + //Now we remove the third party + $result = $thirdparty->delete($thirdparty->id, $user); + $this->assertEquals($result, 1, 'Delete thirdparty'); - return $localobject; - } + return $localobject; + } - /** - * testAdherentValid - * - * @param Adherent $localobject Member instance - * @return Adherent - * - * @depends testAdherentSetThirdPartyId - * The depends says test is run only if previous is ok - */ - public function testAdherentValidate(Adherent $localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAdherentValid + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentSetThirdPartyId + * The depends says test is run only if previous is ok + */ + public function testAdherentValidate(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->validate($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $result=$localobject->validate($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject; - } + return $localobject; + } - /** - * testAdherentOther - * - * @param Adherent $localobject Member instance - * @return int Id of object - * - * @depends testAdherentValidate - * The depends says test is run only if previous is ok - */ - public function testAdherentOther(Adherent $localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAdherentOther + * + * @param Adherent $localobject Member instance + * @return int Id of object + * + * @depends testAdherentValidate + * The depends says test is run only if previous is ok + */ + public function testAdherentOther(Adherent $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); - */ + /*$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, ''); + $localobject->info($localobject->id); + print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; + $this->assertNotEquals($localobject->date_creation, ''); - return $localobject; - } + return $localobject; + } - /** - * testAdherentResiliate - * - * @param Adherent $localobject Member instance - * @return Adherent - * - * @depends testAdherentOther - * The depends says test is run only if previous is ok - */ - public function testAdherentResiliate(Adherent $localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAdherentResiliate + * + * @param Adherent $localobject Member instance + * @return Adherent + * + * @depends testAdherentOther + * The depends says test is run only if previous is ok + */ + public function testAdherentResiliate(Adherent $localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - //Let's resilie un adherent - $result = $localobject->resiliate($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertEquals($result, 1); + //Let's resilie un adherent + $result = $localobject->resiliate($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertEquals($result, 1); - //Is statut updated? - $this->assertEquals($localobject->statut, 0); + //Is statut updated? + $this->assertEquals($localobject->statut, 0); - //We update the object and let's check if it was updated on DB - $localobject->fetch($localobject->id); - $this->assertEquals($localobject->statut, 0); + //We update the object and let's check if it was updated on DB + $localobject->fetch($localobject->id); + $this->assertEquals($localobject->statut, 0); - //Now that status=0, resiliate should return 0 - $result = $localobject->resiliate($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertEquals($result, 0); + //Now that status=0, resiliate should return 0 + $result = $localobject->resiliate($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertEquals($result, 0); - return $localobject; - } + return $localobject; + } - /** - * testAdherentDelete - * - * @param Adherent $localobject Member instance - * @return void - * - * @depends testAdherentResiliate - * The depends says test is run only if previous is ok - */ - public function testAdherentDelete($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAdherentDelete + * + * @param Adherent $localobject Member instance + * @return void + * + * @depends testAdherentResiliate + * The depends says test is run only if previous is ok + */ + public function testAdherentDelete($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->delete($localobject->id, $user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $result=$localobject->delete($localobject->id, $user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject; - } + return $localobject; + } - /** - * testAdherentTypeDelete - * - * @param Adherent $localobject Member instance - * @return void - * - * @depends testAdherentDelete - * The depends says test is run only if previous is ok - */ - public function testAdherentTypeDelete($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testAdherentTypeDelete + * + * @param Adherent $localobject Member instance + * @return void + * + * @depends testAdherentDelete + * The depends says test is run only if previous is ok + */ + public function testAdherentTypeDelete($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobjectat=new AdherentType($this->savdb); - $result=$localobjectat->fetch($localobject->typeid); - $result=$localobjectat->delete(); - print __METHOD__." result=".$result."\n"; - $this->assertLessThan($result, 0); + $localobjectat=new AdherentType($this->savdb); + $result=$localobjectat->fetch($localobject->typeid); + $result=$localobjectat->delete(); + print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject->id; - } + return $localobject->id; + } } diff --git a/test/phpunit/AdminLibTest.php b/test/phpunit/AdminLibTest.php index c7b5aee9e37..9ce135da263 100644 --- a/test/phpunit/AdminLibTest.php +++ b/test/phpunit/AdminLibTest.php @@ -30,9 +30,9 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/admin.lib.php'; if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -46,121 +46,121 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class AdminLibTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return AdminLibTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return AdminLibTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testVersionCompare - * - * @return void - */ - public function testVersionCompare() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testVersionCompare + * + * @return void + */ + public function testVersionCompare() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=versioncompare(array(3,1,-4), array(3,1,1)); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(-3, $result); - $result=versioncompare(array(3,1,0), array(3,1,1)); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(-3, $result); - $result=versioncompare(array(3,1,0), array(3,2,0)); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(-2, $result); - $result=versioncompare(array(3,1,0), array(3,1,0)); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(0, $result); + $result=versioncompare(array(3,1,-4), array(3,1,1)); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(-3, $result); + $result=versioncompare(array(3,1,0), array(3,1,1)); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(-3, $result); + $result=versioncompare(array(3,1,0), array(3,2,0)); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(-2, $result); + $result=versioncompare(array(3,1,0), array(3,1,0)); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(0, $result); - return $result; - } + return $result; + } - /** - * testEnableModule - * - * @return void - */ - public function testEnableModule() - { - global $conf, $db, $langs, $user; + /** + * testEnableModule + * + * @return void + */ + public function testEnableModule() + { + global $conf, $db, $langs, $user; require_once dirname(__FILE__).'/../../htdocs/core/modules/modExpenseReport.class.php'; print "Enable module modExpenseReport"; @@ -177,5 +177,5 @@ class AdminLibTest extends PHPUnit\Framework\TestCase print __METHOD__." result=".$result."\n"; $this->assertEquals(1, $result); $conf->setValues($db); - } + } } diff --git a/test/phpunit/AllTests.php b/test/phpunit/AllTests.php index ce7f1074721..2444e8fe9dc 100644 --- a/test/phpunit/AllTests.php +++ b/test/phpunit/AllTests.php @@ -33,30 +33,25 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; print 'DOL_MAIN_URL_ROOT='.DOL_MAIN_URL_ROOT."\n"; // constant will be used by other tests -if ($langs->defaultlang != 'en_US') -{ - print "Error: Default language for company to run tests must be set to en_US or auto. Current is ".$langs->defaultlang."\n"; - exit(1); +if ($langs->defaultlang != 'en_US') { + print "Error: Default language for company to run tests must be set to en_US or auto. Current is ".$langs->defaultlang."\n"; + exit(1); } -if (empty($conf->adherent->enabled)) -{ +if (empty($conf->adherent->enabled)) { print "Error: Module member must be enabled to have significant results.\n"; exit(1); } -if (! empty($conf->ldap->enabled)) -{ - print "Error: LDAP module should not be enabled.\n"; - exit(1); +if (! empty($conf->ldap->enabled)) { + print "Error: LDAP module should not be enabled.\n"; + exit(1); } -if (! empty($conf->google->enabled)) -{ - print "Warning: Google module should not be enabled.\n"; +if (! empty($conf->google->enabled)) { + print "Warning: Google module should not be enabled.\n"; } -if (empty($user->id)) -{ - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); +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; @@ -67,200 +62,200 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class AllTests { - /** - * Function suite to make all PHPUnit tests - * - * @return void - */ - public static function suite() - { + /** + * Function suite to make all PHPUnit tests + * + * @return void + */ + public static function suite() + { - $suite = new PHPUnit\Framework\TestSuite('PHPUnit Framework'); + $suite = new PHPUnit\Framework\TestSuite('PHPUnit Framework'); - //require_once dirname(__FILE__).'/CoreTest.php'; - //$suite->addTestSuite('CoreTest'); - require_once dirname(__FILE__).'/AdminLibTest.php'; - $suite->addTestSuite('AdminLibTest'); - require_once dirname(__FILE__).'/CompanyLibTest.php'; - $suite->addTestSuite('CompanyLibTest'); - require_once dirname(__FILE__).'/DateLibTest.php'; - $suite->addTestSuite('DateLibTest'); - require_once dirname(__FILE__).'/UtilsTest.php'; - $suite->addTestSuite('UtilsTest'); - require_once dirname(__FILE__).'/LesscTest.php'; - $suite->addTestSuite('LesscTest'); - //require_once dirname(__FILE__).'/DateLibTzFranceTest.php'; - //$suite->addTestSuite('DateLibTzFranceTest'); - require_once dirname(__FILE__).'/MarginsLibTest.php'; - $suite->addTestSuite('MarginsLibTest'); - require_once dirname(__FILE__).'/FilesLibTest.php'; - $suite->addTestSuite('FilesLibTest'); - require_once dirname(__FILE__).'/GetUrlLibTest.php'; - $suite->addTestSuite('GetUrlLibTest'); - require_once dirname(__FILE__).'/JsonLibTest.php'; - $suite->addTestSuite('JsonLibTest'); - require_once dirname(__FILE__).'/ImagesLibTest.php'; - $suite->addTestSuite('ImagesLibTest'); - require_once dirname(__FILE__).'/FunctionsLibTest.php'; - $suite->addTestSuite('FunctionsLibTest'); - require_once dirname(__FILE__).'/Functions2LibTest.php'; - $suite->addTestSuite('Functions2LibTest'); - require_once dirname(__FILE__).'/XCalLibTest.php'; - $suite->addTestSuite('XCalLibTest'); + //require_once dirname(__FILE__).'/CoreTest.php'; + //$suite->addTestSuite('CoreTest'); + require_once dirname(__FILE__).'/AdminLibTest.php'; + $suite->addTestSuite('AdminLibTest'); + require_once dirname(__FILE__).'/CompanyLibTest.php'; + $suite->addTestSuite('CompanyLibTest'); + require_once dirname(__FILE__).'/DateLibTest.php'; + $suite->addTestSuite('DateLibTest'); + require_once dirname(__FILE__).'/UtilsTest.php'; + $suite->addTestSuite('UtilsTest'); + require_once dirname(__FILE__).'/LesscTest.php'; + $suite->addTestSuite('LesscTest'); + //require_once dirname(__FILE__).'/DateLibTzFranceTest.php'; + //$suite->addTestSuite('DateLibTzFranceTest'); + require_once dirname(__FILE__).'/MarginsLibTest.php'; + $suite->addTestSuite('MarginsLibTest'); + require_once dirname(__FILE__).'/FilesLibTest.php'; + $suite->addTestSuite('FilesLibTest'); + require_once dirname(__FILE__).'/GetUrlLibTest.php'; + $suite->addTestSuite('GetUrlLibTest'); + require_once dirname(__FILE__).'/JsonLibTest.php'; + $suite->addTestSuite('JsonLibTest'); + require_once dirname(__FILE__).'/ImagesLibTest.php'; + $suite->addTestSuite('ImagesLibTest'); + require_once dirname(__FILE__).'/FunctionsLibTest.php'; + $suite->addTestSuite('FunctionsLibTest'); + require_once dirname(__FILE__).'/Functions2LibTest.php'; + $suite->addTestSuite('Functions2LibTest'); + require_once dirname(__FILE__).'/XCalLibTest.php'; + $suite->addTestSuite('XCalLibTest'); - // Rules into source files content - require_once dirname(__FILE__).'/LangTest.php'; - $suite->addTestSuite('LangTest'); - require_once dirname(__FILE__).'/CodingSqlTest.php'; - $suite->addTestSuite('CodingSqlTest'); - require_once dirname(__FILE__).'/CodingPhpTest.php'; - $suite->addTestSuite('CodingPhpTest'); + // Rules into source files content + require_once dirname(__FILE__).'/LangTest.php'; + $suite->addTestSuite('LangTest'); + require_once dirname(__FILE__).'/CodingSqlTest.php'; + $suite->addTestSuite('CodingSqlTest'); + require_once dirname(__FILE__).'/CodingPhpTest.php'; + $suite->addTestSuite('CodingPhpTest'); - require_once dirname(__FILE__).'/SecurityTest.php'; - $suite->addTestSuite('SecurityTest'); + require_once dirname(__FILE__).'/SecurityTest.php'; + $suite->addTestSuite('SecurityTest'); - require_once dirname(__FILE__).'/UserTest.php'; - $suite->addTestSuite('UserTest'); - require_once dirname(__FILE__).'/UserGroupTest.php'; - $suite->addTestSuite('UserGroupTest'); + require_once dirname(__FILE__).'/UserTest.php'; + $suite->addTestSuite('UserTest'); + require_once dirname(__FILE__).'/UserGroupTest.php'; + $suite->addTestSuite('UserGroupTest'); - require_once dirname(__FILE__).'/NumberingModulesTest.php'; - $suite->addTestSuite('NumberingModulesTest'); - require_once dirname(__FILE__).'/PgsqlTest.php'; - $suite->addTestSuite('PgsqlTest'); - require_once dirname(__FILE__).'/PdfDocTest.php'; - $suite->addTestSuite('PdfDocTest'); - require_once dirname(__FILE__).'/BuildDocTest.php'; - $suite->addTestSuite('BuildDocTest'); - require_once dirname(__FILE__).'/CMailFileTest.php'; - $suite->addTestSuite('CMailFileTest'); + require_once dirname(__FILE__).'/NumberingModulesTest.php'; + $suite->addTestSuite('NumberingModulesTest'); + require_once dirname(__FILE__).'/PgsqlTest.php'; + $suite->addTestSuite('PgsqlTest'); + require_once dirname(__FILE__).'/PdfDocTest.php'; + $suite->addTestSuite('PdfDocTest'); + require_once dirname(__FILE__).'/BuildDocTest.php'; + $suite->addTestSuite('BuildDocTest'); + require_once dirname(__FILE__).'/CMailFileTest.php'; + $suite->addTestSuite('CMailFileTest'); - require_once dirname(__FILE__).'/CommonObjectTest.php'; - $suite->addTestSuite('CommonObjectTest'); + require_once dirname(__FILE__).'/CommonObjectTest.php'; + $suite->addTestSuite('CommonObjectTest'); - require_once dirname(__FILE__).'/ActionCommTest.php'; - $suite->addTestSuite('ActionCommTest'); - require_once dirname(__FILE__).'/SocieteTest.php'; - $suite->addTestSuite('SocieteTest'); - require_once dirname(__FILE__).'/ContactTest.php'; - $suite->addTestSuite('ContactTest'); - require_once dirname(__FILE__).'/AdherentTest.php'; - $suite->addTestSuite('AdherentTest'); + require_once dirname(__FILE__).'/ActionCommTest.php'; + $suite->addTestSuite('ActionCommTest'); + require_once dirname(__FILE__).'/SocieteTest.php'; + $suite->addTestSuite('SocieteTest'); + require_once dirname(__FILE__).'/ContactTest.php'; + $suite->addTestSuite('ContactTest'); + require_once dirname(__FILE__).'/AdherentTest.php'; + $suite->addTestSuite('AdherentTest'); - require_once dirname(__FILE__).'/ProductTest.php'; - $suite->addTestSuite('ProductTest'); + require_once dirname(__FILE__).'/ProductTest.php'; + $suite->addTestSuite('ProductTest'); - require_once dirname(__FILE__).'/PricesTest.php'; - $suite->addTestSuite('PricesTest'); - require_once dirname(__FILE__).'/DiscountTest.php'; - $suite->addTestSuite('DiscountTest'); + require_once dirname(__FILE__).'/PricesTest.php'; + $suite->addTestSuite('PricesTest'); + require_once dirname(__FILE__).'/DiscountTest.php'; + $suite->addTestSuite('DiscountTest'); - require_once dirname(__FILE__).'/BOMTest.php'; - $suite->addTestSuite('BOMTest'); + require_once dirname(__FILE__).'/BOMTest.php'; + $suite->addTestSuite('BOMTest'); - require_once dirname(__FILE__).'/ContratTest.php'; - $suite->addTestSuite('ContratTest'); + require_once dirname(__FILE__).'/ContratTest.php'; + $suite->addTestSuite('ContratTest'); - require_once dirname(__FILE__).'/FichinterTest.php'; - $suite->addTestSuite('FichinterTest'); - require_once dirname(__FILE__).'/TicketTest.php'; - $suite->addTestSuite('TicketTest'); + require_once dirname(__FILE__).'/FichinterTest.php'; + $suite->addTestSuite('FichinterTest'); + require_once dirname(__FILE__).'/TicketTest.php'; + $suite->addTestSuite('TicketTest'); - require_once dirname(__FILE__).'/PropalTest.php'; - $suite->addTestSuite('PropalTest'); + require_once dirname(__FILE__).'/PropalTest.php'; + $suite->addTestSuite('PropalTest'); - require_once dirname(__FILE__).'/SupplierProposalTest.php'; - $suite->addTestSuite('SupplierProposalTest'); + require_once dirname(__FILE__).'/SupplierProposalTest.php'; + $suite->addTestSuite('SupplierProposalTest'); - require_once dirname(__FILE__).'/CommandeTest.php'; - $suite->addTestSuite('CommandeTest'); + require_once dirname(__FILE__).'/CommandeTest.php'; + $suite->addTestSuite('CommandeTest'); - require_once dirname(__FILE__).'/CommandeFournisseurTest.php'; - $suite->addTestSuite('CommandeFournisseurTest'); + require_once dirname(__FILE__).'/CommandeFournisseurTest.php'; + $suite->addTestSuite('CommandeFournisseurTest'); - require_once dirname(__FILE__).'/FactureTest.php'; - $suite->addTestSuite('FactureTest'); - require_once dirname(__FILE__).'/FactureRecTest.php'; - $suite->addTestSuite('FactureRecTest'); - require_once dirname(__FILE__).'/FactureTestRounding.php'; - $suite->addTestSuite('FactureTestRounding'); - require_once dirname(__FILE__).'/FactureFournisseurTest.php'; - $suite->addTestSuite('FactureFournisseurTest'); + require_once dirname(__FILE__).'/FactureTest.php'; + $suite->addTestSuite('FactureTest'); + require_once dirname(__FILE__).'/FactureRecTest.php'; + $suite->addTestSuite('FactureRecTest'); + require_once dirname(__FILE__).'/FactureTestRounding.php'; + $suite->addTestSuite('FactureTestRounding'); + require_once dirname(__FILE__).'/FactureFournisseurTest.php'; + $suite->addTestSuite('FactureFournisseurTest'); - require_once dirname(__FILE__).'/BankAccountTest.php'; - $suite->addTestSuite('BankAccountTest'); - require_once dirname(__FILE__).'/CompanyBankAccountTest.php'; - $suite->addTestSuite('CompanyBankAccountTest'); - require_once dirname(__FILE__).'/BonPrelevementTest.php'; - $suite->addTestSuite('BonPrelevementTest'); + require_once dirname(__FILE__).'/BankAccountTest.php'; + $suite->addTestSuite('BankAccountTest'); + require_once dirname(__FILE__).'/CompanyBankAccountTest.php'; + $suite->addTestSuite('CompanyBankAccountTest'); + require_once dirname(__FILE__).'/BonPrelevementTest.php'; + $suite->addTestSuite('BonPrelevementTest'); - require_once dirname(__FILE__).'/ChargeSocialesTest.php'; - $suite->addTestSuite('ChargeSocialesTest'); - require_once dirname(__FILE__).'/HolidayTest.php'; - $suite->addTestSuite('HolidayTest'); - require_once dirname(__FILE__).'/ExpenseReportTest.php'; - $suite->addTestSuite('ExpenseReportTest'); - require_once dirname(__FILE__).'/LoanTest.php'; - $suite->addTestSuite('LoanTest'); + require_once dirname(__FILE__).'/ChargeSocialesTest.php'; + $suite->addTestSuite('ChargeSocialesTest'); + require_once dirname(__FILE__).'/HolidayTest.php'; + $suite->addTestSuite('HolidayTest'); + require_once dirname(__FILE__).'/ExpenseReportTest.php'; + $suite->addTestSuite('ExpenseReportTest'); + require_once dirname(__FILE__).'/LoanTest.php'; + $suite->addTestSuite('LoanTest'); - require_once dirname(__FILE__).'/EntrepotTest.php'; - $suite->addTestSuite('EntrepotTest'); - require_once dirname(__FILE__).'/MouvementStockTest.php'; - $suite->addTestSuite('MouvementStockTest'); + require_once dirname(__FILE__).'/EntrepotTest.php'; + $suite->addTestSuite('EntrepotTest'); + require_once dirname(__FILE__).'/MouvementStockTest.php'; + $suite->addTestSuite('MouvementStockTest'); - require_once dirname(__FILE__).'/CategorieTest.php'; - $suite->addTestSuite('CategorieTest'); + require_once dirname(__FILE__).'/CategorieTest.php'; + $suite->addTestSuite('CategorieTest'); - require_once dirname(__FILE__).'/AccountingAccountTest.php'; - $suite->addTestSuite('AccountingAccountTest'); + require_once dirname(__FILE__).'/AccountingAccountTest.php'; + $suite->addTestSuite('AccountingAccountTest'); - require_once dirname(__FILE__).'/RestAPIUserTest.php'; - $suite->addTestSuite('RestAPIUserTest'); - require_once dirname(__FILE__).'/RestAPIDocumentTest.php'; - $suite->addTestSuite('RestAPIDocumentTest'); + require_once dirname(__FILE__).'/RestAPIUserTest.php'; + $suite->addTestSuite('RestAPIUserTest'); + require_once dirname(__FILE__).'/RestAPIDocumentTest.php'; + $suite->addTestSuite('RestAPIDocumentTest'); - // Test only with php7.2 or less - //if ((float) phpversion() < 7.3) - //{ - require_once dirname(__FILE__).'/WebservicesProductsTest.php'; - $suite->addTestSuite('WebservicesProductsTest'); - require_once dirname(__FILE__).'/WebservicesInvoicesTest.php'; - $suite->addTestSuite('WebservicesInvoicesTest'); - require_once dirname(__FILE__).'/WebservicesOrdersTest.php'; - $suite->addTestSuite('WebservicesOrdersTest'); - require_once dirname(__FILE__).'/WebservicesOtherTest.php'; - $suite->addTestSuite('WebservicesOtherTest'); - require_once dirname(__FILE__).'/WebservicesThirdpartyTest.php'; - $suite->addTestSuite('WebservicesThirdpartyTest'); - require_once dirname(__FILE__).'/WebservicesUserTest.php'; - $suite->addTestSuite('WebservicesUserTest'); - //} + // Test only with php7.2 or less + //if ((float) phpversion() < 7.3) + //{ + require_once dirname(__FILE__).'/WebservicesProductsTest.php'; + $suite->addTestSuite('WebservicesProductsTest'); + require_once dirname(__FILE__).'/WebservicesInvoicesTest.php'; + $suite->addTestSuite('WebservicesInvoicesTest'); + require_once dirname(__FILE__).'/WebservicesOrdersTest.php'; + $suite->addTestSuite('WebservicesOrdersTest'); + require_once dirname(__FILE__).'/WebservicesOtherTest.php'; + $suite->addTestSuite('WebservicesOtherTest'); + require_once dirname(__FILE__).'/WebservicesThirdpartyTest.php'; + $suite->addTestSuite('WebservicesThirdpartyTest'); + require_once dirname(__FILE__).'/WebservicesUserTest.php'; + $suite->addTestSuite('WebservicesUserTest'); + //} - require_once dirname(__FILE__).'/ExportTest.php'; - $suite->addTestSuite('ExportTest'); - require_once dirname(__FILE__).'/ImportTest.php'; - $suite->addTestSuite('ImportTest'); + require_once dirname(__FILE__).'/ExportTest.php'; + $suite->addTestSuite('ExportTest'); + require_once dirname(__FILE__).'/ImportTest.php'; + $suite->addTestSuite('ImportTest'); - require_once dirname(__FILE__).'/ScriptsTest.php'; - $suite->addTestSuite('ScriptsTest'); + require_once dirname(__FILE__).'/ScriptsTest.php'; + $suite->addTestSuite('ScriptsTest'); - require_once dirname(__FILE__).'/ModulesTest.php'; // At end because it's the longer - $suite->addTestSuite('ModulesTest'); + require_once dirname(__FILE__).'/ModulesTest.php'; // At end because it's the longer + $suite->addTestSuite('ModulesTest'); - // GUI - require_once dirname(__FILE__).'/FormAdminTest.php'; - $suite->addTestSuite('FormAdminTest'); - require_once dirname(__FILE__).'/FormTest.php'; - $suite->addTestSuite('FormTest'); + // GUI + require_once dirname(__FILE__).'/FormAdminTest.php'; + $suite->addTestSuite('FormAdminTest'); + require_once dirname(__FILE__).'/FormTest.php'; + $suite->addTestSuite('FormTest'); - // Payment services - require_once dirname(__FILE__).'/PaypalTest.php'; - $suite->addTestSuite('PaypalTest'); - require_once dirname(__FILE__).'/StripeTest.php'; - $suite->addTestSuite('StripeTest'); + // Payment services + require_once dirname(__FILE__).'/PaypalTest.php'; + $suite->addTestSuite('PaypalTest'); + require_once dirname(__FILE__).'/StripeTest.php'; + $suite->addTestSuite('StripeTest'); - return $suite; - } + return $suite; + } } diff --git a/test/phpunit/BOMTest.php b/test/phpunit/BOMTest.php index 872d0b09d18..1d8a6cfbfd2 100644 --- a/test/phpunit/BOMTest.php +++ b/test/phpunit/BOMTest.php @@ -75,10 +75,10 @@ class BOMTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ + * setUpBeforeClass + * + * @return void + */ public static function setUpBeforeClass() { global $conf,$user,$langs,$db; @@ -87,11 +87,11 @@ class BOMTest extends PHPUnit\Framework\TestCase print __METHOD__."\n"; } - /** - * tearDownAfterClass - * - * @return void - */ + /** + * tearDownAfterClass + * + * @return void + */ public static function tearDownAfterClass() { global $conf,$user,$langs,$db; @@ -129,7 +129,7 @@ class BOMTest extends PHPUnit\Framework\TestCase /** * testBOMCreate * - * @return int + * @return int */ public function testBOMCreate() { diff --git a/test/phpunit/BankAccountTest.php b/test/phpunit/BankAccountTest.php index fd92d242b31..0c43d2e53e8 100644 --- a/test/phpunit/BankAccountTest.php +++ b/test/phpunit/BankAccountTest.php @@ -30,9 +30,9 @@ 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(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -48,189 +48,189 @@ $langs->load("main"); */ class BankAccountTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return BankAccountTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return BankAccountTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } - /** - * End phpunit tests - * - * @return void - */ - protected function tearDown() - { - print __METHOD__."\n"; - } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testBankAccountCreate - * - * @return int - */ - public function testBankAccountCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testBankAccountCreate + * + * @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); + $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); + print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $result; - } + return $result; + } - /** - * testBankAccountFetch - * - * @param int $id Id of contract - * @return int - * - * @depends testBankAccountCreate - * 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; + /** + * testBankAccountFetch + * + * @param int $id Id of contract + * @return int + * + * @depends testBankAccountCreate + * 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); + $localobject=new Account($this->savdb); + $result=$localobject->fetch($id); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject; - } + return $localobject; + } - /** - * testBankAccountOther - * - * @param Object $localobject Object contract - * @return int - * - * @depends testBankAccountFetch - * 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; + /** + * testBankAccountOther + * + * @param Object $localobject Object contract + * @return int + * + * @depends testBankAccountFetch + * 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); - */ + /*$result=$localobject->setstatus(0); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + */ - $localobject->info($localobject->id); + $localobject->info($localobject->id); - $result = $localobject->needIBAN(); - //print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; - $this->assertEquals(1, $result); + $result = $localobject->needIBAN(); + //print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; + $this->assertEquals(1, $result); - return $localobject->id; - } + 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; + /** + * 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($user); + $localobject=new Account($this->savdb); + $result=$localobject->fetch($id); + $result=$localobject->delete($user); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $result; - } + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $result; + } } diff --git a/test/phpunit/BonPrelevementTest.php b/test/phpunit/BonPrelevementTest.php index 135c77dfa2d..314640aefda 100644 --- a/test/phpunit/BonPrelevementTest.php +++ b/test/phpunit/BonPrelevementTest.php @@ -29,8 +29,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/compta/prelevement/class/bonprelevement.class.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -76,65 +75,65 @@ class BonPrelevementTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testBonPrevelementCreate - * - * @return int - */ - public function testBonPrelevementCreate() - { - global $conf,$user,$langs,$db; + /** + * testBonPrevelementCreate + * + * @return int + */ + public function testBonPrelevementCreate() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -152,42 +151,42 @@ class BonPrelevementTest extends PHPUnit\Framework\TestCase // Create withdraw record and generate SEPA file $localobject=new BonPrelevement($this->savdb); - //$localobject->date_solde=dol_now(); - $result=$localobject->Create(0, 0, 'simu'); + //$localobject->date_solde=dol_now(); + $result=$localobject->Create(0, 0, 'simu'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, 0); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 0); - // Test SEPA file + // Test SEPA file - return $result; - } + return $result; + } - /** - * testBonPrelevementDelete - * - * @param int $id Id of contract - * @return int - * - * @depends testBonPrelevementOther - * The depends says test is run only if previous is ok - */ - /* public function testBonPrelevementDelete($id) - { - global $conf,$user,$langs,$db; + /** + * testBonPrelevementDelete + * + * @param int $id Id of contract + * @return int + * + * @depends testBonPrelevementOther + * The depends says test is run only if previous is ok + */ + /* public function testBonPrelevementDelete($id) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new BonPrelevement($this->savdb); - $result=$localobject->fetch($id); + $result=$localobject->fetch($id); $result=$localobject->delete($id); print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $result; - } - */ + $this->assertLessThan($result, 0); + return $result; + } + */ } diff --git a/test/phpunit/BuildDocTest.php b/test/phpunit/BuildDocTest.php index de4da3790b5..db1a7058307 100644 --- a/test/phpunit/BuildDocTest.php +++ b/test/phpunit/BuildDocTest.php @@ -60,9 +60,9 @@ require_once dirname(__FILE__).'/../../htdocs/core/modules/modExpenseReport.clas if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -76,365 +76,379 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class BuildDocTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return BuildDocTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return BuildDocTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + /** + * setUpBeforeClass + * + * @return void + */ + public static function setUpBeforeClass() + { + global $conf,$user,$langs,$db; - if (! $conf->facture->enabled) { print __METHOD__." invoice module not enabled\n"; die(); } - if (! $conf->commande->enabled) { print __METHOD__." order module not enabled\n"; die(); } - if (! $conf->propal->enabled) { print __METHOD__." propal module not enabled\n"; die(); } - if (! $conf->projet->enabled) { print __METHOD__." project module not enabled\n"; die(); } - if (! $conf->expedition->enabled) { print __METHOD__." shipment module not enabled\n"; die(); } - if (! $conf->ficheinter->enabled) { print __METHOD__." intervention module not enabled\n"; die(); } - if (! $conf->expensereport->enabled) { print __METHOD__." expensereport module not enabled\n"; die(); } + if (! $conf->facture->enabled) { + print __METHOD__." invoice module not enabled\n"; die(); + } + if (! $conf->commande->enabled) { + print __METHOD__." order module not enabled\n"; die(); + } + if (! $conf->propal->enabled) { + print __METHOD__." propal module not enabled\n"; die(); + } + if (! $conf->projet->enabled) { + print __METHOD__." project module not enabled\n"; die(); + } + if (! $conf->expedition->enabled) { + print __METHOD__." shipment module not enabled\n"; die(); + } + if (! $conf->ficheinter->enabled) { + print __METHOD__." intervention module not enabled\n"; die(); + } + if (! $conf->expensereport->enabled) { + print __METHOD__." expensereport module not enabled\n"; die(); + } - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testFactureBuild - * - * @return int - */ - public function testFactureBuild() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFactureBuild + * + * @return int + */ + public function testFactureBuild() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $conf->facture->dir_output.='/temp'; + $conf->facture->dir_output.='/temp'; - $localobjectcom=new Commande($this->savdb); - $localobjectcom->initAsSpecimen(); + $localobjectcom=new Commande($this->savdb); + $localobjectcom->initAsSpecimen(); - $localobject=new Facture($this->savdb); - $localobject->createFromOrder($localobjectcom, $user); - $localobject->date_lim_reglement = dol_now() + 3600 * 24 *30; + $localobject=new Facture($this->savdb); + $localobject->createFromOrder($localobjectcom, $user); + $localobject->date_lim_reglement = dol_now() + 3600 * 24 *30; - // Crabe (english) - $localobject->modelpdf='crabe'; - $result = $localobject->generateDocument($localobject->modelpdf, $langs); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + // Crabe (english) + $localobject->modelpdf='crabe'; + $result = $localobject->generateDocument($localobject->modelpdf, $langs); + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - // Crabe (japanese) - $newlangs1=new Translate("", $conf); - $newlangs1->setDefaultLang('ja_JP'); - $localobject->modelpdf='crabe'; - $result = $localobject->generateDocument($localobject->modelpdf, $newlangs1); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + // Crabe (japanese) + $newlangs1=new Translate("", $conf); + $newlangs1->setDefaultLang('ja_JP'); + $localobject->modelpdf='crabe'; + $result = $localobject->generateDocument($localobject->modelpdf, $newlangs1); + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - // Crabe (saudiarabia) - $newlangs2a=new Translate("", $conf); - $newlangs2a->setDefaultLang('sa_SA'); - $localobject->modelpdf='crabe'; - $result = $localobject->generateDocument($localobject->modelpdf, $newlangs2a); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + // Crabe (saudiarabia) + $newlangs2a=new Translate("", $conf); + $newlangs2a->setDefaultLang('sa_SA'); + $localobject->modelpdf='crabe'; + $result = $localobject->generateDocument($localobject->modelpdf, $newlangs2a); + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - // Crabe (english_saudiarabia) - $newlangs2b=new Translate("", $conf); - $newlangs2b->setDefaultLang('en_SA'); - $localobject->modelpdf='crabe'; - $result = $localobject->generateDocument($localobject->modelpdf, $newlangs2b); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + // Crabe (english_saudiarabia) + $newlangs2b=new Translate("", $conf); + $newlangs2b->setDefaultLang('en_SA'); + $localobject->modelpdf='crabe'; + $result = $localobject->generateDocument($localobject->modelpdf, $newlangs2b); + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - // Crabe (greek) - $newlangs3=new Translate("", $conf); - $newlangs3->setDefaultLang('el_GR'); - $localobject->modelpdf='crabe'; - $result = $localobject->generateDocument($localobject->modelpdf, $newlangs3); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + // Crabe (greek) + $newlangs3=new Translate("", $conf); + $newlangs3->setDefaultLang('el_GR'); + $localobject->modelpdf='crabe'; + $result = $localobject->generateDocument($localobject->modelpdf, $newlangs3); + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - // Crabe (chinese) - $newlangs4=new Translate("", $conf); - $newlangs4->setDefaultLang('zh_CN'); - $localobject->modelpdf='crabe'; - $result = $localobject->generateDocument($localobject->modelpdf, $newlangs4); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + // Crabe (chinese) + $newlangs4=new Translate("", $conf); + $newlangs4->setDefaultLang('zh_CN'); + $localobject->modelpdf='crabe'; + $result = $localobject->generateDocument($localobject->modelpdf, $newlangs4); + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - // Crabe (russian) - $newlangs5=new Translate("", $conf); - $newlangs5->setDefaultLang('ru_RU'); - $localobject->modelpdf='crabe'; - $result = $localobject->generateDocument($localobject->modelpdf, $newlangs5); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + // Crabe (russian) + $newlangs5=new Translate("", $conf); + $newlangs5->setDefaultLang('ru_RU'); + $localobject->modelpdf='crabe'; + $result = $localobject->generateDocument($localobject->modelpdf, $newlangs5); + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - return 0; - } + return 0; + } - /** - * testFactureFournisseurBuild - * - * @return int - */ - public function testFactureFournisseurBuild() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFactureFournisseurBuild + * + * @return int + */ + public function testFactureFournisseurBuild() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $conf->fournisseur->facture->dir_output.='/temp'; - $localobject=new FactureFournisseur($this->savdb); - $localobject->initAsSpecimen(); + $conf->fournisseur->facture->dir_output.='/temp'; + $localobject=new FactureFournisseur($this->savdb); + $localobject->initAsSpecimen(); - // Canelle - $localobject->modelpdf='canelle'; - $result = $localobject->generateDocument($localobject->modelpdf, $langs); + // Canelle + $localobject->modelpdf='canelle'; + $result = $localobject->generateDocument($localobject->modelpdf, $langs); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - return 0; - } + return 0; + } - /** - * testCommandeBuild - * - * @return int - */ - public function testCommandeBuild() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeBuild + * + * @return int + */ + public function testCommandeBuild() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $conf->commande->dir_output.='/temp'; - $localobject=new Commande($this->savdb); - $localobject->initAsSpecimen(); + $conf->commande->dir_output.='/temp'; + $localobject=new Commande($this->savdb); + $localobject->initAsSpecimen(); - // Einstein - $localobject->modelpdf='einstein'; - $result = $localobject->generateDocument($localobject->modelpdf, $langs); + // Einstein + $localobject->modelpdf='einstein'; + $result = $localobject->generateDocument($localobject->modelpdf, $langs); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - return 0; - } + return 0; + } - /** - * testCommandeFournisseurBuild - * - * @return int - */ - public function testCommandeFournisseurBuild() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeFournisseurBuild + * + * @return int + */ + public function testCommandeFournisseurBuild() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $conf->fournisseur->commande->dir_output.='/temp'; - $localobject=new CommandeFournisseur($this->savdb); - $localobject->initAsSpecimen(); + $conf->fournisseur->commande->dir_output.='/temp'; + $localobject=new CommandeFournisseur($this->savdb); + $localobject->initAsSpecimen(); - // Muscadet - $localobject->modelpdf='muscadet'; - $result= $localobject->generateDocument($localobject->modelpdf, $langs); + // Muscadet + $localobject->modelpdf='muscadet'; + $result= $localobject->generateDocument($localobject->modelpdf, $langs); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - return 0; - } + return 0; + } - /** - * testPropalBuild - * - * @return int - */ - public function testPropalBuild() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testPropalBuild + * + * @return int + */ + public function testPropalBuild() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $conf->propal->dir_output.='/temp'; - $localobject=new Propal($this->savdb); - $localobject->initAsSpecimen(); + $conf->propal->dir_output.='/temp'; + $localobject=new Propal($this->savdb); + $localobject->initAsSpecimen(); - // Azur - $localobject->modelpdf='azur'; - $result = $localobject->generateDocument($localobject->modelpdf, $langs); + // Azur + $localobject->modelpdf='azur'; + $result = $localobject->generateDocument($localobject->modelpdf, $langs); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - return 0; - } + return 0; + } - /** - * testProjectBuild - * - * @return int - */ - public function testProjectBuild() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; - $conf->projet->dir_output.='/temp'; - $localobject=new Project($this->savdb); - $localobject->initAsSpecimen(); + /** + * testProjectBuild + * + * @return int + */ + public function testProjectBuild() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + $conf->projet->dir_output.='/temp'; + $localobject=new Project($this->savdb); + $localobject->initAsSpecimen(); - // Baleine - $localobject->modelpdf='baleine'; - $result = $localobject->generateDocument($localobject->modelpdf, $langs); + // Baleine + $localobject->modelpdf='baleine'; + $result = $localobject->generateDocument($localobject->modelpdf, $langs); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - return 0; - } + return 0; + } - /** - * testFichinterBuild - * - * @return int - */ - public function testFichinterBuild() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFichinterBuild + * + * @return int + */ + public function testFichinterBuild() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $conf->ficheinter->dir_output.='/temp'; - $localobject=new Fichinter($this->savdb); - $localobject->initAsSpecimen(); + $conf->ficheinter->dir_output.='/temp'; + $localobject=new Fichinter($this->savdb); + $localobject->initAsSpecimen(); - // Soleil - $localobject->modelpdf='soleil'; - $result=fichinter_create($db, $localobject, $localobject->modelpdf, $langs); + // Soleil + $localobject->modelpdf='soleil'; + $result=fichinter_create($db, $localobject, $localobject->modelpdf, $langs); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - return 0; - } + return 0; + } - /** - * testExpeditionBuild - * - * @return int - */ - public function testExpeditionBuild() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testExpeditionBuild + * + * @return int + */ + public function testExpeditionBuild() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $conf->expedition->dir_output.='/temp'; - $localobject=new Expedition($this->savdb); - $localobject->initAsSpecimen(); + $conf->expedition->dir_output.='/temp'; + $localobject=new Expedition($this->savdb); + $localobject->initAsSpecimen(); - // Merou - $localobject->modelpdf='merou'; - $result= $localobject->generateDocument($localobject->modelpdf, $langs); + // Merou + $localobject->modelpdf='merou'; + $result= $localobject->generateDocument($localobject->modelpdf, $langs); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - // Rouget - $localobject->modelpdf='rouget'; - $result= $localobject->generateDocument($localobject->modelpdf, $langs); + // Rouget + $localobject->modelpdf='rouget'; + $result= $localobject->generateDocument($localobject->modelpdf, $langs); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; - return 0; - } + return 0; + } } diff --git a/test/phpunit/CMailFileTest.php b/test/phpunit/CMailFileTest.php index d407b67d991..7e4b5dbacb7 100755 --- a/test/phpunit/CMailFileTest.php +++ b/test/phpunit/CMailFileTest.php @@ -30,9 +30,9 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/class/CMailFile.class.php'; if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -46,163 +46,163 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class CMailFileTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return CMailFile - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return CMailFile + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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; - $conf->global->MAIN_DISABLE_ALL_MAILS=1; // If I comment/remove this lien, unit test still works alone but failed when ran from AllTest. Don't know why. + $conf->global->MAIN_DISABLE_ALL_MAILS=1; // If I comment/remove this lien, unit test still works alone but failed when ran from AllTest. Don't know why. - print __METHOD__."\n"; - } - /** - * End phpunit tests - * - * @return void - */ - protected function tearDown() - { - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testCMailFileText - * - * @return void - */ - public function testCMailFileText() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCMailFileText + * + * @return void + */ + public function testCMailFileText() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new CMailFile('Test', 'test@test.com', 'from@from.com', 'Message txt', array(), array(), array(), '', '', 1, 0); + $localobject=new CMailFile('Test', 'test@test.com', 'from@from.com', 'Message txt', array(), array(), array(), '', '', 1, 0); - $result=$localobject->sendfile(); - print __METHOD__." result=".$result."\n"; - $this->assertFalse($result); // False because mail send disabled + $result=$localobject->sendfile(); + print __METHOD__." result=".$result."\n"; + $this->assertFalse($result); // False because mail send disabled - return $result; - } + return $result; + } - /** - * testCMailFileStatic - * - * @return string - */ - public function testCMailFileStatic() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCMailFileStatic + * + * @return string + */ + public function testCMailFileStatic() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new CMailFile('', '', '', ''); + $localobject=new CMailFile('', '', '', ''); - $src='John Doe '; - $result=$localobject->getValidAddress($src, 0); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, 'John Doe '); + $src='John Doe '; + $result=$localobject->getValidAddress($src, 0); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 'John Doe '); - $src='John Doe '; - $result=$localobject->getValidAddress($src, 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, ''); + $src='John Doe '; + $result=$localobject->getValidAddress($src, 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, ''); - $src='John Doe '; - $result=$localobject->getValidAddress($src, 2); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, 'john@doe.com'); + $src='John Doe '; + $result=$localobject->getValidAddress($src, 2); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 'john@doe.com'); - $src='John Doe '; - $result=$localobject->getValidAddress($src, 3, 0); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, '"John Doe" '); + $src='John Doe '; + $result=$localobject->getValidAddress($src, 3, 0); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"John Doe" '); - $src='John Doe '; - $result=$localobject->getValidAddress($src, 3, 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, '"=?UTF-8?B?Sm9obiBEb2U=?=" '); + $src='John Doe '; + $result=$localobject->getValidAddress($src, 3, 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"=?UTF-8?B?Sm9obiBEb2U=?=" '); - $src='John Doe '; - $result=$localobject->getValidAddress($src, 4); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, 'John Doe'); + $src='John Doe '; + $result=$localobject->getValidAddress($src, 4); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 'John Doe'); - $src='John Doe , John Doe2 , John Doe3 '; - $result=$localobject->getValidAddress($src, 4); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, 'John Doe,John Doe2,John Doe3'); + $src='John Doe , John Doe2 , John Doe3 '; + $result=$localobject->getValidAddress($src, 4); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 'John Doe,John Doe2,John Doe3'); - $src='John Doe , John Doe2 , John Doe3 '; - $result=$localobject->getValidAddress($src, 4, 0, 2); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, 'John Doe,John Doe2...'); + $src='John Doe , John Doe2 , John Doe3 '; + $result=$localobject->getValidAddress($src, 4, 0, 2); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 'John Doe,John Doe2...'); - return $result; - } + return $result; + } } diff --git a/test/phpunit/CategorieTest.php b/test/phpunit/CategorieTest.php index 11aff6b1a79..67e7f937267 100644 --- a/test/phpunit/CategorieTest.php +++ b/test/phpunit/CategorieTest.php @@ -31,9 +31,9 @@ require_once dirname(__FILE__).'/../../htdocs/categories/class/categorie.class.p require_once dirname(__FILE__).'/../../htdocs/product/class/product.class.php'; if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -47,303 +47,303 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class CategorieTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return CategorieTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return CategorieTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testCategorieCreate - * - * @return int - */ - public function testCategorieCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCategorieCreate + * + * @return int + */ + public function testCategorieCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - // We create a category - $localobject=new Categorie($this->savdb); - $localobject->initAsSpecimen(); + // We create a category + $localobject=new Categorie($this->savdb); + $localobject->initAsSpecimen(); - // Check it does not exist (return 0) - $resultCheck=$localobject->already_exists(); - print __METHOD__." resultCheck=".$resultCheck."\n"; - $this->assertEquals(0, $resultCheck); + // Check it does not exist (return 0) + $resultCheck=$localobject->already_exists(); + print __METHOD__." resultCheck=".$resultCheck."\n"; + $this->assertEquals(0, $resultCheck); - // Create - $resultFirstCreate=$localobject->create($user); - print __METHOD__." resultFirstCreate=".$resultFirstCreate."\n"; - $this->assertGreaterThan(0, $resultFirstCreate); + // Create + $resultFirstCreate=$localobject->create($user); + print __METHOD__." resultFirstCreate=".$resultFirstCreate."\n"; + $this->assertGreaterThan(0, $resultFirstCreate); - // We try to create another one with same ref - $localobject2=new Categorie($this->savdb); - $localobject2->initAsSpecimen(); + // We try to create another one with same ref + $localobject2=new Categorie($this->savdb); + $localobject2->initAsSpecimen(); - // Check it does exist (return 1) - $resultCheck=$localobject2->already_exists(); - print __METHOD__." resultCheck=".$resultCheck."\n"; - $this->assertGreaterThan(0, $resultCheck); + // Check it does exist (return 1) + $resultCheck=$localobject2->already_exists(); + print __METHOD__." resultCheck=".$resultCheck."\n"; + $this->assertGreaterThan(0, $resultCheck); - $resultSecondCreate=$localobject2->create($user); - print __METHOD__." result=".$resultSecondCreate."\n"; - $this->assertEquals(-4, $resultSecondCreate); + $resultSecondCreate=$localobject2->create($user); + print __METHOD__." result=".$resultSecondCreate."\n"; + $this->assertEquals(-4, $resultSecondCreate); - return $resultFirstCreate; - } + return $resultFirstCreate; + } - /** - * testCategorieProduct - * - * @param int $id Id of category - * @return int - * - * @depends testCategorieCreate - * The depends says test is run only if previous is ok - */ - public function testCategorieProduct($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCategorieProduct + * + * @param int $id Id of category + * @return int + * + * @depends testCategorieCreate + * The depends says test is run only if previous is ok + */ + public function testCategorieProduct($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobjecttmp=new Categorie($this->savdb); - $localobjecttmp->initAsSpecimen(); - $localobjecttmp->label='Specimen Category for product'; - $localobjecttmp->type=0; // product category - $catid=$localobjecttmp->create($user); + $localobjecttmp=new Categorie($this->savdb); + $localobjecttmp->initAsSpecimen(); + $localobjecttmp->label='Specimen Category for product'; + $localobjecttmp->type=0; // product category + $catid=$localobjecttmp->create($user); - print __METHOD__." catid=".$catid."\n"; - $this->assertGreaterThan(0, $catid); + print __METHOD__." catid=".$catid."\n"; + $this->assertGreaterThan(0, $catid); - // Try to create product linked to category - $localobject2=new Product($this->savdb); - $localobject2->initAsSpecimen(); - $localobject2->ref.='-CATEG'; - $localobject2->tva_npr=1; - $result=$localobject2->create($user); - $cat = new Categorie($this->savdb); - $cat->id = $catid; - $cat->type = 0; - $result=$cat->add_type($localobject2, "product"); + // Try to create product linked to category + $localobject2=new Product($this->savdb); + $localobject2->initAsSpecimen(); + $localobject2->ref.='-CATEG'; + $localobject2->tva_npr=1; + $result=$localobject2->create($user); + $cat = new Categorie($this->savdb); + $cat->id = $catid; + $cat->type = 0; + $result=$cat->add_type($localobject2, "product"); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); - // Get list of categories for product - $localcateg=new Categorie($this->savdb); - $listofcateg=$localcateg->containing($localobject2->id, Categorie::TYPE_PRODUCT, 'label'); - $this->assertTrue(in_array('Specimen Category for product', $listofcateg), 'Categ not found linked to product when it should'); + // Get list of categories for product + $localcateg=new Categorie($this->savdb); + $listofcateg=$localcateg->containing($localobject2->id, Categorie::TYPE_PRODUCT, 'label'); + $this->assertTrue(in_array('Specimen Category for product', $listofcateg), 'Categ not found linked to product when it should'); - return $id; - } + return $id; + } - /** - * testCategorieFetch - * - * @param int $id Id of category - * @return int - * - * @depends testCategorieProduct - * The depends says test is run only if previous is ok - */ - public function testCategorieFetch($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCategorieFetch + * + * @param int $id Id of category + * @return int + * + * @depends testCategorieProduct + * The depends says test is run only if previous is ok + */ + public function testCategorieFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Categorie($this->savdb); - $result=$localobject->fetch($id); + $localobject=new Categorie($this->savdb); + $result=$localobject->fetch($id); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertGreaterThan(0, $result); - return $localobject; - } + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertGreaterThan(0, $result); + return $localobject; + } - /** - * testCategorieUpdate - * - * @param Categorie $localobject Category - * @return int + /** + * testCategorieUpdate + * + * @param Categorie $localobject Category + * @return int - * @depends testCategorieFetch - * The depends says test is run only if previous is ok - */ - public function testCategorieUpdate($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + * @depends testCategorieFetch + * The depends says test is run only if previous is ok + */ + public function testCategorieUpdate($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject->note='New note after update'; - $result=$localobject->update($user); + $localobject->note='New note after update'; + $result=$localobject->update($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertGreaterThan(0, $result); - return $localobject; - } + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertGreaterThan(0, $result); + return $localobject; + } - /** - * testCategorieOther - * - * @param Categorie $localobject Category - * @return int - * - * @depends testCategorieUpdate - * The depends says test is run only if previous is ok - */ - public function testCategorieOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCategorieOther + * + * @param Categorie $localobject Category + * @return int + * + * @depends testCategorieUpdate + * The depends says test is run only if previous is ok + */ + public function testCategorieOther($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); - */ - $localobject2=new Categorie($db); - $localobject2->initAsSpecimen(); + /*$result=$localobject->setstatus(0); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + */ + $localobject2=new Categorie($db); + $localobject2->initAsSpecimen(); - $retarray=$localobject->liste_photos('/'); - print __METHOD__." retarray size=".count($retarray)."\n"; - $this->assertTrue(is_array($retarray)); + $retarray=$localobject->liste_photos('/'); + print __METHOD__." retarray size=".count($retarray)."\n"; + $this->assertTrue(is_array($retarray)); - return $localobject->id; - } + return $localobject->id; + } - /** - * testCategorieDelete - * - * @param int $id Id of category - * @return int - * - * @depends testCategorieOther - * The depends says test is run only if previous is ok - */ - public function testCategorieDelete($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCategorieDelete + * + * @param int $id Id of category + * @return int + * + * @depends testCategorieOther + * The depends says test is run only if previous is ok + */ + public function testCategorieDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Categorie($this->savdb); - $result=$localobject->fetch($id); - $result=$localobject->delete($user); + $localobject=new Categorie($this->savdb); + $result=$localobject->fetch($id); + $result=$localobject->delete($user); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertGreaterThan(0, $result); - return $result; - } + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertGreaterThan(0, $result); + return $result; + } - /** - * testCategorieStatic - * - * @return void - * - * @depends testCategorieDelete - */ - public function testCategorieStatic() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCategorieStatic + * + * @return void + * + * @depends testCategorieDelete + */ + public function testCategorieStatic() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Categorie($this->savdb); - $retarray=$localobject->get_full_arbo(3); + $localobject=new Categorie($this->savdb); + $retarray=$localobject->get_full_arbo(3); - print __METHOD__." retarray size=".count($retarray)."\n"; - $this->assertTrue(is_array($retarray)); - return $retarray; - } + print __METHOD__." retarray size=".count($retarray)."\n"; + $this->assertTrue(is_array($retarray)); + return $retarray; + } } diff --git a/test/phpunit/ChargeSocialesTest.php b/test/phpunit/ChargeSocialesTest.php index 33349449795..386aa84a38b 100644 --- a/test/phpunit/ChargeSocialesTest.php +++ b/test/phpunit/ChargeSocialesTest.php @@ -29,11 +29,10 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/compta/sociales/class/chargesociales.class.php'; -if (empty($user->id)) -{ - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); +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; @@ -47,206 +46,206 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class ChargeSocialesTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return ChargeSocialesTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return ChargeSocialesTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testChargeSocialesCreate - * - * @return void - */ - public function testChargeSocialesCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testChargeSocialesCreate + * + * @return void + */ + public function testChargeSocialesCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new ChargeSociales($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user, $langs, $conf); - print __METHOD__." result=".$result."\n"; + $localobject=new ChargeSociales($this->savdb); + $localobject->initAsSpecimen(); + $result=$localobject->create($user, $langs, $conf); + print __METHOD__." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $result; - } + $this->assertLessThan($result, 0); + return $result; + } - /** - * testChargeSocialesFetch - * - * @param int $id Id of social contribution - * @return void - * - * @depends testChargeSocialesCreate - * The depends says test is run only if previous is ok - */ - public function testChargeSocialesFetch($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testChargeSocialesFetch + * + * @param int $id Id of social contribution + * @return void + * + * @depends testChargeSocialesCreate + * The depends says test is run only if previous is ok + */ + public function testChargeSocialesFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new ChargeSociales($this->savdb); - $result=$localobject->fetch($id); - print __METHOD__." id=".$id." result=".$result."\n"; + $localobject=new ChargeSociales($this->savdb); + $result=$localobject->fetch($id); + print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testChargeSocialesValid - * - * @param Object $localobject Social contribution - * @return void - * - * @depends testChargeSocialesFetch - * The depends says test is run only if previous is ok - */ - public function testChargeSocialesValid($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testChargeSocialesValid + * + * @param Object $localobject Social contribution + * @return void + * + * @depends testChargeSocialesFetch + * The depends says test is run only if previous is ok + */ + public function testChargeSocialesValid($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->set_paid($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $result=$localobject->set_paid($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testChargeSocialesOther - * - * @param Object $localobject Social contribution - * @return void - * - * @depends testChargeSocialesValid - * The depends says test is run only if previous is ok - */ - public function testChargeSocialesOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testChargeSocialesOther + * + * @param Object $localobject Social contribution + * @return void + * + * @depends testChargeSocialesValid + * The depends says test is run only if previous is ok + */ + public function testChargeSocialesOther($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->getNomUrl(1); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertNotEquals($result, ''); + $result=$localobject->getNomUrl(1); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertNotEquals($result, ''); - $result=$localobject->getSommePaiement(); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThanOrEqual($result, 0); + $result=$localobject->getSommePaiement(); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThanOrEqual($result, 0); - return $localobject->id; - } + return $localobject->id; + } - /** - * testChargeSocialesDelete - * - * @param int $id Social contribution - * @return void - * - * @depends testChargeSocialesOther - * The depends says test is run only if previous is ok - */ - public function testChargeSocialesDelete($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testChargeSocialesDelete + * + * @param int $id Social contribution + * @return void + * + * @depends testChargeSocialesOther + * The depends says test is run only if previous is ok + */ + public function testChargeSocialesDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new ChargeSociales($this->savdb); - $result=$localobject->fetch($id); - $result=$localobject->delete($id); + $localobject=new ChargeSociales($this->savdb); + $result=$localobject->fetch($id); + $result=$localobject->delete($id); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $result; - } + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $result; + } } diff --git a/test/phpunit/CodingPhpTest.php b/test/phpunit/CodingPhpTest.php index 9acb13432d2..e993428adf0 100644 --- a/test/phpunit/CodingPhpTest.php +++ b/test/phpunit/CodingPhpTest.php @@ -30,22 +30,41 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/security.lib.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/security2.lib.php'; -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); -if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +if (! defined('NOREQUIREUSER')) { + define('NOREQUIREUSER', '1'); +} +if (! defined('NOREQUIREDB')) { + define('NOREQUIREDB', '1'); +} +if (! defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (! defined('NOREQUIRETRAN')) { + define('NOREQUIRETRAN', '1'); +} +if (! defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (! defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (! defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); // If there is no menu to show +} +if (! defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +} +if (! defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (! defined("NOLOGIN")) { + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +} -if (empty($user->id)) -{ - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); +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; @@ -59,313 +78,306 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class CodingPhpTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return SecurityTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return SecurityTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } - /** - * End phpunit tests - * - * @return void - */ - protected function tearDown() - { - print __METHOD__."\n"; - } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testSql - * - * @return string - */ - public function testPHP() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testSql + * + * @return string + */ + public function testPHP() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $filesarray = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, '\.php', null, 'fullname'); - //$filesarray = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, '\.php', null, 'fullname'); + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $filesarray = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, '\.php', null, 'fullname'); + //$filesarray = dol_dir_list(DOL_DOCUMENT_ROOT, 'files', 1, '\.php', null, 'fullname'); - foreach ($filesarray as $key => $file) - { - if (preg_match('/\/htdocs\/includes\//', $file['fullname'])) continue; - if (preg_match('/\/htdocs\/custom\//', $file['fullname'])) continue; - if (preg_match('/\/htdocs\/dolimed/', $file['fullname'])) continue; - if (preg_match('/\/htdocs\/nltechno/', $file['fullname'])) continue; - if (preg_match('/\/htdocs\/teclib/', $file['fullname'])) continue; + foreach ($filesarray as $key => $file) { + if (preg_match('/\/htdocs\/includes\//', $file['fullname'])) { + continue; + } + if (preg_match('/\/htdocs\/custom\//', $file['fullname'])) { + continue; + } + if (preg_match('/\/htdocs\/dolimed/', $file['fullname'])) { + continue; + } + if (preg_match('/\/htdocs\/nltechno/', $file['fullname'])) { + continue; + } + if (preg_match('/\/htdocs\/teclib/', $file['fullname'])) { + continue; + } - print 'Check php file '.$file['fullname']."\n"; - $filecontent=file_get_contents($file['fullname']); + print 'Check php file '.$file['fullname']."\n"; + $filecontent=file_get_contents($file['fullname']); - if (preg_match('/\.class\.php/', $file['relativename']) - || preg_match('/boxes\/box_/', $file['relativename']) - || preg_match('/modules\/.*\/doc\/(doc|pdf)_/', $file['relativename']) - || preg_match('/modules\/(import|mailings|printing)\//', $file['relativename']) - || in_array($file['name'], array('modules_boxes.php', 'rapport.pdf.php', 'TraceableDB.php'))) { - if (! in_array($file['name'], array( - 'api.class.php', - 'actioncomm.class.php', - 'commonobject.class.php', - 'conf.class.php', - 'html.form.class.php', - 'html.formmail.class.php', - 'infobox.class.php', - 'link.class.php', - 'translate.class.php', - 'utils.class.php', - 'modules_product.class.php', - 'modules_societe.class.php', - 'TraceableDB.php', - 'expeditionbatch.class.php', - 'expensereport_ik.class.php', - 'expensereport_rule.class.php', - 'multicurrency.class.php', - 'productbatch.class.php', - 'reception.class.php', - 'societe.class.php' - ))) { - // Must must not found $db-> - $ok=true; - $matches=array(); - // Check string get_class... - preg_match_all('/'.preg_quote('$db->', '/').'/', $filecontent, $matches, PREG_SET_ORDER); - foreach ($matches as $key => $val) - { - $ok=false; - break; - } - //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; - $this->assertTrue($ok, 'Found string $db-> into a .class.php file in '.$file['relativename']); - //exit; - } - } else { - if (! in_array($file['name'], array( - 'extrafieldsinexport.inc.php', - 'DolQueryCollector.php' - ))) { - // Must must not found $this->db-> - $ok=true; - $matches=array(); - // Check string get_class... - preg_match_all('/'.preg_quote('$this->db->', '/').'/', $filecontent, $matches, PREG_SET_ORDER); - foreach ($matches as $key => $val) - { - $ok=false; - break; - } - //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; - $this->assertTrue($ok, 'Found string $this->db-> in '.$file['relativename']); - //exit; - } - } + if (preg_match('/\.class\.php/', $file['relativename']) + || preg_match('/boxes\/box_/', $file['relativename']) + || preg_match('/modules\/.*\/doc\/(doc|pdf)_/', $file['relativename']) + || preg_match('/modules\/(import|mailings|printing)\//', $file['relativename']) + || in_array($file['name'], array('modules_boxes.php', 'rapport.pdf.php', 'TraceableDB.php'))) { + if (! in_array($file['name'], array( + 'api.class.php', + 'actioncomm.class.php', + 'commonobject.class.php', + 'conf.class.php', + 'html.form.class.php', + 'html.formmail.class.php', + 'infobox.class.php', + 'link.class.php', + 'translate.class.php', + 'utils.class.php', + 'modules_product.class.php', + 'modules_societe.class.php', + 'TraceableDB.php', + 'expeditionbatch.class.php', + 'expensereport_ik.class.php', + 'expensereport_rule.class.php', + 'multicurrency.class.php', + 'productbatch.class.php', + 'reception.class.php', + 'societe.class.php' + ))) { + // Must must not found $db-> + $ok=true; + $matches=array(); + // Check string get_class... + preg_match_all('/'.preg_quote('$db->', '/').'/', $filecontent, $matches, PREG_SET_ORDER); + foreach ($matches as $key => $val) { + $ok=false; + break; + } + //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; + $this->assertTrue($ok, 'Found string $db-> into a .class.php file in '.$file['relativename']); + //exit; + } + } else { + if (! in_array($file['name'], array( + 'extrafieldsinexport.inc.php', + 'DolQueryCollector.php' + ))) { + // Must must not found $this->db-> + $ok=true; + $matches=array(); + // Check string get_class... + preg_match_all('/'.preg_quote('$this->db->', '/').'/', $filecontent, $matches, PREG_SET_ORDER); + foreach ($matches as $key => $val) { + $ok=false; + break; + } + //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; + $this->assertTrue($ok, 'Found string $this->db-> in '.$file['relativename']); + //exit; + } + } - $ok=true; - $matches=array(); - // Check string get_class... - preg_match_all('/'.preg_quote('get_class($this)."::".__METHOD__', '/').'/', $filecontent, $matches, PREG_SET_ORDER); - foreach ($matches as $key => $val) - { - $ok=false; - break; - } - //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; - $this->assertTrue($ok, 'Found string get_class($this)."::".__METHOD__ that must be replaced with __METHOD__ only in '.$file['relativename']); - //exit; + $ok=true; + $matches=array(); + // Check string get_class... + preg_match_all('/'.preg_quote('get_class($this)."::".__METHOD__', '/').'/', $filecontent, $matches, PREG_SET_ORDER); + foreach ($matches as $key => $val) { + $ok=false; + break; + } + //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; + $this->assertTrue($ok, 'Found string get_class($this)."::".__METHOD__ that must be replaced with __METHOD__ only in '.$file['relativename']); + //exit; - $ok=true; - $matches=array(); - // Check string $this->db->idate without quotes - preg_match_all('/(..)\s*\.\s*\$this->db->idate\(/', $filecontent, $matches, PREG_SET_ORDER); - foreach ($matches as $key => $val) - { - if ($val[1] != '\'"' && $val[1] != '\'\'') - { - $ok=false; - break; - } - //if ($reg[0] != 'db') $ok=false; - } - //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; - $this->assertTrue($ok, 'Found a $this->db->idate to forge a sql request without quotes around this date field '.$file['relativename']); - //exit; + $ok=true; + $matches=array(); + // Check string $this->db->idate without quotes + preg_match_all('/(..)\s*\.\s*\$this->db->idate\(/', $filecontent, $matches, PREG_SET_ORDER); + foreach ($matches as $key => $val) { + if ($val[1] != '\'"' && $val[1] != '\'\'') { + $ok=false; + break; + } + //if ($reg[0] != 'db') $ok=false; + } + //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; + $this->assertTrue($ok, 'Found a $this->db->idate to forge a sql request without quotes around this date field '.$file['relativename']); + //exit; - $ok=true; - $matches=array(); + $ok=true; + $matches=array(); - // Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request. - preg_match_all('/=\s*\'"\s*\.\s*\$this->(....)/', $filecontent, $matches, PREG_SET_ORDER); - foreach ($matches as $key => $val) - { - if ($val[1] != 'db->' && $val[1] != 'esca') - { - $ok=false; - break; - } - //if ($reg[0] != 'db') $ok=false; - } - //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; - $this->assertTrue($ok, 'Found non escaped string in building of a sql request '.$file['relativename'].' - Bad.'); - //exit; + // Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request. + preg_match_all('/=\s*\'"\s*\.\s*\$this->(....)/', $filecontent, $matches, PREG_SET_ORDER); + foreach ($matches as $key => $val) { + if ($val[1] != 'db->' && $val[1] != 'esca') { + $ok=false; + break; + } + //if ($reg[0] != 'db') $ok=false; + } + //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; + $this->assertTrue($ok, 'Found non escaped string in building of a sql request '.$file['relativename'].' - Bad.'); + //exit; - // Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request. - preg_match_all('/sql.+\s*\'"\s*\.\s*\$(.........)/', $filecontent, $matches, PREG_SET_ORDER); - foreach ($matches as $key => $val) - { - if (! in_array($val[1], array('this->db-', 'this->esc', 'db->escap', 'dbsession', 'db->idate', 'excludeGr', 'includeGr'))) { - $ok=false; - break; - } - //if ($reg[0] != 'db') $ok=false; - } - //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; - $this->assertTrue($ok, 'Found non escaped string in building of a sql request '.$file['relativename'].': '.$val[0].' - Bad.'); - //exit; + // Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request. + preg_match_all('/sql.+\s*\'"\s*\.\s*\$(.........)/', $filecontent, $matches, PREG_SET_ORDER); + foreach ($matches as $key => $val) { + if (! in_array($val[1], array('this->db-', 'this->esc', 'db->escap', 'dbsession', 'db->idate', 'excludeGr', 'includeGr'))) { + $ok=false; + break; + } + //if ($reg[0] != 'db') $ok=false; + } + //print __METHOD__." Result for checking we don't have non escaped string in sql requests for file ".$file."\n"; + $this->assertTrue($ok, 'Found non escaped string in building of a sql request '.$file['relativename'].': '.$val[0].' - Bad.'); + //exit; - // Test that output of $_SERVER\[\'QUERY_STRING\'\] is escaped. - $ok=true; - $matches=array(); - // Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request. - preg_match_all('/(..............)\$_SERVER\[\'QUERY_STRING\'\]/', $filecontent, $matches, PREG_SET_ORDER); - foreach ($matches as $key => $val) - { - if ($val[1] != 'scape_htmltag(' && $val[1] != 'ing_nohtmltag(' && $val[1] != 'dol_escape_js(') - { - $ok=false; - break; - } - } - $this->assertTrue($ok, 'Found a $_SERVER[\'QUERY_STRING\'] without dol_escape_htmltag neither dol_string_nohtmltag around it, in file '.$file['relativename'].' ('.$val[1].'$_SERVER[\'QUERY_STRING\']). Bad.'); + // Test that output of $_SERVER\[\'QUERY_STRING\'\] is escaped. + $ok=true; + $matches=array(); + // Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request. + preg_match_all('/(..............)\$_SERVER\[\'QUERY_STRING\'\]/', $filecontent, $matches, PREG_SET_ORDER); + foreach ($matches as $key => $val) { + if ($val[1] != 'scape_htmltag(' && $val[1] != 'ing_nohtmltag(' && $val[1] != 'dol_escape_js(') { + $ok=false; + break; + } + } + $this->assertTrue($ok, 'Found a $_SERVER[\'QUERY_STRING\'] without dol_escape_htmltag neither dol_string_nohtmltag around it, in file '.$file['relativename'].' ('.$val[1].'$_SERVER[\'QUERY_STRING\']). Bad.'); - // Test that first param of print_liste_field_titre is a translation key and not the translated value - $ok=true; - $matches=array(); - // Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request. - preg_match_all('/print_liste_field_titre\(\$langs/', $filecontent, $matches, PREG_SET_ORDER); - foreach ($matches as $key => $val) - { - $ok=false; - break; - } - $this->assertTrue($ok, 'Found a use of print_liste_field_titre with first parameter that is a translated value instead of just the translation key in file '.$file['relativename'].'. Bad.'); + // Test that first param of print_liste_field_titre is a translation key and not the translated value + $ok=true; + $matches=array(); + // Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request. + preg_match_all('/print_liste_field_titre\(\$langs/', $filecontent, $matches, PREG_SET_ORDER); + foreach ($matches as $key => $val) { + $ok=false; + break; + } + $this->assertTrue($ok, 'Found a use of print_liste_field_titre with first parameter that is a translated value instead of just the translation key in file '.$file['relativename'].'. Bad.'); - // Test we don't have
- $ok=true; - $matches=array(); - // Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request. - preg_match_all('/
/', $filecontent, $matches, PREG_SET_ORDER); - foreach ($matches as $key => $val) - { - if ($file['name'] != 'functions.lib.php') - { - $ok=false; - break; - } - } - $this->assertTrue($ok, 'Found a tag
that is for xml in file '.$file['relativename'].'. You must use html syntax
instead.'); + // Test we don't have
+ $ok=true; + $matches=array(); + // Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request. + preg_match_all('/
/', $filecontent, $matches, PREG_SET_ORDER); + foreach ($matches as $key => $val) { + if ($file['name'] != 'functions.lib.php') { + $ok=false; + break; + } + } + $this->assertTrue($ok, 'Found a tag
that is for xml in file '.$file['relativename'].'. You must use html syntax
instead.'); - // Test we don't have name="token" value="'.$_SESSION['newtoken'], we must use name="token" value="'.newToken() instead. - $ok=true; - $matches=array(); - // Check string name="token" value="'.$_SESSINON - preg_match_all('/name="token" value="\'\s*\.\s*\$_SESSION/', $filecontent, $matches, PREG_SET_ORDER); - foreach ($matches as $key => $val) - { - if ($file['name'] != 'excludefile.php') - { - $ok=false; - break; - } - } - $this->assertTrue($ok, 'Found a forbidden string sequence into '.$file['relativename'].' : name="token" value="\'.$_SESSION[..., you must use a newToken() instead of $_SESSION[\'newtoken\'].'); + // Test we don't have name="token" value="'.$_SESSION['newtoken'], we must use name="token" value="'.newToken() instead. + $ok=true; + $matches=array(); + // Check string name="token" value="'.$_SESSINON + preg_match_all('/name="token" value="\'\s*\.\s*\$_SESSION/', $filecontent, $matches, PREG_SET_ORDER); + foreach ($matches as $key => $val) { + if ($file['name'] != 'excludefile.php') { + $ok=false; + break; + } + } + $this->assertTrue($ok, 'Found a forbidden string sequence into '.$file['relativename'].' : name="token" value="\'.$_SESSION[..., you must use a newToken() instead of $_SESSION[\'newtoken\'].'); - // Test we don't have @var array( - $ok=true; - $matches=array(); - // Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request. - preg_match_all('/@var\s+array\(/', $filecontent, $matches, PREG_SET_ORDER); - foreach ($matches as $key => $val) - { - $ok=false; - break; - } - $this->assertTrue($ok, 'Found a declaration @var array() instead of @var array in file '.$file['relativename'].'.'); - } + // Test we don't have @var array( + $ok=true; + $matches=array(); + // Check string ='".$this->xxx with xxx that is not 'escape'. It means we forget a db->escape when forging sql request. + preg_match_all('/@var\s+array\(/', $filecontent, $matches, PREG_SET_ORDER); + foreach ($matches as $key => $val) { + $ok=false; + break; + } + $this->assertTrue($ok, 'Found a declaration @var array() instead of @var array in file '.$file['relativename'].'.'); + } - return; - } + return; + } } diff --git a/test/phpunit/CodingSqlTest.php b/test/phpunit/CodingSqlTest.php index 3e065bb141c..9217ebbe7f6 100644 --- a/test/phpunit/CodingSqlTest.php +++ b/test/phpunit/CodingSqlTest.php @@ -30,22 +30,41 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/security.lib.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/security2.lib.php'; -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); -if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +if (! defined('NOREQUIREUSER')) { + define('NOREQUIREUSER', '1'); +} +if (! defined('NOREQUIREDB')) { + define('NOREQUIREDB', '1'); +} +if (! defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (! defined('NOREQUIRETRAN')) { + define('NOREQUIRETRAN', '1'); +} +if (! defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (! defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (! defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); // If there is no menu to show +} +if (! defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +} +if (! defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (! defined("NOLOGIN")) { + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +} -if (empty($user->id)) -{ - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); +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; @@ -59,205 +78,201 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class CodingSqlTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return SecurityTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return SecurityTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } - /** - * End phpunit tests - * - * @return void - */ - protected function tearDown() - { - print __METHOD__."\n"; - } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testSql - * - * @return string - */ - public function testSql() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testSql + * + * @return string + */ + public function testSql() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $listofsqldir = array(DOL_DOCUMENT_ROOT.'/install/mysql/data', DOL_DOCUMENT_ROOT.'/install/mysql/tables', DOL_DOCUMENT_ROOT.'/install/mysql/migration'); + $listofsqldir = array(DOL_DOCUMENT_ROOT.'/install/mysql/data', DOL_DOCUMENT_ROOT.'/install/mysql/tables', DOL_DOCUMENT_ROOT.'/install/mysql/migration'); - foreach ($listofsqldir as $dir) - { - print 'Process dir '.$dir."\n"; - $filesarray = scandir($dir); + foreach ($listofsqldir as $dir) { + print 'Process dir '.$dir."\n"; + $filesarray = scandir($dir); - foreach ($filesarray as $key => $file) - { - if (! preg_match('/\.sql$/', $file)) - continue; + foreach ($filesarray as $key => $file) { + if (! preg_match('/\.sql$/', $file)) { + continue; + } - print 'Check sql file '.$file."\n"; - $filecontent = file_get_contents($dir.'/'.$file); + print 'Check sql file '.$file."\n"; + $filecontent = file_get_contents($dir.'/'.$file); - // Allow ` for 'rank' column name - $filecontent = str_replace('`rank`', '_rank_', $filecontent); + // Allow ` for 'rank' column name + $filecontent = str_replace('`rank`', '_rank_', $filecontent); - $result=strpos($filecontent, '`'); - //print __METHOD__." Result for checking we don't have back quote = ".$result."\n"; - $this->assertTrue($result===false, 'Found back quote into '.$file.'. Bad.'); + $result=strpos($filecontent, '`'); + //print __METHOD__." Result for checking we don't have back quote = ".$result."\n"; + $this->assertTrue($result===false, 'Found back quote into '.$file.'. Bad.'); - $result=strpos($filecontent, '"'); - if ($result) - { - $result=(! strpos($filecontent, '["') && ! strpos($filecontent, '{"')); - } - //print __METHOD__." Result for checking we don't have double quote = ".$result."\n"; - $this->assertTrue($result===false, 'Found double quote that is not [" neither {" (used for json content) into '.$file.'. Bad.'); + $result=strpos($filecontent, '"'); + if ($result) { + $result=(! strpos($filecontent, '["') && ! strpos($filecontent, '{"')); + } + //print __METHOD__." Result for checking we don't have double quote = ".$result."\n"; + $this->assertTrue($result===false, 'Found double quote that is not [" neither {" (used for json content) into '.$file.'. Bad.'); - $result=strpos($filecontent, 'int('); - //print __METHOD__." Result for checking we don't have 'int(' instead of 'integer' = ".$result."\n"; - $this->assertTrue($result===false, 'Found int(x) or tinyint(x) instead of integer or tinyint into '.$file.'. Bad.'); + $result=strpos($filecontent, 'int('); + //print __METHOD__." Result for checking we don't have 'int(' instead of 'integer' = ".$result."\n"; + $this->assertTrue($result===false, 'Found int(x) or tinyint(x) instead of integer or tinyint into '.$file.'. Bad.'); - $result=strpos($filecontent, 'ON DELETE CASCADE'); - //print __METHOD__." Result for checking we don't have 'ON DELETE CASCADE' = ".$result."\n"; - $this->assertTrue($result===false, 'Found ON DELETE CASCADE into '.$file.'. Bad.'); + $result=strpos($filecontent, 'ON DELETE CASCADE'); + //print __METHOD__." Result for checking we don't have 'ON DELETE CASCADE' = ".$result."\n"; + $this->assertTrue($result===false, 'Found ON DELETE CASCADE into '.$file.'. Bad.'); - $result=strpos($filecontent, 'NUMERIC('); - //print __METHOD__." Result for checking we don't have 'NUMERIC(' = ".$result."\n"; - $this->assertTrue($result===false, 'Found NUMERIC( into '.$file.'. Bad.'); + $result=strpos($filecontent, 'NUMERIC('); + //print __METHOD__." Result for checking we don't have 'NUMERIC(' = ".$result."\n"; + $this->assertTrue($result===false, 'Found NUMERIC( into '.$file.'. Bad.'); - $result=strpos($filecontent, 'NUMERIC('); - //print __METHOD__." Result for checking we don't have 'curdate(' = ".$result."\n"; - $this->assertTrue($result===false, 'Found curdate( into '.$file.'. Bad. Current date must be generated with PHP.'); + $result=strpos($filecontent, 'NUMERIC('); + //print __METHOD__." Result for checking we don't have 'curdate(' = ".$result."\n"; + $this->assertTrue($result===false, 'Found curdate( into '.$file.'. Bad. Current date must be generated with PHP.'); - $result=strpos($filecontent, 'integer('); - //print __METHOD__." Result for checking we don't have 'integer(' = ".$result."\n"; - $this->assertTrue($result===false, 'Found value in parenthesis after the integer. It must be integer not integer(x) into '.$file.'. Bad.'); + $result=strpos($filecontent, 'integer('); + //print __METHOD__." Result for checking we don't have 'integer(' = ".$result."\n"; + $this->assertTrue($result===false, 'Found value in parenthesis after the integer. It must be integer not integer(x) into '.$file.'. Bad.'); - if ($dir == DOL_DOCUMENT_ROOT.'/install/mysql/migration') - { - // Test for migration files only - } elseif ($dir == DOL_DOCUMENT_ROOT.'/install/mysql/data') - { - // Test for data files only - } else { - if (preg_match('/\.key\.sql$/', $file)) - { - // Test for key files only - } else { - // Test for non key files only - $result=(strpos($filecontent, 'KEY ') && strpos($filecontent, 'PRIMARY KEY') == 0); - //print __METHOD__." Result for checking we don't have ' KEY ' instead of a sql file to create index = ".$result."\n"; - $this->assertTrue($result===false, 'Found KEY into '.$file.'. Bad.'); + if ($dir == DOL_DOCUMENT_ROOT.'/install/mysql/migration') { + // Test for migration files only + } elseif ($dir == DOL_DOCUMENT_ROOT.'/install/mysql/data') { + // Test for data files only + } else { + if (preg_match('/\.key\.sql$/', $file)) { + // Test for key files only + } else { + // Test for non key files only + $result=(strpos($filecontent, 'KEY ') && strpos($filecontent, 'PRIMARY KEY') == 0); + //print __METHOD__." Result for checking we don't have ' KEY ' instead of a sql file to create index = ".$result."\n"; + $this->assertTrue($result===false, 'Found KEY into '.$file.'. Bad.'); - $result=stripos($filecontent, 'ENGINE=innodb'); - //print __METHOD__." Result for checking we have the ENGINE=innodb string = ".$result."\n"; - $this->assertGreaterThan(0, $result, 'The ENGINE=innodb was not found into '.$file.'. Add it or just fix syntax to match case.'); - } - } - } - } + $result=stripos($filecontent, 'ENGINE=innodb'); + //print __METHOD__." Result for checking we have the ENGINE=innodb string = ".$result."\n"; + $this->assertGreaterThan(0, $result, 'The ENGINE=innodb was not found into '.$file.'. Add it or just fix syntax to match case.'); + } + } + } + } - return; - } + return; + } - /** - * testInitData - * - * @return string - */ - public function testInitData() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testInitData + * + * @return string + */ + public function testInitData() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $filesarray = scandir(DOL_DOCUMENT_ROOT.'/../dev/initdemo'); - foreach ($filesarray as $key => $file) { - if (! preg_match('/\.sql$/', $file)) - continue; + $filesarray = scandir(DOL_DOCUMENT_ROOT.'/../dev/initdemo'); + foreach ($filesarray as $key => $file) { + if (! preg_match('/\.sql$/', $file)) { + continue; + } - print 'Check sql file '.$file."\n"; - $filecontent=file_get_contents(DOL_DOCUMENT_ROOT.'/../dev/initdemo/'.$file); + print 'Check sql file '.$file."\n"; + $filecontent=file_get_contents(DOL_DOCUMENT_ROOT.'/../dev/initdemo/'.$file); - $result=strpos($filecontent, '@gmail.com'); - print __METHOD__." Result for checking we don't have personal data = ".$result."\n"; - $this->assertTrue($result===false, 'Found a bad key @gmail into file '.$file); + $result=strpos($filecontent, '@gmail.com'); + print __METHOD__." Result for checking we don't have personal data = ".$result."\n"; + $this->assertTrue($result===false, 'Found a bad key @gmail into file '.$file); - $result=strpos($filecontent, 'eldy@'); - print __METHOD__." Result for checking we don't have personal data = ".$result."\n"; - $this->assertTrue($result===false, 'Found a bad key eldy@ into file '.$file); - } + $result=strpos($filecontent, 'eldy@'); + print __METHOD__." Result for checking we don't have personal data = ".$result."\n"; + $this->assertTrue($result===false, 'Found a bad key eldy@ into file '.$file); + } - return; - } + return; + } } diff --git a/test/phpunit/CommandeFournisseurTest.php b/test/phpunit/CommandeFournisseurTest.php index 0ee65e3383e..4c26edcd644 100644 --- a/test/phpunit/CommandeFournisseurTest.php +++ b/test/phpunit/CommandeFournisseurTest.php @@ -31,9 +31,9 @@ require_once dirname(__FILE__).'/../../htdocs/fourn/class/fournisseur.commande.c require_once dirname(__FILE__).'/../../htdocs/fourn/class/fournisseur.product.class.php'; if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -48,351 +48,353 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class CommandeFournisseurTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return CommandeFournisseurTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return CommandeFournisseurTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - //print $db->getVersion()."\n"; - } - /** - * End phpunit tests - * - * @return void - */ - protected function tearDown() - { - print __METHOD__."\n"; - } + print __METHOD__."\n"; + //print $db->getVersion()."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testCommandeFournisseurCreate - * - * @return int ID of purchase order - */ - public function testCommandeFournisseurCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeFournisseurCreate + * + * @return int ID of purchase order + */ + public function testCommandeFournisseurCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - // Set supplier and product to use - $socid=1; - $societe=new Societe($db); - $societe->fetch($socid); - $product=new ProductFournisseur($db); - $product->fetch(0, 'PIDRESS'); - if ($product->id <= 0) { print "\n".__METHOD__." A product with ref PIDRESS must exists into database"; die(); } + // Set supplier and product to use + $socid=1; + $societe=new Societe($db); + $societe->fetch($socid); + $product=new ProductFournisseur($db); + $product->fetch(0, 'PIDRESS'); + if ($product->id <= 0) { + print "\n".__METHOD__." A product with ref PIDRESS must exists into database"; die(); + } - $quantity=10; - $ref_fourn='SUPPLIER_REF_PHPUNIT'; - $tva_tx=19.6; + $quantity=10; + $ref_fourn='SUPPLIER_REF_PHPUNIT'; + $tva_tx=19.6; - // Delete existing supplier prices - // TODO + // Delete existing supplier prices + // TODO - // Create 1 supplier price with min qty = 10; - $result=$product->add_fournisseur($user, $societe->id, $ref_fourn, $quantity); // This insert record with no value for price. Values are update later with update_buyprice - print __METHOD__." add_fournisseur result=".$result."\n"; - $this->assertGreaterThanOrEqual(0, $result, 'Create 1 supplier price with min qty = 10 if not exists'); - $result=$product->update_buyprice($quantity, 20, $user, 'HT', $societe, '', $ref_fourn, $tva_tx, 0, 0); - print __METHOD__." update_buyprice result=".$result."\n"; - $this->assertGreaterThanOrEqual(0, $result, 'Update buyprice'); + // Create 1 supplier price with min qty = 10; + $result=$product->add_fournisseur($user, $societe->id, $ref_fourn, $quantity); // This insert record with no value for price. Values are update later with update_buyprice + print __METHOD__." add_fournisseur result=".$result."\n"; + $this->assertGreaterThanOrEqual(0, $result, 'Create 1 supplier price with min qty = 10 if not exists'); + $result=$product->update_buyprice($quantity, 20, $user, 'HT', $societe, '', $ref_fourn, $tva_tx, 0, 0); + print __METHOD__." update_buyprice result=".$result."\n"; + $this->assertGreaterThanOrEqual(0, $result, 'Update buyprice'); - // Create purchase order with a too low quantity and option SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY is on - $conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY = 1; + // Create purchase order with a too low quantity and option SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY is on + $conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY = 1; - $localobject=new CommandeFournisseur($db); - $localobject->initAsSpecimen(); - $localobject->lines=array(); // Overwrite lines of order - $line=new CommandeFournisseurLigne($db); - $line->desc=$langs->trans("Description")." specimen line with qty too low"; - $line->qty=1; // So lower than $quantity - $line->subprice=100; - $line->fk_product=$product->id; - $line->ref_fourn=$ref_fourn; - $localobject->lines[]=$line; + $localobject=new CommandeFournisseur($db); + $localobject->initAsSpecimen(); + $localobject->lines=array(); // Overwrite lines of order + $line=new CommandeFournisseurLigne($db); + $line->desc=$langs->trans("Description")." specimen line with qty too low"; + $line->qty=1; // So lower than $quantity + $line->subprice=100; + $line->fk_product=$product->id; + $line->ref_fourn=$ref_fourn; + $localobject->lines[]=$line; - $result=$localobject->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(-1, $result, 'Creation of too low quantity'); // must be -1 because quantity is lower than minimum of supplier price + $result=$localobject->create($user); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(-1, $result, 'Creation of too low quantity'); // must be -1 because quantity is lower than minimum of supplier price - $sql="DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur where ref=''"; - $db->query($sql); + $sql="DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur where ref=''"; + $db->query($sql); - // Create purchase order - $localobject2=new CommandeFournisseur($db); - $localobject2->initAsSpecimen(); // This create 5 lines of first product found for socid 1 - $localobject2->lines=array(); // Overwrite lines of order - $line=new CommandeFournisseurLigne($db); - $line->desc=$langs->trans("Description")." specimen line ok"; - $line->qty=10; // So enough quantity - $line->subprice=100; - $line->fk_product=$product->id; - $line->ref_fourn=$ref_fourn; - $localobject2->lines[]=$line; + // Create purchase order + $localobject2=new CommandeFournisseur($db); + $localobject2->initAsSpecimen(); // This create 5 lines of first product found for socid 1 + $localobject2->lines=array(); // Overwrite lines of order + $line=new CommandeFournisseurLigne($db); + $line->desc=$langs->trans("Description")." specimen line ok"; + $line->qty=10; // So enough quantity + $line->subprice=100; + $line->fk_product=$product->id; + $line->ref_fourn=$ref_fourn; + $localobject2->lines[]=$line; - $result=$localobject2->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + $result=$localobject2->create($user); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); - // Create purchase order with a too low quantity but option SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY is off - $conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY = 0; + // Create purchase order with a too low quantity but option SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY is off + $conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY = 0; - $localobject3=new CommandeFournisseur($db); - $localobject3->initAsSpecimen(); - $localobject3->lines=array(); // Overwrite lines of order - $line=new CommandeFournisseurLigne($db); - $line->desc=$langs->trans("Description")." specimen line with qty too low"; - $line->qty=1; // So lower than $quantity - $line->subprice=100; - $line->fk_product=$product->id; - $line->ref_fourn=$ref_fourn; - $localobject3->lines[]=$line; + $localobject3=new CommandeFournisseur($db); + $localobject3->initAsSpecimen(); + $localobject3->lines=array(); // Overwrite lines of order + $line=new CommandeFournisseurLigne($db); + $line->desc=$langs->trans("Description")." specimen line with qty too low"; + $line->qty=1; // So lower than $quantity + $line->subprice=100; + $line->fk_product=$product->id; + $line->ref_fourn=$ref_fourn; + $localobject3->lines[]=$line; - $result=$localobject3->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result, 'Creation of too low quantity should be ok'); // must be id of line because there is no test on minimum quantity + $result=$localobject3->create($user); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result, 'Creation of too low quantity should be ok'); // must be id of line because there is no test on minimum quantity - $sql="DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur where ref=''"; - $db->query($sql); + $sql="DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseur where ref=''"; + $db->query($sql); - // Create purchase order - $localobject4=new CommandeFournisseur($db); - $localobject4->initAsSpecimen(); // This create 5 lines of first product found for socid 1 - $localobject4->lines=array(); // Overwrite lines of order - $line=new CommandeFournisseurLigne($db); - $line->desc=$langs->trans("Description")." specimen line ok"; - $line->qty=10; // So enough quantity - $line->subprice=100; - $line->fk_product=$product->id; - $line->ref_fourn=$ref_fourn; - $localobject4->lines[]=$line; + // Create purchase order + $localobject4=new CommandeFournisseur($db); + $localobject4->initAsSpecimen(); // This create 5 lines of first product found for socid 1 + $localobject4->lines=array(); // Overwrite lines of order + $line=new CommandeFournisseurLigne($db); + $line->desc=$langs->trans("Description")." specimen line ok"; + $line->qty=10; // So enough quantity + $line->subprice=100; + $line->fk_product=$product->id; + $line->ref_fourn=$ref_fourn; + $localobject4->lines[]=$line; - $result=$localobject4->create($user); - print __METHOD__." id for purchase order created by testCommandeFournisseurCreate = ".$result."\n"; - $this->assertGreaterThan(0, $result, 'Test to create a purchase order by testCommandeFournisseurCreate'); + $result=$localobject4->create($user); + print __METHOD__." id for purchase order created by testCommandeFournisseurCreate = ".$result."\n"; + $this->assertGreaterThan(0, $result, 'Test to create a purchase order by testCommandeFournisseurCreate'); - return $result; - } + return $result; + } - /** - * testCommandeFournisseurFetch - * - * @param int $id Id of purchase order - * @return CommandeFournisseur Purchase order - * - * @depends testCommandeFournisseurCreate - * The depends says test is run only if previous is ok - */ - public function testCommandeFournisseurFetch($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeFournisseurFetch + * + * @param int $id Id of purchase order + * @return CommandeFournisseur Purchase order + * + * @depends testCommandeFournisseurCreate + * The depends says test is run only if previous is ok + */ + public function testCommandeFournisseurFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new CommandeFournisseur($this->savdb); - $result=$localobject->fetch($id); + $localobject=new CommandeFournisseur($this->savdb); + $result=$localobject->fetch($id); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0, 'Failed to fetch supplier order with id '.$id); - return $localobject; - } + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0, 'Failed to fetch supplier order with id '.$id); + return $localobject; + } - /** - * testCommandeFournisseurValid - * - * @param Object $localobject Supplier order - * @return CommandeFournisseur Supplier order - * - * @depends testCommandeFournisseurFetch - * The depends says test is run only if previous is ok - */ - public function testCommandeFournisseurValid($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeFournisseurValid + * + * @param Object $localobject Supplier order + * @return CommandeFournisseur Supplier order + * + * @depends testCommandeFournisseurFetch + * The depends says test is run only if previous is ok + */ + public function testCommandeFournisseurValid($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->valid($user); + $result=$localobject->valid($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testCommandeFournisseurApprove - * - * @param Object $localobject Supplier order - * @return CommandeFournisseur Supplier order - * - * @depends testCommandeFournisseurValid - * The depends says test is run only if previous is ok - */ - public function testCommandeFournisseurApprove($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeFournisseurApprove + * + * @param Object $localobject Supplier order + * @return CommandeFournisseur Supplier order + * + * @depends testCommandeFournisseurValid + * The depends says test is run only if previous is ok + */ + public function testCommandeFournisseurApprove($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->approve($user); + $result=$localobject->approve($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testCommandeFournisseurCancel - * - * @param Object $localobject Supplier order - * @return CommandeFournisseur Supplier order - * - * @depends testCommandeFournisseurApprove - * The depends says test is run only if previous is ok - */ - public function testCommandeFournisseurCancel($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeFournisseurCancel + * + * @param Object $localobject Supplier order + * @return CommandeFournisseur Supplier order + * + * @depends testCommandeFournisseurApprove + * The depends says test is run only if previous is ok + */ + public function testCommandeFournisseurCancel($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->cancel($user); + $result=$localobject->cancel($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testCommandeFournisseurOther - * - * @param Object $localobject Supplier order - * @return int Id of purchase order - * - * @depends testCommandeFournisseurCancel - * The depends says test is run only if previous is ok - */ - public function testCommandeFournisseurOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeFournisseurOther + * + * @param Object $localobject Supplier order + * @return int Id of purchase order + * + * @depends testCommandeFournisseurCancel + * The depends says test is run only if previous is ok + */ + public function testCommandeFournisseurOther($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); - */ + /*$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, ''); - */ - $this->assertEquals(1, 1); + /*$localobject->info($localobject->id); + print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; + $this->assertNotEquals($localobject->date_creation, ''); + */ + $this->assertEquals(1, 1); - return $localobject->id; - } + return $localobject->id; + } - /** - * testCommandeFournisseurDelete - * - * @param int $id Id of order - * @return int Result of delete - * - * @depends testCommandeFournisseurOther - * The depends says test is run only if previous is ok - */ - public function testCommandeFournisseurDelete($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeFournisseurDelete + * + * @param int $id Id of order + * @return int Result of delete + * + * @depends testCommandeFournisseurOther + * The depends says test is run only if previous is ok + */ + public function testCommandeFournisseurDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new CommandeFournisseur($this->savdb); - $result=$localobject->fetch($id); - $result=$localobject->delete($user); + $localobject=new CommandeFournisseur($this->savdb); + $result=$localobject->fetch($id); + $result=$localobject->delete($user); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $result; - } + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $result; + } } diff --git a/test/phpunit/CommandeTest.php b/test/phpunit/CommandeTest.php index 1decbe4e201..c735890b02e 100644 --- a/test/phpunit/CommandeTest.php +++ b/test/phpunit/CommandeTest.php @@ -30,9 +30,9 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/commande/class/commande.class.php'; if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -46,260 +46,262 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class CommandeTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return CommandeTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return CommandeTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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. - if (empty($conf->commande->enabled)) { print __METHOD__." module customer order must be enabled.\n"; die(); } + if (empty($conf->commande->enabled)) { + print __METHOD__." module customer order must be enabled.\n"; die(); + } - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - //print $db->getVersion()."\n"; - } + print __METHOD__."\n"; + //print $db->getVersion()."\n"; + } - /** - * End phpunit tests - * - * @return void - */ - protected function tearDown() - { - print __METHOD__."\n"; - } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testCommandeCreate - * - * @return void - */ - public function testCommandeCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeCreate + * + * @return void + */ + public function testCommandeCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Commande($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user); + $localobject=new Commande($this->savdb); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; - return $result; - } + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + return $result; + } - /** - * testCommandeFetch - * - * @param int $id Id order - * @return Commande - * - * @depends testCommandeCreate - * The depends says test is run only if previous is ok - */ - public function testCommandeFetch($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeFetch + * + * @param int $id Id order + * @return Commande + * + * @depends testCommandeCreate + * The depends says test is run only if previous is ok + */ + public function testCommandeFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Commande($this->savdb); - $result=$localobject->fetch($id); + $localobject=new Commande($this->savdb); + $result=$localobject->fetch($id); - $this->assertLessThan($result, 0); - print __METHOD__." id=".$id." result=".$result."\n"; - return $localobject; - } + $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + return $localobject; + } - /** - * testCommandeUpdate - * - * @param Object $localobject Commande - * @return Commande - * - * @depends testCommandeFetch - * The depends says test is run only if previous is ok - */ - public function testCommandeUpdate($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeUpdate + * + * @param Object $localobject Commande + * @return Commande + * + * @depends testCommandeFetch + * The depends says test is run only if previous is ok + */ + public function testCommandeUpdate($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject->note_private='New note private after update'; - $result=$localobject->update($user); + $localobject->note_private='New note private after update'; + $result=$localobject->update($user); - $this->assertLessThan($result, 0); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - return $localobject; - } + $this->assertLessThan($result, 0); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + return $localobject; + } - /** - * testCommandeValid - * - * @param Object $localobject Order - * @return Commande - * - * @depends testCommandeUpdate - * The depends says test is run only if previous is ok - */ - public function testCommandeValid($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeValid + * + * @param Object $localobject Order + * @return Commande + * + * @depends testCommandeUpdate + * The depends says test is run only if previous is ok + */ + public function testCommandeValid($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->valid($user); + $result=$localobject->valid($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testCommandeCancel - * - * @param Object $localobject Order - * @return Commande - * - * @depends testCommandeValid - * The depends says test is run only if previous is ok - */ - public function testCommandeCancel($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeCancel + * + * @param Object $localobject Order + * @return Commande + * + * @depends testCommandeValid + * The depends says test is run only if previous is ok + */ + public function testCommandeCancel($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->cancel(); + $result=$localobject->cancel(); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testCommandeOther - * - * @param Object $localobject Order - * @return int Order id - * - * @depends testCommandeCancel - * The depends says test is run only if previous is ok - */ - public function testCommandeOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeOther + * + * @param Object $localobject Order + * @return int Order id + * + * @depends testCommandeCancel + * The depends says test is run only if previous is ok + */ + public function testCommandeOther($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); - */ + /*$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, ''); + $localobject->info($localobject->id); + print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; + $this->assertNotEquals($localobject->date_creation, ''); - return $localobject->id; - } + return $localobject->id; + } - /** - * testCommandeDelete - * - * @param int $id Id of order - * @return void - * - * @depends testCommandeOther - * The depends says test is run only if previous is ok - */ - public function testCommandeDelete($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCommandeDelete + * + * @param int $id Id of order + * @return void + * + * @depends testCommandeOther + * The depends says test is run only if previous is ok + */ + public function testCommandeDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Commande($this->savdb); - $result=$localobject->fetch($id); - $result=$localobject->delete($user); + $localobject=new Commande($this->savdb); + $result=$localobject->fetch($id); + $result=$localobject->delete($user); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $result; - } + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $result; + } } diff --git a/test/phpunit/CommonInvoiceTest.php b/test/phpunit/CommonInvoiceTest.php index 5e9c45825ec..9addda59cef 100644 --- a/test/phpunit/CommonInvoiceTest.php +++ b/test/phpunit/CommonInvoiceTest.php @@ -30,9 +30,9 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture.class.php'; if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -46,110 +46,110 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class CommonInvoiceTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return CommonObjectTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return CommonObjectTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testFetchUser - * - * @return void - */ - public function testCalculateDateLimReglement() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFetchUser + * + * @return void + */ + public function testCalculateDateLimReglement() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Facture($this->savdb); - $localobject->fetch(1); - $localobject->date = dol_mktime(12, 0, 0, 1, 1, 2010); + $localobject=new Facture($this->savdb); + $localobject->fetch(1); + $localobject->date = dol_mktime(12, 0, 0, 1, 1, 2010); - $result = 0; + $result = 0; - // TODO Insert payment terms + // TODO Insert payment terms - //$result=$localobject->calculate_date_lim_reglement(1); - //print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, 0); - return $result; - } + //$result=$localobject->calculate_date_lim_reglement(1); + //print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 0); + return $result; + } } diff --git a/test/phpunit/CommonObjectTest.php b/test/phpunit/CommonObjectTest.php index 6c68423e8a9..7a01f750eef 100644 --- a/test/phpunit/CommonObjectTest.php +++ b/test/phpunit/CommonObjectTest.php @@ -31,9 +31,9 @@ require_once dirname(__FILE__).'/../../htdocs/commande/class/commande.class.php' require_once dirname(__FILE__).'/../../htdocs/projet/class/project.class.php'; if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -47,150 +47,150 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class CommonObjectTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return CommonObjectTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return CommonObjectTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testFetchUser - * - * @return void - */ - public function testFetchUser() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFetchUser + * + * @return void + */ + public function testFetchUser() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Commande($this->savdb); - $localobject->fetch(1); + $localobject=new Commande($this->savdb); + $localobject->fetch(1); - $result=$localobject->fetch_user(1); + $result=$localobject->fetch_user(1); - print __METHOD__." result=".$result."\n"; - $this->assertLessThan($localobject->user->id, 0); - return $result; - } + print __METHOD__." result=".$result."\n"; + $this->assertLessThan($localobject->user->id, 0); + return $result; + } - /** - * testFetchProjet - * - * @return void - */ - public function testFetchProjet() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFetchProjet + * + * @return void + */ + public function testFetchProjet() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Commande($this->savdb); - $localobject->fetch(1); - $result=$localobject->fetch_projet(); + $localobject=new Commande($this->savdb); + $localobject->fetch(1); + $result=$localobject->fetch_projet(); - print __METHOD__." result=".$result."\n"; - $this->assertLessThanOrEqual($result, 0); - return $result; - } + print __METHOD__." result=".$result."\n"; + $this->assertLessThanOrEqual($result, 0); + return $result; + } - /** - * testFetchThirdParty - * - * @return void - */ - public function testFetchThirdParty() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFetchThirdParty + * + * @return void + */ + public function testFetchThirdParty() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Commande($this->savdb); - $localobject->fetch(1); + $localobject=new Commande($this->savdb); + $localobject->fetch(1); - $result=$localobject->fetch_thirdparty(); + $result=$localobject->fetch_thirdparty(); - print __METHOD__." result=".$result."\n"; - $this->assertLessThanOrEqual($result, 0); - return $result; - } + print __METHOD__." result=".$result."\n"; + $this->assertLessThanOrEqual($result, 0); + return $result; + } } diff --git a/test/phpunit/CompanyBankAccountTest.php b/test/phpunit/CompanyBankAccountTest.php index 1979f89fabb..17f6a9ccacf 100644 --- a/test/phpunit/CompanyBankAccountTest.php +++ b/test/phpunit/CompanyBankAccountTest.php @@ -29,8 +29,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/societe/class/companybankaccount.class.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -74,40 +73,40 @@ class CompanyBankAccountTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + protected function setUp() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -115,132 +114,132 @@ class CompanyBankAccountTest extends PHPUnit\Framework\TestCase print __METHOD__."\n"; //print $db->getVersion()."\n"; - } + } /** * End phpunit tests * * @return void */ - protected function tearDown() - { - print __METHOD__."\n"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testCompanyBankAccountCreate - * - * @return int - */ - public function testCompanyBankAccountCreate() - { - global $conf,$user,$langs,$db; + /** + * testCompanyBankAccountCreate + * + * @return int + */ + public function testCompanyBankAccountCreate() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new CompanyBankAccount($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); - print __METHOD__." result=".$result." id=".$localobject->id."\n"; - $this->assertLessThan($result, 0); - return $localobject->id; - } + print __METHOD__." result=".$result." id=".$localobject->id."\n"; + $this->assertLessThan($result, 0); + return $localobject->id; + } - /** - * testCompanyBankAccountFetch - * - * @param int $id Id of bank account - * @return Object Bank account object - * - * @depends testCompanyBankAccountCreate - * The depends says test is run only if previous is ok - */ - public function testCompanyBankAccountFetch($id) - { - global $conf,$user,$langs,$db; + /** + * testCompanyBankAccountFetch + * + * @param int $id Id of bank account + * @return Object Bank account object + * + * @depends testCompanyBankAccountCreate + * The depends says test is run only if previous is ok + */ + public function testCompanyBankAccountFetch($id) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new CompanyBankAccount($this->savdb); - $result=$localobject->fetch($id); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + $result=$localobject->fetch($id); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testCompanyBankAccountSetAsDefault - * - * @param Object $localobject Bank account - * @return int - * - * @depends testCompanyBankAccountFetch - */ - public function testCompanyBankAccountSetAsDefault($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCompanyBankAccountSetAsDefault + * + * @param Object $localobject Bank account + * @return int + * + * @depends testCompanyBankAccountFetch + */ + public function testCompanyBankAccountSetAsDefault($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->setAsDefault($localobject->id); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + $result=$localobject->setAsDefault($localobject->id); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testCompanyBankAccountUpdate - * - * @param Object $localobject Bank account object - * @return int - * - * @depends testCompanyBankAccountFetch - * The depends says test is run only if previous is ok - */ - public function testCompanyBankAccountUpdate($localobject) - { - global $conf,$user,$langs,$db; + /** + * testCompanyBankAccountUpdate + * + * @param Object $localobject Bank account object + * @return int + * + * @depends testCompanyBankAccountFetch + * The depends says test is run only if previous is ok + */ + public function testCompanyBankAccountUpdate($localobject) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject->owner='New owner'; - $result=$localobject->update($user); + $result=$localobject->update($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testCompanyBankAccountOther - * - * @param Object $localobject Bank account - * @return int - * - * @depends testCompanyBankAccountFetch - * The depends says test is run only if previous is ok - */ - public function testCompanyBankAccountOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testCompanyBankAccountOther + * + * @param Object $localobject Bank account + * @return int + * + * @depends testCompanyBankAccountFetch + * The depends says test is run only if previous is ok + */ + public function testCompanyBankAccountOther($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject->owner='New owner'; - $result=$localobject->update($user); + $localobject->owner='New owner'; + $result=$localobject->update($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject->id; - } + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject->id; + } } diff --git a/test/phpunit/CompanyLibTest.php b/test/phpunit/CompanyLibTest.php index ab9eb414634..a2a83ee70a7 100644 --- a/test/phpunit/CompanyLibTest.php +++ b/test/phpunit/CompanyLibTest.php @@ -30,9 +30,9 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/company.lib.php'; if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -46,108 +46,108 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class CompanyLibTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return AdminLibTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return AdminLibTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testNameCurrency - * - * @return void - */ - public function testNameCurrency() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testNameCurrency + * + * @return void + */ + public function testNameCurrency() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=currency_name('USD'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('US Dollars', $result, 'Test to get currency name USD in default language '.$langs->defaultlang); + $result=currency_name('USD'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('US Dollars', $result, 'Test to get currency name USD in default language '.$langs->defaultlang); - $outputlangs=new Translate('', $conf); - $outputlangs->setDefaultLang('fr_FR'); + $outputlangs=new Translate('', $conf); + $outputlangs->setDefaultLang('fr_FR'); - $result=currency_name('USD', 1, $outputlangs); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('USD - Dollars US', $result, 'Test to get currency name USD in default language '.$outputlangs->getDefaultLang()); + $result=currency_name('USD', 1, $outputlangs); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('USD - Dollars US', $result, 'Test to get currency name USD in default language '.$outputlangs->getDefaultLang()); - return $result; - } + return $result; + } } diff --git a/test/phpunit/ContactTest.php b/test/phpunit/ContactTest.php index 7d7e2740bc1..1f8977f6919 100755 --- a/test/phpunit/ContactTest.php +++ b/test/phpunit/ContactTest.php @@ -30,14 +30,12 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/contact/class/contact.class.php'; $langs->load("dict"); -if ($langs->defaultlang != 'en_US') -{ +if ($langs->defaultlang != 'en_US') { print "Error: Default language for company to run tests must be set to en_US or auto. Current is ".$langs->defaultlang."\n"; exit(1); } -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -82,118 +80,118 @@ class ContactTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + /** + * setUpBeforeClass + * + * @return void + */ + 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. + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testContactCreate - * - * @return int - */ - public function testContactCreate() - { - global $conf,$user,$langs,$db; + /** + * testContactCreate + * + * @return int + */ + public function testContactCreate() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Contact($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $result; - } + return $result; + } - /** - * testContactFetch - * - * @param int $id Id of contact - * @return int - * @depends testContactCreate - * The depends says test is run only if previous is ok - */ - public function testContactFetch($id) - { - global $conf,$user,$langs,$db; + /** + * testContactFetch + * + * @param int $id Id of contact + * @return int + * @depends testContactCreate + * The depends says test is run only if previous is ok + */ + public function testContactFetch($id) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Contact($this->savdb); - $result=$localobject->fetch($id); + $result=$localobject->fetch($id); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject; - } + return $localobject; + } - /** - * testContactUpdate - * - * @param Contact $localobject Contact - * @return int - * - * @depends testContactFetch - * The depends says test is run only if previous is ok - */ - public function testContactUpdate($localobject) - { - global $conf,$user,$langs,$db; + /** + * testContactUpdate + * + * @param Contact $localobject Contact + * @return int + * + * @depends testContactFetch + * The depends says test is run only if previous is ok + */ + public function testContactUpdate($localobject) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -208,8 +206,8 @@ class ContactTest extends PHPUnit\Framework\TestCase $localobject->address='New address'; $localobject->zip='New zip'; $localobject->town='New town'; - $localobject->country_id=2; - //$localobject->status=0; + $localobject->country_id=2; + //$localobject->status=0; $localobject->phone_pro='New tel pro'; $localobject->phone_perso='New tel perso'; $localobject->phone_mobile='New tel mobile'; @@ -219,8 +217,8 @@ class ContactTest extends PHPUnit\Framework\TestCase $localobject->default_lang='es_ES'; $result=$localobject->update($localobject->id, $user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0, 'Contact::update error'); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0, 'Contact::update error'); $result=$localobject->update_note($localobject->note_private, '_private'); print __METHOD__." id=".$localobject->id." result=".$result."\n"; @@ -231,60 +229,60 @@ class ContactTest extends PHPUnit\Framework\TestCase $this->assertLessThan($result, 0, 'Contact::update_note (public) error'); $newobject=new Contact($this->savdb); - $result=$newobject->fetch($localobject->id); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0, 'Contact::fetch error'); + $result=$newobject->fetch($localobject->id); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0, 'Contact::fetch error'); - print __METHOD__." old=".$localobject->note_private." new=".$newobject->note_private."\n"; - $this->assertEquals($localobject->note_private, $newobject->note_private); - //print __METHOD__." old=".$localobject->note_public." new=".$newobject->note_public."\n"; - //$this->assertEquals($localobject->note_public, $newobject->note_public); - print __METHOD__." old=".$localobject->lastname." new=".$newobject->lastname."\n"; - $this->assertEquals($localobject->lastname, $newobject->lastname); - print __METHOD__." old=".$localobject->firstname." new=".$newobject->firstname."\n"; - $this->assertEquals($localobject->firstname, $newobject->firstname); - print __METHOD__." old=".$localobject->address." new=".$newobject->address."\n"; - $this->assertEquals($localobject->address, $newobject->address); - print __METHOD__." old=".$localobject->zip." new=".$newobject->zip."\n"; - $this->assertEquals($localobject->zip, $newobject->zip); - print __METHOD__." old=".$localobject->town." new=".$newobject->town."\n"; - $this->assertEquals($localobject->town, $newobject->town); - print __METHOD__." old=".$localobject->country_id." new=".$newobject->country_id."\n"; - $this->assertEquals($localobject->country_id, $newobject->country_id); - print __METHOD__." old=BE new=".$newobject->country_code."\n"; - $this->assertEquals('BE', $newobject->country_code); - //print __METHOD__." old=".$localobject->status." new=".$newobject->status."\n"; - //$this->assertEquals($localobject->status, $newobject->status); - print __METHOD__." old=".$localobject->phone_pro." new=".$newobject->phone_pro."\n"; - $this->assertEquals($localobject->phone_pro, $newobject->phone_pro); - print __METHOD__." old=".$localobject->phone_pro." new=".$newobject->phone_pro."\n"; - $this->assertEquals($localobject->phone_perso, $newobject->phone_perso); - print __METHOD__." old=".$localobject->phone_mobile." new=".$newobject->phone_mobile."\n"; - $this->assertEquals($localobject->phone_mobile, $newobject->phone_mobile); - print __METHOD__." old=".$localobject->fax." new=".$newobject->fax."\n"; - $this->assertEquals($localobject->fax, $newobject->fax); - print __METHOD__." old=".$localobject->email." new=".$newobject->email."\n"; - $this->assertEquals($localobject->email, $newobject->email); - print __METHOD__." old=".$localobject->socialnetworks['jabber']." new=".$newobject->socialnetworks['jabber']."\n"; - $this->assertEquals($localobject->socialnetworks['jabber'], $newobject->socialnetworks['jabber']); - print __METHOD__." old=".$localobject->default_lang." new=".$newobject->default_lang."\n"; - $this->assertEquals($localobject->default_lang, $newobject->default_lang); + print __METHOD__." old=".$localobject->note_private." new=".$newobject->note_private."\n"; + $this->assertEquals($localobject->note_private, $newobject->note_private); + //print __METHOD__." old=".$localobject->note_public." new=".$newobject->note_public."\n"; + //$this->assertEquals($localobject->note_public, $newobject->note_public); + print __METHOD__." old=".$localobject->lastname." new=".$newobject->lastname."\n"; + $this->assertEquals($localobject->lastname, $newobject->lastname); + print __METHOD__." old=".$localobject->firstname." new=".$newobject->firstname."\n"; + $this->assertEquals($localobject->firstname, $newobject->firstname); + print __METHOD__." old=".$localobject->address." new=".$newobject->address."\n"; + $this->assertEquals($localobject->address, $newobject->address); + print __METHOD__." old=".$localobject->zip." new=".$newobject->zip."\n"; + $this->assertEquals($localobject->zip, $newobject->zip); + print __METHOD__." old=".$localobject->town." new=".$newobject->town."\n"; + $this->assertEquals($localobject->town, $newobject->town); + print __METHOD__." old=".$localobject->country_id." new=".$newobject->country_id."\n"; + $this->assertEquals($localobject->country_id, $newobject->country_id); + print __METHOD__." old=BE new=".$newobject->country_code."\n"; + $this->assertEquals('BE', $newobject->country_code); + //print __METHOD__." old=".$localobject->status." new=".$newobject->status."\n"; + //$this->assertEquals($localobject->status, $newobject->status); + print __METHOD__." old=".$localobject->phone_pro." new=".$newobject->phone_pro."\n"; + $this->assertEquals($localobject->phone_pro, $newobject->phone_pro); + print __METHOD__." old=".$localobject->phone_pro." new=".$newobject->phone_pro."\n"; + $this->assertEquals($localobject->phone_perso, $newobject->phone_perso); + print __METHOD__." old=".$localobject->phone_mobile." new=".$newobject->phone_mobile."\n"; + $this->assertEquals($localobject->phone_mobile, $newobject->phone_mobile); + print __METHOD__." old=".$localobject->fax." new=".$newobject->fax."\n"; + $this->assertEquals($localobject->fax, $newobject->fax); + print __METHOD__." old=".$localobject->email." new=".$newobject->email."\n"; + $this->assertEquals($localobject->email, $newobject->email); + print __METHOD__." old=".$localobject->socialnetworks['jabber']." new=".$newobject->socialnetworks['jabber']."\n"; + $this->assertEquals($localobject->socialnetworks['jabber'], $newobject->socialnetworks['jabber']); + print __METHOD__." old=".$localobject->default_lang." new=".$newobject->default_lang."\n"; + $this->assertEquals($localobject->default_lang, $newobject->default_lang); - return $localobject; - } + return $localobject; + } - /** - * testContactOther - * - * @param Contact $localobject Contact - * @return void - * - * @depends testContactUpdate - * The depends says test is run only if previous is ok - */ - public function testContactOther($localobject) - { - global $conf,$user,$langs,$db; + /** + * testContactOther + * + * @param Contact $localobject Contact + * @return void + * + * @depends testContactUpdate + * The depends says test is run only if previous is ok + */ + public function testContactOther($localobject) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -292,108 +290,108 @@ class ContactTest extends PHPUnit\Framework\TestCase //$localobject->fetch($localobject->id); - $result=$localobject->getNomUrl(1); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertNotEquals($result, ''); + $result=$localobject->getNomUrl(1); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertNotEquals($result, ''); - $result=$localobject->getFullAddress(1); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertContains("New address\nNew zip New town\nBelgium", $result); + $result=$localobject->getFullAddress(1); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertContains("New address\nNew zip New town\nBelgium", $result); - $localobject->info($localobject->id); - print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; - $this->assertNotEquals($localobject->date_creation, ''); + $localobject->info($localobject->id); + print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; + $this->assertNotEquals($localobject->date_creation, ''); - return $localobject->id; - } + return $localobject->id; + } - /** - * testContactDelete - * - * @param int $id Id of contact - * @return void - * - * @depends testContactOther - * The depends says test is run only if previous is ok - */ - public function testContactDelete($id) - { - global $conf,$user,$langs,$db; + /** + * testContactDelete + * + * @param int $id Id of contact + * @return void + * + * @depends testContactOther + * The depends says test is run only if previous is ok + */ + public function testContactDelete($id) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Contact($this->savdb); - $result=$localobject->fetch($id); + $result=$localobject->fetch($id); - $result=$localobject->delete(0); + $result=$localobject->delete(0); print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $this->assertLessThan($result, 0); - return $result; - } + return $result; + } - /** - * testContactGetFullAddress - * - * @return int $id Id of company - */ - public function testContactGetFullAddress() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testContactGetFullAddress + * + * @return int $id Id of company + */ + public function testContactGetFullAddress() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobjectadd=new Contact($db); - $localobjectadd->initAsSpecimen(); + $localobjectadd=new Contact($db); + $localobjectadd->initAsSpecimen(); - // France - unset($localobjectadd->country_code); - $localobjectadd->country_id=1; - $localobjectadd->name='New name'; - $localobjectadd->address='New address'; - $localobjectadd->zip='New zip'; - $localobjectadd->town='New town'; - $result=$localobjectadd->getFullAddress(1); - print __METHOD__." id=".$localobjectadd->id." result=".$result."\n"; - $this->assertContains("New address\nNew zip New town\nFrance", $result); + // France + unset($localobjectadd->country_code); + $localobjectadd->country_id=1; + $localobjectadd->name='New name'; + $localobjectadd->address='New address'; + $localobjectadd->zip='New zip'; + $localobjectadd->town='New town'; + $result=$localobjectadd->getFullAddress(1); + print __METHOD__." id=".$localobjectadd->id." result=".$result."\n"; + $this->assertContains("New address\nNew zip New town\nFrance", $result); - // Belgium - unset($localobjectadd->country_code); - $localobjectadd->country_id=2; - $localobjectadd->name='New name'; - $localobjectadd->address='New address'; - $localobjectadd->zip='New zip'; - $localobjectadd->town='New town'; - $result=$localobjectadd->getFullAddress(1); - print __METHOD__." id=".$localobjectadd->id." result=".$result."\n"; - $this->assertContains("New address\nNew zip New town\nBelgium", $result); + // Belgium + unset($localobjectadd->country_code); + $localobjectadd->country_id=2; + $localobjectadd->name='New name'; + $localobjectadd->address='New address'; + $localobjectadd->zip='New zip'; + $localobjectadd->town='New town'; + $result=$localobjectadd->getFullAddress(1); + print __METHOD__." id=".$localobjectadd->id." result=".$result."\n"; + $this->assertContains("New address\nNew zip New town\nBelgium", $result); - // Switzerland - unset($localobjectadd->country_code); - $localobjectadd->country_id=6; - $localobjectadd->name='New name'; - $localobjectadd->address='New address'; - $localobjectadd->zip='New zip'; - $localobjectadd->town='New town'; - $result=$localobjectadd->getFullAddress(1); - print __METHOD__." id=".$localobjectadd->id." result=".$result."\n"; - $this->assertContains("New address\nNew zip New town\nSwitzerland", $result); + // Switzerland + unset($localobjectadd->country_code); + $localobjectadd->country_id=6; + $localobjectadd->name='New name'; + $localobjectadd->address='New address'; + $localobjectadd->zip='New zip'; + $localobjectadd->town='New town'; + $result=$localobjectadd->getFullAddress(1); + print __METHOD__." id=".$localobjectadd->id." result=".$result."\n"; + $this->assertContains("New address\nNew zip New town\nSwitzerland", $result); - // USA - unset($localobjectadd->country_code); - $localobjectadd->country_id=11; - $localobjectadd->name='New name'; - $localobjectadd->address='New address'; - $localobjectadd->zip='New zip'; - $localobjectadd->town='New town'; - $result=$localobjectadd->getFullAddress(1); - print __METHOD__." id=".$localobjectadd->id." result=".$result."\n"; - $this->assertContains("New address\nNew town, New zip\nUnited States", $result); + // USA + unset($localobjectadd->country_code); + $localobjectadd->country_id=11; + $localobjectadd->name='New name'; + $localobjectadd->address='New address'; + $localobjectadd->zip='New zip'; + $localobjectadd->town='New town'; + $result=$localobjectadd->getFullAddress(1); + print __METHOD__." id=".$localobjectadd->id." result=".$result."\n"; + $this->assertContains("New address\nNew town, New zip\nUnited States", $result); - return $localobjectadd->id; - } + return $localobjectadd->id; + } } diff --git a/test/phpunit/ContratTest.php b/test/phpunit/ContratTest.php index d364d6c9dff..5749d08cbae 100644 --- a/test/phpunit/ContratTest.php +++ b/test/phpunit/ContratTest.php @@ -29,11 +29,10 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/contrat/class/contrat.class.php'; -if (empty($user->id)) -{ - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); +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; @@ -47,185 +46,185 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class ContratTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return ContratTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return ContratTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testContratCreate - * - * @return int - */ - public function testContratCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testContratCreate + * + * @return int + */ + public function testContratCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Contrat($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user); + $localobject=new Contrat($this->savdb); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $result; - } + 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 testContratFetch($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testContratFetch + * + * @param int $id Id of contract + * @return int + * + * @depends testContratCreate + * The depends says test is run only if previous is ok + */ + public function testContratFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Contrat($this->savdb); - $result=$localobject->fetch($id); + $localobject=new Contrat($this->savdb); + $result=$localobject->fetch($id); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject; - } + return $localobject; + } - /** - * testContratOther - * - * @param Object $localobject Object contract - * @return int - * - * @depends testContratFetch - * The depends says test is run only if previous is ok - */ - public function testContratOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testContratOther + * + * @param Object $localobject Object contract + * @return int + * + * @depends testContratFetch + * The depends says test is run only if previous is ok + */ + public function testContratOther($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); - */ + /*$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, ''); + $localobject->info($localobject->id); + print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; + $this->assertNotEquals($localobject->date_creation, ''); - return $localobject->id; - } + return $localobject->id; + } - /** - * testContratDelete - * - * @param int $id Id of contract - * @return int - * - * @depends testContratOther - * The depends says test is run only if previous is ok - */ - public function testContratDelete($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testContratDelete + * + * @param int $id Id of contract + * @return int + * + * @depends testContratOther + * The depends says test is run only if previous is ok + */ + public function testContratDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Contrat($this->savdb); - $result=$localobject->fetch($id); - $result=$localobject->delete($user); + $localobject=new Contrat($this->savdb); + $result=$localobject->fetch($id); + $result=$localobject->delete($user); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $result; - } + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $result; + } } diff --git a/test/phpunit/CoreTest.php b/test/phpunit/CoreTest.php index 22649a80724..87f3a3940f4 100644 --- a/test/phpunit/CoreTest.php +++ b/test/phpunit/CoreTest.php @@ -28,16 +28,36 @@ global $conf,$user,$langs,$db; //require_once 'PHPUnit/Autoload.php'; //require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); -if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +if (! defined('NOREQUIREUSER')) { + define('NOREQUIREUSER', '1'); +} +if (! defined('NOREQUIREDB')) { + define('NOREQUIREDB', '1'); +} +if (! defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (! defined('NOREQUIRETRAN')) { + define('NOREQUIRETRAN', '1'); +} +if (! defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (! defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (! defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); // If there is no menu to show +} +if (! defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +} +if (! defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (! defined("NOLOGIN")) { + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +} /** @@ -49,191 +69,190 @@ if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page i */ class CoreTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return CoreTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return CoreTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + //print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - //$db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + //$db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testDetectURLROOT - * - * @return void - */ - public function testDetectURLROOT() - { - global $dolibarr_main_prod; + /** + * testDetectURLROOT + * + * @return void + */ + public function testDetectURLROOT() + { + global $dolibarr_main_prod; - global $dolibarr_main_url_root; - global $dolibarr_main_data_root; - global $dolibarr_main_document_root; - global $dolibarr_main_data_root_alt; - global $dolibarr_main_document_root_alt; - global $dolibarr_main_db_host; - global $dolibarr_main_db_port; - global $dolibarr_main_db_type; - global $dolibarr_main_db_prefix; + global $dolibarr_main_url_root; + global $dolibarr_main_data_root; + global $dolibarr_main_document_root; + global $dolibarr_main_data_root_alt; + global $dolibarr_main_document_root_alt; + global $dolibarr_main_db_host; + global $dolibarr_main_db_port; + global $dolibarr_main_db_type; + global $dolibarr_main_db_prefix; - $testtodo=0; + $testtodo=0; - // Case 1: - // Test for subdir dolibarrnew (that point to htdocs) in root directory /var/www - // URL: http://localhost/dolibarrnew/admin/system/phpinfo.php - // To prepare this test: - // - Create link from htdocs to /var/www/dolibarrnew - // - Put into conf.php $dolibarr_main_document_root='/var/www/dolibarrnew'; - if ($testtodo == 1) { - $_SERVER["HTTPS"]=''; - $_SERVER["SERVER_NAME"]='localhost'; - $_SERVER["SERVER_PORT"]='80'; - $_SERVER["DOCUMENT_ROOT"]='/var/www'; - $_SERVER["SCRIPT_NAME"]='/dolibarrnew/admin/system/phpinfo.php'; - $expectedresult='/dolibarrnew'; - } + // Case 1: + // Test for subdir dolibarrnew (that point to htdocs) in root directory /var/www + // URL: http://localhost/dolibarrnew/admin/system/phpinfo.php + // To prepare this test: + // - Create link from htdocs to /var/www/dolibarrnew + // - Put into conf.php $dolibarr_main_document_root='/var/www/dolibarrnew'; + if ($testtodo == 1) { + $_SERVER["HTTPS"]=''; + $_SERVER["SERVER_NAME"]='localhost'; + $_SERVER["SERVER_PORT"]='80'; + $_SERVER["DOCUMENT_ROOT"]='/var/www'; + $_SERVER["SCRIPT_NAME"]='/dolibarrnew/admin/system/phpinfo.php'; + $expectedresult='/dolibarrnew'; + } - // Case 2: - // Test for subdir aaa (that point to dolibarr) in root directory /var/www - // URL: http://localhost/aaa/htdocs/admin/system/phpinfo.php - // To prepare this test: - // - Create link from dolibarr to /var/www/aaa - // - Put into conf.php $dolibarr_main_document_root='/var/www/aaa/htdocs'; - if ($testtodo == 2) { - $_SERVER["HTTPS"]=''; - $_SERVER["SERVER_NAME"]='localhost'; - $_SERVER["SERVER_PORT"]='80'; - $_SERVER["DOCUMENT_ROOT"]='/var/www'; - $_SERVER["SCRIPT_NAME"]='/aaa/htdocs/admin/system/phpinfo.php'; - $expectedresult='/aaa/htdocs'; - } + // Case 2: + // Test for subdir aaa (that point to dolibarr) in root directory /var/www + // URL: http://localhost/aaa/htdocs/admin/system/phpinfo.php + // To prepare this test: + // - Create link from dolibarr to /var/www/aaa + // - Put into conf.php $dolibarr_main_document_root='/var/www/aaa/htdocs'; + if ($testtodo == 2) { + $_SERVER["HTTPS"]=''; + $_SERVER["SERVER_NAME"]='localhost'; + $_SERVER["SERVER_PORT"]='80'; + $_SERVER["DOCUMENT_ROOT"]='/var/www'; + $_SERVER["SCRIPT_NAME"]='/aaa/htdocs/admin/system/phpinfo.php'; + $expectedresult='/aaa/htdocs'; + } - // Case 3: - // Test for virtual host localhostdolibarrnew that point to htdocs directory with - // a direct document root - // URL: http://localhostdolibarrnew/admin/system/phpinfo.php - // To prepare this test: - // - Create virtual host localhostdolibarrnew that point to /home/ldestailleur/git/dolibarr/htdocs - // - Put into conf.php $dolibarr_main_document_root='/home/ldestailleur/git/dolibarr/htdocs'; - if ($testtodo == 3) { - $_SERVER["HTTPS"]=''; - $_SERVER["SERVER_NAME"]='localhostdolibarrnew'; - $_SERVER["SERVER_PORT"]='80'; - $_SERVER["DOCUMENT_ROOT"]='/home/ldestailleur/git/dolibarr/htdocs'; - $_SERVER["SCRIPT_NAME"]='/admin/system/phpinfo.php'; - $expectedresult=''; - } + // Case 3: + // Test for virtual host localhostdolibarrnew that point to htdocs directory with + // a direct document root + // URL: http://localhostdolibarrnew/admin/system/phpinfo.php + // To prepare this test: + // - Create virtual host localhostdolibarrnew that point to /home/ldestailleur/git/dolibarr/htdocs + // - Put into conf.php $dolibarr_main_document_root='/home/ldestailleur/git/dolibarr/htdocs'; + if ($testtodo == 3) { + $_SERVER["HTTPS"]=''; + $_SERVER["SERVER_NAME"]='localhostdolibarrnew'; + $_SERVER["SERVER_PORT"]='80'; + $_SERVER["DOCUMENT_ROOT"]='/home/ldestailleur/git/dolibarr/htdocs'; + $_SERVER["SCRIPT_NAME"]='/admin/system/phpinfo.php'; + $expectedresult=''; + } - // Case 4: - // Test for virtual host localhostdolibarrnew that point to htdocs directory with - // a symbolic link - // URL: http://localhostdolibarrnew/admin/system/phpinfo.php - if ($testtodo == 4) { - $_SERVER["HTTPS"]=''; - $_SERVER["SERVER_NAME"]='localhostdolibarrnew'; - $_SERVER["SERVER_PORT"]='80'; - $_SERVER["DOCUMENT_ROOT"]='/var/www/dolibarr'; // This is a link that point to /home/ldestail/workspace/dolibarr/htdocs - $_SERVER["SCRIPT_NAME"]='/admin/system/phpinfo.php'; - $expectedresult=''; - } + // Case 4: + // Test for virtual host localhostdolibarrnew that point to htdocs directory with + // a symbolic link + // URL: http://localhostdolibarrnew/admin/system/phpinfo.php + if ($testtodo == 4) { + $_SERVER["HTTPS"]=''; + $_SERVER["SERVER_NAME"]='localhostdolibarrnew'; + $_SERVER["SERVER_PORT"]='80'; + $_SERVER["DOCUMENT_ROOT"]='/var/www/dolibarr'; // This is a link that point to /home/ldestail/workspace/dolibarr/htdocs + $_SERVER["SCRIPT_NAME"]='/admin/system/phpinfo.php'; + $expectedresult=''; + } - // Case 5: - // Test for alias /dolibarralias, Test when using nginx, Test when using lighttpd - // URL: http://localhost/dolibarralias/admin/system/phpinfo.php - // To prepare this test: - // - Copy content of dolibarr project into /var/www/dolibarr - // - Put into conf.php $dolibarr_main_document_root='/var/www/dolibarr/htdocs'; - // - Put into conf.php $dolibarr_main_url_root='http://localhost/dolibarralias'; (because autodetect will fails in this case) - if ($testtodo == 5) { - $_SERVER["HTTPS"]=''; - $_SERVER["SERVER_NAME"]='localhost'; - $_SERVER["SERVER_PORT"]='80'; - $_SERVER["DOCUMENT_ROOT"]='/var/www'; - $_SERVER["SCRIPT_NAME"]='/dolibarralias/admin/system/phpinfo.php'; - $expectedresult='/dolibarralias'; - } + // Case 5: + // Test for alias /dolibarralias, Test when using nginx, Test when using lighttpd + // URL: http://localhost/dolibarralias/admin/system/phpinfo.php + // To prepare this test: + // - Copy content of dolibarr project into /var/www/dolibarr + // - Put into conf.php $dolibarr_main_document_root='/var/www/dolibarr/htdocs'; + // - Put into conf.php $dolibarr_main_url_root='http://localhost/dolibarralias'; (because autodetect will fails in this case) + if ($testtodo == 5) { + $_SERVER["HTTPS"]=''; + $_SERVER["SERVER_NAME"]='localhost'; + $_SERVER["SERVER_PORT"]='80'; + $_SERVER["DOCUMENT_ROOT"]='/var/www'; + $_SERVER["SCRIPT_NAME"]='/dolibarralias/admin/system/phpinfo.php'; + $expectedresult='/dolibarralias'; + } - // Force to rerun filefunc.inc.php - include dirname(__FILE__).'/../../htdocs/filefunc.inc.php'; + // Force to rerun filefunc.inc.php + include dirname(__FILE__).'/../../htdocs/filefunc.inc.php'; - if ($testtodo != 0) - { - print __METHOD__." DOL_MAIN_URL_ROOT=".DOL_MAIN_URL_ROOT."\n"; - print __METHOD__." DOL_URL_ROOT=".DOL_URL_ROOT."\n"; - $this->assertEquals($expectedresult, DOL_URL_ROOT); - } + if ($testtodo != 0) { + print __METHOD__." DOL_MAIN_URL_ROOT=".DOL_MAIN_URL_ROOT."\n"; + print __METHOD__." DOL_URL_ROOT=".DOL_URL_ROOT."\n"; + $this->assertEquals($expectedresult, DOL_URL_ROOT); + } - return true; - } + return true; + } } diff --git a/test/phpunit/DateLibTest.php b/test/phpunit/DateLibTest.php index 2d5598f49b3..366a8fd4ec8 100644 --- a/test/phpunit/DateLibTest.php +++ b/test/phpunit/DateLibTest.php @@ -29,8 +29,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/date.lib.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -75,64 +74,64 @@ class DateLibTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - 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. + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testNumBetweenDay - * - * @return void - */ - public function testNumBetweenDay() - { - global $conf,$user,$langs,$db; + /** + * testNumBetweenDay + * + * @return void + */ + public function testNumBetweenDay() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -143,11 +142,11 @@ class DateLibTest extends PHPUnit\Framework\TestCase $date2=dol_mktime(0, 0, 0, 1, 2, 2012); $result=num_between_day($date1, $date2, 1); - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertEquals(2, $result); $result=num_between_day($date1, $date2, 0); - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertEquals(1, $result); // With different hours @@ -155,11 +154,11 @@ class DateLibTest extends PHPUnit\Framework\TestCase $date2=dol_mktime(12, 0, 0, 1, 2, 2012); $result=num_between_day($date1, $date2, 1); - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertEquals(2, $result); $result=num_between_day($date1, $date2, 0); - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertEquals(1, $result); // With different date before and after sunlight hour (day to change sunlight hour is 2014-03-30) @@ -167,277 +166,277 @@ class DateLibTest extends PHPUnit\Framework\TestCase $date2=dol_mktime(0, 0, 0, 3, 31, 2014, true); $result=num_between_day($date1, $date2, 1); - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertEquals(4, $result); $result=num_between_day($date1, $date2, 0); - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertEquals(3, $result); return $result; - } + } - /** - * testNumPublicHoliday - * - * @return void - */ - public function testNumPublicHoliday() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testNumPublicHoliday + * + * @return void + */ + public function testNumPublicHoliday() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - // With same hours - Tuesday/Wednesday jan 2013 - $date1=dol_mktime(0, 0, 0, 1, 1, 2013); - $date2=dol_mktime(0, 0, 0, 1, 2, 2013); - $date3=dol_mktime(0, 0, 0, 1, 3, 2013); + // With same hours - Tuesday/Wednesday jan 2013 + $date1=dol_mktime(0, 0, 0, 1, 1, 2013); + $date2=dol_mktime(0, 0, 0, 1, 2, 2013); + $date3=dol_mktime(0, 0, 0, 1, 3, 2013); - $result=num_public_holiday($date1, $date2, 'FR', 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(1, $result, 'NumPublicHoliday for Tuesday 1 - Wednesday 2 jan 2013 for FR'); // 1 closed days (country france) + $result=num_public_holiday($date1, $date2, 'FR', 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(1, $result, 'NumPublicHoliday for Tuesday 1 - Wednesday 2 jan 2013 for FR'); // 1 closed days (country france) - $result=num_public_holiday($date1, $date2, 'XX', 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(1, $result, 'NumPublicHoliday for Tuesday 1 - Wednesday 2 jan 2013 for XX'); // 1 closed days (country unknown) + $result=num_public_holiday($date1, $date2, 'XX', 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(1, $result, 'NumPublicHoliday for Tuesday 1 - Wednesday 2 jan 2013 for XX'); // 1 closed days (country unknown) - $result=num_public_holiday($date2, $date3, 'FR', 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(0, $result, 'NumPublicHoliday for Wednesday 2 - Thursday 3 jan 2013 for FR'); // no closed days + $result=num_public_holiday($date2, $date3, 'FR', 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(0, $result, 'NumPublicHoliday for Wednesday 2 - Thursday 3 jan 2013 for FR'); // no closed days - // Check with easter monday - $date1=dol_mktime(0, 0, 0, 4, 21, 2019); - $date2=dol_mktime(0, 0, 0, 4, 23, 2019); + // Check with easter monday + $date1=dol_mktime(0, 0, 0, 4, 21, 2019); + $date2=dol_mktime(0, 0, 0, 4, 23, 2019); - $result=num_public_holiday($date1, $date2, 'XX', 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(1, $result, 'NumPublicHoliday including eastermonday for XX'); // 2 opened day, 1 closed days (sunday) + $result=num_public_holiday($date1, $date2, 'XX', 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(1, $result, 'NumPublicHoliday including eastermonday for XX'); // 2 opened day, 1 closed days (sunday) - $result=num_public_holiday($date1, $date2, 'FR', 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(2, $result, 'NumPublicHoliday including eastermonday for FR'); // 1 opened day, 2 closed days (sunday + easter monday) + $result=num_public_holiday($date1, $date2, 'FR', 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(2, $result, 'NumPublicHoliday including eastermonday for FR'); // 1 opened day, 2 closed days (sunday + easter monday) - // Check for sunday/saturday - Friday 4 - Sunday 6 jan 2013 - $date1=dol_mktime(0, 0, 0, 1, 4, 2013); - $date2=dol_mktime(0, 0, 0, 1, 6, 2013); + // Check for sunday/saturday - Friday 4 - Sunday 6 jan 2013 + $date1=dol_mktime(0, 0, 0, 1, 4, 2013); + $date2=dol_mktime(0, 0, 0, 1, 6, 2013); - $result=num_public_holiday($date1, $date2, 'FR', 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(2, $result, 'NumPublicHoliday for FR'); // 1 opened day, 2 closed days + $result=num_public_holiday($date1, $date2, 'FR', 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(2, $result, 'NumPublicHoliday for FR'); // 1 opened day, 2 closed days - $result=num_public_holiday($date1, $date2, 'FR', 1, 1, 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(2, $result, 'NumPublicHoliday for FR'); // 1 opened day, 2 closed days + $result=num_public_holiday($date1, $date2, 'FR', 1, 1, 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(2, $result, 'NumPublicHoliday for FR'); // 1 opened day, 2 closed days - $result=num_public_holiday($date1, $date2, 'FR', 1, 1, 0); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(1, $result, 'NumPublicHoliday for FR'); // 2 opened day, 1 closed days + $result=num_public_holiday($date1, $date2, 'FR', 1, 1, 0); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(1, $result, 'NumPublicHoliday for FR'); // 2 opened day, 1 closed days - $result=num_public_holiday($date1, $date2, 'FR', 1, 0, 0); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(0, $result, 'NumPublicHoliday for FR'); // 3 opened day, 0 closed days + $result=num_public_holiday($date1, $date2, 'FR', 1, 0, 0); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(0, $result, 'NumPublicHoliday for FR'); // 3 opened day, 0 closed days - $result=num_public_holiday($date1, $date2, 'XX', 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(2, $result, 'NumPublicHoliday for XX'); // 1 opened day, 2 closed days (even if country unknown) - } + $result=num_public_holiday($date1, $date2, 'XX', 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(2, $result, 'NumPublicHoliday for XX'); // 1 opened day, 2 closed days (even if country unknown) + } - /** - * testNumOpenDay - * - * @return void - */ - public function testNumOpenDay() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testNumOpenDay + * + * @return void + */ + public function testNumOpenDay() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - // With same hours - Tuesday/Wednesday jan 2013 - $date1=dol_mktime(0, 0, 0, 1, 1, 2013); - $date2=dol_mktime(0, 0, 0, 1, 2, 2013); - $date3=dol_mktime(0, 0, 0, 1, 3, 2013); + // With same hours - Tuesday/Wednesday jan 2013 + $date1=dol_mktime(0, 0, 0, 1, 1, 2013); + $date2=dol_mktime(0, 0, 0, 1, 2, 2013); + $date3=dol_mktime(0, 0, 0, 1, 3, 2013); - $result=num_open_day($date1, $date2, 0, 1, 0, 'FR'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(1, $result, 'NumOpenDay Tuesday 1 - Wednesday 2 jan 2013 for FR'); // 1 opened days (country france) + $result=num_open_day($date1, $date2, 0, 1, 0, 'FR'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(1, $result, 'NumOpenDay Tuesday 1 - Wednesday 2 jan 2013 for FR'); // 1 opened days (country france) - $result=num_open_day($date1, $date2, 0, 1, 0, 'XX'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(1, $result, 'NumOpenDay Tuesday 1 - Wednesday 2 jan 2013 for XX'); // 1 opened days (country unknown) + $result=num_open_day($date1, $date2, 0, 1, 0, 'XX'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(1, $result, 'NumOpenDay Tuesday 1 - Wednesday 2 jan 2013 for XX'); // 1 opened days (country unknown) - $result=num_open_day($date2, $date3, 0, 1, 0, 'FR'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(2, $result, 'NumOpenDay Wednesday 2 - Thursday 3 jan 2013 for FR'); // 2 opened days + $result=num_open_day($date2, $date3, 0, 1, 0, 'FR'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(2, $result, 'NumOpenDay Wednesday 2 - Thursday 3 jan 2013 for FR'); // 2 opened days - // With same hours - Friday/Sunday jan 2013 - $date1=dol_mktime(0, 0, 0, 1, 4, 2013); - $date2=dol_mktime(0, 0, 0, 1, 6, 2013); + // With same hours - Friday/Sunday jan 2013 + $date1=dol_mktime(0, 0, 0, 1, 4, 2013); + $date2=dol_mktime(0, 0, 0, 1, 6, 2013); - $result=num_open_day($date1, $date2, 0, 1, 0, 'FR'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(1, $result, 'NumOpenDay for FR'); // 1 opened day, 2 closed + $result=num_open_day($date1, $date2, 0, 1, 0, 'FR'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(1, $result, 'NumOpenDay for FR'); // 1 opened day, 2 closed - $result=num_open_day($date1, $date2, 'XX', 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(1, $result, 'NumOpenDay for XX'); // 1 opened day, 2 closes (even if country unknown) - } + $result=num_open_day($date1, $date2, 'XX', 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(1, $result, 'NumOpenDay for XX'); // 1 opened day, 2 closes (even if country unknown) + } - /** - * testConvertTime2Seconds - * - * @return void - */ - public function testConvertTime2Seconds() - { - global $conf,$user,$langs,$db; + /** + * testConvertTime2Seconds + * + * @return void + */ + public function testConvertTime2Seconds() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $result=convertTime2Seconds(1, 1, 2); - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertEquals(3662, $result); return $result; - } + } - /** - * testConvertSecondToTime - * - * @return void - */ - public function testConvertSecondToTime() - { - global $conf,$user,$langs,$db; + /** + * testConvertSecondToTime + * + * @return void + */ + public function testConvertSecondToTime() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $result=convertSecondToTime(0, 'all', 86400); - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertEquals('0', $result); $result=convertSecondToTime(86400, 'all', 86400); - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertSame('1 '.$langs->trans("Day"), $result); return $result; - } + } - /** - * testDolPrintDate - * - * @return void - */ - public function testDolPrintDate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testDolPrintDate + * + * @return void + */ + public function testDolPrintDate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - // Check %Y-%m-%d %H:%M:%S format - $result=dol_print_date(0, '%Y-%m-%d %H:%M:%S', true); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('1970-01-01 00:00:00', $result); + // Check %Y-%m-%d %H:%M:%S format + $result=dol_print_date(0, '%Y-%m-%d %H:%M:%S', true); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('1970-01-01 00:00:00', $result); - // Check %Y-%m-%d %H:%M:%S format - $result=dol_print_date(16725225600, '%Y-%m-%d %H:%M:%S', true); // http://www.epochconverter.com/ - print __METHOD__." result=".$result."\n"; - $this->assertEquals('2500-01-01 00:00:00', $result); + // Check %Y-%m-%d %H:%M:%S format + $result=dol_print_date(16725225600, '%Y-%m-%d %H:%M:%S', true); // http://www.epochconverter.com/ + print __METHOD__." result=".$result."\n"; + $this->assertEquals('2500-01-01 00:00:00', $result); - // Check %Y-%m-%d %H:%M:%S format - $result=dol_print_date(-1830384000, '%Y-%m-%d %H:%M:%S', true); // http://www.epochconverter.com/ - print __METHOD__." result=".$result."\n"; - $this->assertEquals('1912-01-01 00:00:00', $result); // dol_print_date use TZ (good) but epoch converter does not use it. + // Check %Y-%m-%d %H:%M:%S format + $result=dol_print_date(-1830384000, '%Y-%m-%d %H:%M:%S', true); // http://www.epochconverter.com/ + print __METHOD__." result=".$result."\n"; + $this->assertEquals('1912-01-01 00:00:00', $result); // dol_print_date use TZ (good) but epoch converter does not use it. - // Check %Y-%m-%d %H:%M:%S format - $result=dol_print_date(-11676096000, '%Y-%m-%d %H:%M:%S', true); // http://www.epochconverter.com/ - print __METHOD__." result=".$result."\n"; - $this->assertEquals('1600-01-01 00:00:00', $result); + // Check %Y-%m-%d %H:%M:%S format + $result=dol_print_date(-11676096000, '%Y-%m-%d %H:%M:%S', true); // http://www.epochconverter.com/ + print __METHOD__." result=".$result."\n"; + $this->assertEquals('1600-01-01 00:00:00', $result); - // test with negative timezone - $result=dol_print_date(-1, '%Y-%m-%d %H:%M:%S', true); // http://www.epochconverter.com/ - print __METHOD__." result=".$result."\n"; - $this->assertEquals('1969-12-31 23:59:59', $result); + // test with negative timezone + $result=dol_print_date(-1, '%Y-%m-%d %H:%M:%S', true); // http://www.epochconverter.com/ + print __METHOD__." result=".$result."\n"; + $this->assertEquals('1969-12-31 23:59:59', $result); - // Check dayhour format for fr_FR - $outputlangs=new Translate('', $conf); - $outputlangs->setDefaultLang('fr_FR'); - $outputlangs->load("main"); + // Check dayhour format for fr_FR + $outputlangs=new Translate('', $conf); + $outputlangs->setDefaultLang('fr_FR'); + $outputlangs->load("main"); - $result=dol_print_date(0+24*3600, 'dayhour', true, $outputlangs); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('02/01/1970 00:00', $result); + $result=dol_print_date(0+24*3600, 'dayhour', true, $outputlangs); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('02/01/1970 00:00', $result); - // Check %a and %b format for fr_FR - $result=dol_print_date(0, '%a %b %B', true, $outputlangs); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('Jeu Jan. Janvier', $result); + // Check %a and %b format for fr_FR + $result=dol_print_date(0, '%a %b %B', true, $outputlangs); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('Jeu Jan. Janvier', $result); - // Check day format for en_US - $outputlangs=new Translate('', $conf); - $outputlangs->setDefaultLang('en_US'); - $outputlangs->load("main"); + // Check day format for en_US + $outputlangs=new Translate('', $conf); + $outputlangs->setDefaultLang('en_US'); + $outputlangs->load("main"); - $result=dol_print_date(0+24*3600, 'day', true, $outputlangs); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('01/02/1970', $result); + $result=dol_print_date(0+24*3600, 'day', true, $outputlangs); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('01/02/1970', $result); - // Check %a and %b format for en_US - $result=dol_print_date(0, '%a %b %B', true, $outputlangs); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('Thu Jan January', $result); + // Check %a and %b format for en_US + $result=dol_print_date(0, '%a %b %B', true, $outputlangs); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('Thu Jan January', $result); - return $result; - } + return $result; + } - /** - * testDolTimePlusDuree - * - * @return int - */ - public function testDolTimePlusDuree() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testDolTimePlusDuree + * + * @return int + */ + public function testDolTimePlusDuree() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - // Check dayhour format for fr_FR - $outputlangs=new Translate('', $conf); - $outputlangs->setDefaultLang('fr_FR'); - $outputlangs->load("main"); + // Check dayhour format for fr_FR + $outputlangs=new Translate('', $conf); + $outputlangs->setDefaultLang('fr_FR'); + $outputlangs->load("main"); - $result=dol_print_date(dol_time_plus_duree(dol_time_plus_duree(dol_time_plus_duree(0, 1, 'm'), 1, 'y'), 1, 'd'), 'dayhour', true, $outputlangs); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('02/02/1971 00:00', $result); + $result=dol_print_date(dol_time_plus_duree(dol_time_plus_duree(dol_time_plus_duree(0, 1, 'm'), 1, 'y'), 1, 'd'), 'dayhour', true, $outputlangs); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('02/02/1971 00:00', $result); - return $result; - } + return $result; + } - /** - * testDolStringToTime - * - * @return int - */ - public function testDolStringToTime() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testDolStringToTime + * + * @return int + */ + public function testDolStringToTime() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; $stime='19700102'; $result=dol_stringtotime($stime); @@ -445,18 +444,18 @@ class DateLibTest extends PHPUnit\Framework\TestCase $this->assertEquals(86400, $result); $stime='1970-01-01T02:00:00Z'; - $result=dol_stringtotime($stime); - print __METHOD__." result=".$result."\n"; + $result=dol_stringtotime($stime); + print __METHOD__." result=".$result."\n"; $this->assertEquals(7200, $result); - $stime='1970-01-01 02:00:00'; - $result=dol_stringtotime($stime); - print __METHOD__." result=".$result."\n"; + $stime='1970-01-01 02:00:00'; + $result=dol_stringtotime($stime); + print __METHOD__." result=".$result."\n"; $this->assertEquals(7200, $result); - $stime='19700101T020000Z'; - $result=dol_stringtotime($stime); - print __METHOD__." result=".$result."\n"; + $stime='19700101T020000Z'; + $result=dol_stringtotime($stime); + print __METHOD__." result=".$result."\n"; $this->assertEquals(7200, $result); $stime='19700101020000'; @@ -464,26 +463,26 @@ class DateLibTest extends PHPUnit\Framework\TestCase print __METHOD__." result=".$result."\n"; $this->assertEquals(7200, $result); - return $result; - } + return $result; + } - /** - * testDolGetFirstDayWeek - * - * @return int - */ - public function testDolGetFirstDayWeek() - { - global $conf; + /** + * testDolGetFirstDayWeek + * + * @return int + */ + public function testDolGetFirstDayWeek() + { + global $conf; - $day=3; $month=2; $year=2015; - $conf->global->MAIN_START_WEEK = 1; // start on monday - $prev = dol_get_first_day_week($day, $month, $year); + $day=3; $month=2; $year=2015; + $conf->global->MAIN_START_WEEK = 1; // start on monday + $prev = dol_get_first_day_week($day, $month, $year); $this->assertEquals(2, (int) $prev['first_day']); // monday for month 2, year 2014 is the 2 - $day=3; $month=2; $year=2015; - $conf->global->MAIN_START_WEEK = 0; // start on sunday - $prev = dol_get_first_day_week($day, $month, $year); + $day=3; $month=2; $year=2015; + $conf->global->MAIN_START_WEEK = 0; // start on sunday + $prev = dol_get_first_day_week($day, $month, $year); $this->assertEquals(1, (int) $prev['first_day']); // sunday for month 2, year 2015 is the 1st - } + } } diff --git a/test/phpunit/DateLibTzFranceTest.php b/test/phpunit/DateLibTzFranceTest.php index 7e96e39030e..63893a9c881 100644 --- a/test/phpunit/DateLibTzFranceTest.php +++ b/test/phpunit/DateLibTzFranceTest.php @@ -29,8 +29,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/date.lib.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -74,139 +73,139 @@ class DateLibTzFranceTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + /** + * setUpBeforeClass + * + * @return void + */ + public static function setUpBeforeClass() + { + global $conf,$user,$langs,$db; - if (getServerTimeZoneString() != 'Europe/Paris') { - print "\n".__METHOD__." This PHPUnit test can be launched manually only onto a server with PHP timezone set to TZ+1 Europe/Paris, not a TZ=".getServerTimeZoneString().".\n"; die(); - } + if (getServerTimeZoneString() != 'Europe/Paris') { + print "\n".__METHOD__." This PHPUnit test can be launched manually only onto a server with PHP timezone set to TZ+1 Europe/Paris, not a TZ=".getServerTimeZoneString().".\n"; die(); + } - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testDolPrintDateTzFrance - * Same than official testDolPrintDate but with parameter tzoutput that is false='tzserver'. - * This test works only onto a server using TZ+1 Europe/Paris. - * - * You can use http://www.epochconverter.com/ to generate more tests. - * - * @return void - */ - public function testDolPrintDateTzFrance() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testDolPrintDateTzFrance + * Same than official testDolPrintDate but with parameter tzoutput that is false='tzserver'. + * This test works only onto a server using TZ+1 Europe/Paris. + * + * You can use http://www.epochconverter.com/ to generate more tests. + * + * @return void + */ + public function testDolPrintDateTzFrance() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - // Check %Y-%m-%d %H:%M:%S format - $result=dol_print_date(0, '%Y-%m-%d %H:%M:%S', false); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('1970-01-01 01:00:00', $result); + // Check %Y-%m-%d %H:%M:%S format + $result=dol_print_date(0, '%Y-%m-%d %H:%M:%S', false); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('1970-01-01 01:00:00', $result); - // Check %Y-%m-%d %H:%M:%S format - $result=dol_print_date(16725225600, '%Y-%m-%d %H:%M:%S', false); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('2500-01-01 01:00:00', $result); + // Check %Y-%m-%d %H:%M:%S format + $result=dol_print_date(16725225600, '%Y-%m-%d %H:%M:%S', false); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('2500-01-01 01:00:00', $result); - // Check %Y-%m-%d %H:%M:%S format - $result=dol_print_date(-1830384000, '%Y-%m-%d %H:%M:%S', false); // http://www.epochconverter.com/ - print __METHOD__." result=".$result."\n"; - $this->assertEquals('1912-01-01 01:00:00', $result); // dol_print_date use a timezone, not epoch converter as it did not exists this year + // Check %Y-%m-%d %H:%M:%S format + $result=dol_print_date(-1830384000, '%Y-%m-%d %H:%M:%S', false); // http://www.epochconverter.com/ + print __METHOD__." result=".$result."\n"; + $this->assertEquals('1912-01-01 01:00:00', $result); // dol_print_date use a timezone, not epoch converter as it did not exists this year - // Specific cas during war + // Specific cas during war - // 1940, no timezone - $result=dol_print_date(-946771200, '%Y-%m-%d %H:%M:%S', false); // http://www.epochconverter.com/ - print __METHOD__." result=".$result."\n"; - $this->assertEquals('1940-01-01 01:00:00', $result); // dol_print_date use a modern timezone, not epoch converter as it did not exists this year + // 1940, no timezone + $result=dol_print_date(-946771200, '%Y-%m-%d %H:%M:%S', false); // http://www.epochconverter.com/ + print __METHOD__." result=".$result."\n"; + $this->assertEquals('1940-01-01 01:00:00', $result); // dol_print_date use a modern timezone, not epoch converter as it did not exists this year - // 1941, timezone is added by germany to +2 (same for 1942) - $result=dol_print_date(-915148800, '%Y-%m-%d %H:%M:%S', false); // http://www.epochconverter.com/ - print __METHOD__." result=".$result."\n"; - $this->assertEquals('1941-01-01 01:00:00', $result); // dol_print_date use a modern timezone, epoch converter use historic timezone + // 1941, timezone is added by germany to +2 (same for 1942) + $result=dol_print_date(-915148800, '%Y-%m-%d %H:%M:%S', false); // http://www.epochconverter.com/ + print __METHOD__." result=".$result."\n"; + $this->assertEquals('1941-01-01 01:00:00', $result); // dol_print_date use a modern timezone, epoch converter use historic timezone - // 1943, timezone is +1 - $result=dol_print_date(-852076800, '%Y-%m-%d %H:%M:%S', false); // http://www.epochconverter.com/ - print __METHOD__." result=".$result."\n"; - $this->assertEquals('1943-01-01 01:00:00', $result); + // 1943, timezone is +1 + $result=dol_print_date(-852076800, '%Y-%m-%d %H:%M:%S', false); // http://www.epochconverter.com/ + print __METHOD__." result=".$result."\n"; + $this->assertEquals('1943-01-01 01:00:00', $result); - // test with negative timezone - $result=dol_print_date(-1, '%Y-%m-%d %H:%M:%S', false); // http://www.epochconverter.com/ - print __METHOD__." result=".$result."\n"; - $this->assertEquals('1970-01-01 00:59:59', $result); + // test with negative timezone + $result=dol_print_date(-1, '%Y-%m-%d %H:%M:%S', false); // http://www.epochconverter.com/ + print __METHOD__." result=".$result."\n"; + $this->assertEquals('1970-01-01 00:59:59', $result); - // Check dayhour format for fr_FR - $outputlangs=new Translate('', $conf); - $outputlangs->setDefaultLang('fr_FR'); - $outputlangs->load("main"); + // Check dayhour format for fr_FR + $outputlangs=new Translate('', $conf); + $outputlangs->setDefaultLang('fr_FR'); + $outputlangs->load("main"); - $result=dol_print_date(0+24*3600, 'dayhour', false, $outputlangs); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('02/01/1970 01:00', $result); + $result=dol_print_date(0+24*3600, 'dayhour', false, $outputlangs); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('02/01/1970 01:00', $result); - // Check day format for en_US - $outputlangs=new Translate('', $conf); - $outputlangs->setDefaultLang('en_US'); - $outputlangs->load("main"); + // Check day format for en_US + $outputlangs=new Translate('', $conf); + $outputlangs->setDefaultLang('en_US'); + $outputlangs->load("main"); - $result=dol_print_date(0+24*3600, 'day', false, $outputlangs); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('01/02/1970', $result); + $result=dol_print_date(0+24*3600, 'day', false, $outputlangs); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('01/02/1970', $result); - // Check %a and %b format for en_US - $result=dol_print_date(0, '%a %b', false, $outputlangs); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('Thu Jan', $result); + // Check %a and %b format for en_US + $result=dol_print_date(0, '%a %b', false, $outputlangs); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('Thu Jan', $result); - return $result; - } + return $result; + } } diff --git a/test/phpunit/DiscountTest.php b/test/phpunit/DiscountTest.php index 9eba2460655..5841ba59c37 100644 --- a/test/phpunit/DiscountTest.php +++ b/test/phpunit/DiscountTest.php @@ -29,8 +29,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/class/discount.class.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -75,39 +74,39 @@ class DiscountTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + protected function setUp() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -115,87 +114,87 @@ class DiscountTest extends PHPUnit\Framework\TestCase print __METHOD__."\n"; //print $db->getVersion()."\n"; - } + } /** * End phpunit tests * * @return void */ - protected function tearDown() - { - print __METHOD__."\n"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testDiscountCreate - * - * @return int - */ - public function testDiscountCreate() - { - global $conf,$user,$langs,$db; + /** + * testDiscountCreate + * + * @return int + */ + public function testDiscountCreate() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new DiscountAbsolute($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; - return $result; - } + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + return $result; + } - /** - * testDiscountFetch - * - * @param int $id Id of discount - * @return int - * - * @depends testDiscountCreate - * The depends says test is run only if previous is ok - */ - public function testDiscountFetch($id) - { - global $conf,$user,$langs,$db; + /** + * testDiscountFetch + * + * @param int $id Id of discount + * @return int + * + * @depends testDiscountCreate + * The depends says test is run only if previous is ok + */ + public function testDiscountFetch($id) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new DiscountAbsolute($this->savdb); - $result=$localobject->fetch($id); + $result=$localobject->fetch($id); - $this->assertLessThan($result, 0); - print __METHOD__." id=".$id." result=".$result."\n"; - return $id; - } + $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + return $id; + } - /** - * testDiscountDelete - * - * @param int $id Id of discount - * @return int - * - * @depends testDiscountFetch - * The depends says test is run only if previous is ok - */ - public function testDiscountDelete($id) - { - global $conf,$user,$langs,$db; + /** + * testDiscountDelete + * + * @param int $id Id of discount + * @return int + * + * @depends testDiscountFetch + * The depends says test is run only if previous is ok + */ + public function testDiscountDelete($id) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new DiscountAbsolute($this->savdb); - $result=$localobject->fetch($id); + $result=$localobject->fetch($id); $result=$localobject->delete($user); print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $result; - } + $this->assertLessThan($result, 0); + return $result; + } } diff --git a/test/phpunit/EntrepotTest.php b/test/phpunit/EntrepotTest.php index 8cad99243cc..6be9b5ba349 100644 --- a/test/phpunit/EntrepotTest.php +++ b/test/phpunit/EntrepotTest.php @@ -29,8 +29,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/product/stock/class/entrepot.class.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -74,146 +73,148 @@ class EntrepotTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + /** + * setUpBeforeClass + * + * @return void + */ + public static function setUpBeforeClass() + { + global $conf,$user,$langs,$db; - if (empty($conf->stock->enabled)) { print __METHOD__." Module Stock must be enabled.\n"; die(); } + if (empty($conf->stock->enabled)) { + print __METHOD__." Module Stock must be enabled.\n"; die(); + } - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testEntrepotCreate - * - * @return void - */ - public function testEntrepotCreate() - { - global $conf,$user,$langs,$db; + /** + * testEntrepotCreate + * + * @return void + */ + public function testEntrepotCreate() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Entrepot($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); - return $result; - } + return $result; + } - /** - * testEntrepotFetch - * - * @param int $id Id entrepot - * @return Entrepot - * - * @depends testEntrepotCreate - * The depends says test is run only if previous is ok - */ - public function testEntrepotFetch($id) - { - global $conf,$user,$langs,$db; + /** + * testEntrepotFetch + * + * @param int $id Id entrepot + * @return Entrepot + * + * @depends testEntrepotCreate + * The depends says test is run only if previous is ok + */ + public function testEntrepotFetch($id) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Entrepot($this->savdb); - $result=$localobject->fetch($id); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $result=$localobject->fetch($id); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject; - } + return $localobject; + } - /** - * testEntrepotUpdate - * - * @param Entrepot $localobject Entrepot - * @return void - * - * @depends testEntrepotFetch - * The depends says test is run only if previous is ok - */ - public function testEntrepotUpdate($localobject) - { - global $conf,$user,$langs,$db; + /** + * testEntrepotUpdate + * + * @param Entrepot $localobject Entrepot + * @return void + * + * @depends testEntrepotFetch + * The depends says test is run only if previous is ok + */ + public function testEntrepotUpdate($localobject) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject->note='New note after update'; - $result=$localobject->update($localobject->id, $user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $result=$localobject->update($localobject->id, $user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject; - } + return $localobject; + } - /** - * testEntrepotOther - * - * @param Entrepot $localobject Entrepot - * @return void - * - * @depends testEntrepotUpdate - * The depends says test is run only if previous is ok - */ - public function testEntrepotOther($localobject) - { - global $conf,$user,$langs,$db; + /** + * testEntrepotOther + * + * @param Entrepot $localobject Entrepot + * @return void + * + * @depends testEntrepotUpdate + * The depends says test is run only if previous is ok + */ + public function testEntrepotOther($localobject) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -222,33 +223,33 @@ class EntrepotTest extends PHPUnit\Framework\TestCase $result = $localobject->get_full_arbo(); $this->assertEquals('WAREHOUSE SPECIMEN', $result); - return $localobject->id; - } + return $localobject->id; + } - /** - * testEntrepotDelete - * - * @param int $id Id of entrepot - * @return void - * - * @depends testEntrepotOther - * The depends says test is run only if previous is ok - */ - public function testEntrepotDelete($id) - { - global $conf,$user,$langs,$db; + /** + * testEntrepotDelete + * + * @param int $id Id of entrepot + * @return void + * + * @depends testEntrepotOther + * The depends says test is run only if previous is ok + */ + public function testEntrepotDelete($id) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Entrepot($this->savdb); - $result=$localobject->fetch($id); + $result=$localobject->fetch($id); - $result=$localobject->delete($user); + $result=$localobject->delete($user); print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0, $localobject->errorsToString()); + $this->assertLessThan($result, 0, $localobject->errorsToString()); - return $result; - } + return $result; + } } diff --git a/test/phpunit/ExpenseReportTest.php b/test/phpunit/ExpenseReportTest.php index 2d6fdca3b27..c24bf9d19e9 100644 --- a/test/phpunit/ExpenseReportTest.php +++ b/test/phpunit/ExpenseReportTest.php @@ -30,9 +30,9 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/expensereport/class/expensereport.class.php'; if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -47,270 +47,270 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class ExpenseReportTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return ExpenseReportTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return ExpenseReportTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - //print $db->getVersion()."\n"; - } - /** - * End phpunit tests - * - * @return void - */ - protected function tearDown() - { - print __METHOD__."\n"; - } + print __METHOD__."\n"; + //print $db->getVersion()."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testExpenseReportCreate - * - * @return void - */ - public function testExpenseReportCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testExpenseReportCreate + * + * @return void + */ + public function testExpenseReportCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - // Create supplier order with a too low quantity - $localobject=new ExpenseReport($db); - $localobject->initAsSpecimen(); // Init a specimen with lines - $localobject->status = 0; - $localobject->fk_statut = 0; - $localobject->date_fin = null; // Force bad value + // Create supplier order with a too low quantity + $localobject=new ExpenseReport($db); + $localobject->initAsSpecimen(); // Init a specimen with lines + $localobject->status = 0; + $localobject->fk_statut = 0; + $localobject->date_fin = null; // Force bad value - $result=$localobject->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(-1, $result, "Error on test ExpenseReport create 1 : ".$localobject->error); // must be -1 because of missing mandatory fields + $result=$localobject->create($user); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(-1, $result, "Error on test ExpenseReport create 1 : ".$localobject->error); // must be -1 because of missing mandatory fields - $sql="DELETE FROM ".MAIN_DB_PREFIX."expensereport where ref=''"; - $db->query($sql); + $sql="DELETE FROM ".MAIN_DB_PREFIX."expensereport where ref=''"; + $db->query($sql); - // Create supplier order - $localobject2=new ExpenseReport($db); - $localobject2->initAsSpecimen(); // Init a specimen with lines - $localobject2->status = 0; - $localobject2->fk_statut = 0; + // Create supplier order + $localobject2=new ExpenseReport($db); + $localobject2->initAsSpecimen(); // Init a specimen with lines + $localobject2->status = 0; + $localobject2->fk_statut = 0; - $result=$localobject2->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThanOrEqual(0, $result, "Error on test ExpenseReport create 2 : ".$localobject2->error); + $result=$localobject2->create($user); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThanOrEqual(0, $result, "Error on test ExpenseReport create 2 : ".$localobject2->error); - return $result; - } + return $result; + } - /** - * testExpenseReportFetch - * - * @param int $id Id of supplier order - * @return void - * - * @depends testExpenseReportCreate - * The depends says test is run only if previous is ok - */ - public function testExpenseReportFetch($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testExpenseReportFetch + * + * @param int $id Id of supplier order + * @return void + * + * @depends testExpenseReportCreate + * The depends says test is run only if previous is ok + */ + public function testExpenseReportFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new ExpenseReport($this->savdb); - $result=$localobject->fetch($id); + $localobject=new ExpenseReport($this->savdb); + $result=$localobject->fetch($id); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testExpenseReportValid - * - * @param Object $localobject Supplier order - * @return void - * - * @depends testExpenseReportFetch - * The depends says test is run only if previous is ok - */ - public function testExpenseReportValid($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testExpenseReportValid + * + * @param Object $localobject Supplier order + * @return void + * + * @depends testExpenseReportFetch + * The depends says test is run only if previous is ok + */ + public function testExpenseReportValid($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->setValidate($user); + $result=$localobject->setValidate($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testExpenseReportApprove - * - * @param Object $localobject Supplier order - * @return void - * - * @depends testExpenseReportValid - * The depends says test is run only if previous is ok - */ - public function testExpenseReportApprove($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testExpenseReportApprove + * + * @param Object $localobject Supplier order + * @return void + * + * @depends testExpenseReportValid + * The depends says test is run only if previous is ok + */ + public function testExpenseReportApprove($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->setApproved($user); + $result=$localobject->setApproved($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testExpenseReportCancel - * - * @param Object $localobject Supplier order - * @return void - * - * @depends testExpenseReportApprove - * The depends says test is run only if previous is ok - */ - public function testExpenseReportCancel($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testExpenseReportCancel + * + * @param Object $localobject Supplier order + * @return void + * + * @depends testExpenseReportApprove + * The depends says test is run only if previous is ok + */ + public function testExpenseReportCancel($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->set_cancel($user, 'Because...'); + $result=$localobject->set_cancel($user, 'Because...'); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testExpenseReportOther - * - * @param Object $localobject Supplier order - * @return void - * - * @depends testExpenseReportCancel - * The depends says test is run only if previous is ok - */ - public function testExpenseReportOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testExpenseReportOther + * + * @param Object $localobject Supplier order + * @return void + * + * @depends testExpenseReportCancel + * The depends says test is run only if previous is ok + */ + public function testExpenseReportOther($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->getSumPayments(); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertGreaterThanOrEqual(0, $result); + $result=$localobject->getSumPayments(); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertGreaterThanOrEqual(0, $result); - return $localobject->id; - } + return $localobject->id; + } - /** - * testExpenseReportDelete - * - * @param int $id Id of order - * @return void - * - * @depends testExpenseReportOther - * The depends says test is run only if previous is ok - */ - public function testExpenseReportDelete($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testExpenseReportDelete + * + * @param int $id Id of order + * @return void + * + * @depends testExpenseReportOther + * The depends says test is run only if previous is ok + */ + public function testExpenseReportDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new ExpenseReport($this->savdb); - $result=$localobject->fetch($id); - $result=$localobject->delete($user); + $localobject=new ExpenseReport($this->savdb); + $result=$localobject->fetch($id); + $result=$localobject->delete($user); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertGreaterThan(0, $result); - return $result; - } + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertGreaterThan(0, $result); + return $result; + } } diff --git a/test/phpunit/ExportTest.php b/test/phpunit/ExportTest.php index 0f5b0bd82e3..a3386c7aef5 100644 --- a/test/phpunit/ExportTest.php +++ b/test/phpunit/ExportTest.php @@ -30,16 +30,36 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/exports/class/export.class.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/files.lib.php'; -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); -if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +if (! defined('NOREQUIREUSER')) { + define('NOREQUIREUSER', '1'); +} +if (! defined('NOREQUIREDB')) { + define('NOREQUIREDB', '1'); +} +if (! defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (! defined('NOREQUIRETRAN')) { + define('NOREQUIRETRAN', '1'); +} +if (! defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (! defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (! defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); // If there is no menu to show +} +if (! defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +} +if (! defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (! defined("NOLOGIN")) { + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +} /** @@ -79,296 +99,294 @@ class ExportTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * Other tests - * - * @return void - */ - public function testExportOther() - { - global $conf,$user,$langs,$db; - - $model='csv'; - - $conf->global->EXPORT_CSV_SEPARATOR_TO_USE = ','; - print 'EXPORT_CSV_SEPARATOR_TO_USE = '.$conf->global->EXPORT_CSV_SEPARATOR_TO_USE; - - // Creation of class to export using model ExportXXX - $dir = DOL_DOCUMENT_ROOT . "/core/modules/export/"; - $file = "export_".$model.".modules.php"; - $classname = "Export".$model; - require_once $dir.$file; - $objmodel = new $classname($db); - - // First test without option USE_STRICT_CSV_RULES - unset($conf->global->USE_STRICT_CSV_RULES); - - $valtotest='A simple string'; - print __METHOD__." valtotest=".$valtotest."\n"; - $result = $objmodel->csvClean($valtotest, $langs->charset_output); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, 'A simple string'); - - $valtotest='A string with , and ; inside'; - print __METHOD__." valtotest=".$valtotest."\n"; - $result = $objmodel->csvClean($valtotest, $langs->charset_output); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, '"A string with , and ; inside"', 'Error in csvClean for '.$file); - - $valtotest='A string with " inside'; - print __METHOD__." valtotest=".$valtotest."\n"; - $result = $objmodel->csvClean($valtotest, $langs->charset_output); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, '"A string with "" inside"'); - - $valtotest='A string with " inside and '."\r\n".' carriage returns'; - print __METHOD__." valtotest=".$valtotest."\n"; - $result = $objmodel->csvClean($valtotest, $langs->charset_output); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, '"A string with "" inside and \n carriage returns"'); - - $valtotest='A string with html
content
inside
'."\n"; - print __METHOD__." valtotest=".$valtotest."\n"; - $result = $objmodel->csvClean($valtotest, $langs->charset_output); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, '"A string with html
content
inside"'); - - // Same tests with strict mode - $conf->global->USE_STRICT_CSV_RULES = 1; - - $valtotest='A simple string'; - print __METHOD__." valtotest=".$valtotest."\n"; - $result = $objmodel->csvClean($valtotest, $langs->charset_output); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, 'A simple string'); - - $valtotest='A string with , and ; inside'; - print __METHOD__." valtotest=".$valtotest."\n"; - $result = $objmodel->csvClean($valtotest, $langs->charset_output); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, '"A string with , and ; inside"'); - - $valtotest='A string with " inside'; - print __METHOD__." valtotest=".$valtotest."\n"; - $result = $objmodel->csvClean($valtotest, $langs->charset_output); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, '"A string with "" inside"'); - - $valtotest='A string with " inside and '."\r\n".' carriage returns'; - print __METHOD__." valtotest=".$valtotest."\n"; - $result = $objmodel->csvClean($valtotest, $langs->charset_output); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, "\"A string with \"\" inside and \r\n carriage returns\""); - - $valtotest='A string with html
content
inside
'."\n"; - print __METHOD__." valtotest=".$valtotest."\n"; - $result = $objmodel->csvClean($valtotest, $langs->charset_output); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, '"A string with html
content
inside"'); - } - - /** - * Test export function for a personalized dataset - * - * @depends testExportOther + /** + * Other tests + * * @return void - */ - public function testExportPersonalizedExport() - { - global $conf,$user,$langs,$db; + */ + public function testExportOther() + { + global $conf,$user,$langs,$db; - $sql = "SELECT f.ref as f_ref, f.total as f_total, f.tva as f_tva FROM ".MAIN_DB_PREFIX."facture f"; + $model='csv'; - $objexport=new Export($db); - //$objexport->load_arrays($user,$datatoexport); + $conf->global->EXPORT_CSV_SEPARATOR_TO_USE = ','; + print 'EXPORT_CSV_SEPARATOR_TO_USE = '.$conf->global->EXPORT_CSV_SEPARATOR_TO_USE; - // Define properties - $datatoexport='test'; - $array_selected = array("f.ref"=>1, "f.total"=>2, "f.tva"=>3); - $array_export_fields = array("f.ref"=>"FacNumber", "f.total"=>"FacTotal", "f.tva"=>"FacVat"); - $array_alias = array("f_ref"=>"ref", "f_total"=>"total", "f_tva"=>"tva"); - $objexport->array_export_fields[0]=$array_export_fields; - $objexport->array_export_alias[0]=$array_alias; + // Creation of class to export using model ExportXXX + $dir = DOL_DOCUMENT_ROOT . "/core/modules/export/"; + $file = "export_".$model.".modules.php"; + $classname = "Export".$model; + require_once $dir.$file; + $objmodel = new $classname($db); - dol_mkdir($conf->export->dir_temp); + // First test without option USE_STRICT_CSV_RULES + unset($conf->global->USE_STRICT_CSV_RULES); - $model='csv'; + $valtotest='A simple string'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 'A simple string'); - // Build export file - print "Process build_file for model = ".$model."\n"; - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); + $valtotest='A string with , and ; inside'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"A string with , and ; inside"', 'Error in csvClean for '.$file); + + $valtotest='A string with " inside'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"A string with "" inside"'); + + $valtotest='A string with " inside and '."\r\n".' carriage returns'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"A string with "" inside and \n carriage returns"'); + + $valtotest='A string with html
content
inside
'."\n"; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"A string with html
content
inside"'); + + // Same tests with strict mode + $conf->global->USE_STRICT_CSV_RULES = 1; + + $valtotest='A simple string'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 'A simple string'); + + $valtotest='A string with , and ; inside'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"A string with , and ; inside"'); + + $valtotest='A string with " inside'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"A string with "" inside"'); + + $valtotest='A string with " inside and '."\r\n".' carriage returns'; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, "\"A string with \"\" inside and \r\n carriage returns\""); + + $valtotest='A string with html
content
inside
'."\n"; + print __METHOD__." valtotest=".$valtotest."\n"; + $result = $objmodel->csvClean($valtotest, $langs->charset_output); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, '"A string with html
content
inside"'); + } + + /** + * Test export function for a personalized dataset + * + * @depends testExportOther + * @return void + */ + public function testExportPersonalizedExport() + { + global $conf,$user,$langs,$db; + + $sql = "SELECT f.ref as f_ref, f.total as f_total, f.tva as f_tva FROM ".MAIN_DB_PREFIX."facture f"; + + $objexport=new Export($db); + //$objexport->load_arrays($user,$datatoexport); + + // Define properties + $datatoexport='test'; + $array_selected = array("f.ref"=>1, "f.total"=>2, "f.tva"=>3); + $array_export_fields = array("f.ref"=>"FacNumber", "f.total"=>"FacTotal", "f.tva"=>"FacVat"); + $array_alias = array("f_ref"=>"ref", "f_total"=>"total", "f_tva"=>"tva"); + $objexport->array_export_fields[0]=$array_export_fields; + $objexport->array_export_alias[0]=$array_alias; + + dol_mkdir($conf->export->dir_temp); + + $model='csv'; + + // Build export file + print "Process build_file for model = ".$model."\n"; + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); $expectedresult = 1; - $this->assertEquals($expectedresult, $result, 'Error in CSV export'); + $this->assertEquals($expectedresult, $result, 'Error in CSV export'); - $model='tsv'; + $model='tsv'; - // Build export file - print "Process build_file for model = ".$model."\n"; - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); + // Build export file + print "Process build_file for model = ".$model."\n"; + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); $expectedresult=1; - $this->assertEquals($expectedresult, $result, 'Error in TSV export'); + $this->assertEquals($expectedresult, $result, 'Error in TSV export'); - $model='excel2007new'; + $model='excel2007new'; - // Build export file - /* ko on php 7.4 on travis (zip not available) */ - print "Process build_file for model = ".$model."\n"; - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); + // Build export file + /* ko on php 7.4 on travis (zip not available) */ + print "Process build_file for model = ".$model."\n"; + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); $expectedresult=1; - $this->assertEquals($expectedresult, $result, 'Error in Excel2007new export'); + $this->assertEquals($expectedresult, $result, 'Error in Excel2007new export'); - return true; - } + return true; + } - /** - * Test export function for a personalized dataset with filters - * - * @depends testExportPersonalizedExport - * @return void - */ - public function testExportPersonalizedWithFilter() - { - global $conf,$user,$langs,$db; - /* - $sql = "SELECT f.ref as f_ref, f.total as f_total, f.tva as f_tva FROM ".MAIN_DB_PREFIX."facture f"; - - $objexport=new Export($db); - //$objexport->load_arrays($user,$datatoexport); - - // Define properties - $datatoexport='test_filtered'; - $array_selected = array("f.ref"=>1, "f.total"=>2, "f.tva"=>3); - $array_export_fields = array("f.ref"=>"FacNumber", "f.total"=>"FacTotal", "f.tva"=>"FacVat"); - $array_filtervalue = array("f.total" => ">100"); - $array_filtered = array("f.total" => 1); - $array_alias = array("f_ref"=>"ref", "f_total"=>"total", "f_tva"=>"tva"); - $objexport->array_export_fields[0]=$array_export_fields; - $objexport->array_export_alias[0]=$array_alias; - - dol_mkdir($conf->export->dir_temp); - - $model='csv'; - - // Build export file - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $sql); - $expectedresult=1; - $this->assertEquals($expectedresult,$result); - - $model='tsv'; - - // Build export file - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $sql); - $expectedresult=1; - $this->assertEquals($expectedresult,$result); - - $model='excel'; - - // Build export file - $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $sql); - $expectedresult=1; - $this->assertEquals($expectedresult,$result); - */ - $this->assertEquals(true, true); - return true; - } - - /** - * Test export function for all dataset predefined into modules - * - * @depends testExportPersonalizedWithFilter + /** + * Test export function for a personalized dataset with filters + * + * @depends testExportPersonalizedExport * @return void - */ - public function testExportModulesDatasets() - { - global $conf,$user,$langs,$db; + */ + public function testExportPersonalizedWithFilter() + { + global $conf,$user,$langs,$db; + /* + $sql = "SELECT f.ref as f_ref, f.total as f_total, f.tva as f_tva FROM ".MAIN_DB_PREFIX."facture f"; - $model='csv'; + $objexport=new Export($db); + //$objexport->load_arrays($user,$datatoexport); - $filterdatatoexport=''; - //$filterdatatoexport=''; - //$array_selected = array("s.rowid"=>1, "s.nom"=>2); // Mut be fields found into declaration of dataset + // Define properties + $datatoexport='test_filtered'; + $array_selected = array("f.ref"=>1, "f.total"=>2, "f.tva"=>3); + $array_export_fields = array("f.ref"=>"FacNumber", "f.total"=>"FacTotal", "f.tva"=>"FacVat"); + $array_filtervalue = array("f.total" => ">100"); + $array_filtered = array("f.total" => 1); + $array_alias = array("f_ref"=>"ref", "f_total"=>"total", "f_tva"=>"tva"); + $objexport->array_export_fields[0]=$array_export_fields; + $objexport->array_export_alias[0]=$array_alias; - // Load properties of arrays to make export - $objexport=new Export($db); - $result=$objexport->load_arrays($user, $filterdatatoexport); // This load ->array_export_xxx properties for datatoexport + dol_mkdir($conf->export->dir_temp); - // Loop on each dataset - foreach ($objexport->array_export_code as $key => $datatoexport) - { - $exportfile=$conf->export->dir_temp.'/'.$user->id.'/export_'.$datatoexport.'.csv'; - print "Process export for dataset ".$datatoexport." into ".$exportfile."\n"; - dol_delete_file($exportfile); + $model='csv'; - // Generate $array_selected - $i=0; - $array_selected=array(); - foreach ($objexport->array_export_fields[$key] as $key => $val) - { + // Build export file + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $sql); + $expectedresult=1; + $this->assertEquals($expectedresult,$result); + + $model='tsv'; + + // Build export file + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $sql); + $expectedresult=1; + $this->assertEquals($expectedresult,$result); + + $model='excel'; + + // Build export file + $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, $array_filtervalue, $sql); + $expectedresult=1; + $this->assertEquals($expectedresult,$result); + */ + $this->assertEquals(true, true); + return true; + } + + /** + * Test export function for all dataset predefined into modules + * + * @depends testExportPersonalizedWithFilter + * @return void + */ + public function testExportModulesDatasets() + { + global $conf,$user,$langs,$db; + + $model='csv'; + + $filterdatatoexport=''; + //$filterdatatoexport=''; + //$array_selected = array("s.rowid"=>1, "s.nom"=>2); // Mut be fields found into declaration of dataset + + // Load properties of arrays to make export + $objexport=new Export($db); + $result=$objexport->load_arrays($user, $filterdatatoexport); // This load ->array_export_xxx properties for datatoexport + + // Loop on each dataset + foreach ($objexport->array_export_code as $key => $datatoexport) { + $exportfile=$conf->export->dir_temp.'/'.$user->id.'/export_'.$datatoexport.'.csv'; + print "Process export for dataset ".$datatoexport." into ".$exportfile."\n"; + dol_delete_file($exportfile); + + // Generate $array_selected + $i=0; + $array_selected=array(); + foreach ($objexport->array_export_fields[$key] as $key => $val) { $array_selected[$key]=$i++; } //var_dump($array_selected); - // Build export file - $sql = ""; + // Build export file + $sql = ""; $result=$objexport->build_file($user, $model, $datatoexport, $array_selected, array(), $sql); $expectedresult = 1; - $this->assertEquals($expectedresult, $result, "Call build_file() to export ".$exportfile.' failed: '.$objexport->error); - $result=dol_is_file($exportfile); - $this->assertTrue($result, 'File '.$exportfile.' not found'); - } + $this->assertEquals($expectedresult, $result, "Call build_file() to export ".$exportfile.' failed: '.$objexport->error); + $result=dol_is_file($exportfile); + $this->assertTrue($result, 'File '.$exportfile.' not found'); + } - return true; - } + return true; + } } diff --git a/test/phpunit/FactureFournisseurTest.php b/test/phpunit/FactureFournisseurTest.php index d9cd44a40d2..c7873ae3206 100644 --- a/test/phpunit/FactureFournisseurTest.php +++ b/test/phpunit/FactureFournisseurTest.php @@ -30,8 +30,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/fourn/class/fournisseur.facture.class.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -76,204 +75,204 @@ class FactureFournisseurTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testFactureFournisseurCreate - * - * @return int - */ - public function testFactureFournisseurCreate() - { - global $conf,$user,$langs,$db; + /** + * testFactureFournisseurCreate + * + * @return int + */ + public function testFactureFournisseurCreate() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new FactureFournisseur($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); - $this->assertLessThan($result, 0, $localobject->errorsToString()); - print __METHOD__." result=".$result."\n"; - return $result; - } + $this->assertLessThan($result, 0, $localobject->errorsToString()); + print __METHOD__." result=".$result."\n"; + return $result; + } - /** - * testFactureFournisseurFetch - * - * @param int $id If supplier invoice - * @return void - * - * @depends testFactureFournisseurCreate - * The depends says test is run only if previous is ok - */ - public function testFactureFournisseurFetch($id) - { - global $conf,$user,$langs,$db; + /** + * testFactureFournisseurFetch + * + * @param int $id If supplier invoice + * @return void + * + * @depends testFactureFournisseurCreate + * The depends says test is run only if previous is ok + */ + public function testFactureFournisseurFetch($id) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new FactureFournisseur($this->savdb); - $result=$localobject->fetch($id); + $result=$localobject->fetch($id); - $this->assertLessThan($result, 0, $localobject->errorsToString()); - print __METHOD__." id=".$id." result=".$result."\n"; - return $localobject; - } + $this->assertLessThan($result, 0, $localobject->errorsToString()); + print __METHOD__." id=".$id." result=".$result."\n"; + return $localobject; + } - /** - * testFactureFournisseurUpdate - * - * @param Object $localobject Supplier invoice - * @return int - * - * @depends testFactureFournisseurFetch - * The depends says test is run only if previous is ok - */ - public function testFactureFournisseurUpdate($localobject) - { - global $conf,$user,$langs,$db; + /** + * testFactureFournisseurUpdate + * + * @param Object $localobject Supplier invoice + * @return int + * + * @depends testFactureFournisseurFetch + * The depends says test is run only if previous is ok + */ + public function testFactureFournisseurUpdate($localobject) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject->note='New note after update'; - $result=$localobject->update($user); + $result=$localobject->update($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0, $localobject->errorsToString()); - return $localobject; - } + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0, $localobject->errorsToString()); + return $localobject; + } - /** - * testFactureFournisseurValid - * - * @param Object $localobject Supplier invoice - * @return void - * - * @depends testFactureFournisseurUpdate - * The depends says test is run only if previous is ok - */ - public function testFactureFournisseurValid($localobject) - { - global $conf,$user,$langs,$db; + /** + * testFactureFournisseurValid + * + * @param Object $localobject Supplier invoice + * @return void + * + * @depends testFactureFournisseurUpdate + * The depends says test is run only if previous is ok + */ + public function testFactureFournisseurValid($localobject) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - $result=$localobject->validate($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $result=$localobject->validate($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0, $localobject->errorsToString()); - return $localobject; - } + $this->assertLessThan($result, 0, $localobject->errorsToString()); + return $localobject; + } - /** - * testFactureFournisseurOther - * - * @param Object $localobject Supplier invoice - * @return void - * - * @depends testFactureFournisseurValid - * The depends says test is run only if previous is ok - */ - public function testFactureFournisseurOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFactureFournisseurOther + * + * @param Object $localobject Supplier invoice + * @return void + * + * @depends testFactureFournisseurValid + * The depends says test is run only if previous is ok + */ + public function testFactureFournisseurOther($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); - */ + /*$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, ''); + $localobject->info($localobject->id); + print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; + $this->assertNotEquals($localobject->date_creation, ''); - return $localobject->id; - } + return $localobject->id; + } - /** - * testFactureFournisseurDelete - * - * @param int $id Id of supplier invoice - * @return void - * - * @depends testFactureFournisseurOther - * The depends says test is run only if previous is ok - */ - public function testFactureFournisseurDelete($id) - { - global $conf,$user,$langs,$db; + /** + * testFactureFournisseurDelete + * + * @param int $id Id of supplier invoice + * @return void + * + * @depends testFactureFournisseurOther + * The depends says test is run only if previous is ok + */ + public function testFactureFournisseurDelete($id) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new FactureFournisseur($this->savdb); - $result=$localobject->fetch($id); + $result=$localobject->fetch($id); $result=$localobject->delete($user); print __METHOD__." id=".$id." result=".$result."\n"; $this->assertLessThan($result, 0, $localobject->errorsToString()); - return $result; - } + return $result; + } } diff --git a/test/phpunit/FactureRecTest.php b/test/phpunit/FactureRecTest.php index 0250b659e47..459bea8ae87 100644 --- a/test/phpunit/FactureRecTest.php +++ b/test/phpunit/FactureRecTest.php @@ -30,8 +30,7 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture.class.php'; require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture-rec.class.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -75,66 +74,66 @@ class FactureRecTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testFactureCreate - * - * @return int - */ - public function testFactureRecCreate() - { - global $conf,$user,$langs,$db; + /** + * testFactureCreate + * + * @return int + */ + public function testFactureRecCreate() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -145,60 +144,62 @@ class FactureRecTest extends PHPUnit\Framework\TestCase $localobjectinv->create($user); $localobject=new FactureRec($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user, $localobjectinv->id); + $localobject->initAsSpecimen(); + $result=$localobject->create($user, $localobjectinv->id); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; - return $result; - } + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + return $result; + } - /** - * Edit an object to test updates - * - * @param mixed $localobject Object Facture - * @return void - */ - public function changeProperties(&$localobject) - { - $localobject->note_private='New note'; - //$localobject->note='New note after update'; - } + /** + * Edit an object to test updates + * + * @param mixed $localobject Object Facture + * @return void + */ + public function changeProperties(&$localobject) + { + $localobject->note_private='New note'; + //$localobject->note='New note after update'; + } - /** - * Compare all public properties values of 2 objects - * - * @param Object $oA Object operand 1 - * @param Object $oB Object operand 2 - * @param boolean $ignoretype False will not report diff if type of value differs - * @param array $fieldstoignorearray Array of fields to ignore in diff + /** + * Compare all public properties values of 2 objects + * + * @param Object $oA Object operand 1 + * @param Object $oB Object operand 2 + * @param boolean $ignoretype False will not report diff if type of value differs + * @param array $fieldstoignorearray Array of fields to ignore in diff * @return array Array with differences - */ - public function objCompare($oA, $oB, $ignoretype = true, $fieldstoignorearray = array('id')) - { - $retAr=array(); + */ + public function objCompare($oA, $oB, $ignoretype = true, $fieldstoignorearray = array('id')) + { + $retAr=array(); - if (get_class($oA) !== get_class($oB)) { - $retAr[]="Supplied objects are not of same class."; - } else { - $oVarsA=get_object_vars($oA); - $oVarsB=get_object_vars($oB); - $aKeys=array_keys($oVarsA); - foreach ($aKeys as $sKey) { - if (in_array($sKey, $fieldstoignorearray)) continue; - if (! $ignoretype && ($oVarsA[$sKey] !== $oVarsB[$sKey])) { - $retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]); - } - if ($ignoretype && ($oVarsA[$sKey] != $oVarsB[$sKey])) { - $retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]); - } - } - } - return $retAr; - } + if (get_class($oA) !== get_class($oB)) { + $retAr[]="Supplied objects are not of same class."; + } else { + $oVarsA=get_object_vars($oA); + $oVarsB=get_object_vars($oB); + $aKeys=array_keys($oVarsA); + foreach ($aKeys as $sKey) { + if (in_array($sKey, $fieldstoignorearray)) { + continue; + } + if (! $ignoretype && ($oVarsA[$sKey] !== $oVarsB[$sKey])) { + $retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]); + } + if ($ignoretype && ($oVarsA[$sKey] != $oVarsB[$sKey])) { + $retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]); + } + } + } + return $retAr; + } } diff --git a/test/phpunit/FactureTest.php b/test/phpunit/FactureTest.php index 64959e1cd4f..506013599bc 100644 --- a/test/phpunit/FactureTest.php +++ b/test/phpunit/FactureTest.php @@ -31,9 +31,9 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture.class.php'; if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; @@ -47,192 +47,196 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class FactureTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return FactureTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return FactureTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + /** + * setUpBeforeClass + * + * @return void + */ + public static function setUpBeforeClass() + { + global $conf,$user,$langs,$db; - if (empty($conf->facture->enabled)) { print __METHOD__." module customer invoice must be enabled.\n"; die(); } - if (! empty($conf->ecotaxdeee->enabled)) { print __METHOD__." ecotaxdeee module must not be enabled.\n"; die(); } + if (empty($conf->facture->enabled)) { + print __METHOD__." module customer invoice must be enabled.\n"; die(); + } + if (! empty($conf->ecotaxdeee->enabled)) { + print __METHOD__." ecotaxdeee module must not be enabled.\n"; die(); + } - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } - /** - * End phpunit tests - * - * @return void - */ - protected function tearDown() - { - print __METHOD__."\n"; - } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testFactureCreate - * - * @return int - */ - public function testFactureCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFactureCreate + * + * @return int + */ + public function testFactureCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; - return $result; - } + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + return $result; + } - /** - * testFactureFetch - * - * @param int $id Id invoice - * @return int - * - * @depends testFactureCreate - * The depends says test is run only if previous is ok - */ - public function testFactureFetch($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFactureFetch + * + * @param int $id Id invoice + * @return int + * + * @depends testFactureCreate + * The depends says test is run only if previous is ok + */ + public function testFactureFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Facture($this->savdb); - $result=$localobject->fetch($id); + $localobject=new Facture($this->savdb); + $result=$localobject->fetch($id); - $this->assertLessThan($result, 0); - print __METHOD__." id=".$id." result=".$result."\n"; - return $localobject; - } + $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + return $localobject; + } - /** - * testFactureFetch - * - * @param Object $localobject Invoice - * @return int - * - * @depends testFactureFetch - * The depends says test is run only if previous is ok - */ - public function testFactureUpdate($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFactureFetch + * + * @param Object $localobject Invoice + * @return int + * + * @depends testFactureFetch + * The depends says test is run only if previous is ok + */ + public function testFactureUpdate($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $this->changeProperties($localobject); - $result=$localobject->update($user); + $this->changeProperties($localobject); + $result=$localobject->update($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testFactureValid - * - * @param Object $localobject Invoice - * @return void - * - * @depends testFactureUpdate - * The depends says test is run only if previous is ok - */ - public function testFactureValid($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFactureValid + * + * @param Object $localobject Invoice + * @return void + * + * @depends testFactureUpdate + * The depends says test is run only if previous is ok + */ + public function testFactureValid($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=$localobject->validate($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $result=$localobject->validate($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $this->assertLessThan($result, 0); - // Test everything are still same than specimen - $newlocalobject=new Facture($this->savdb); - $newlocalobject->initAsSpecimen(); - $this->changeProperties($newlocalobject); + // Test everything are still same than specimen + $newlocalobject=new Facture($this->savdb); + $newlocalobject->initAsSpecimen(); + $this->changeProperties($newlocalobject); - // Hack to avoid test to be wrong when module sellyoursaas is on - unset($localobject->array_options['options_commission']); - unset($localobject->array_options['options_reseller']); + // Hack to avoid test to be wrong when module sellyoursaas is on + unset($localobject->array_options['options_commission']); + unset($localobject->array_options['options_reseller']); - $arraywithdiff = $this->objCompare( + $arraywithdiff = $this->objCompare( $localobject, $newlocalobject, true, @@ -245,140 +249,142 @@ class FactureTest extends PHPUnit\Framework\TestCase 'trackid','user_creat','user_valid' ) ); - $this->assertEquals($arraywithdiff, array()); // Actual, Expected + $this->assertEquals($arraywithdiff, array()); // Actual, Expected - return $localobject; - } + return $localobject; + } - /** - * testFactureOther - * - * @param Object $localobject Invoice - * @return int - * - * @depends testFactureValid - * The depends says test is run only if previous is ok - */ - public function testFactureOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFactureOther + * + * @param Object $localobject Invoice + * @return int + * + * @depends testFactureValid + * The depends says test is run only if previous is ok + */ + public function testFactureOther($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); - */ + /*$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, ''); + $localobject->info($localobject->id); + print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; + $this->assertNotEquals($localobject->date_creation, ''); - $result=$localobject->demande_prelevement($user); - print __METHOD__." result=".$result."\n"; - $this->assertLessThan($result, 0); + $result=$localobject->demande_prelevement($user); + print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject->id; - } + return $localobject->id; + } - /** - * testFactureDelete - * - * @param int $id Id of invoice - * @return int - * - * @depends testFactureOther - * The depends says test is run only if previous is ok - */ - public function testFactureDelete($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFactureDelete + * + * @param int $id Id of invoice + * @return int + * + * @depends testFactureOther + * The depends says test is run only if previous is ok + */ + public function testFactureDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - // Force default setup - unset($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED); - unset($conf->global->INVOICE_CAN_NEVER_BE_REMOVED); + // Force default setup + unset($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED); + unset($conf->global->INVOICE_CAN_NEVER_BE_REMOVED); - $localobject=new Facture($this->savdb); - $result=$localobject->fetch($id); + $localobject=new Facture($this->savdb); + $result=$localobject->fetch($id); - // Create another invoice and validate it after $localobject - $localobject2=new Facture($this->savdb); - $result=$localobject2->initAsSpecimen(); - $result=$localobject2->create($user); - $result=$localobject2->validate($user); + // Create another invoice and validate it after $localobject + $localobject2=new Facture($this->savdb); + $result=$localobject2->initAsSpecimen(); + $result=$localobject2->create($user); + $result=$localobject2->validate($user); print 'Invoice $localobject ref = '.$localobject->ref."\n"; - print 'Invoice $localobject2 created with ref = '.$localobject2->ref."\n"; + print 'Invoice $localobject2 created with ref = '.$localobject2->ref."\n"; - $conf->global->INVOICE_CAN_NEVER_BE_REMOVED = 1; + $conf->global->INVOICE_CAN_NEVER_BE_REMOVED = 1; - $result=$localobject2->delete($user); // Deletion is KO, option INVOICE_CAN_NEVER_BE_REMOVED is on - print __METHOD__." id=".$localobject2->id." ref=".$localobject2->ref." result=".$result."\n"; - $this->assertEquals(0, $result, 'Deletion should fail, option INVOICE_CAN_NEVER_BE_REMOVED is on'); + $result=$localobject2->delete($user); // Deletion is KO, option INVOICE_CAN_NEVER_BE_REMOVED is on + print __METHOD__." id=".$localobject2->id." ref=".$localobject2->ref." result=".$result."\n"; + $this->assertEquals(0, $result, 'Deletion should fail, option INVOICE_CAN_NEVER_BE_REMOVED is on'); - unset($conf->global->INVOICE_CAN_NEVER_BE_REMOVED); + unset($conf->global->INVOICE_CAN_NEVER_BE_REMOVED); - $result=$localobject->delete($user); // Deletion is KO, it is not last invoice - print __METHOD__." id=".$localobject->id." ref=".$localobject->ref." result=".$result."\n"; - $this->assertEquals(0, $result, 'Deletion should fail, it is not last invoice'); + $result=$localobject->delete($user); // Deletion is KO, it is not last invoice + print __METHOD__." id=".$localobject->id." ref=".$localobject->ref." result=".$result."\n"; + $this->assertEquals(0, $result, 'Deletion should fail, it is not last invoice'); - $result=$localobject2->delete($user); // Deletion is OK, it is last invoice - print __METHOD__." id=".$localobject2->id." ref=".$localobject2->ref." result=".$result."\n"; - $this->assertGreaterThan(0, $result, 'Deletion should work, it is last invoice'); + $result=$localobject2->delete($user); // Deletion is OK, it is last invoice + print __METHOD__." id=".$localobject2->id." ref=".$localobject2->ref." result=".$result."\n"; + $this->assertGreaterThan(0, $result, 'Deletion should work, it is last invoice'); - $result=$localobject->delete($user); // Deletion is KO, it is not last invoice - print __METHOD__." id=".$localobject->id." ref=".$localobject->ref." result=".$result."\n"; - $this->assertGreaterThan(0, $result, 'Deletion should work, it is again last invoice'); + $result=$localobject->delete($user); // Deletion is KO, it is not last invoice + print __METHOD__." id=".$localobject->id." ref=".$localobject->ref." result=".$result."\n"; + $this->assertGreaterThan(0, $result, 'Deletion should work, it is again last invoice'); - return $result; - } + return $result; + } - /** - * Edit an object to test updates - * - * @param mixed $localobject Object Facture - * @return void - */ - public function changeProperties(&$localobject) - { - $localobject->note_private='New note'; - //$localobject->note='New note after update'; - } + /** + * Edit an object to test updates + * + * @param mixed $localobject Object Facture + * @return void + */ + public function changeProperties(&$localobject) + { + $localobject->note_private='New note'; + //$localobject->note='New note after update'; + } - /** - * Compare all public properties values of 2 objects - * - * @param Object $oA Object operand 1 - * @param Object $oB Object operand 2 - * @param boolean $ignoretype False will not report diff if type of value differs - * @param array $fieldstoignorearray Array of fields to ignore in diff - * @return array Array with differences - */ - public function objCompare($oA, $oB, $ignoretype = true, $fieldstoignorearray = array('id')) - { - $retAr=array(); + /** + * Compare all public properties values of 2 objects + * + * @param Object $oA Object operand 1 + * @param Object $oB Object operand 2 + * @param boolean $ignoretype False will not report diff if type of value differs + * @param array $fieldstoignorearray Array of fields to ignore in diff + * @return array Array with differences + */ + public function objCompare($oA, $oB, $ignoretype = true, $fieldstoignorearray = array('id')) + { + $retAr=array(); - if (get_class($oA) !== get_class($oB)) { - $retAr[]="Supplied objects are not of same class."; - } else { - $oVarsA=get_object_vars($oA); - $oVarsB=get_object_vars($oB); - $aKeys=array_keys($oVarsA); - foreach ($aKeys as $sKey) { - if (in_array($sKey, $fieldstoignorearray)) continue; - if (! $ignoretype && ($oVarsA[$sKey] !== $oVarsB[$sKey])) { - $retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]); - } - if ($ignoretype && ($oVarsA[$sKey] != $oVarsB[$sKey])) { - $retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]); - } - } - } - return $retAr; - } + if (get_class($oA) !== get_class($oB)) { + $retAr[]="Supplied objects are not of same class."; + } else { + $oVarsA=get_object_vars($oA); + $oVarsB=get_object_vars($oB); + $aKeys=array_keys($oVarsA); + foreach ($aKeys as $sKey) { + if (in_array($sKey, $fieldstoignorearray)) { + continue; + } + if (! $ignoretype && ($oVarsA[$sKey] !== $oVarsB[$sKey])) { + $retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]); + } + if ($ignoretype && ($oVarsA[$sKey] != $oVarsB[$sKey])) { + $retAr[]=$sKey.' : '.(is_object($oVarsA[$sKey])?get_class($oVarsA[$sKey]):$oVarsA[$sKey]).' <> '.(is_object($oVarsB[$sKey])?get_class($oVarsB[$sKey]):$oVarsB[$sKey]); + } + } + } + return $retAr; + } } diff --git a/test/phpunit/FactureTestRounding.php b/test/phpunit/FactureTestRounding.php index f0165a88d0b..7c225167e35 100644 --- a/test/phpunit/FactureTestRounding.php +++ b/test/phpunit/FactureTestRounding.php @@ -29,8 +29,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture.class.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -75,272 +74,270 @@ class FactureTestRounding extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testFactureRoundingCreate1 - * Test according to page http://wiki.dolibarr.org/index.php/Draft:VAT_calculation_and_rounding#Standard_usage - * - * @return int - */ - public function testFactureRoundingCreate1() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFactureRoundingCreate1 + * Test according to page http://wiki.dolibarr.org/index.php/Draft:VAT_calculation_and_rounding#Standard_usage + * + * @return int + */ + public function testFactureRoundingCreate1() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=0; - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->lines=array(); - unset($localobject->total_ht); - unset($localobject->total_ttc); - unset($localobject->total_tva); - $result=$localobject->create($user); + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->lines=array(); + unset($localobject->total_ht); + unset($localobject->total_ttc); + unset($localobject->total_tva); + $result=$localobject->create($user); - // Add two lines - for ($i=0; $i<2; $i++) - { - $localobject->addline('Description '.$i, 1.24, 1, 10); - } + // Add two lines + for ($i=0; $i<2; $i++) { + $localobject->addline('Description '.$i, 1.24, 1, 10); + } - $newlocalobject=new Facture($this->savdb); - $newlocalobject->fetch($result); - //var_dump($newlocalobject); + $newlocalobject=new Facture($this->savdb); + $newlocalobject->fetch($result); + //var_dump($newlocalobject); - $this->assertEquals($newlocalobject->total_ht, 2.48); - $this->assertEquals($newlocalobject->total_tva, 0.24); - $this->assertEquals($newlocalobject->total_ttc, 2.72); - return $result; - } + $this->assertEquals($newlocalobject->total_ht, 2.48); + $this->assertEquals($newlocalobject->total_tva, 0.24); + $this->assertEquals($newlocalobject->total_ttc, 2.72); + return $result; + } - /** - * testFactureRoundingCreate2 - * - * @return int - * - * @depends testFactureRoundingCreate1 - * Test according to page http://wiki.dolibarr.org/index.php/Draft:VAT_calculation_and_rounding#Standard_usage - */ - public function testFactureRoundingCreate2() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFactureRoundingCreate2 + * + * @return int + * + * @depends testFactureRoundingCreate1 + * Test according to page http://wiki.dolibarr.org/index.php/Draft:VAT_calculation_and_rounding#Standard_usage + */ + public function testFactureRoundingCreate2() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=0; + $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=0; - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->lines=array(); - unset($localobject->total_ht); - unset($localobject->total_ttc); - unset($localobject->total_vat); - $result=$localobject->create($user); + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->lines=array(); + unset($localobject->total_ht); + unset($localobject->total_ttc); + unset($localobject->total_vat); + $result=$localobject->create($user); - // Add two lines - for ($i=0; $i<2; $i++) - { - $localobject->addline('Description '.$i, 1.24, 1, 10); - } + // Add two lines + for ($i=0; $i<2; $i++) { + $localobject->addline('Description '.$i, 1.24, 1, 10); + } - $newlocalobject=new Facture($this->savdb); - $newlocalobject->fetch($result); - //var_dump($newlocalobject); + $newlocalobject=new Facture($this->savdb); + $newlocalobject->fetch($result); + //var_dump($newlocalobject); - $this->assertEquals($newlocalobject->total_ht, 2.48); - //$this->assertEquals($newlocalobject->total_tva, 0.25); - //$this->assertEquals($newlocalobject->total_ttc, 2.73); - return $result; - } + $this->assertEquals($newlocalobject->total_ht, 2.48); + //$this->assertEquals($newlocalobject->total_tva, 0.25); + //$this->assertEquals($newlocalobject->total_ttc, 2.73); + return $result; + } - /** - * testFactureAddLine1 - * - * @return void - */ - public function testFactureAddLine1() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFactureAddLine1 + * + * @return void + */ + public function testFactureAddLine1() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - // With option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 0 - $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=0; + // With option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 0 + $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=0; - $localobject1a=new Facture($this->savdb); - $localobject1a->initAsSpecimen('nolines'); - $facid=$localobject1a->create($user); - $localobject1a->addline('Line 1', 6.36, 15, 21); // This include update_price - print __METHOD__." id=".$facid." total_ttc=".$localobject1a->total_ttc."\n"; - $this->assertEquals(95.40, $localobject1a->total_ht); - $this->assertEquals(20.03, $localobject1a->total_tva); - $this->assertEquals(115.43, $localobject1a->total_ttc); + $localobject1a=new Facture($this->savdb); + $localobject1a->initAsSpecimen('nolines'); + $facid=$localobject1a->create($user); + $localobject1a->addline('Line 1', 6.36, 15, 21); // This include update_price + print __METHOD__." id=".$facid." total_ttc=".$localobject1a->total_ttc."\n"; + $this->assertEquals(95.40, $localobject1a->total_ht); + $this->assertEquals(20.03, $localobject1a->total_tva); + $this->assertEquals(115.43, $localobject1a->total_ttc); - // With option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 1 - $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=1; + // With option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 1 + $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=1; - $localobject1b=new Facture($this->savdb); - $localobject1b->initAsSpecimen('nolines'); - $facid=$localobject1b->create($user); - $localobject1b->addline('Line 1', 6.36, 15, 21); // This include update_price - print __METHOD__." id=".$facid." total_ttc=".$localobject1b->total_ttc."\n"; - $this->assertEquals(95.40, $localobject1b->total_ht, 'testFactureAddLine1 total_ht'); - $this->assertEquals(20.03, $localobject1b->total_tva, 'testFactureAddLine1 total_tva'); - $this->assertEquals(115.43, $localobject1b->total_ttc, 'testFactureAddLine1 total_ttc'); - } + $localobject1b=new Facture($this->savdb); + $localobject1b->initAsSpecimen('nolines'); + $facid=$localobject1b->create($user); + $localobject1b->addline('Line 1', 6.36, 15, 21); // This include update_price + print __METHOD__." id=".$facid." total_ttc=".$localobject1b->total_ttc."\n"; + $this->assertEquals(95.40, $localobject1b->total_ht, 'testFactureAddLine1 total_ht'); + $this->assertEquals(20.03, $localobject1b->total_tva, 'testFactureAddLine1 total_tva'); + $this->assertEquals(115.43, $localobject1b->total_ttc, 'testFactureAddLine1 total_ttc'); + } - /** - * testFactureAddLine2 - * - * @return void - * - * @depends testFactureAddLine1 - * The depends says test is run only if previous is ok - */ - public function testFactureAddLine2() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFactureAddLine2 + * + * @return void + * + * @depends testFactureAddLine1 + * The depends says test is run only if previous is ok + */ + public function testFactureAddLine2() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - // With option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 0 - $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=0; + // With option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 0 + $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=0; - $localobject2=new Facture($this->savdb); - $localobject2->initAsSpecimen('nolines'); - $facid=$localobject2->create($user); - $localobject2->addline('Line 1', 6.36, 5, 21); - $localobject2->addline('Line 2', 6.36, 5, 21); - $localobject2->addline('Line 3', 6.36, 5, 21); - print __METHOD__." id=".$facid." total_ttc=".$localobject2->total_ttc."\n"; - $this->assertEquals(95.40, $localobject2->total_ht); - $this->assertEquals(20.04, $localobject2->total_tva); - $this->assertEquals(115.44, $localobject2->total_ttc); + $localobject2=new Facture($this->savdb); + $localobject2->initAsSpecimen('nolines'); + $facid=$localobject2->create($user); + $localobject2->addline('Line 1', 6.36, 5, 21); + $localobject2->addline('Line 2', 6.36, 5, 21); + $localobject2->addline('Line 3', 6.36, 5, 21); + print __METHOD__." id=".$facid." total_ttc=".$localobject2->total_ttc."\n"; + $this->assertEquals(95.40, $localobject2->total_ht); + $this->assertEquals(20.04, $localobject2->total_tva); + $this->assertEquals(115.44, $localobject2->total_ttc); - // With option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 1 - $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=1; + // With option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 1 + $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=1; - $localobject2=new Facture($this->savdb); - $localobject2->initAsSpecimen('nolines'); - $facid=$localobject2->create($user); - $localobject2->addline('Line 1', 6.36, 5, 21); - $localobject2->addline('Line 2', 6.36, 5, 21); - $localobject2->addline('Line 3', 6.36, 5, 21); - print __METHOD__." id=".$facid." total_ttc=".$localobject2->total_ttc."\n"; - $this->assertEquals(95.40, $localobject2->total_ht); - $this->assertEquals(20.03, $localobject2->total_tva); - $this->assertEquals(115.43, $localobject2->total_ttc); - } + $localobject2=new Facture($this->savdb); + $localobject2->initAsSpecimen('nolines'); + $facid=$localobject2->create($user); + $localobject2->addline('Line 1', 6.36, 5, 21); + $localobject2->addline('Line 2', 6.36, 5, 21); + $localobject2->addline('Line 3', 6.36, 5, 21); + print __METHOD__." id=".$facid." total_ttc=".$localobject2->total_ttc."\n"; + $this->assertEquals(95.40, $localobject2->total_ht); + $this->assertEquals(20.03, $localobject2->total_tva); + $this->assertEquals(115.43, $localobject2->total_ttc); + } - /** - * testFactureAddLine3 - * - * @return void - * - * @depends testFactureAddLine2 - * The depends says test is run only if previous is ok - */ - public function testFactureAddLine3() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFactureAddLine3 + * + * @return void + * + * @depends testFactureAddLine2 + * The depends says test is run only if previous is ok + */ + public function testFactureAddLine3() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - // With option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 0 - $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=0; + // With option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 0 + $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=0; - $localobject3=new Facture($this->savdb); - $localobject3->initAsSpecimen('nolines'); - $facid=$localobject3->create($user); - $localobject3->addline('Line 1', 6.36, 3, 21); - $localobject3->addline('Line 2', 6.36, 3, 21); - $localobject3->addline('Line 3', 6.36, 3, 21); - $localobject3->addline('Line 4', 6.36, 3, 21); - $localobject3->addline('Line 5', 6.36, 3, 21); - print __METHOD__." id=".$facid." total_ttc=".$localobject3->total_ttc."\n"; - $this->assertEquals(95.40, $localobject3->total_ht); - $this->assertEquals(20.05, $localobject3->total_tva); - $this->assertEquals(115.45, $localobject3->total_ttc); + $localobject3=new Facture($this->savdb); + $localobject3->initAsSpecimen('nolines'); + $facid=$localobject3->create($user); + $localobject3->addline('Line 1', 6.36, 3, 21); + $localobject3->addline('Line 2', 6.36, 3, 21); + $localobject3->addline('Line 3', 6.36, 3, 21); + $localobject3->addline('Line 4', 6.36, 3, 21); + $localobject3->addline('Line 5', 6.36, 3, 21); + print __METHOD__." id=".$facid." total_ttc=".$localobject3->total_ttc."\n"; + $this->assertEquals(95.40, $localobject3->total_ht); + $this->assertEquals(20.05, $localobject3->total_tva); + $this->assertEquals(115.45, $localobject3->total_ttc); - // With option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 1 - $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=1; + // With option MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND = 1 + $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=1; - $localobject3=new Facture($this->savdb); - $localobject3->initAsSpecimen('nolines'); - $facid=$localobject3->create($user); - $localobject3->addline('Line 1', 6.36, 3, 21); - $localobject3->addline('Line 2', 6.36, 3, 21); - $localobject3->addline('Line 3', 6.36, 3, 21); - $localobject3->addline('Line 4', 6.36, 3, 21); - $localobject3->addline('Line 5', 6.36, 3, 21); - print __METHOD__." id=".$facid." total_ttc=".$localobject3->total_ttc."\n"; - $this->assertEquals(95.40, $localobject3->total_ht); - $this->assertEquals(20.03, $localobject3->total_tva); - $this->assertEquals(115.43, $localobject3->total_ttc); - } + $localobject3=new Facture($this->savdb); + $localobject3->initAsSpecimen('nolines'); + $facid=$localobject3->create($user); + $localobject3->addline('Line 1', 6.36, 3, 21); + $localobject3->addline('Line 2', 6.36, 3, 21); + $localobject3->addline('Line 3', 6.36, 3, 21); + $localobject3->addline('Line 4', 6.36, 3, 21); + $localobject3->addline('Line 5', 6.36, 3, 21); + print __METHOD__." id=".$facid." total_ttc=".$localobject3->total_ttc."\n"; + $this->assertEquals(95.40, $localobject3->total_ht); + $this->assertEquals(20.03, $localobject3->total_tva); + $this->assertEquals(115.43, $localobject3->total_ttc); + } } diff --git a/test/phpunit/FichinterTest.php b/test/phpunit/FichinterTest.php index f78e9250471..b2b0b3daf91 100644 --- a/test/phpunit/FichinterTest.php +++ b/test/phpunit/FichinterTest.php @@ -29,8 +29,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/fichinter/class/fichinter.class.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -75,181 +74,181 @@ class FichinterTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testFichinterCreate - * - * @return int - */ - public function testFichinterCreate() - { - global $conf,$user,$langs,$db; + /** + * testFichinterCreate + * + * @return int + */ + public function testFichinterCreate() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Fichinter($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $result; - } + return $result; + } - /** - * testFichinterFetch - * - * @param int $id Id of intervention - * @return int - * - * @depends testFichinterCreate - * The depends says test is run only if previous is ok - */ - public function testFichinterFetch($id) - { - global $conf,$user,$langs,$db; + /** + * testFichinterFetch + * + * @param int $id Id of intervention + * @return int + * + * @depends testFichinterCreate + * The depends says test is run only if previous is ok + */ + public function testFichinterFetch($id) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Fichinter($this->savdb); - $result=$localobject->fetch($id); + $result=$localobject->fetch($id); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject; - } + return $localobject; + } - /** - * testFichinterValid - * - * @param Fichinter $localobject Intervention - * @return int - * - * @depends testFichinterFetch - * The depends says test is run only if previous is ok - */ - public function testFichinterValid($localobject) - { - global $conf,$user,$langs,$db; + /** + * testFichinterValid + * + * @param Fichinter $localobject Intervention + * @return int + * + * @depends testFichinterFetch + * The depends says test is run only if previous is ok + */ + public function testFichinterValid($localobject) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - $result=$localobject->setValid($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $result=$localobject->setValid($user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + $this->assertLessThan($result, 0); + return $localobject; + } - /** - * testFichinterValid - * - * @param Object $localobject Object intervention - * @return int - * - * @depends testFichinterValid - * The depends says test is run only if previous is ok - */ - public function testFichinterOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testFichinterValid + * + * @param Object $localobject Object intervention + * @return int + * + * @depends testFichinterValid + * The depends says test is run only if previous is ok + */ + public function testFichinterOther($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); - */ + /*$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, ''); + $localobject->info($localobject->id); + print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; + $this->assertNotEquals($localobject->date_creation, ''); - return $localobject->id; - } + return $localobject->id; + } - /** - * testFichinterDelete - * - * @param int $id Id of intervention - * @return int - * - * @depends testFichinterOther - * The depends says test is run only if previous is ok - */ - public function testFichinterDelete($id) - { - global $conf,$user,$langs,$db; + /** + * testFichinterDelete + * + * @param int $id Id of intervention + * @return int + * + * @depends testFichinterOther + * The depends says test is run only if previous is ok + */ + public function testFichinterDelete($id) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Fichinter($this->savdb); - $result=$localobject->fetch($id); + $result=$localobject->fetch($id); $result=$localobject->delete($user); print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $result; - } + $this->assertLessThan($result, 0); + return $result; + } } diff --git a/test/phpunit/FilesLibTest.php b/test/phpunit/FilesLibTest.php index ae8ea17efb6..5d73067760d 100644 --- a/test/phpunit/FilesLibTest.php +++ b/test/phpunit/FilesLibTest.php @@ -32,8 +32,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/files.lib.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -77,97 +76,97 @@ class FilesLibTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } /** - * testDolBasename - * - * @return void - */ - public function testDolBasename() - { - global $conf,$user,$langs,$db; + * testDolBasename + * + * @return void + */ + public function testDolBasename() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - $result=dol_basename('adir/afile'); - print __METHOD__." result=".$result."\n"; + $result=dol_basename('adir/afile'); + print __METHOD__." result=".$result."\n"; $this->assertEquals('afile', $result); $result=dol_basename('adir/afile/'); - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertEquals('afile', $result); $result=dol_basename('adir/νεο'); // With cyrillic data. Here basename fails to return correct value - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertEquals('νεο', $result); $result=dol_basename('adir/νεο/'); // With cyrillic data. Here basename fails to return correct value - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertEquals('νεο', $result); - } + } - /** - * testDolCountNbOfLine - * - * @return int - */ - public function testDolCountNbOfLine() - { - global $conf,$user,$langs,$db; + /** + * testDolCountNbOfLine + * + * @return int + */ + public function testDolCountNbOfLine() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -175,20 +174,20 @@ class FilesLibTest extends PHPUnit\Framework\TestCase $file=dirname(__FILE__).'/Example_import_company_1.csv'; $result=dol_count_nb_of_line($file); - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertEquals(3, $result); return $result; - } + } - /** - * testDolIsFileDir - * - * @return int - */ - public function testDolIsFileDir() - { - global $conf,$user,$langs,$db; + /** + * testDolIsFileDir + * + * @return int + */ + public function testDolIsFileDir() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -197,322 +196,322 @@ class FilesLibTest extends PHPUnit\Framework\TestCase $file=dirname(__FILE__).'/Example_import_company_1.csv'; $result=dol_is_file($file); - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertTrue($result); $result=dol_is_dir($file); - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result."\n"; $this->assertFalse($result); return $result; - } + } - /** - * testDolOther - * - * @return boolean - */ - public function testDolOther() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testDolOther + * + * @return boolean + */ + public function testDolOther() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $url='http://www.dolibarr.org'; - $result=dol_is_url($url); - print __METHOD__." result=".$result."\n"; - $this->assertTrue($result); + $url='http://www.dolibarr.org'; + $result=dol_is_url($url); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result); - $url='https://www.dolibarr.org'; - $result=dol_is_url($url); - print __METHOD__." result=".$result."\n"; - $this->assertTrue($result); + $url='https://www.dolibarr.org'; + $result=dol_is_url($url); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result); - $url='file://www.dolibarr.org/download/file.zip'; - $result=dol_is_url($url); - print __METHOD__." result=".$result."\n"; - $this->assertTrue($result); + $url='file://www.dolibarr.org/download/file.zip'; + $result=dol_is_url($url); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result); - return $result; - } + return $result; + } - /** - * testDolMimeType - * - * @return void - */ - public function testDolMimeType() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testDolMimeType + * + * @return void + */ + public function testDolMimeType() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - // file.png - $result=dol_mimetype('file.png', '', 0); - $this->assertEquals('image/png', $result); - $result=dol_mimetype('file.png', '', 1); - $this->assertEquals('png', $result); - $result=dol_mimetype('file.png', '', 2); - $this->assertEquals('image.png', $result); - $result=dol_mimetype('file.png', '', 3); - $this->assertEquals('', $result); - // file.odt - $result=dol_mimetype('file.odt', '', 0); - $this->assertEquals('application/vnd.oasis.opendocument.text', $result); - $result=dol_mimetype('file.odt', '', 1); - $this->assertEquals('vnd.oasis.opendocument.text', $result); - $result=dol_mimetype('file.odt', '', 2); - $this->assertEquals('ooffice.png', $result); - $result=dol_mimetype('file.odt', '', 3); - $this->assertEquals('', $result); - // file.php - $result=dol_mimetype('file.php', '', 0); - $this->assertEquals('text/plain', $result); - $result=dol_mimetype('file.php', '', 1); - $this->assertEquals('plain', $result); - $result=dol_mimetype('file.php', '', 2); - $this->assertEquals('php.png', $result); - $result=dol_mimetype('file.php', '', 3); - $this->assertEquals('php', $result); - // file.php.noexe - $result=dol_mimetype('file.php.noexe', '', 0); - $this->assertEquals('text/plain', $result); - } + // file.png + $result=dol_mimetype('file.png', '', 0); + $this->assertEquals('image/png', $result); + $result=dol_mimetype('file.png', '', 1); + $this->assertEquals('png', $result); + $result=dol_mimetype('file.png', '', 2); + $this->assertEquals('image.png', $result); + $result=dol_mimetype('file.png', '', 3); + $this->assertEquals('', $result); + // file.odt + $result=dol_mimetype('file.odt', '', 0); + $this->assertEquals('application/vnd.oasis.opendocument.text', $result); + $result=dol_mimetype('file.odt', '', 1); + $this->assertEquals('vnd.oasis.opendocument.text', $result); + $result=dol_mimetype('file.odt', '', 2); + $this->assertEquals('ooffice.png', $result); + $result=dol_mimetype('file.odt', '', 3); + $this->assertEquals('', $result); + // file.php + $result=dol_mimetype('file.php', '', 0); + $this->assertEquals('text/plain', $result); + $result=dol_mimetype('file.php', '', 1); + $this->assertEquals('plain', $result); + $result=dol_mimetype('file.php', '', 2); + $this->assertEquals('php.png', $result); + $result=dol_mimetype('file.php', '', 3); + $this->assertEquals('php', $result); + // file.php.noexe + $result=dol_mimetype('file.php.noexe', '', 0); + $this->assertEquals('text/plain', $result); + } - /** - * testDolDeleteDir - * - * @return void - */ - public function testDolDeleteDir() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testDolDeleteDir + * + * @return void + */ + public function testDolDeleteDir() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $dirout=$conf->admin->dir_temp.'/test'; - $dirout2=$conf->admin->dir_temp.'/test2'; + $dirout=$conf->admin->dir_temp.'/test'; + $dirout2=$conf->admin->dir_temp.'/test2'; - $count=0; - $result=dol_delete_dir_recursive($dirout, $count); // If it has no permission to delete, it will fails as if dir does not exists, so we can't test it - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThanOrEqual(0, $result); + $count=0; + $result=dol_delete_dir_recursive($dirout, $count); // If it has no permission to delete, it will fails as if dir does not exists, so we can't test it + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThanOrEqual(0, $result); - $count=0; - $countdeleted=0; - $result=dol_delete_dir_recursive($dirout, $count, 1, 0, $countdeleted); // If it has no permission to delete, it will fails as if dir does not exists, so we can't test it - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThanOrEqual(0, $result); - $this->assertGreaterThanOrEqual(0, $countdeleted); + $count=0; + $countdeleted=0; + $result=dol_delete_dir_recursive($dirout, $count, 1, 0, $countdeleted); // If it has no permission to delete, it will fails as if dir does not exists, so we can't test it + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThanOrEqual(0, $result); + $this->assertGreaterThanOrEqual(0, $countdeleted); - dol_mkdir($dirout2); - $count=0; - $countdeleted=0; - $result=dol_delete_dir_recursive($dirout2, $count, 1, 0, $countdeleted); // If it has no permission to delete, it will fails as if dir does not exists, so we can't test it - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThanOrEqual(1, $result); - $this->assertGreaterThanOrEqual(1, $countdeleted); - } + dol_mkdir($dirout2); + $count=0; + $countdeleted=0; + $result=dol_delete_dir_recursive($dirout2, $count, 1, 0, $countdeleted); // If it has no permission to delete, it will fails as if dir does not exists, so we can't test it + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThanOrEqual(1, $result); + $this->assertGreaterThanOrEqual(1, $countdeleted); + } - /** - * testDolCopyMoveDelete - * - * @return void - */ - public function testDolCopyMoveDelete() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testDolCopyMoveDelete + * + * @return void + */ + public function testDolCopyMoveDelete() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $file=dirname(__FILE__).'/Example_import_company_1.csv'; + $file=dirname(__FILE__).'/Example_import_company_1.csv'; - $result=dol_copy($file, '/adir/that/does/not/exists/file.csv'); - print __METHOD__." result=".$result."\n"; - $this->assertLessThan(0, $result, 'copy dir that does not exists'); // We should have error + $result=dol_copy($file, '/adir/that/does/not/exists/file.csv'); + print __METHOD__." result=".$result."\n"; + $this->assertLessThan(0, $result, 'copy dir that does not exists'); // We should have error - $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv', 0, 1); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThanOrEqual(1, $result, 'copy file ('.$file.') into a dir that exists ('.$conf->admin->dir_temp.'/file.csv)'); // Should be 1 + $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv', 0, 1); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThanOrEqual(1, $result, 'copy file ('.$file.') into a dir that exists ('.$conf->admin->dir_temp.'/file.csv)'); // Should be 1 - // Again to test with overwriting=0 - $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv', 0, 0); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(0, $result, 'copy destination already exists, no overwrite'); // Should be 0 + // Again to test with overwriting=0 + $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv', 0, 0); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(0, $result, 'copy destination already exists, no overwrite'); // Should be 0 - // Again to test with overwriting=1 - $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv', 0, 1); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThanOrEqual(1, $result, 'copy destination already exists, overwrite'); // Should be 1 + // Again to test with overwriting=1 + $result=dol_copy($file, $conf->admin->dir_temp.'/file.csv', 0, 1); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThanOrEqual(1, $result, 'copy destination already exists, overwrite'); // Should be 1 - // To test a move that should work - $result=dol_move($conf->admin->dir_temp.'/file.csv', $conf->admin->dir_temp.'/file2.csv', 0, 1); - print __METHOD__." result=".$result."\n"; - $this->assertTrue($result, 'move with default mask'); + // To test a move that should work + $result=dol_move($conf->admin->dir_temp.'/file.csv', $conf->admin->dir_temp.'/file2.csv', 0, 1); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result, 'move with default mask'); - // To test a move that should work with forced mask - $result=dol_move($conf->admin->dir_temp.'/file2.csv', $conf->admin->dir_temp.'/file3.csv', '0754', 1); // file should be rwxr-wr-- - print __METHOD__." result=".$result."\n"; - $this->assertTrue($result, 'move with forced mask'); + // To test a move that should work with forced mask + $result=dol_move($conf->admin->dir_temp.'/file2.csv', $conf->admin->dir_temp.'/file3.csv', '0754', 1); // file should be rwxr-wr-- + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result, 'move with forced mask'); - // To test a delete that should success - $result=dol_delete_file($conf->admin->dir_temp.'/file3.csv'); - print __METHOD__." result=".$result."\n"; - $this->assertTrue($result, 'delete file'); + // To test a delete that should success + $result=dol_delete_file($conf->admin->dir_temp.'/file3.csv'); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result, 'delete file'); - // Again to test there is error when deleting a non existing file with option disableglob - $result=dol_delete_file($conf->admin->dir_temp.'/file3.csv', 1, 1); - print __METHOD__." result=".$result."\n"; - $this->assertFalse($result, 'delete file that does not exists with disableglo must return ko'); + // Again to test there is error when deleting a non existing file with option disableglob + $result=dol_delete_file($conf->admin->dir_temp.'/file3.csv', 1, 1); + print __METHOD__." result=".$result."\n"; + $this->assertFalse($result, 'delete file that does not exists with disableglo must return ko'); - // Again to test there is no error when deleting a non existing file without option disableglob - $result=dol_delete_file($conf->admin->dir_temp.'/file3csv', 0, 1); - print __METHOD__." result=".$result."\n"; - $this->assertTrue($result, 'delete file that does not exists without disabling glob must return ok'); + // Again to test there is no error when deleting a non existing file without option disableglob + $result=dol_delete_file($conf->admin->dir_temp.'/file3csv', 0, 1); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result, 'delete file that does not exists without disabling glob must return ok'); - // Test copy with special char / delete with blob - $result=dol_copy($file, $conf->admin->dir_temp.'/file with [x] and é.csv', 0, 1); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThanOrEqual(1, $result, 'copy file with special chars, overwrite'); // Should be 1 + // Test copy with special char / delete with blob + $result=dol_copy($file, $conf->admin->dir_temp.'/file with [x] and é.csv', 0, 1); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThanOrEqual(1, $result, 'copy file with special chars, overwrite'); // Should be 1 - // Try to delete using a glob criteria - $result=dol_delete_file($conf->admin->dir_temp.'/file with [x]*é.csv'); - print __METHOD__." result=".$result."\n"; - $this->assertTrue($result, 'delete file using glob'); - } + // Try to delete using a glob criteria + $result=dol_delete_file($conf->admin->dir_temp.'/file with [x]*é.csv'); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result, 'delete file using glob'); + } - /** - * testDolCompressUnCompress - * - * @return void - */ - public function testDolCompressUnCompress() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testDolCompressUnCompress + * + * @return void + */ + public function testDolCompressUnCompress() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $format='zip'; - $filein=dirname(__FILE__).'/Example_import_company_1.csv'; - $fileout=$conf->admin->dir_temp.'/test.'.$format; - $dirout=$conf->admin->dir_temp.'/test'; + $format='zip'; + $filein=dirname(__FILE__).'/Example_import_company_1.csv'; + $fileout=$conf->admin->dir_temp.'/test.'.$format; + $dirout=$conf->admin->dir_temp.'/test'; - dol_delete_file($fileout); - $count=0; - dol_delete_dir_recursive($dirout, $count, 1); + dol_delete_file($fileout); + $count=0; + dol_delete_dir_recursive($dirout, $count, 1); - $errorstring = ''; + $errorstring = ''; - dol_mkdir($conf->admin->dir_temp); - $conf->global->MAIN_ENABLE_LOG_TO_HTML=1; $conf->syslog->enabled=1; $_REQUEST['logtohtml']=1; - $conf->logbuffer=array(); + dol_mkdir($conf->admin->dir_temp); + $conf->global->MAIN_ENABLE_LOG_TO_HTML=1; $conf->syslog->enabled=1; $_REQUEST['logtohtml']=1; + $conf->logbuffer=array(); - $result=dol_compress_file($filein, $fileout, $format, $errorstring); - print __METHOD__." result=".$result."\n"; - print join(', ', $conf->logbuffer); - $this->assertGreaterThanOrEqual(1, $result, "Pb with dol_compress_file on ".$filein." into ".$fileout." : ".$errorstring); + $result=dol_compress_file($filein, $fileout, $format, $errorstring); + print __METHOD__." result=".$result."\n"; + print join(', ', $conf->logbuffer); + $this->assertGreaterThanOrEqual(1, $result, "Pb with dol_compress_file on ".$filein." into ".$fileout." : ".$errorstring); - $result=dol_uncompress($fileout, $dirout); - print __METHOD__." result=".join(',', $result)."\n"; - $this->assertEquals(0, count($result), "Pb with dol_uncompress_file of file ".$fileout); - } + $result=dol_uncompress($fileout, $dirout); + print __METHOD__." result=".join(',', $result)."\n"; + $this->assertEquals(0, count($result), "Pb with dol_uncompress_file of file ".$fileout); + } - /** - * testDolDirList - * - * @return void - * - * @depends testDolCompressUnCompress - * The depends says test is run only if previous is ok - */ - public function testDolDirList() - { - global $conf,$user,$langs,$db; + /** + * testDolDirList + * + * @return void + * + * @depends testDolCompressUnCompress + * The depends says test is run only if previous is ok + */ + public function testDolDirList() + { + global $conf,$user,$langs,$db; - // Scan dir to guaruante we on't have library jquery twice (we accept exception of duplicte into ckeditor because all dir is removed for debian package, so there is no duplicate). - $founddirs=dol_dir_list(DOL_DOCUMENT_ROOT.'/includes/', 'files', 1, '^jquery\.js', array('ckeditor')); - print __METHOD__." count(founddirs)=".count($founddirs)."\n"; - $this->assertEquals(1, count($founddirs)); - } + // Scan dir to guaruante we on't have library jquery twice (we accept exception of duplicte into ckeditor because all dir is removed for debian package, so there is no duplicate). + $founddirs=dol_dir_list(DOL_DOCUMENT_ROOT.'/includes/', 'files', 1, '^jquery\.js', array('ckeditor')); + print __METHOD__." count(founddirs)=".count($founddirs)."\n"; + $this->assertEquals(1, count($founddirs)); + } - /** - * testDolCheckSecureAccessDocument - * - * @return void - */ - public function testDolCheckSecureAccessDocument() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testDolCheckSecureAccessDocument + * + * @return void + */ + public function testDolCheckSecureAccessDocument() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - //$dummyuser=new User($db); - //$result=restrictedArea($dummyuser,'societe'); + //$dummyuser=new User($db); + //$result=restrictedArea($dummyuser,'societe'); - // We save user properties - $savpermlire = $user->rights->facture->lire; - $savpermcreer = $user->rights->facture->creer; + // We save user properties + $savpermlire = $user->rights->facture->lire; + $savpermcreer = $user->rights->facture->creer; // Check access to SPECIMEN - $user->rights->facture->lire = 0; - $user->rights->facture->creer = 0; - $filename='SPECIMEN.pdf'; // Filename relative to module part - $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'read'); - $this->assertEquals(1, $result['accessallowed']); + $user->rights->facture->lire = 0; + $user->rights->facture->creer = 0; + $filename='SPECIMEN.pdf'; // Filename relative to module part + $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'read'); + $this->assertEquals(1, $result['accessallowed']); - // Check read permission - $user->rights->facture->lire = 1; - $user->rights->facture->creer = 1; - $filename='FA010101/FA010101.pdf'; // Filename relative to module part - $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'read'); - $this->assertEquals(1, $result['accessallowed']); + // Check read permission + $user->rights->facture->lire = 1; + $user->rights->facture->creer = 1; + $filename='FA010101/FA010101.pdf'; // Filename relative to module part + $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'read'); + $this->assertEquals(1, $result['accessallowed']); - $user->rights->facture->lire = 0; - $user->rights->facture->creer = 0; - $filename='FA010101/FA010101.pdf'; // Filename relative to module part - $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'read'); - $this->assertEquals(0, $result['accessallowed']); + $user->rights->facture->lire = 0; + $user->rights->facture->creer = 0; + $filename='FA010101/FA010101.pdf'; // Filename relative to module part + $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'read'); + $this->assertEquals(0, $result['accessallowed']); - // Check write permission - $user->rights->facture->lire = 0; - $user->rights->facture->creer = 0; - $filename='FA010101/FA010101.pdf'; // Filename relative to module part - $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'write'); - $this->assertEquals(0, $result['accessallowed']); + // Check write permission + $user->rights->facture->lire = 0; + $user->rights->facture->creer = 0; + $filename='FA010101/FA010101.pdf'; // Filename relative to module part + $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'write'); + $this->assertEquals(0, $result['accessallowed']); - $user->rights->facture->lire = 1; - $user->rights->facture->creer = 1; - $filename='FA010101/FA010101.pdf'; // Filename relative to module part - $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'write'); - $this->assertEquals(1, $result['accessallowed']); + $user->rights->facture->lire = 1; + $user->rights->facture->creer = 1; + $filename='FA010101/FA010101.pdf'; // Filename relative to module part + $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'write'); + $this->assertEquals(1, $result['accessallowed']); - $user->rights->facture->lire = 1; - $user->rights->facture->creer = 0; - $filename='FA010101/FA010101.pdf'; // Filename relative to module part - $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'write'); - $this->assertEquals(0, $result['accessallowed']); + $user->rights->facture->lire = 1; + $user->rights->facture->creer = 0; + $filename='FA010101/FA010101.pdf'; // Filename relative to module part + $result=dol_check_secure_access_document('facture', $filename, 0, '', '', 'write'); + $this->assertEquals(0, $result['accessallowed']); - // We restore user properties - $user->rights->facture->lire = $savpermlire; - $user->rights->facture->creer = $savpermcreer; - } + // We restore user properties + $user->rights->facture->lire = $savpermlire; + $user->rights->facture->creer = $savpermcreer; + } } diff --git a/test/phpunit/FormAdminTest.php b/test/phpunit/FormAdminTest.php index a434841930c..79019e1e7ed 100644 --- a/test/phpunit/FormAdminTest.php +++ b/test/phpunit/FormAdminTest.php @@ -29,8 +29,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/class/html.formadmin.class.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -75,75 +74,75 @@ class FormAdminTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testSelectPaperFormat - * - * @return int - */ - public function testSelectPaperFormat() - { - global $conf,$user,$langs,$db; + /** + * testSelectPaperFormat + * + * @return int + */ + public function testSelectPaperFormat() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new FormAdmin($this->savdb); - $result=$localobject->select_paper_format('', 'paperformat_id', 'A4'); + $result=$localobject->select_paper_format('', 'paperformat_id', 'A4'); - $this->assertEquals($result, ''); - print __METHOD__." result=".$result."\n"; - return $result; - } + $this->assertEquals($result, ''); + print __METHOD__." result=".$result."\n"; + return $result; + } } diff --git a/test/phpunit/FormTest.php b/test/phpunit/FormTest.php index 76e7c4e69a8..3345c7ddd1e 100644 --- a/test/phpunit/FormTest.php +++ b/test/phpunit/FormTest.php @@ -29,8 +29,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/class/html.form.class.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -75,46 +74,46 @@ class FormTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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 @@ -122,18 +121,18 @@ class FormTest extends PHPUnit\Framework\TestCase * @return void */ protected function tearDown() - { - print __METHOD__."\n"; - } + { + print __METHOD__."\n"; + } - /** - * testSelectProduitsList - * - * @return int - */ - public function testSelectProduitsList() - { - global $conf,$user,$langs,$db; + /** + * testSelectProduitsList + * + * @return int + */ + public function testSelectProduitsList() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -142,16 +141,16 @@ class FormTest extends PHPUnit\Framework\TestCase $localobject=new Form($this->savdb); $result=$localobject->select_produits_list('', 'productid', '', 5, 0, '', 1, 2, 1); - $this->assertEquals(count($result), 5); - print __METHOD__." count result=".count($result)."\n"; + $this->assertEquals(count($result), 5); + print __METHOD__." count result=".count($result)."\n"; - $conf->global->ENTREPOT_EXTRA_STATUS = 1; + $conf->global->ENTREPOT_EXTRA_STATUS = 1; - // Exclude stock in warehouseinternal - $result=$localobject->select_produits_list('', 'productid', '', 5, 0, '', 1, 2, 1, 0, '1', 0, '', 0, 'warehouseclosed,warehouseopen'); - $this->assertEquals(count($result), 5); - print __METHOD__." count result=".count($result)."\n"; + // Exclude stock in warehouseinternal + $result=$localobject->select_produits_list('', 'productid', '', 5, 0, '', 1, 2, 1, 0, '1', 0, '', 0, 'warehouseclosed,warehouseopen'); + $this->assertEquals(count($result), 5); + print __METHOD__." count result=".count($result)."\n"; - return $result; - } + return $result; + } } diff --git a/test/phpunit/Functions2LibTest.php b/test/phpunit/Functions2LibTest.php index be050b83b4f..db131fee67c 100644 --- a/test/phpunit/Functions2LibTest.php +++ b/test/phpunit/Functions2LibTest.php @@ -29,16 +29,36 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/functions2.lib.php'; -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); -if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +if (! defined('NOREQUIREUSER')) { + define('NOREQUIREUSER', '1'); +} +if (! defined('NOREQUIREDB')) { + define('NOREQUIREDB', '1'); +} +if (! defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (! defined('NOREQUIRETRAN')) { + define('NOREQUIRETRAN', '1'); +} +if (! defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (! defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (! defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); // If there is no menu to show +} +if (! defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +} +if (! defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (! defined("NOLOGIN")) { + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +} /** @@ -50,216 +70,216 @@ if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page i */ class Functions2LibTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return CoreTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return CoreTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - //$db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + //$db->rollback(); - print __METHOD__."\n"; - } + 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; + protected function setUp() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } /** * End phpunit tests * * @return void */ - protected function tearDown() - { - print __METHOD__."\n"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testJsUnEscape - * - * @return void - */ - public function testJsUnEscape() - { - $result=jsUnEscape('%u03BD%u03B5%u03BF'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('νεο', $result); - } + /** + * testJsUnEscape + * + * @return void + */ + public function testJsUnEscape() + { + $result=jsUnEscape('%u03BD%u03B5%u03BF'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('νεο', $result); + } - /** - * testIsValidMailDomain - * - * @return void - */ - public function testIsValidMailDomain() - { - $mail = 'bidon@unvalid.unvalid'; - $result = isValidMailDomain($mail); - $this->assertEquals(0, $result, 'Email isValidMailDomain('.$mail.') should return 0 (not valid) but returned '.$result); + /** + * testIsValidMailDomain + * + * @return void + */ + public function testIsValidMailDomain() + { + $mail = 'bidon@unvalid.unvalid'; + $result = isValidMailDomain($mail); + $this->assertEquals(0, $result, 'Email isValidMailDomain('.$mail.') should return 0 (not valid) but returned '.$result); - $mail = 'bidon@dolibarr.org'; - $result = isValidMailDomain($mail); - $this->assertEquals(1, $result, 'Email isValidMailDomain('.$mail.') should return 1 (valid) but returned '.$result); - } + $mail = 'bidon@dolibarr.org'; + $result = isValidMailDomain($mail); + $this->assertEquals(1, $result, 'Email isValidMailDomain('.$mail.') should return 1 (valid) but returned '.$result); + } - /** - * testIsValidURL - * - * @return void - */ - public function testIsValidUrl() - { - //Simple check - $result = isValidUrl('http://google.com'); - $this->assertEquals(1, $result); + /** + * testIsValidURL + * + * @return void + */ + public function testIsValidUrl() + { + //Simple check + $result = isValidUrl('http://google.com'); + $this->assertEquals(1, $result); - $result = isValidUrl('goo=gle'); // This is good, it might be an alias of hostname - $this->assertEquals(1, $result); + $result = isValidUrl('goo=gle'); // This is good, it might be an alias of hostname + $this->assertEquals(1, $result); - //With scheme check - $result = isValidUrl('http://www.google.com', 1); - $this->assertEquals(1, $result); + //With scheme check + $result = isValidUrl('http://www.google.com', 1); + $this->assertEquals(1, $result); - $result = isValidUrl('ftp://www.google.com', 1); - $this->assertEquals(0, $result); + $result = isValidUrl('ftp://www.google.com', 1); + $this->assertEquals(0, $result); - //With password check invalid. This test should be ko but currently it is not - //$result = isValidUrl('http://user:password@http://www.google.com', 1, 1); - //$this->assertEquals(0, $result); + //With password check invalid. This test should be ko but currently it is not + //$result = isValidUrl('http://user:password@http://www.google.com', 1, 1); + //$this->assertEquals(0, $result); - //With password check valid - $result = isValidUrl('http://user:password@www.google.com', 1, 1); - $this->assertEquals(1, $result); + //With password check valid + $result = isValidUrl('http://user:password@www.google.com', 1, 1); + $this->assertEquals(1, $result); - $result = isValidUrl('http://www.google.com', 1, 1); - $this->assertEquals(0, $result); + $result = isValidUrl('http://www.google.com', 1, 1); + $this->assertEquals(0, $result); - //With port check - $result = isValidUrl('http://google.com:8080', 0, 0, 1); - $this->assertEquals(1, $result); + //With port check + $result = isValidUrl('http://google.com:8080', 0, 0, 1); + $this->assertEquals(1, $result); - $result = isValidUrl('http://google.com', 0, 0, 1); - $this->assertEquals(0, $result); + $result = isValidUrl('http://google.com', 0, 0, 1); + $this->assertEquals(0, $result); - //With path check - $result = isValidUrl('http://google.com/search', 0, 0, 0, 1); - $this->assertEquals(1, $result); + //With path check + $result = isValidUrl('http://google.com/search', 0, 0, 0, 1); + $this->assertEquals(1, $result); - $result = isValidUrl('http://google.com', 0, 0, 0, 0); - $this->assertEquals(1, $result); + $result = isValidUrl('http://google.com', 0, 0, 0, 0); + $this->assertEquals(1, $result); - //With query check - $result = isValidUrl('http://google.com/search?test=test', 0, 0, 0, 0, 1); - $this->assertEquals(1, $result); + //With query check + $result = isValidUrl('http://google.com/search?test=test', 0, 0, 0, 0, 1); + $this->assertEquals(1, $result); - //With query check - $result = isValidUrl('http://google.com?test=test', 0, 0, 0, 0, 1); - $this->assertEquals(1, $result); + //With query check + $result = isValidUrl('http://google.com?test=test', 0, 0, 0, 0, 1); + $this->assertEquals(1, $result); - $result = isValidUrl('http://google.com', 0, 0, 0, 0, 1); - $this->assertEquals(0, $result); + $result = isValidUrl('http://google.com', 0, 0, 0, 0, 1); + $this->assertEquals(0, $result); - //With anchor check - $result = isValidUrl('http://google.com/search#done', 0, 0, 0, 0, 0, 1); - $this->assertEquals(1, $result); + //With anchor check + $result = isValidUrl('http://google.com/search#done', 0, 0, 0, 0, 0, 1); + $this->assertEquals(1, $result); - $result = isValidUrl('http://google.com/search', 0, 0, 0, 0, 0, 1); - $this->assertEquals(0, $result); - } + $result = isValidUrl('http://google.com/search', 0, 0, 0, 0, 0, 1); + $this->assertEquals(0, $result); + } - /** - * testIsIP - * - * @return void - */ - public function testIsIP() - { - // Not valid - $ip='a299.299.299.299'; - $result=is_ip($ip); - print __METHOD__." for ".$ip." result=".$result."\n"; - $this->assertEquals(0, $result, $ip); + /** + * testIsIP + * + * @return void + */ + public function testIsIP() + { + // Not valid + $ip='a299.299.299.299'; + $result=is_ip($ip); + print __METHOD__." for ".$ip." result=".$result."\n"; + $this->assertEquals(0, $result, $ip); - // Reserved IP range (not checked by is_ip function) - $ip='169.254.0.0'; - $result=is_ip($ip); - print __METHOD__." for ".$ip." result=".$result."\n"; - //$this->assertEquals(2,$result,$ip); // Assertion disabled because returned value differs between PHP patch version + // Reserved IP range (not checked by is_ip function) + $ip='169.254.0.0'; + $result=is_ip($ip); + print __METHOD__." for ".$ip." result=".$result."\n"; + //$this->assertEquals(2,$result,$ip); // Assertion disabled because returned value differs between PHP patch version - $ip='1.2.3.4'; - $result=is_ip($ip); - print __METHOD__." for ".$ip." result=".$result."\n"; - $this->assertEquals(1, $result, $ip); + $ip='1.2.3.4'; + $result=is_ip($ip); + print __METHOD__." for ".$ip." result=".$result."\n"; + $this->assertEquals(1, $result, $ip); - // Private IP ranges - $ip='10.0.0.0'; - $result=is_ip($ip); - print __METHOD__." for ".$ip." result=".$result."\n"; - $this->assertEquals(2, $result, $ip); + // Private IP ranges + $ip='10.0.0.0'; + $result=is_ip($ip); + print __METHOD__." for ".$ip." result=".$result."\n"; + $this->assertEquals(2, $result, $ip); - $ip='172.16.0.0'; - $result=is_ip($ip); - print __METHOD__." for ".$ip." result=".$result."\n"; - $this->assertEquals(2, $result, $ip); + $ip='172.16.0.0'; + $result=is_ip($ip); + print __METHOD__." for ".$ip." result=".$result."\n"; + $this->assertEquals(2, $result, $ip); - $ip='192.168.0.0'; - $result=is_ip($ip); - print __METHOD__." for ".$ip." result=".$result."\n"; - $this->assertEquals(2, $result, $ip); - } + $ip='192.168.0.0'; + $result=is_ip($ip); + print __METHOD__." for ".$ip." result=".$result."\n"; + $this->assertEquals(2, $result, $ip); + } } diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 8dc903642e0..4f6bfb1963e 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -30,16 +30,36 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/date.lib.php'; -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); -if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +if (! defined('NOREQUIREUSER')) { + define('NOREQUIREUSER', '1'); +} +if (! defined('NOREQUIREDB')) { + define('NOREQUIREDB', '1'); +} +if (! defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (! defined('NOREQUIRETRAN')) { + define('NOREQUIRETRAN', '1'); +} +if (! defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (! defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (! defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); // If there is no menu to show +} +if (! defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +} +if (! defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (! defined("NOLOGIN")) { + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +} /** * Class for PHPUnit tests @@ -50,1445 +70,1447 @@ if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page i */ class FunctionsLibTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; - - /** - * Constructor - * We save global variables into local variables - * - * @return CoreTest - */ - public function __construct() - { - parent::__construct(); - - //$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"; - } - - /** - * setUpBeforeClass - * - * @return void - */ - 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. - - if (! function_exists('mb_substr')) { print "\n".__METHOD__." function mb_substr must be enabled.\n"; die(); } - - print __METHOD__."\n"; - } - - /** - * tearDownAfterClass - * - * @return void - */ - 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"; - } - - /** - * testIsValidEmail - * - * @return void - */ - public function testIsValidEmail() - { - // Nb of line is same than entry text - - $input="bidon@bademail"; - $result=isValidEmail($input); - print __METHOD__." result=".$result."\n"; - $this->assertFalse($result, 'Check isValidEmail '.$input); - - $input="test@yahoo.com"; - $result=isValidEmail($input); - print __METHOD__." result=".$result."\n"; - $this->assertTrue($result, 'Check isValidEmail '.$input); - - $input="The name of sender "; - $result=isValidEmail($input); - print __METHOD__." result=".$result."\n"; - $this->assertFalse($result, 'Check isValidEmail '.$input); - - $input="1234.abcdefg@domainame.com.br"; - $result=isValidEmail($input); - print __METHOD__." result=".$result."\n"; - $this->assertTrue($result, 'Check isValidEmail '.$input); - } - - /** - * testIsValidMXRecord - * - * @return void - */ - public function testIsValidMXRecord() - { - // Nb of line is same than entry text - - $input="yahoo.com"; - $result=isValidMXRecord($input); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(1, $result); - - $input="yhaoo.com"; - $result=isValidMXRecord($input); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(0, $result); - - $input="dolibarr.fr"; - $result=isValidMXRecord($input); - print __METHOD__." result=".$result."\n"; - $this->assertEquals(0, $result); - } - - /** - * testDolGetFirstLineOfText - * - * @return void - */ - public function testDolGetFirstLineOfText() - { - // Nb of line is same than entry text - - $input="aaaa"; - $result=dolGetFirstLineOfText($input); - print __METHOD__." result=".$result."\n"; - $this->assertEquals("aaaa", $result); - - $input="aaaa\nbbbbbbbbbbbb\n"; - $result=dolGetFirstLineOfText($input, 2); - print __METHOD__." result=".$result."\n"; - $this->assertEquals("aaaa\nbbbbbbbbbbbb", $result); - - $input="aaaa
bbbbbbbbbbbb
"; - $result=dolGetFirstLineOfText($input, 2); - print __METHOD__." result=".$result."\n"; - $this->assertEquals("aaaa
\nbbbbbbbbbbbb", $result); - - // Nb of line is lower - - $input="aaaa\nbbbbbbbbbbbb\ncccccc\n"; - $result=dolGetFirstLineOfText($input); - print __METHOD__." result=".$result."\n"; - $this->assertEquals("aaaa...", $result); - - $input="aaaa
bbbbbbbbbbbb
cccccc
"; - $result=dolGetFirstLineOfText($input); - print __METHOD__." result=".$result."\n"; - $this->assertEquals("aaaa...", $result); - - $input="aaaa\nbbbbbbbbbbbb\ncccccc\n"; - $result=dolGetFirstLineOfText($input, 2); - print __METHOD__." result=".$result."\n"; - $this->assertEquals("aaaa\nbbbbbbbbbbbb...", $result); - - $input="aaaa
bbbbbbbbbbbb
cccccc
"; - $result=dolGetFirstLineOfText($input, 2); - print __METHOD__." result=".$result."\n"; - $this->assertEquals("aaaa
\nbbbbbbbbbbbb...", $result); - - // Nb of line is higher - - $input="aaaa
bbbbbbbbbbbb
cccccc"; - $result=dolGetFirstLineOfText($input, 100); - print __METHOD__." result=".$result."\n"; - $this->assertEquals("aaaa
\nbbbbbbbbbbbb
\ncccccc", $result, 'dolGetFirstLineOfText with nb 100 a'); - - $input="aaaa
bbbbbbbbbbbb
cccccc
"; - $result=dolGetFirstLineOfText($input, 100); - print __METHOD__." result=".$result."\n"; - $this->assertEquals("aaaa
\nbbbbbbbbbbbb
\ncccccc", $result, 'dolGetFirstLineOfText with nb 100 b'); - - $input="aaaa
bbbbbbbbbbbb
cccccc
\n"; - $result=dolGetFirstLineOfText($input, 100); - print __METHOD__." result=".$result."\n"; - $this->assertEquals("aaaa
\nbbbbbbbbbbbb
\ncccccc", $result, 'dolGetFirstLineOfText with nb 100 c'); - } - - - /** - * testDolBuildPath - * - * @return void - */ - public function testDolBuildPath() - { - /*$tmp=dol_buildpath('/google/oauth2callback.php', 0); - var_dump($tmp); - */ - - /*$tmp=dol_buildpath('/google/oauth2callback.php', 1); - var_dump($tmp); - */ - - $result=dol_buildpath('/google/oauth2callback.php', 2); - print __METHOD__." result=".$result."\n"; - $this->assertStringStartsWith('http', $result); - - $result=dol_buildpath('/google/oauth2callback.php', 3); - print __METHOD__." result=".$result."\n"; - $this->assertStringStartsWith('http', $result); - } - - - /** - * testGetBrowserInfo - * - * @return void - */ - public function testGetBrowserInfo() - { - // MSIE 5.0 - $user_agent ='Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt; KITV4 Wanadoo; KITV5 Wanadoo)'; - $tmp=getBrowserInfo($user_agent); - $this->assertEquals('ie', $tmp['browsername']); - $this->assertEquals('5.0', $tmp['browserversion']); - $this->assertEmpty($tmp['phone']); - $this->assertFalse($tmp['tablet']); - $this->assertEquals('classic', $tmp['layout']); - - // Firefox 0.9.1 - $user_agent ='Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5a) Gecko/20030728 Mozilla Firefox/0.9.1'; - $tmp=getBrowserInfo($user_agent); - $this->assertEquals('firefox', $tmp['browsername']); - $this->assertEquals('0.9.1', $tmp['browserversion']); - $this->assertEmpty($tmp['phone']); - $this->assertFalse($tmp['tablet']); - $this->assertEquals('classic', $tmp['layout']); - - $user_agent ='Mozilla/3.0 (Windows 98; U) Opera 6.03 [en]'; - $tmp=getBrowserInfo($user_agent); - $this->assertEquals('opera', $tmp['browsername']); - $this->assertEquals('6.03', $tmp['browserversion']); - $this->assertEmpty($tmp['phone']); - $this->assertFalse($tmp['tablet']); - $this->assertEquals('classic', $tmp['layout']); - - $user_agent ='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21'; - $tmp=getBrowserInfo($user_agent); - $this->assertEquals('chrome', $tmp['browsername']); - $this->assertEquals('19.0.1042.0', $tmp['browserversion']); - $this->assertEmpty($tmp['phone']); - $this->assertFalse($tmp['tablet']); - $this->assertEquals('classic', $tmp['layout']); - - $user_agent ='chrome (Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11)'; - $tmp=getBrowserInfo($user_agent); - $this->assertEquals('chrome', $tmp['browsername']); - $this->assertEquals('17.0.963.56', $tmp['browserversion']); - $this->assertEmpty($tmp['phone']); - $this->assertFalse($tmp['tablet']); - $this->assertEquals('classic', $tmp['layout']); - - $user_agent ='Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1'; - $tmp=getBrowserInfo($user_agent); - $this->assertEquals('safari', $tmp['browsername']); - $this->assertEquals('533.21.1', $tmp['browserversion']); - $this->assertEmpty($tmp['phone']); - $this->assertFalse($tmp['tablet']); - $this->assertEquals('classic', $tmp['layout']); - - //Internet Explorer 11 - $user_agent = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'; - $tmp=getBrowserInfo($user_agent); - $this->assertEquals('ie', $tmp['browsername']); - $this->assertEquals('11.0', $tmp['browserversion']); - $this->assertEmpty($tmp['phone']); - $this->assertFalse($tmp['tablet']); - $this->assertEquals('classic', $tmp['layout']); - - //Internet Explorer 11 bis - $user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; NP06; rv:11.0) like Gecko'; - $tmp=getBrowserInfo($user_agent); - $this->assertEquals('ie', $tmp['browsername']); - $this->assertEquals('11.0', $tmp['browserversion']); - $this->assertEmpty($tmp['phone']); - $this->assertFalse($tmp['tablet']); - $this->assertEquals('classic', $tmp['layout']); - - //iPad - $user_agent = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25'; - $tmp=getBrowserInfo($user_agent); - $this->assertEquals('safari', $tmp['browsername']); - $this->assertEquals('8536.25', $tmp['browserversion']); - $this->assertEquals('ios', $tmp['browseros']); - $this->assertEquals('tablet', $tmp['layout']); - $this->assertEquals('iphone', $tmp['phone']); - } - - - /** - * testGetLanguageCodeFromCountryCode - * - * @return void - */ - public function testGetLanguageCodeFromCountryCode() - { - global $mysoc; - - $language = getLanguageCodeFromCountryCode('US'); - $this->assertEquals('en_US', $language, 'US'); - - $language = getLanguageCodeFromCountryCode('ES'); - $this->assertEquals('es_ES', $language, 'ES'); - - $language = getLanguageCodeFromCountryCode('CL'); - $this->assertEquals('es_CL', $language, 'CL'); - - $language = getLanguageCodeFromCountryCode('CA'); - $this->assertEquals('en_CA', $language, 'CA'); - - $language = getLanguageCodeFromCountryCode('MQ'); - $this->assertEquals('fr_CA', $language); - - $language = getLanguageCodeFromCountryCode('FR'); - $this->assertEquals('fr_FR', $language); - - $language = getLanguageCodeFromCountryCode('BE'); - $this->assertEquals('fr_BE', $language); - - $mysoc->country_code = 'FR'; - $language = getLanguageCodeFromCountryCode('CH'); - $this->assertEquals('fr_CH', $language); - - $mysoc->country_code = 'DE'; - $language = getLanguageCodeFromCountryCode('CH'); - $this->assertEquals('de_CH', $language); - - $language = getLanguageCodeFromCountryCode('DE'); - $this->assertEquals('de_DE', $language); - - $language = getLanguageCodeFromCountryCode('SA'); - $this->assertEquals('ar_SA', $language); - - $language = getLanguageCodeFromCountryCode('SE'); - $this->assertEquals('sv_SE', $language); - - $language = getLanguageCodeFromCountryCode('DK'); - $this->assertEquals('da_DK', $language); - } - - /** - * testDolTextIsHtml - * - * @return void - */ - public function testDolTextIsHtml() - { - // True - $input='xxx'; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with html tag'); - $input='xxx'; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with body tag'); - $input='xxx yyy zzz'; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with b tag'); - $input='xxx yyy zzz'; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with u tag'); - $input='text with
some div
'; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with div tag'); - $input='text with HTML   entities'; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with entities tag'); - $input='xxx
'; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with entities br'); - $input='xxx
'; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with entities br'); - $input='xxx
'; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with entities br and attributes'); - $input='xxx
'; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with entities br and attributes bis'); - $input='

abc

'; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with entities h2'); - $input=''; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with img tag'); - $input=''; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with a tag'); - $input='This is a text with html spaces'; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with a  '); - $input='This is a text with accent é'; - $after=dol_textishtml($input); - $this->assertTrue($after, 'Test with a é'); - - // False - $input='xxx < br>'; - $after=dol_textishtml($input); - $this->assertFalse($after); - $input='xxx '; // is html, assertFalse($after); - $input='xxx '; - $after=dol_textishtml($input); - $this->assertFalse($after); - $input='This is a text with html comments '; // we suppose this is not enough to be html content - $after=dol_textishtml($input); - $this->assertFalse($after); - } - - - /** - * testDolHtmlCleanLastBr - * - * @return boolean - */ - public function testDolHtmlCleanLastBr() - { - $input="A string\n"; - $after=dol_htmlcleanlastbr($input); - $this->assertEquals("A string", $after); - - $input="A string first\nA string second\n"; - $after=dol_htmlcleanlastbr($input); - $this->assertEquals("A string first\nA string second", $after); - - $input="A string\n\n\n"; - $after=dol_htmlcleanlastbr($input); - $this->assertEquals("A string", $after); - - $input="A string
"; - $after=dol_htmlcleanlastbr($input); - $this->assertEquals("A string", $after); - - $input="A string first
\nA string second
"; - $after=dol_htmlcleanlastbr($input); - $this->assertEquals("A string first
\nA string second", $after); - - $input="A string\n
\n"; - $after=dol_htmlcleanlastbr($input); - $this->assertEquals("A string", $after); - - $input="A string\n

\n\n"; - $after=dol_htmlcleanlastbr($input); - $this->assertEquals("A string", $after); - - return true; - } - - /** - * testDolConcat - * - * @return boolean - */ - public function testDolConcat() - { - $text1="A string 1"; $text2="A string 2"; // text 1 and 2 are text, concat need only \n - $after=dol_concatdesc($text1, $text2); - $this->assertEquals("A string 1\nA string 2", $after); - - $text1="A
string 1"; $text2="A string 2"; // text 1 is html, concat need
\n - $after=dol_concatdesc($text1, $text2); - $this->assertEquals("A
string 1
\nA string 2", $after); - - $text1="A string 1"; $text2="A string 2"; // text 2 is html, concat need
\n - $after=dol_concatdesc($text1, $text2); - $this->assertEquals("A string 1
\nA string 2", $after); - - return true; - } - - - /** - * testDolStringNohtmltag - * - * @return boolean - */ - public function testDolStringNohtmltag() - { - $text="A\nstring\n\nand more\n"; - $after=dol_string_nohtmltag($text, 0); - $this->assertEquals("A\nstring\n\nand more", $after, "test1a"); - - $text="A string
\n
\n\nwith html tag
\n"; - $after=dol_string_nohtmltag($text, 0); - $this->assertEquals("A string\n\n\n\n\nwith html tag", $after, 'test2a 2 br and 3 \n give 5 \n'); - - $text="A string
\n
\n\nwith html tag
\n"; - $after=dol_string_nohtmltag($text, 1); - $this->assertEquals("A string with html tag", $after, 'test2b 2 br and 3 \n give 1 space'); - - $text="A string
\n
\n\nwith html tag
\n"; - $after=dol_string_nohtmltag($text, 2); - $this->assertEquals("A string\n\nwith html tag", $after, 'test2c 2 br and 3 \n give 2 \n'); - - $text="A string
\r\n
\r\n\r\nwith html tag
\n"; - $after=dol_string_nohtmltag($text, 2); - $this->assertEquals("A string\n\nwith html tag", $after, 'test2c 2 br and 3 \r\n give 2 \n'); - - $text="A string
Another string"; - $after=dol_string_nohtmltag($text, 0); - $this->assertEquals("A string\nAnother string", $after, "test4"); - - $text="A string
Another string"; - $after=dol_string_nohtmltag($text, 1); - $this->assertEquals("A string Another string", $after, "test5"); - - $text='
ABC'; - $after=dol_string_nohtmltag($text, 1); - $this->assertEquals("ABC", $after, "test6"); - - $text='DEF'; - $after=dol_string_nohtmltag($text, 1); - $this->assertEquals("DEF", $after, "test7"); - - $text='HIJ'; - $after=dol_string_nohtmltag($text, 0); - $this->assertEquals("HIJ", $after, "test8"); - - $text="A string\n\nwith html tag and '<' chars
\n"; - $after=dol_string_nohtmltag($text, 0); - $this->assertEquals("A string\n\nwith html tag and '<' chars", $after, "test9"); - - $text="A string\n\nwith tag with < chars
\n"; - $after=dol_string_nohtmltag($text, 1); - $this->assertEquals("A string with tag with < chars", $after, "test10"); - - return true; - } - - - - /** - * testDolHtmlEntitiesBr - * - * @return boolean - */ - public function testDolHtmlEntitiesBr() - { - // Text not already HTML - - $input="A string\nwith a é, &, < and >."; - $after=dol_htmlentitiesbr($input, 0); // Add
before \n - $this->assertEquals("A string
\nwith a é, &, < and >.", $after); - - $input="A string\nwith a é, &, < and >."; - $after=dol_htmlentitiesbr($input, 1); // Replace \n with
- $this->assertEquals("A string
with a é, &, < and >.", $after); - - $input="A string\nwith a é, &, < and >.\n\n"; // With some \n at end that should be cleaned - $after=dol_htmlentitiesbr($input, 0); // Add
before \n - $this->assertEquals("A string
\nwith a é, &, < and >.", $after); - - $input="A string\nwith a é, &, < and >.\n\n"; // With some \n at end that should be cleaned - $after=dol_htmlentitiesbr($input, 1); // Replace \n with
- $this->assertEquals("A string
with a é, &, < and >.", $after); - - // Text already HTML, so &,<,> should not be converted - - $input="A string
\nwith a é, &, < and >."; - $after=dol_htmlentitiesbr($input); - $this->assertEquals("A string
\nwith a é, &, < and >.", $after); - - $input="
  • \nA string with a é, &, < and >.
  • \nAnother string"; - $after=dol_htmlentitiesbr($input); - $this->assertEquals("
  • \nA string with a é, &, < and >.
  • \nAnother string", $after); - - $input="A string
    \nwith a é, &, < and >.
    "; // With some
    at end that should be cleaned - $after=dol_htmlentitiesbr($input); - $this->assertEquals("A string
    \nwith a é, &, < and >.", $after); - - $input="
  • \nA string with a é, &, < and >.
  • \nAnother string
    "; // With some
    at end that should be cleaned - $after=dol_htmlentitiesbr($input); - $this->assertEquals("
  • \nA string with a é, &, < and >.
  • \nAnother string", $after); - - // TODO Add test with param $removelasteolbr = 0 - - return true; - } - - - /** - * testDolNbOfLinesBis - * - * @return boolean - */ - public function testDolNbOfLinesBis() - { - // This is not a html string so nb of lines depends on \n - $input="A string\nwith a é, &, < and > and bold tag.\nThird line"; - $after=dol_nboflines_bis($input, 0); - $this->assertEquals($after, 3); - - // This is a html string so nb of lines depends on
    - $input="A string\nwith a é, &, < and > and bold tag.\nThird line"; - $after=dol_nboflines_bis($input, 0); - $this->assertEquals($after, 1); - - // This is a html string so nb of lines depends on
    - $input="A string
    with a é, &, < and > and bold tag.
    Third line"; - $after=dol_nboflines_bis($input, 0); - $this->assertEquals($after, 3); - - return true; - } - - - /** - * testDolUnaccent - * - * @return boolean - */ - public function testDolUnaccent() - { - // Text not already HTML - - $input="A string\nwith a à ä é è ë ï ü ö ÿ, &, < and >."; - $after=dol_string_unaccent($input); - $this->assertEquals("A string\nwith a a a e e e i u o y, &, < and >.", $after); - } - - - /** - * testDolUtf8Check - * - * @return void - */ - public function testDolUtf8Check() - { - // True - $result=utf8_check('azerty'); - $this->assertTrue($result); - - $file=dirname(__FILE__).'/textutf8.txt'; - $filecontent=file_get_contents($file); - $result=utf8_check($filecontent); - $this->assertTrue($result); - - $file=dirname(__FILE__).'/textiso.txt'; - $filecontent=file_get_contents($file); - $result=utf8_check($filecontent); - $this->assertFalse($result); - } - - /** - * testDolAsciiCheck - * - * @return void - */ - public function testDolAsciiCheck() - { - // True - $result=ascii_check('azerty'); - $this->assertTrue($result); - - $result=ascii_check('é'); - $this->assertFalse($result); - - $file=dirname(__FILE__).'/textutf8.txt'; - $filecontent=file_get_contents($file); - $result=ascii_check($filecontent); - $this->assertFalse($result); - } - - /** - * testDolTrunc - * - * @return boolean - */ - public function testDolTrunc() - { - // Default trunc (will add ... if truncation truncation or keep last char if only one char) - $input="éeéeéeàa"; - $after=dol_trunc($input, 3); - $this->assertEquals("éeé...", $after, 'Test A1'); - $after=dol_trunc($input, 2); - $this->assertEquals("ée...", $after, 'Test A2'); - $after=dol_trunc($input, 1); - $this->assertEquals("é...", $after, 'Test A3'); - $input="éeéeé"; - $after=dol_trunc($input, 3); - $this->assertEquals("éeéeé", $after, 'Test B1'); - $after=dol_trunc($input, 2); - $this->assertEquals("éeéeé", $after, 'Test B2'); - $after=dol_trunc($input, 1); - $this->assertEquals("é...", $after, 'Test B3'); - $input="éeée"; - $after=dol_trunc($input, 3); - $this->assertEquals("éeée", $after, 'Test C1'); - $after=dol_trunc($input, 2); - $this->assertEquals("éeée", $after, 'Test C2'); - $after=dol_trunc($input, 1); - $this->assertEquals("éeée", $after, 'Test C3'); - $input="éeé"; - $after=dol_trunc($input, 3); - $this->assertEquals("éeé", $after, 'Test C'); - $after=dol_trunc($input, 2); - $this->assertEquals("éeé", $after, 'Test D'); - $after=dol_trunc($input, 1); - $this->assertEquals("éeé", $after, 'Test E'); - // Trunc with no ... - $input="éeéeéeàa"; - $after=dol_trunc($input, 3, 'right', 'UTF-8', 1); - $this->assertEquals("éeé", $after, 'Test F'); - $after=dol_trunc($input, 2, 'right', 'UTF-8', 1); - $this->assertEquals("ée", $after, 'Test G'); - $input="éeé"; - $after=dol_trunc($input, 3, 'right', 'UTF-8', 1); - $this->assertEquals("éeé", $after, 'Test H'); - $after=dol_trunc($input, 2, 'right', 'UTF-8', 1); - $this->assertEquals("ée", $after, 'Test I'); - $after=dol_trunc($input, 1, 'right', 'UTF-8', 1); - $this->assertEquals("é", $after, 'Test J'); - $input="éeéeéeàa"; - $after=dol_trunc($input, 4, 'middle'); - $this->assertEquals("ée...àa", $after, 'Test K'); - - return true; - } - - /** - * testDolMkTime - * - * @return void - */ - public function testDolMkTime() - { - global $conf; - - $savtz=date_default_timezone_get(); - - // Some test for UTC TZ - date_default_timezone_set('UTC'); - - // Check bad hours - $result=dol_mktime(25, 0, 0, 1, 1, 1970, 1, 1); // Error (25 hours) - print __METHOD__." result=".$result."\n"; - $this->assertEquals('', $result); - $result=dol_mktime(2, 61, 0, 1, 1, 1970, 1, 1); // Error (61 minutes) - print __METHOD__." result=".$result."\n"; - $this->assertEquals('', $result); - $result=dol_mktime(2, 1, 61, 1, 1, 1970, 1, 1); // Error (61 seconds) - print __METHOD__." result=".$result."\n"; - $this->assertEquals('', $result); - $result=dol_mktime(2, 1, 1, 1, 32, 1970, 1, 1); // Error (day 32) - print __METHOD__." result=".$result."\n"; - $this->assertEquals('', $result); - $result=dol_mktime(2, 1, 1, 13, 1, 1970, 1, 1); // Error (month 13) - print __METHOD__." result=".$result."\n"; - $this->assertEquals('', $result); - - $result=dol_mktime(2, 1, 1, 1, 1, 1970, 1); // 1970-01-01 02:01:01 in GMT area -> 7261 - print __METHOD__." result=".$result."\n"; - $this->assertEquals(7261, $result); - - $result=dol_mktime(2, 0, 0, 1, 1, 1970, 0); // 1970-01-01 02:00:00 = 7200 in local area Europe/Paris = 3600 GMT - print __METHOD__." result=".$result."\n"; - $tz=getServerTimeZoneInt('winter'); // +1 in Europe/Paris at this time (this time is winter) - $this->assertEquals(7200-($tz*3600), $result); // 7200 if we are at greenwich winter, 7200-($tz*3600) at local winter - - // Some test for local TZ Europe/Paris - date_default_timezone_set('Europe/Paris'); - - // Check that tz for paris in winter is used - $result=dol_mktime(2, 0, 0, 1, 1, 1970, 'server'); // 1970-01-01 02:00:00 = 7200 in local area Europe/Paris = 3600 GMT - print __METHOD__." result=".$result."\n"; - $this->assertEquals(3600, $result); // 7200 if we are at greenwich winter, 3600 at Europe/Paris - - // Check that daylight saving time is used - $result=dol_mktime(2, 0, 0, 6, 1, 2014, 0); // 2014-06-01 02:00:00 = 1401588000-3600(location)-3600(daylight) in local area Europe/Paris = 1401588000 GMT - print __METHOD__." result=".$result."\n"; - $this->assertEquals(1401588000-3600-3600, $result); // 1401588000 are at greenwich summer, 1401588000-3600(location)-3600(daylight) at Europe/Paris summer - - date_default_timezone_set($savtz); - } - - - /** - * testDolEscapeJs - * - * @return void - */ - public function testDolEscapeJs() - { - $input="x&#,\"'"; // " will be converted into ' - $result=dol_escape_js($input); - $this->assertEquals("x&#,\'\'", $result, "Test mode=0"); - - $result=dol_escape_js($input, 1); - $this->assertEquals("x&#,\"\'", $result, "Test mode=1"); - - $result=dol_escape_js($input, 2); - $this->assertEquals("x&#,\\\"'", $result, "Test mode=2"); - } - - - /** - * testDolEscapeHtmlTag - * - * @return void - */ - public function testDolEscapeHtmlTag() - { - $input='x&#,"'; // & and " are converted into html entities, are removed - $result=dol_escape_htmltag($input); - $this->assertEquals('x&#,"', $result); - - $input='x&#,"'; // & and " are converted into html entities, are not removed - $result=dol_escape_htmltag($input, 1); - $this->assertEquals('x&<b>#</b>,"', $result); - } - - - /** - * testDolFormatAddress - * - * @return void - */ - public function testDolFormatAddress() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; - - $object=new Societe($db); - $object->initAsSpecimen(); - - $object->country_code='FR'; - $address=dol_format_address($object); - $this->assertEquals("21 jump street\n99999 MyTown", $address); - - $object->country_code='GB'; - $address=dol_format_address($object); - $this->assertEquals("21 jump street\nMyTown, MyState\n99999", $address); - - $object->country_code='US'; - $address=dol_format_address($object); - $this->assertEquals("21 jump street\nMyTown, MyState, 99999", $address); - - $object->country_code='AU'; - $address=dol_format_address($object); - $this->assertEquals("21 jump street\nMyTown, MyState, 99999", $address); - } - - - /** - * testDolFormatAddress - * - * @return void - */ - public function testDolPrintPhone() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; - - $object=new Societe($db); - $object->initAsSpecimen(); - - $object->country_code='FR'; - $phone=dol_print_phone('1234567890', $object->country_code); - $this->assertEquals('12 34 56 78 90', $phone, 'Phone for FR 1'); - - $object->country_code='FR'; - $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ''); - $this->assertEquals('1234567890', $phone, 'Phone for FR 2'); - - $object->country_code='FR'; - $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ' '); - $this->assertEquals('12 34 56 78 90', $phone, 'Phone for FR 3'); - - $object->country_code='CA'; - $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ' '); - $this->assertEquals('(123) 456-7890', $phone, 'Phone for CA 1'); - } - - - /** - * testImgPicto - * - * @return void - */ - public function testImgPicto() - { - $s=img_picto('title', 'user'); - print __METHOD__." s=".$s."\n"; - $this->assertContains('fa-user', $s, 'testImgPicto1'); - - $s=img_picto('title', 'img.png', 'style="float: right"', 0); - print __METHOD__." s=".$s."\n"; - $this->assertContains('theme', $s, 'testImgPicto2'); - $this->assertContains('style="float: right"', $s, 'testImgPicto2'); - - $s=img_picto('title', '/fullpath/img.png', '', 1); - print __METHOD__." s=".$s."\n"; - $this->assertEquals('', $s, 'testImgPicto3'); - - $s=img_picto('title', '/fullpath/img.png', '', true); - print __METHOD__." s=".$s."\n"; - $this->assertEquals('', $s, 'testImgPicto4'); - - $s=img_picto('title', 'delete', '', 0, 1); - print __METHOD__." s=".$s."\n"; - $this->assertEquals(DOL_URL_ROOT.'/theme/eldy/img/delete.png', $s, 'testImgPicto5'); - } - - /** - * testDolNow - * - * @return void - */ - public function testDolNow() - { - $now=dol_now('gmt'); - $nowtzserver=dol_now('tzserver'); - print __METHOD__." getServerTimeZoneInt=".(getServerTimeZoneInt('now')*3600)."\n"; - $this->assertEquals(getServerTimeZoneInt('now')*3600, ($nowtzserver-$now)); - } - - /** - * testVerifCond - * - * @return void - */ - public function testVerifCond() - { - $verifcond=verifCond('1==1'); - $this->assertTrue($verifcond, 'Test a true comparison'); - - $verifcond=verifCond('1==2'); - $this->assertFalse($verifcond, 'Test a false comparison'); - - $verifcond=verifCond('$conf->facture->enabled'); - $this->assertTrue($verifcond, 'Test that conf property of a module report true when enabled'); - - $verifcond=verifCond('$conf->moduledummy->enabled'); - $this->assertFalse($verifcond, 'Test that conf property of a module report false when disabled'); - - $verifcond=verifCond(''); - $this->assertTrue($verifcond); - } - - /** - * testGetDefaultTva - * - * @return void - */ - public function testGetDefaultTva() - { - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; - - // Sellers - $companyfrnovat=new Societe($db); - $companyfrnovat->country_code='FR'; - $companyfrnovat->tva_assuj=0; - - $companyfr=new Societe($db); - $companyfr->country_code='FR'; - $companyfr->tva_assuj=1; - $companyfr->tva_intra='FR9999'; - - // Buyers - $companymc=new Societe($db); - $companymc->country_code='MC'; - $companymc->tva_assuj=1; - $companyfr->tva_intra='MC9999'; - - $companyit=new Societe($db); - $companyit->country_code='IT'; - $companyit->tva_assuj=1; - $companyit->tva_intra='IT99999'; - - $companyde=new Societe($db); - $companyde->country_code='DE'; - $companyde->tva_assuj=1; - $companyde->tva_intra='DE99999'; - - $notcompanyde=new Societe($db); - $notcompanyde->country_code='DE'; - $notcompanyde->tva_assuj=0; - $notcompanyde->tva_intra=''; - $notcompanyde->typent_code='TE_PRIVATE'; - - $companyus=new Societe($db); - $companyus->country_code='US'; - $companyus->tva_assuj=1; - $companyus->tva_intra=''; - - - // Test RULE 0 (FR-DE) - // Not tested - - // Test RULE 1 - $vat=get_default_tva($companyfrnovat, $companymc, 0); - $this->assertEquals(0, $vat, 'RULE 1'); - - // Test RULE 2 (FR-FR) - $vat=get_default_tva($companyfr, $companyfr, 0); - $this->assertEquals(20, $vat, 'RULE 2'); - - // Test RULE 2 (FR-MC) - $vat=get_default_tva($companyfr, $companymc, 0); - $this->assertEquals(20, $vat, 'RULE 2'); - - // Test RULE 3 (FR-DE company) - $vat=get_default_tva($companyfr, $companyit, 0); - $this->assertEquals(0, $vat, 'RULE 3'); - - // Test RULE 4 (FR-DE not a company) - $vat=get_default_tva($companyfr, $notcompanyde, 0); - $this->assertEquals(20, $vat, 'RULE 4'); - - // Test RULE 5 (FR-US) - $vat=get_default_tva($companyfr, $companyus, 0); - $this->assertEquals(0, $vat, 'RULE 5'); - - - // We do same tests but with option SERVICE_ARE_ECOMMERCE_200238EC on. - $conf->global->SERVICE_ARE_ECOMMERCE_200238EC = 1; - - - // Test RULE 1 (FR-US) - $vat=get_default_tva($companyfr, $companyus, 0); - $this->assertEquals(0, $vat, 'RULE 1 ECOMMERCE_200238EC'); - - // Test RULE 2 (FR-FR) - $vat=get_default_tva($companyfr, $companyfr, 0); - $this->assertEquals(20, $vat, 'RULE 2 ECOMMERCE_200238EC'); - - // Test RULE 3 (FR-DE company) - $vat=get_default_tva($companyfr, $companyde, 0); - $this->assertEquals(0, $vat, 'RULE 3 ECOMMERCE_200238EC'); - - // Test RULE 4 (FR-DE not a company) - $vat=get_default_tva($companyfr, $notcompanyde, 0); - $this->assertEquals(19, $vat, 'RULE 4 ECOMMERCE_200238EC'); - - // Test RULE 5 (FR-US) - $vat=get_default_tva($companyfr, $companyus, 0); - $this->assertEquals(0, $vat, 'RULE 5 ECOMMERCE_200238EC'); - } - - /** - * testGetDefaultTva - * - * @return void - */ - public function testGetDefaultLocalTax() - { - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; - - $companyfrnovat=new Societe($db); - $companyfrnovat->country_code='FR'; - $companyfrnovat->tva_assuj=0; - $companyfrnovat->localtax1_assuj=0; - $companyfrnovat->localtax2_assuj=0; - - $companyes=new Societe($db); - $companyes->country_code='ES'; - $companyes->tva_assuj=1; - $companyes->localtax1_assuj=1; - $companyes->localtax2_assuj=1; - - $companymc=new Societe($db); - $companymc->country_code='MC'; - $companymc->tva_assuj=1; - $companymc->localtax1_assuj=0; - $companymc->localtax2_assuj=0; - - $companyit=new Societe($db); - $companyit->country_code='IT'; - $companyit->tva_assuj=1; - $companyit->tva_intra='IT99999'; - $companyit->localtax1_assuj=0; - $companyit->localtax2_assuj=0; - - $notcompanyit=new Societe($db); - $notcompanyit->country_code='IT'; - $notcompanyit->tva_assuj=1; - $notcompanyit->tva_intra=''; - $notcompanyit->typent_code='TE_PRIVATE'; - $notcompanyit->localtax1_assuj=0; - $notcompanyit->localtax2_assuj=0; - - $companyus=new Societe($db); - $companyus->country_code='US'; - $companyus->tva_assuj=1; - $companyus->tva_intra=''; - $companyus->localtax1_assuj=0; - $companyus->localtax2_assuj=0; - - // Test RULE FR-MC - $vat1=get_default_localtax($companyfrnovat, $companymc, 1, 0); - $vat2=get_default_localtax($companyfrnovat, $companymc, 2, 0); - $this->assertEquals(0, $vat1); - $this->assertEquals(0, $vat2); - - // Test RULE ES-ES - $vat1=get_default_localtax($companyes, $companyes, 1, 0); - $vat2=get_default_localtax($companyes, $companyes, 2, 0); - $this->assertEquals($vat1, 5.2); - $this->assertStringStartsWith((string) $vat2, '-19:-15:-9'); // Can be -19 (old version) or '-19:-15:-9' (new setup) - - // Test RULE ES-IT - $vat1=get_default_localtax($companyes, $companyit, 1, 0); - $vat2=get_default_localtax($companyes, $companyit, 2, 0); - $this->assertEquals(0, $vat1); - $this->assertEquals(0, $vat2); - - // Test RULE ES-IT - $vat1=get_default_localtax($companyes, $notcompanyit, 1, 0); - $vat2=get_default_localtax($companyes, $notcompanyit, 2, 0); - $this->assertEquals(0, $vat1); - $this->assertEquals(0, $vat2); - - // Test RULE FR-IT - // Not tested - - // Test RULE ES-US - $vat1=get_default_localtax($companyes, $companyus, 1, 0); - $vat2=get_default_localtax($companyes, $companyus, 2, 0); - $this->assertEquals(0, $vat1); - $this->assertEquals(0, $vat2); - } - - - /** - * testDolExplodeIntoArray - * - * @return void - */ - public function testDolExplodeIntoArray() - { - $stringtoexplode='AA=B/B.CC=.EE=FF.HH=GG;.'; - $tmp=dolExplodeIntoArray($stringtoexplode, '.', '='); - - print __METHOD__." tmp=".json_encode($tmp)."\n"; - $this->assertEquals('{"AA":"B\/B","CC":"","EE":"FF","HH":"GG;"}', json_encode($tmp)); - } - - /** - * dol_nl2br - * - * @return void - */ - public function testDolNl2Br() - { - - //String to encode - $string = "a\na"; - - $this->assertEquals(dol_nl2br($string), "a
    \na"); - - //With $forxml parameter - $this->assertEquals(dol_nl2br($string, 0, 1), "a
    \na"); - - //Replacing \n by br - $this->assertEquals(dol_nl2br($string, 1), "a
    a"); - - //With $forxml parameter - $this->assertEquals(dol_nl2br($string, 1, 1), "a
    a"); - } - - /** - * testDolPrice2Num - * - * @return boolean - */ - public function testDolPrice2Num() - { - global $langs, $conf; - - $oldlangs = $langs; - - $newlangs = new Translate('', $conf); - $newlangs->setDefaultLang('en_US'); - $newlangs->load("main"); - $langs = $newlangs; - - $this->assertEquals(150, price2num('(SELECT/**/CASE/**/WHEN/**/(0<1)/**/THEN/**/SLEEP(5)/**/ELSE/**/SLEEP(0)/**/END)')); - - $this->assertEquals(1000, price2num('1 000.0')); - $this->assertEquals(1000, price2num('1 000', 'MT')); - $this->assertEquals(1000, price2num('1 000', 'MU')); - - $this->assertEquals(1000.123456, price2num('1 000.123456')); - - // Round down - $this->assertEquals(1000.12, price2num('1 000.123452', 'MT')); - $this->assertEquals(1000.12345, price2num('1 000.123452', 'MU'), "Test MU"); - - // Round up - $this->assertEquals(1000.13, price2num('1 000.125456', 'MT')); - $this->assertEquals(1000.12546, price2num('1 000.125456', 'MU'), "Test MU"); - - $this->assertEquals(1, price2num('1.000'), 'Test 1.000 give 1 with english language'); - - // Text can't be converted - $this->assertEquals('12.4$', price2num('12.4$')); - $this->assertEquals('12.4$', price2num('12r.4$')); - - // For spanish language - $newlangs2 = new Translate('', $conf); - $newlangs2->setDefaultLang('es_ES'); - $newlangs2->load("main"); - $langs = $newlangs2; - - // Test with 3 chars after . or , - // If a . is used and there is 3 digits after, it is a thousand separator - $this->assertEquals(1234, price2num('1.234', '', 2), 'Test 1.234 give 1234 with spanish language if user input'); - $this->assertEquals(1.234, price2num('1,234', '', 2), 'Test 1,234 give 1234 with spanish language if user input'); - $this->assertEquals(1234, price2num('1 234', '', 2), 'Test 1 234 give 1234 with spanish language if user input'); - $this->assertEquals(-1.234, price2num('-1.234'), 'Test 1.234 give 1.234 with spanish language'); - $this->assertEquals(-1.234, price2num('-1,234'), 'Test 1,234 give 1234 with spanish language'); - $this->assertEquals(-1234, price2num('-1 234'), 'Test 1 234 give 1234 with spanish language'); - $this->assertEquals(21500123, price2num('21.500.123'), 'Test 21.500.123 give 21500123 with spanish language'); - $this->assertEquals(21500123, price2num('21500.123', 0, 2), 'Test 21500.123 give 21500123 with spanish language if user input'); - $this->assertEquals(21500.123, price2num('21500.123'), 'Test 21500.123 give 21500123 with spanish language'); - $this->assertEquals(21500.123, price2num('21500,123'), 'Test 21500,123 give 21500.123 with spanish language'); - // Test with 2 digits - $this->assertEquals(21500.12, price2num('21500.12'), 'Test 21500.12 give 21500.12 with spanish language'); - $this->assertEquals(21500.12, price2num('21500,12'), 'Test 21500,12 give 21500.12 with spanish language'); - // Test with 3 digits - $this->assertEquals(12123, price2num('12.123', '', 2), 'Test 12.123 give 12123 with spanish language if user input'); - $this->assertEquals(12.123, price2num('12,123', '', 2), 'Test 12,123 give 12.123 with spanish language if user input'); - $this->assertEquals(12.123, price2num('12.123'), 'Test 12.123 give 12.123 with spanish language'); - $this->assertEquals(12.123, price2num('12,123'), 'Test 12,123 give 12.123 with spanish language'); - - // For french language - $newlangs3 = new Translate('', $conf); - $newlangs3->setDefaultLang('fr_FR'); - $newlangs3->load("main"); - $langs = $newlangs3; - - $this->assertEquals(1, price2num('1.000', '', 2), 'Test 1.000 give 1 with french language if user input'); - $this->assertEquals(1, price2num('1.000'), 'Test 1.000 give 1 with french language'); - $this->assertEquals(1000, price2num('1 000'), 'Test 1.000 give 1 with french language'); - $this->assertEquals(1.234, price2num('1.234', '', 2), 'Test 1.234 give 1.234 with french language if user input'); - $this->assertEquals(1.234, price2num('1.234'), 'Test 1.234 give 1.234 with french language'); - $this->assertEquals(1.234, price2num('1,234', '', 2), 'Test 1,234 give 1.234 with french language if user input'); - $this->assertEquals(1.234, price2num('1,234'), 'Test 1,234 give 1.234 with french language'); - $this->assertEquals(21500000, price2num('21500 000'), 'Test 21500 000 give 21500000 with french language'); - $this->assertEquals(21500000, price2num('21 500 000'), 'Test 21 500 000 give 21500000 with french language'); - $this->assertEquals(21500, price2num('21500.00'), 'Test 21500.00 give 21500 with french language'); - $this->assertEquals(21500, price2num('21500,00'), 'Test 21500,00 give 21500 with french language'); - - $langs = $oldlangs; - - return true; - } - - /** - * testDolGetDate - * - * @return boolean - */ - public function testDolGetDate() - { - global $conf; - - $conf->global->MAIN_START_WEEK = 0; - - $tmp=dol_getdate(24*60*60+1); // 2/1/1970 and 1 second = friday - $this->assertEquals(5, $tmp['wday']); - - $conf->global->MAIN_START_WEEK = 1; - - $tmp=dol_getdate(1); // 1/1/1970 and 1 second = thirday - $this->assertEquals(4, $tmp['wday']); - - $tmp=dol_getdate(24*60*60+1); // 2/1/1970 and 1 second = friday - $this->assertEquals(5, $tmp['wday']); - - $tmp=dol_getdate(1, false, "Europe/Paris"); // 1/1/1970 and 1 second = thirday - $this->assertEquals(1970, $tmp['year']); - $this->assertEquals(1, $tmp['mon']); - $this->assertEquals(1, $tmp['mday']); - $this->assertEquals(4, $tmp['wday']); - $this->assertEquals(0, $tmp['yday']); - $this->assertEquals(1, $tmp['hours']); // We are winter, so we are GMT+1 even during summer - $this->assertEquals(0, $tmp['minutes']); - $this->assertEquals(1, $tmp['seconds']); - - $tmp=dol_getdate(15638401, false, "Europe/Paris"); // 1/7/1970 and 1 second = wednesday - $this->assertEquals(1970, $tmp['year']); - $this->assertEquals(7, $tmp['mon']); - $this->assertEquals(1, $tmp['mday']); - $this->assertEquals(3, $tmp['wday']); - $this->assertEquals(181, $tmp['yday']); - $this->assertEquals(1, $tmp['hours']); // There is no daylight in 1970, so we are GMT+1 even during summer - $this->assertEquals(0, $tmp['minutes']); - $this->assertEquals(1, $tmp['seconds']); - - $tmp=dol_getdate(1593561601, false, "Europe/Paris"); // 1/7/2020 and 1 second = wednesday - $this->assertEquals(2020, $tmp['year']); - $this->assertEquals(7, $tmp['mon']); - $this->assertEquals(1, $tmp['mday']); - $this->assertEquals(3, $tmp['wday']); - $this->assertEquals(182, $tmp['yday']); // 182 and not 181, due to the 29th february - $this->assertEquals(2, $tmp['hours']); // There is a daylight, so we are GMT+2 - $this->assertEquals(0, $tmp['minutes']); - $this->assertEquals(1, $tmp['seconds']); - - $conf->global->MAIN_USE_OLD_FUNCTIONS_FOR_GETDATE = 1; - - $tmp=dol_getdate(1); // 1/1/1970 and 1 second = thirday - $this->assertEquals(1970, $tmp['year']); - $this->assertEquals(1, $tmp['mon']); - $this->assertEquals(1, $tmp['mday']); - $this->assertEquals(4, $tmp['wday']); - $this->assertEquals(0, $tmp['yday']); - // We must disable this because on CI, timezone is may be UTC or something else - //$this->assertEquals(1, $tmp['hours']); // We are winter, so we are GMT+1 even during summer - $this->assertEquals(0, $tmp['minutes']); - $this->assertEquals(1, $tmp['seconds']); - - $tmp=dol_getdate(15638401); // 1/7/1970 and 1 second = wednesday - $this->assertEquals(1970, $tmp['year']); - $this->assertEquals(7, $tmp['mon']); - $this->assertEquals(1, $tmp['mday']); - $this->assertEquals(3, $tmp['wday']); - $this->assertEquals(181, $tmp['yday']); - // We must disable this because on CI, timezone is may be UTC or something else - //$this->assertEquals(1, $tmp['hours']); // There is no daylight in 1970, so we are GMT+1 even during summer - $this->assertEquals(0, $tmp['minutes']); - $this->assertEquals(1, $tmp['seconds']); - - $tmp=dol_getdate(1593561601); // 1/7/2020 and 1 second = wednesday - $this->assertEquals(2020, $tmp['year']); - $this->assertEquals(7, $tmp['mon']); - $this->assertEquals(1, $tmp['mday']); - $this->assertEquals(3, $tmp['wday']); - $this->assertEquals(182, $tmp['yday']); // 182 and not 181, due to the 29th february - // We must disable this because on CI, timezone is may be UTC or something else - //$this->assertEquals(2, $tmp['hours']); // There is a daylight, so we are GMT+2 - $this->assertEquals(0, $tmp['minutes']); - $this->assertEquals(1, $tmp['seconds']); - - return true; - } - - - /** - * testMakeSubstitutions - * - * @return boolean - */ - public function testMakeSubstitutions() - { - global $conf, $langs; - $langs->load("main"); - - $substit=array("AAA"=>'Not used', "BBB"=>'Not used', "CCC"=>"C replaced"); - $chaine='This is a string with __[MAIN_THEME]__ and __(DIRECTION)__ and __CCC__'; - $newstring = make_substitutions($chaine, $substit); - $this->assertEquals($newstring, 'This is a string with eldy and ltr and __C replaced__'); - - return true; - } - - /** - * testDolStringIsGoodIso - * - * @return boolean - */ - public function testDolStringIsGoodIso() - { - global $conf, $langs; - - $chaine='This is an ISO string'; - $result = dol_string_is_good_iso($chaine); - $this->assertEquals($result, 1); - - $chaine='This is a not ISO string '.chr(0); - $result = dol_string_is_good_iso($chaine); - $this->assertEquals($result, 0); - - return true; - } - - - /** - * testGetUserRemoteIP - * - * @return boolean - */ - public function testGetUserRemoteIP() - { - global $conf, $langs; - - $_SERVER['HTTP_X_FORWARDED_FOR']='1.2.3.4'; - $_SERVER['HTTP_CLIENT_IP']='5.6.7.8'; - $result = getUserRemoteIP(); - $this->assertEquals($result, '1.2.3.4'); - - $_SERVER['HTTP_X_FORWARDED_FOR']='1.2.3.4'; - $_SERVER['HTTP_CLIENT_IP']='5.6.7.8'; - $result = getUserRemoteIP(); - $this->assertEquals($result, '5.6.7.8'); - - $_SERVER['HTTP_X_FORWARDED_FOR']='[1:2:3:4]'; - $_SERVER['HTTP_CLIENT_IP']='5.6.7.8'; - $result = getUserRemoteIP(); - $this->assertEquals($result, '[1:2:3:4]'); - - return true; - } + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; + + /** + * Constructor + * We save global variables into local variables + * + * @return CoreTest + */ + public function __construct() + { + parent::__construct(); + + //$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"; + } + + /** + * setUpBeforeClass + * + * @return void + */ + 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. + + if (! function_exists('mb_substr')) { + print "\n".__METHOD__." function mb_substr must be enabled.\n"; die(); + } + + print __METHOD__."\n"; + } + + /** + * tearDownAfterClass + * + * @return void + */ + 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"; + } + + /** + * testIsValidEmail + * + * @return void + */ + public function testIsValidEmail() + { + // Nb of line is same than entry text + + $input="bidon@bademail"; + $result=isValidEmail($input); + print __METHOD__." result=".$result."\n"; + $this->assertFalse($result, 'Check isValidEmail '.$input); + + $input="test@yahoo.com"; + $result=isValidEmail($input); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result, 'Check isValidEmail '.$input); + + $input="The name of sender "; + $result=isValidEmail($input); + print __METHOD__." result=".$result."\n"; + $this->assertFalse($result, 'Check isValidEmail '.$input); + + $input="1234.abcdefg@domainame.com.br"; + $result=isValidEmail($input); + print __METHOD__." result=".$result."\n"; + $this->assertTrue($result, 'Check isValidEmail '.$input); + } + + /** + * testIsValidMXRecord + * + * @return void + */ + public function testIsValidMXRecord() + { + // Nb of line is same than entry text + + $input="yahoo.com"; + $result=isValidMXRecord($input); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(1, $result); + + $input="yhaoo.com"; + $result=isValidMXRecord($input); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(0, $result); + + $input="dolibarr.fr"; + $result=isValidMXRecord($input); + print __METHOD__." result=".$result."\n"; + $this->assertEquals(0, $result); + } + + /** + * testDolGetFirstLineOfText + * + * @return void + */ + public function testDolGetFirstLineOfText() + { + // Nb of line is same than entry text + + $input="aaaa"; + $result=dolGetFirstLineOfText($input); + print __METHOD__." result=".$result."\n"; + $this->assertEquals("aaaa", $result); + + $input="aaaa\nbbbbbbbbbbbb\n"; + $result=dolGetFirstLineOfText($input, 2); + print __METHOD__." result=".$result."\n"; + $this->assertEquals("aaaa\nbbbbbbbbbbbb", $result); + + $input="aaaa
    bbbbbbbbbbbb
    "; + $result=dolGetFirstLineOfText($input, 2); + print __METHOD__." result=".$result."\n"; + $this->assertEquals("aaaa
    \nbbbbbbbbbbbb", $result); + + // Nb of line is lower + + $input="aaaa\nbbbbbbbbbbbb\ncccccc\n"; + $result=dolGetFirstLineOfText($input); + print __METHOD__." result=".$result."\n"; + $this->assertEquals("aaaa...", $result); + + $input="aaaa
    bbbbbbbbbbbb
    cccccc
    "; + $result=dolGetFirstLineOfText($input); + print __METHOD__." result=".$result."\n"; + $this->assertEquals("aaaa...", $result); + + $input="aaaa\nbbbbbbbbbbbb\ncccccc\n"; + $result=dolGetFirstLineOfText($input, 2); + print __METHOD__." result=".$result."\n"; + $this->assertEquals("aaaa\nbbbbbbbbbbbb...", $result); + + $input="aaaa
    bbbbbbbbbbbb
    cccccc
    "; + $result=dolGetFirstLineOfText($input, 2); + print __METHOD__." result=".$result."\n"; + $this->assertEquals("aaaa
    \nbbbbbbbbbbbb...", $result); + + // Nb of line is higher + + $input="aaaa
    bbbbbbbbbbbb
    cccccc"; + $result=dolGetFirstLineOfText($input, 100); + print __METHOD__." result=".$result."\n"; + $this->assertEquals("aaaa
    \nbbbbbbbbbbbb
    \ncccccc", $result, 'dolGetFirstLineOfText with nb 100 a'); + + $input="aaaa
    bbbbbbbbbbbb
    cccccc
    "; + $result=dolGetFirstLineOfText($input, 100); + print __METHOD__." result=".$result."\n"; + $this->assertEquals("aaaa
    \nbbbbbbbbbbbb
    \ncccccc", $result, 'dolGetFirstLineOfText with nb 100 b'); + + $input="aaaa
    bbbbbbbbbbbb
    cccccc
    \n"; + $result=dolGetFirstLineOfText($input, 100); + print __METHOD__." result=".$result."\n"; + $this->assertEquals("aaaa
    \nbbbbbbbbbbbb
    \ncccccc", $result, 'dolGetFirstLineOfText with nb 100 c'); + } + + + /** + * testDolBuildPath + * + * @return void + */ + public function testDolBuildPath() + { + /*$tmp=dol_buildpath('/google/oauth2callback.php', 0); + var_dump($tmp); + */ + + /*$tmp=dol_buildpath('/google/oauth2callback.php', 1); + var_dump($tmp); + */ + + $result=dol_buildpath('/google/oauth2callback.php', 2); + print __METHOD__." result=".$result."\n"; + $this->assertStringStartsWith('http', $result); + + $result=dol_buildpath('/google/oauth2callback.php', 3); + print __METHOD__." result=".$result."\n"; + $this->assertStringStartsWith('http', $result); + } + + + /** + * testGetBrowserInfo + * + * @return void + */ + public function testGetBrowserInfo() + { + // MSIE 5.0 + $user_agent ='Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt; KITV4 Wanadoo; KITV5 Wanadoo)'; + $tmp=getBrowserInfo($user_agent); + $this->assertEquals('ie', $tmp['browsername']); + $this->assertEquals('5.0', $tmp['browserversion']); + $this->assertEmpty($tmp['phone']); + $this->assertFalse($tmp['tablet']); + $this->assertEquals('classic', $tmp['layout']); + + // Firefox 0.9.1 + $user_agent ='Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.5a) Gecko/20030728 Mozilla Firefox/0.9.1'; + $tmp=getBrowserInfo($user_agent); + $this->assertEquals('firefox', $tmp['browsername']); + $this->assertEquals('0.9.1', $tmp['browserversion']); + $this->assertEmpty($tmp['phone']); + $this->assertFalse($tmp['tablet']); + $this->assertEquals('classic', $tmp['layout']); + + $user_agent ='Mozilla/3.0 (Windows 98; U) Opera 6.03 [en]'; + $tmp=getBrowserInfo($user_agent); + $this->assertEquals('opera', $tmp['browsername']); + $this->assertEquals('6.03', $tmp['browserversion']); + $this->assertEmpty($tmp['phone']); + $this->assertFalse($tmp['tablet']); + $this->assertEquals('classic', $tmp['layout']); + + $user_agent ='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.21 (KHTML, like Gecko) Chrome/19.0.1042.0 Safari/535.21'; + $tmp=getBrowserInfo($user_agent); + $this->assertEquals('chrome', $tmp['browsername']); + $this->assertEquals('19.0.1042.0', $tmp['browserversion']); + $this->assertEmpty($tmp['phone']); + $this->assertFalse($tmp['tablet']); + $this->assertEquals('classic', $tmp['layout']); + + $user_agent ='chrome (Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11)'; + $tmp=getBrowserInfo($user_agent); + $this->assertEquals('chrome', $tmp['browsername']); + $this->assertEquals('17.0.963.56', $tmp['browserversion']); + $this->assertEmpty($tmp['phone']); + $this->assertFalse($tmp['tablet']); + $this->assertEquals('classic', $tmp['layout']); + + $user_agent ='Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; de-at) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1'; + $tmp=getBrowserInfo($user_agent); + $this->assertEquals('safari', $tmp['browsername']); + $this->assertEquals('533.21.1', $tmp['browserversion']); + $this->assertEmpty($tmp['phone']); + $this->assertFalse($tmp['tablet']); + $this->assertEquals('classic', $tmp['layout']); + + //Internet Explorer 11 + $user_agent = 'Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko'; + $tmp=getBrowserInfo($user_agent); + $this->assertEquals('ie', $tmp['browsername']); + $this->assertEquals('11.0', $tmp['browserversion']); + $this->assertEmpty($tmp['phone']); + $this->assertFalse($tmp['tablet']); + $this->assertEquals('classic', $tmp['layout']); + + //Internet Explorer 11 bis + $user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; NP06; rv:11.0) like Gecko'; + $tmp=getBrowserInfo($user_agent); + $this->assertEquals('ie', $tmp['browsername']); + $this->assertEquals('11.0', $tmp['browserversion']); + $this->assertEmpty($tmp['phone']); + $this->assertFalse($tmp['tablet']); + $this->assertEquals('classic', $tmp['layout']); + + //iPad + $user_agent = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25'; + $tmp=getBrowserInfo($user_agent); + $this->assertEquals('safari', $tmp['browsername']); + $this->assertEquals('8536.25', $tmp['browserversion']); + $this->assertEquals('ios', $tmp['browseros']); + $this->assertEquals('tablet', $tmp['layout']); + $this->assertEquals('iphone', $tmp['phone']); + } + + + /** + * testGetLanguageCodeFromCountryCode + * + * @return void + */ + public function testGetLanguageCodeFromCountryCode() + { + global $mysoc; + + $language = getLanguageCodeFromCountryCode('US'); + $this->assertEquals('en_US', $language, 'US'); + + $language = getLanguageCodeFromCountryCode('ES'); + $this->assertEquals('es_ES', $language, 'ES'); + + $language = getLanguageCodeFromCountryCode('CL'); + $this->assertEquals('es_CL', $language, 'CL'); + + $language = getLanguageCodeFromCountryCode('CA'); + $this->assertEquals('en_CA', $language, 'CA'); + + $language = getLanguageCodeFromCountryCode('MQ'); + $this->assertEquals('fr_CA', $language); + + $language = getLanguageCodeFromCountryCode('FR'); + $this->assertEquals('fr_FR', $language); + + $language = getLanguageCodeFromCountryCode('BE'); + $this->assertEquals('fr_BE', $language); + + $mysoc->country_code = 'FR'; + $language = getLanguageCodeFromCountryCode('CH'); + $this->assertEquals('fr_CH', $language); + + $mysoc->country_code = 'DE'; + $language = getLanguageCodeFromCountryCode('CH'); + $this->assertEquals('de_CH', $language); + + $language = getLanguageCodeFromCountryCode('DE'); + $this->assertEquals('de_DE', $language); + + $language = getLanguageCodeFromCountryCode('SA'); + $this->assertEquals('ar_SA', $language); + + $language = getLanguageCodeFromCountryCode('SE'); + $this->assertEquals('sv_SE', $language); + + $language = getLanguageCodeFromCountryCode('DK'); + $this->assertEquals('da_DK', $language); + } + + /** + * testDolTextIsHtml + * + * @return void + */ + public function testDolTextIsHtml() + { + // True + $input='xxx'; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with html tag'); + $input='xxx'; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with body tag'); + $input='xxx yyy zzz'; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with b tag'); + $input='xxx yyy zzz'; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with u tag'); + $input='text with
    some div
    '; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with div tag'); + $input='text with HTML   entities'; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with entities tag'); + $input='xxx
    '; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with entities br'); + $input='xxx
    '; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with entities br'); + $input='xxx
    '; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with entities br and attributes'); + $input='xxx
    '; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with entities br and attributes bis'); + $input='

    abc

    '; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with entities h2'); + $input=''; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with img tag'); + $input=''; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with a tag'); + $input='This is a text with html spaces'; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with a  '); + $input='This is a text with accent é'; + $after=dol_textishtml($input); + $this->assertTrue($after, 'Test with a é'); + + // False + $input='xxx < br>'; + $after=dol_textishtml($input); + $this->assertFalse($after); + $input='xxx '; // is html, assertFalse($after); + $input='xxx '; + $after=dol_textishtml($input); + $this->assertFalse($after); + $input='This is a text with html comments '; // we suppose this is not enough to be html content + $after=dol_textishtml($input); + $this->assertFalse($after); + } + + + /** + * testDolHtmlCleanLastBr + * + * @return boolean + */ + public function testDolHtmlCleanLastBr() + { + $input="A string\n"; + $after=dol_htmlcleanlastbr($input); + $this->assertEquals("A string", $after); + + $input="A string first\nA string second\n"; + $after=dol_htmlcleanlastbr($input); + $this->assertEquals("A string first\nA string second", $after); + + $input="A string\n\n\n"; + $after=dol_htmlcleanlastbr($input); + $this->assertEquals("A string", $after); + + $input="A string
    "; + $after=dol_htmlcleanlastbr($input); + $this->assertEquals("A string", $after); + + $input="A string first
    \nA string second
    "; + $after=dol_htmlcleanlastbr($input); + $this->assertEquals("A string first
    \nA string second", $after); + + $input="A string\n
    \n"; + $after=dol_htmlcleanlastbr($input); + $this->assertEquals("A string", $after); + + $input="A string\n

    \n\n"; + $after=dol_htmlcleanlastbr($input); + $this->assertEquals("A string", $after); + + return true; + } + + /** + * testDolConcat + * + * @return boolean + */ + public function testDolConcat() + { + $text1="A string 1"; $text2="A string 2"; // text 1 and 2 are text, concat need only \n + $after=dol_concatdesc($text1, $text2); + $this->assertEquals("A string 1\nA string 2", $after); + + $text1="A
    string 1"; $text2="A string 2"; // text 1 is html, concat need
    \n + $after=dol_concatdesc($text1, $text2); + $this->assertEquals("A
    string 1
    \nA string 2", $after); + + $text1="A string 1"; $text2="A string 2"; // text 2 is html, concat need
    \n + $after=dol_concatdesc($text1, $text2); + $this->assertEquals("A string 1
    \nA string 2", $after); + + return true; + } + + + /** + * testDolStringNohtmltag + * + * @return boolean + */ + public function testDolStringNohtmltag() + { + $text="A\nstring\n\nand more\n"; + $after=dol_string_nohtmltag($text, 0); + $this->assertEquals("A\nstring\n\nand more", $after, "test1a"); + + $text="A string
    \n
    \n\nwith html tag
    \n"; + $after=dol_string_nohtmltag($text, 0); + $this->assertEquals("A string\n\n\n\n\nwith html tag", $after, 'test2a 2 br and 3 \n give 5 \n'); + + $text="A string
    \n
    \n\nwith html tag
    \n"; + $after=dol_string_nohtmltag($text, 1); + $this->assertEquals("A string with html tag", $after, 'test2b 2 br and 3 \n give 1 space'); + + $text="A string
    \n
    \n\nwith html tag
    \n"; + $after=dol_string_nohtmltag($text, 2); + $this->assertEquals("A string\n\nwith html tag", $after, 'test2c 2 br and 3 \n give 2 \n'); + + $text="A string
    \r\n
    \r\n\r\nwith html tag
    \n"; + $after=dol_string_nohtmltag($text, 2); + $this->assertEquals("A string\n\nwith html tag", $after, 'test2c 2 br and 3 \r\n give 2 \n'); + + $text="A string
    Another string"; + $after=dol_string_nohtmltag($text, 0); + $this->assertEquals("A string\nAnother string", $after, "test4"); + + $text="A string
    Another string"; + $after=dol_string_nohtmltag($text, 1); + $this->assertEquals("A string Another string", $after, "test5"); + + $text='
    ABC'; + $after=dol_string_nohtmltag($text, 1); + $this->assertEquals("ABC", $after, "test6"); + + $text='DEF'; + $after=dol_string_nohtmltag($text, 1); + $this->assertEquals("DEF", $after, "test7"); + + $text='HIJ'; + $after=dol_string_nohtmltag($text, 0); + $this->assertEquals("HIJ", $after, "test8"); + + $text="A string\n\nwith html tag and '<' chars
    \n"; + $after=dol_string_nohtmltag($text, 0); + $this->assertEquals("A string\n\nwith html tag and '<' chars", $after, "test9"); + + $text="A string\n\nwith tag with < chars
    \n"; + $after=dol_string_nohtmltag($text, 1); + $this->assertEquals("A string with tag with < chars", $after, "test10"); + + return true; + } + + + + /** + * testDolHtmlEntitiesBr + * + * @return boolean + */ + public function testDolHtmlEntitiesBr() + { + // Text not already HTML + + $input="A string\nwith a é, &, < and >."; + $after=dol_htmlentitiesbr($input, 0); // Add
    before \n + $this->assertEquals("A string
    \nwith a é, &, < and >.", $after); + + $input="A string\nwith a é, &, < and >."; + $after=dol_htmlentitiesbr($input, 1); // Replace \n with
    + $this->assertEquals("A string
    with a é, &, < and >.", $after); + + $input="A string\nwith a é, &, < and >.\n\n"; // With some \n at end that should be cleaned + $after=dol_htmlentitiesbr($input, 0); // Add
    before \n + $this->assertEquals("A string
    \nwith a é, &, < and >.", $after); + + $input="A string\nwith a é, &, < and >.\n\n"; // With some \n at end that should be cleaned + $after=dol_htmlentitiesbr($input, 1); // Replace \n with
    + $this->assertEquals("A string
    with a é, &, < and >.", $after); + + // Text already HTML, so &,<,> should not be converted + + $input="A string
    \nwith a é, &, < and >."; + $after=dol_htmlentitiesbr($input); + $this->assertEquals("A string
    \nwith a é, &, < and >.", $after); + + $input="
  • \nA string with a é, &, < and >.
  • \nAnother string"; + $after=dol_htmlentitiesbr($input); + $this->assertEquals("
  • \nA string with a é, &, < and >.
  • \nAnother string", $after); + + $input="A string
    \nwith a é, &, < and >.
    "; // With some
    at end that should be cleaned + $after=dol_htmlentitiesbr($input); + $this->assertEquals("A string
    \nwith a é, &, < and >.", $after); + + $input="
  • \nA string with a é, &, < and >.
  • \nAnother string
    "; // With some
    at end that should be cleaned + $after=dol_htmlentitiesbr($input); + $this->assertEquals("
  • \nA string with a é, &, < and >.
  • \nAnother string", $after); + + // TODO Add test with param $removelasteolbr = 0 + + return true; + } + + + /** + * testDolNbOfLinesBis + * + * @return boolean + */ + public function testDolNbOfLinesBis() + { + // This is not a html string so nb of lines depends on \n + $input="A string\nwith a é, &, < and > and bold tag.\nThird line"; + $after=dol_nboflines_bis($input, 0); + $this->assertEquals($after, 3); + + // This is a html string so nb of lines depends on
    + $input="A string\nwith a é, &, < and > and bold tag.\nThird line"; + $after=dol_nboflines_bis($input, 0); + $this->assertEquals($after, 1); + + // This is a html string so nb of lines depends on
    + $input="A string
    with a é, &, < and > and bold tag.
    Third line"; + $after=dol_nboflines_bis($input, 0); + $this->assertEquals($after, 3); + + return true; + } + + + /** + * testDolUnaccent + * + * @return boolean + */ + public function testDolUnaccent() + { + // Text not already HTML + + $input="A string\nwith a à ä é è ë ï ü ö ÿ, &, < and >."; + $after=dol_string_unaccent($input); + $this->assertEquals("A string\nwith a a a e e e i u o y, &, < and >.", $after); + } + + + /** + * testDolUtf8Check + * + * @return void + */ + public function testDolUtf8Check() + { + // True + $result=utf8_check('azerty'); + $this->assertTrue($result); + + $file=dirname(__FILE__).'/textutf8.txt'; + $filecontent=file_get_contents($file); + $result=utf8_check($filecontent); + $this->assertTrue($result); + + $file=dirname(__FILE__).'/textiso.txt'; + $filecontent=file_get_contents($file); + $result=utf8_check($filecontent); + $this->assertFalse($result); + } + + /** + * testDolAsciiCheck + * + * @return void + */ + public function testDolAsciiCheck() + { + // True + $result=ascii_check('azerty'); + $this->assertTrue($result); + + $result=ascii_check('é'); + $this->assertFalse($result); + + $file=dirname(__FILE__).'/textutf8.txt'; + $filecontent=file_get_contents($file); + $result=ascii_check($filecontent); + $this->assertFalse($result); + } + + /** + * testDolTrunc + * + * @return boolean + */ + public function testDolTrunc() + { + // Default trunc (will add ... if truncation truncation or keep last char if only one char) + $input="éeéeéeàa"; + $after=dol_trunc($input, 3); + $this->assertEquals("éeé...", $after, 'Test A1'); + $after=dol_trunc($input, 2); + $this->assertEquals("ée...", $after, 'Test A2'); + $after=dol_trunc($input, 1); + $this->assertEquals("é...", $after, 'Test A3'); + $input="éeéeé"; + $after=dol_trunc($input, 3); + $this->assertEquals("éeéeé", $after, 'Test B1'); + $after=dol_trunc($input, 2); + $this->assertEquals("éeéeé", $after, 'Test B2'); + $after=dol_trunc($input, 1); + $this->assertEquals("é...", $after, 'Test B3'); + $input="éeée"; + $after=dol_trunc($input, 3); + $this->assertEquals("éeée", $after, 'Test C1'); + $after=dol_trunc($input, 2); + $this->assertEquals("éeée", $after, 'Test C2'); + $after=dol_trunc($input, 1); + $this->assertEquals("éeée", $after, 'Test C3'); + $input="éeé"; + $after=dol_trunc($input, 3); + $this->assertEquals("éeé", $after, 'Test C'); + $after=dol_trunc($input, 2); + $this->assertEquals("éeé", $after, 'Test D'); + $after=dol_trunc($input, 1); + $this->assertEquals("éeé", $after, 'Test E'); + // Trunc with no ... + $input="éeéeéeàa"; + $after=dol_trunc($input, 3, 'right', 'UTF-8', 1); + $this->assertEquals("éeé", $after, 'Test F'); + $after=dol_trunc($input, 2, 'right', 'UTF-8', 1); + $this->assertEquals("ée", $after, 'Test G'); + $input="éeé"; + $after=dol_trunc($input, 3, 'right', 'UTF-8', 1); + $this->assertEquals("éeé", $after, 'Test H'); + $after=dol_trunc($input, 2, 'right', 'UTF-8', 1); + $this->assertEquals("ée", $after, 'Test I'); + $after=dol_trunc($input, 1, 'right', 'UTF-8', 1); + $this->assertEquals("é", $after, 'Test J'); + $input="éeéeéeàa"; + $after=dol_trunc($input, 4, 'middle'); + $this->assertEquals("ée...àa", $after, 'Test K'); + + return true; + } + + /** + * testDolMkTime + * + * @return void + */ + public function testDolMkTime() + { + global $conf; + + $savtz=date_default_timezone_get(); + + // Some test for UTC TZ + date_default_timezone_set('UTC'); + + // Check bad hours + $result=dol_mktime(25, 0, 0, 1, 1, 1970, 1, 1); // Error (25 hours) + print __METHOD__." result=".$result."\n"; + $this->assertEquals('', $result); + $result=dol_mktime(2, 61, 0, 1, 1, 1970, 1, 1); // Error (61 minutes) + print __METHOD__." result=".$result."\n"; + $this->assertEquals('', $result); + $result=dol_mktime(2, 1, 61, 1, 1, 1970, 1, 1); // Error (61 seconds) + print __METHOD__." result=".$result."\n"; + $this->assertEquals('', $result); + $result=dol_mktime(2, 1, 1, 1, 32, 1970, 1, 1); // Error (day 32) + print __METHOD__." result=".$result."\n"; + $this->assertEquals('', $result); + $result=dol_mktime(2, 1, 1, 13, 1, 1970, 1, 1); // Error (month 13) + print __METHOD__." result=".$result."\n"; + $this->assertEquals('', $result); + + $result=dol_mktime(2, 1, 1, 1, 1, 1970, 1); // 1970-01-01 02:01:01 in GMT area -> 7261 + print __METHOD__." result=".$result."\n"; + $this->assertEquals(7261, $result); + + $result=dol_mktime(2, 0, 0, 1, 1, 1970, 0); // 1970-01-01 02:00:00 = 7200 in local area Europe/Paris = 3600 GMT + print __METHOD__." result=".$result."\n"; + $tz=getServerTimeZoneInt('winter'); // +1 in Europe/Paris at this time (this time is winter) + $this->assertEquals(7200-($tz*3600), $result); // 7200 if we are at greenwich winter, 7200-($tz*3600) at local winter + + // Some test for local TZ Europe/Paris + date_default_timezone_set('Europe/Paris'); + + // Check that tz for paris in winter is used + $result=dol_mktime(2, 0, 0, 1, 1, 1970, 'server'); // 1970-01-01 02:00:00 = 7200 in local area Europe/Paris = 3600 GMT + print __METHOD__." result=".$result."\n"; + $this->assertEquals(3600, $result); // 7200 if we are at greenwich winter, 3600 at Europe/Paris + + // Check that daylight saving time is used + $result=dol_mktime(2, 0, 0, 6, 1, 2014, 0); // 2014-06-01 02:00:00 = 1401588000-3600(location)-3600(daylight) in local area Europe/Paris = 1401588000 GMT + print __METHOD__." result=".$result."\n"; + $this->assertEquals(1401588000-3600-3600, $result); // 1401588000 are at greenwich summer, 1401588000-3600(location)-3600(daylight) at Europe/Paris summer + + date_default_timezone_set($savtz); + } + + + /** + * testDolEscapeJs + * + * @return void + */ + public function testDolEscapeJs() + { + $input="x&#,\"'"; // " will be converted into ' + $result=dol_escape_js($input); + $this->assertEquals("x&#,\'\'", $result, "Test mode=0"); + + $result=dol_escape_js($input, 1); + $this->assertEquals("x&#,\"\'", $result, "Test mode=1"); + + $result=dol_escape_js($input, 2); + $this->assertEquals("x&#,\\\"'", $result, "Test mode=2"); + } + + + /** + * testDolEscapeHtmlTag + * + * @return void + */ + public function testDolEscapeHtmlTag() + { + $input='x&#,"'; // & and " are converted into html entities, are removed + $result=dol_escape_htmltag($input); + $this->assertEquals('x&#,"', $result); + + $input='x&#,"'; // & and " are converted into html entities, are not removed + $result=dol_escape_htmltag($input, 1); + $this->assertEquals('x&<b>#</b>,"', $result); + } + + + /** + * testDolFormatAddress + * + * @return void + */ + public function testDolFormatAddress() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $object=new Societe($db); + $object->initAsSpecimen(); + + $object->country_code='FR'; + $address=dol_format_address($object); + $this->assertEquals("21 jump street\n99999 MyTown", $address); + + $object->country_code='GB'; + $address=dol_format_address($object); + $this->assertEquals("21 jump street\nMyTown, MyState\n99999", $address); + + $object->country_code='US'; + $address=dol_format_address($object); + $this->assertEquals("21 jump street\nMyTown, MyState, 99999", $address); + + $object->country_code='AU'; + $address=dol_format_address($object); + $this->assertEquals("21 jump street\nMyTown, MyState, 99999", $address); + } + + + /** + * testDolFormatAddress + * + * @return void + */ + public function testDolPrintPhone() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $object=new Societe($db); + $object->initAsSpecimen(); + + $object->country_code='FR'; + $phone=dol_print_phone('1234567890', $object->country_code); + $this->assertEquals('12 34 56 78 90', $phone, 'Phone for FR 1'); + + $object->country_code='FR'; + $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ''); + $this->assertEquals('1234567890', $phone, 'Phone for FR 2'); + + $object->country_code='FR'; + $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ' '); + $this->assertEquals('12 34 56 78 90', $phone, 'Phone for FR 3'); + + $object->country_code='CA'; + $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ' '); + $this->assertEquals('(123) 456-7890', $phone, 'Phone for CA 1'); + } + + + /** + * testImgPicto + * + * @return void + */ + public function testImgPicto() + { + $s=img_picto('title', 'user'); + print __METHOD__." s=".$s."\n"; + $this->assertContains('fa-user', $s, 'testImgPicto1'); + + $s=img_picto('title', 'img.png', 'style="float: right"', 0); + print __METHOD__." s=".$s."\n"; + $this->assertContains('theme', $s, 'testImgPicto2'); + $this->assertContains('style="float: right"', $s, 'testImgPicto2'); + + $s=img_picto('title', '/fullpath/img.png', '', 1); + print __METHOD__." s=".$s."\n"; + $this->assertEquals('', $s, 'testImgPicto3'); + + $s=img_picto('title', '/fullpath/img.png', '', true); + print __METHOD__." s=".$s."\n"; + $this->assertEquals('', $s, 'testImgPicto4'); + + $s=img_picto('title', 'delete', '', 0, 1); + print __METHOD__." s=".$s."\n"; + $this->assertEquals(DOL_URL_ROOT.'/theme/eldy/img/delete.png', $s, 'testImgPicto5'); + } + + /** + * testDolNow + * + * @return void + */ + public function testDolNow() + { + $now=dol_now('gmt'); + $nowtzserver=dol_now('tzserver'); + print __METHOD__." getServerTimeZoneInt=".(getServerTimeZoneInt('now')*3600)."\n"; + $this->assertEquals(getServerTimeZoneInt('now')*3600, ($nowtzserver-$now)); + } + + /** + * testVerifCond + * + * @return void + */ + public function testVerifCond() + { + $verifcond=verifCond('1==1'); + $this->assertTrue($verifcond, 'Test a true comparison'); + + $verifcond=verifCond('1==2'); + $this->assertFalse($verifcond, 'Test a false comparison'); + + $verifcond=verifCond('$conf->facture->enabled'); + $this->assertTrue($verifcond, 'Test that conf property of a module report true when enabled'); + + $verifcond=verifCond('$conf->moduledummy->enabled'); + $this->assertFalse($verifcond, 'Test that conf property of a module report false when disabled'); + + $verifcond=verifCond(''); + $this->assertTrue($verifcond); + } + + /** + * testGetDefaultTva + * + * @return void + */ + public function testGetDefaultTva() + { + global $conf,$user,$langs,$db; + $this->savconf=$conf; + $this->savuser=$user; + $this->savlangs=$langs; + $this->savdb=$db; + + // Sellers + $companyfrnovat=new Societe($db); + $companyfrnovat->country_code='FR'; + $companyfrnovat->tva_assuj=0; + + $companyfr=new Societe($db); + $companyfr->country_code='FR'; + $companyfr->tva_assuj=1; + $companyfr->tva_intra='FR9999'; + + // Buyers + $companymc=new Societe($db); + $companymc->country_code='MC'; + $companymc->tva_assuj=1; + $companyfr->tva_intra='MC9999'; + + $companyit=new Societe($db); + $companyit->country_code='IT'; + $companyit->tva_assuj=1; + $companyit->tva_intra='IT99999'; + + $companyde=new Societe($db); + $companyde->country_code='DE'; + $companyde->tva_assuj=1; + $companyde->tva_intra='DE99999'; + + $notcompanyde=new Societe($db); + $notcompanyde->country_code='DE'; + $notcompanyde->tva_assuj=0; + $notcompanyde->tva_intra=''; + $notcompanyde->typent_code='TE_PRIVATE'; + + $companyus=new Societe($db); + $companyus->country_code='US'; + $companyus->tva_assuj=1; + $companyus->tva_intra=''; + + + // Test RULE 0 (FR-DE) + // Not tested + + // Test RULE 1 + $vat=get_default_tva($companyfrnovat, $companymc, 0); + $this->assertEquals(0, $vat, 'RULE 1'); + + // Test RULE 2 (FR-FR) + $vat=get_default_tva($companyfr, $companyfr, 0); + $this->assertEquals(20, $vat, 'RULE 2'); + + // Test RULE 2 (FR-MC) + $vat=get_default_tva($companyfr, $companymc, 0); + $this->assertEquals(20, $vat, 'RULE 2'); + + // Test RULE 3 (FR-DE company) + $vat=get_default_tva($companyfr, $companyit, 0); + $this->assertEquals(0, $vat, 'RULE 3'); + + // Test RULE 4 (FR-DE not a company) + $vat=get_default_tva($companyfr, $notcompanyde, 0); + $this->assertEquals(20, $vat, 'RULE 4'); + + // Test RULE 5 (FR-US) + $vat=get_default_tva($companyfr, $companyus, 0); + $this->assertEquals(0, $vat, 'RULE 5'); + + + // We do same tests but with option SERVICE_ARE_ECOMMERCE_200238EC on. + $conf->global->SERVICE_ARE_ECOMMERCE_200238EC = 1; + + + // Test RULE 1 (FR-US) + $vat=get_default_tva($companyfr, $companyus, 0); + $this->assertEquals(0, $vat, 'RULE 1 ECOMMERCE_200238EC'); + + // Test RULE 2 (FR-FR) + $vat=get_default_tva($companyfr, $companyfr, 0); + $this->assertEquals(20, $vat, 'RULE 2 ECOMMERCE_200238EC'); + + // Test RULE 3 (FR-DE company) + $vat=get_default_tva($companyfr, $companyde, 0); + $this->assertEquals(0, $vat, 'RULE 3 ECOMMERCE_200238EC'); + + // Test RULE 4 (FR-DE not a company) + $vat=get_default_tva($companyfr, $notcompanyde, 0); + $this->assertEquals(19, $vat, 'RULE 4 ECOMMERCE_200238EC'); + + // Test RULE 5 (FR-US) + $vat=get_default_tva($companyfr, $companyus, 0); + $this->assertEquals(0, $vat, 'RULE 5 ECOMMERCE_200238EC'); + } + + /** + * testGetDefaultTva + * + * @return void + */ + public function testGetDefaultLocalTax() + { + global $conf,$user,$langs,$db; + $this->savconf=$conf; + $this->savuser=$user; + $this->savlangs=$langs; + $this->savdb=$db; + + $companyfrnovat=new Societe($db); + $companyfrnovat->country_code='FR'; + $companyfrnovat->tva_assuj=0; + $companyfrnovat->localtax1_assuj=0; + $companyfrnovat->localtax2_assuj=0; + + $companyes=new Societe($db); + $companyes->country_code='ES'; + $companyes->tva_assuj=1; + $companyes->localtax1_assuj=1; + $companyes->localtax2_assuj=1; + + $companymc=new Societe($db); + $companymc->country_code='MC'; + $companymc->tva_assuj=1; + $companymc->localtax1_assuj=0; + $companymc->localtax2_assuj=0; + + $companyit=new Societe($db); + $companyit->country_code='IT'; + $companyit->tva_assuj=1; + $companyit->tva_intra='IT99999'; + $companyit->localtax1_assuj=0; + $companyit->localtax2_assuj=0; + + $notcompanyit=new Societe($db); + $notcompanyit->country_code='IT'; + $notcompanyit->tva_assuj=1; + $notcompanyit->tva_intra=''; + $notcompanyit->typent_code='TE_PRIVATE'; + $notcompanyit->localtax1_assuj=0; + $notcompanyit->localtax2_assuj=0; + + $companyus=new Societe($db); + $companyus->country_code='US'; + $companyus->tva_assuj=1; + $companyus->tva_intra=''; + $companyus->localtax1_assuj=0; + $companyus->localtax2_assuj=0; + + // Test RULE FR-MC + $vat1=get_default_localtax($companyfrnovat, $companymc, 1, 0); + $vat2=get_default_localtax($companyfrnovat, $companymc, 2, 0); + $this->assertEquals(0, $vat1); + $this->assertEquals(0, $vat2); + + // Test RULE ES-ES + $vat1=get_default_localtax($companyes, $companyes, 1, 0); + $vat2=get_default_localtax($companyes, $companyes, 2, 0); + $this->assertEquals($vat1, 5.2); + $this->assertStringStartsWith((string) $vat2, '-19:-15:-9'); // Can be -19 (old version) or '-19:-15:-9' (new setup) + + // Test RULE ES-IT + $vat1=get_default_localtax($companyes, $companyit, 1, 0); + $vat2=get_default_localtax($companyes, $companyit, 2, 0); + $this->assertEquals(0, $vat1); + $this->assertEquals(0, $vat2); + + // Test RULE ES-IT + $vat1=get_default_localtax($companyes, $notcompanyit, 1, 0); + $vat2=get_default_localtax($companyes, $notcompanyit, 2, 0); + $this->assertEquals(0, $vat1); + $this->assertEquals(0, $vat2); + + // Test RULE FR-IT + // Not tested + + // Test RULE ES-US + $vat1=get_default_localtax($companyes, $companyus, 1, 0); + $vat2=get_default_localtax($companyes, $companyus, 2, 0); + $this->assertEquals(0, $vat1); + $this->assertEquals(0, $vat2); + } + + + /** + * testDolExplodeIntoArray + * + * @return void + */ + public function testDolExplodeIntoArray() + { + $stringtoexplode='AA=B/B.CC=.EE=FF.HH=GG;.'; + $tmp=dolExplodeIntoArray($stringtoexplode, '.', '='); + + print __METHOD__." tmp=".json_encode($tmp)."\n"; + $this->assertEquals('{"AA":"B\/B","CC":"","EE":"FF","HH":"GG;"}', json_encode($tmp)); + } + + /** + * dol_nl2br + * + * @return void + */ + public function testDolNl2Br() + { + + //String to encode + $string = "a\na"; + + $this->assertEquals(dol_nl2br($string), "a
    \na"); + + //With $forxml parameter + $this->assertEquals(dol_nl2br($string, 0, 1), "a
    \na"); + + //Replacing \n by br + $this->assertEquals(dol_nl2br($string, 1), "a
    a"); + + //With $forxml parameter + $this->assertEquals(dol_nl2br($string, 1, 1), "a
    a"); + } + + /** + * testDolPrice2Num + * + * @return boolean + */ + public function testDolPrice2Num() + { + global $langs, $conf; + + $oldlangs = $langs; + + $newlangs = new Translate('', $conf); + $newlangs->setDefaultLang('en_US'); + $newlangs->load("main"); + $langs = $newlangs; + + $this->assertEquals(150, price2num('(SELECT/**/CASE/**/WHEN/**/(0<1)/**/THEN/**/SLEEP(5)/**/ELSE/**/SLEEP(0)/**/END)')); + + $this->assertEquals(1000, price2num('1 000.0')); + $this->assertEquals(1000, price2num('1 000', 'MT')); + $this->assertEquals(1000, price2num('1 000', 'MU')); + + $this->assertEquals(1000.123456, price2num('1 000.123456')); + + // Round down + $this->assertEquals(1000.12, price2num('1 000.123452', 'MT')); + $this->assertEquals(1000.12345, price2num('1 000.123452', 'MU'), "Test MU"); + + // Round up + $this->assertEquals(1000.13, price2num('1 000.125456', 'MT')); + $this->assertEquals(1000.12546, price2num('1 000.125456', 'MU'), "Test MU"); + + $this->assertEquals(1, price2num('1.000'), 'Test 1.000 give 1 with english language'); + + // Text can't be converted + $this->assertEquals('12.4$', price2num('12.4$')); + $this->assertEquals('12.4$', price2num('12r.4$')); + + // For spanish language + $newlangs2 = new Translate('', $conf); + $newlangs2->setDefaultLang('es_ES'); + $newlangs2->load("main"); + $langs = $newlangs2; + + // Test with 3 chars after . or , + // If a . is used and there is 3 digits after, it is a thousand separator + $this->assertEquals(1234, price2num('1.234', '', 2), 'Test 1.234 give 1234 with spanish language if user input'); + $this->assertEquals(1.234, price2num('1,234', '', 2), 'Test 1,234 give 1234 with spanish language if user input'); + $this->assertEquals(1234, price2num('1 234', '', 2), 'Test 1 234 give 1234 with spanish language if user input'); + $this->assertEquals(-1.234, price2num('-1.234'), 'Test 1.234 give 1.234 with spanish language'); + $this->assertEquals(-1.234, price2num('-1,234'), 'Test 1,234 give 1234 with spanish language'); + $this->assertEquals(-1234, price2num('-1 234'), 'Test 1 234 give 1234 with spanish language'); + $this->assertEquals(21500123, price2num('21.500.123'), 'Test 21.500.123 give 21500123 with spanish language'); + $this->assertEquals(21500123, price2num('21500.123', 0, 2), 'Test 21500.123 give 21500123 with spanish language if user input'); + $this->assertEquals(21500.123, price2num('21500.123'), 'Test 21500.123 give 21500123 with spanish language'); + $this->assertEquals(21500.123, price2num('21500,123'), 'Test 21500,123 give 21500.123 with spanish language'); + // Test with 2 digits + $this->assertEquals(21500.12, price2num('21500.12'), 'Test 21500.12 give 21500.12 with spanish language'); + $this->assertEquals(21500.12, price2num('21500,12'), 'Test 21500,12 give 21500.12 with spanish language'); + // Test with 3 digits + $this->assertEquals(12123, price2num('12.123', '', 2), 'Test 12.123 give 12123 with spanish language if user input'); + $this->assertEquals(12.123, price2num('12,123', '', 2), 'Test 12,123 give 12.123 with spanish language if user input'); + $this->assertEquals(12.123, price2num('12.123'), 'Test 12.123 give 12.123 with spanish language'); + $this->assertEquals(12.123, price2num('12,123'), 'Test 12,123 give 12.123 with spanish language'); + + // For french language + $newlangs3 = new Translate('', $conf); + $newlangs3->setDefaultLang('fr_FR'); + $newlangs3->load("main"); + $langs = $newlangs3; + + $this->assertEquals(1, price2num('1.000', '', 2), 'Test 1.000 give 1 with french language if user input'); + $this->assertEquals(1, price2num('1.000'), 'Test 1.000 give 1 with french language'); + $this->assertEquals(1000, price2num('1 000'), 'Test 1.000 give 1 with french language'); + $this->assertEquals(1.234, price2num('1.234', '', 2), 'Test 1.234 give 1.234 with french language if user input'); + $this->assertEquals(1.234, price2num('1.234'), 'Test 1.234 give 1.234 with french language'); + $this->assertEquals(1.234, price2num('1,234', '', 2), 'Test 1,234 give 1.234 with french language if user input'); + $this->assertEquals(1.234, price2num('1,234'), 'Test 1,234 give 1.234 with french language'); + $this->assertEquals(21500000, price2num('21500 000'), 'Test 21500 000 give 21500000 with french language'); + $this->assertEquals(21500000, price2num('21 500 000'), 'Test 21 500 000 give 21500000 with french language'); + $this->assertEquals(21500, price2num('21500.00'), 'Test 21500.00 give 21500 with french language'); + $this->assertEquals(21500, price2num('21500,00'), 'Test 21500,00 give 21500 with french language'); + + $langs = $oldlangs; + + return true; + } + + /** + * testDolGetDate + * + * @return boolean + */ + public function testDolGetDate() + { + global $conf; + + $conf->global->MAIN_START_WEEK = 0; + + $tmp=dol_getdate(24*60*60+1); // 2/1/1970 and 1 second = friday + $this->assertEquals(5, $tmp['wday']); + + $conf->global->MAIN_START_WEEK = 1; + + $tmp=dol_getdate(1); // 1/1/1970 and 1 second = thirday + $this->assertEquals(4, $tmp['wday']); + + $tmp=dol_getdate(24*60*60+1); // 2/1/1970 and 1 second = friday + $this->assertEquals(5, $tmp['wday']); + + $tmp=dol_getdate(1, false, "Europe/Paris"); // 1/1/1970 and 1 second = thirday + $this->assertEquals(1970, $tmp['year']); + $this->assertEquals(1, $tmp['mon']); + $this->assertEquals(1, $tmp['mday']); + $this->assertEquals(4, $tmp['wday']); + $this->assertEquals(0, $tmp['yday']); + $this->assertEquals(1, $tmp['hours']); // We are winter, so we are GMT+1 even during summer + $this->assertEquals(0, $tmp['minutes']); + $this->assertEquals(1, $tmp['seconds']); + + $tmp=dol_getdate(15638401, false, "Europe/Paris"); // 1/7/1970 and 1 second = wednesday + $this->assertEquals(1970, $tmp['year']); + $this->assertEquals(7, $tmp['mon']); + $this->assertEquals(1, $tmp['mday']); + $this->assertEquals(3, $tmp['wday']); + $this->assertEquals(181, $tmp['yday']); + $this->assertEquals(1, $tmp['hours']); // There is no daylight in 1970, so we are GMT+1 even during summer + $this->assertEquals(0, $tmp['minutes']); + $this->assertEquals(1, $tmp['seconds']); + + $tmp=dol_getdate(1593561601, false, "Europe/Paris"); // 1/7/2020 and 1 second = wednesday + $this->assertEquals(2020, $tmp['year']); + $this->assertEquals(7, $tmp['mon']); + $this->assertEquals(1, $tmp['mday']); + $this->assertEquals(3, $tmp['wday']); + $this->assertEquals(182, $tmp['yday']); // 182 and not 181, due to the 29th february + $this->assertEquals(2, $tmp['hours']); // There is a daylight, so we are GMT+2 + $this->assertEquals(0, $tmp['minutes']); + $this->assertEquals(1, $tmp['seconds']); + + $conf->global->MAIN_USE_OLD_FUNCTIONS_FOR_GETDATE = 1; + + $tmp=dol_getdate(1); // 1/1/1970 and 1 second = thirday + $this->assertEquals(1970, $tmp['year']); + $this->assertEquals(1, $tmp['mon']); + $this->assertEquals(1, $tmp['mday']); + $this->assertEquals(4, $tmp['wday']); + $this->assertEquals(0, $tmp['yday']); + // We must disable this because on CI, timezone is may be UTC or something else + //$this->assertEquals(1, $tmp['hours']); // We are winter, so we are GMT+1 even during summer + $this->assertEquals(0, $tmp['minutes']); + $this->assertEquals(1, $tmp['seconds']); + + $tmp=dol_getdate(15638401); // 1/7/1970 and 1 second = wednesday + $this->assertEquals(1970, $tmp['year']); + $this->assertEquals(7, $tmp['mon']); + $this->assertEquals(1, $tmp['mday']); + $this->assertEquals(3, $tmp['wday']); + $this->assertEquals(181, $tmp['yday']); + // We must disable this because on CI, timezone is may be UTC or something else + //$this->assertEquals(1, $tmp['hours']); // There is no daylight in 1970, so we are GMT+1 even during summer + $this->assertEquals(0, $tmp['minutes']); + $this->assertEquals(1, $tmp['seconds']); + + $tmp=dol_getdate(1593561601); // 1/7/2020 and 1 second = wednesday + $this->assertEquals(2020, $tmp['year']); + $this->assertEquals(7, $tmp['mon']); + $this->assertEquals(1, $tmp['mday']); + $this->assertEquals(3, $tmp['wday']); + $this->assertEquals(182, $tmp['yday']); // 182 and not 181, due to the 29th february + // We must disable this because on CI, timezone is may be UTC or something else + //$this->assertEquals(2, $tmp['hours']); // There is a daylight, so we are GMT+2 + $this->assertEquals(0, $tmp['minutes']); + $this->assertEquals(1, $tmp['seconds']); + + return true; + } + + + /** + * testMakeSubstitutions + * + * @return boolean + */ + public function testMakeSubstitutions() + { + global $conf, $langs; + $langs->load("main"); + + $substit=array("AAA"=>'Not used', "BBB"=>'Not used', "CCC"=>"C replaced"); + $chaine='This is a string with __[MAIN_THEME]__ and __(DIRECTION)__ and __CCC__'; + $newstring = make_substitutions($chaine, $substit); + $this->assertEquals($newstring, 'This is a string with eldy and ltr and __C replaced__'); + + return true; + } + + /** + * testDolStringIsGoodIso + * + * @return boolean + */ + public function testDolStringIsGoodIso() + { + global $conf, $langs; + + $chaine='This is an ISO string'; + $result = dol_string_is_good_iso($chaine); + $this->assertEquals($result, 1); + + $chaine='This is a not ISO string '.chr(0); + $result = dol_string_is_good_iso($chaine); + $this->assertEquals($result, 0); + + return true; + } + + + /** + * testGetUserRemoteIP + * + * @return boolean + */ + public function testGetUserRemoteIP() + { + global $conf, $langs; + + $_SERVER['HTTP_X_FORWARDED_FOR']='1.2.3.4'; + $_SERVER['HTTP_CLIENT_IP']='5.6.7.8'; + $result = getUserRemoteIP(); + $this->assertEquals($result, '1.2.3.4'); + + $_SERVER['HTTP_X_FORWARDED_FOR']='1.2.3.4'; + $_SERVER['HTTP_CLIENT_IP']='5.6.7.8'; + $result = getUserRemoteIP(); + $this->assertEquals($result, '5.6.7.8'); + + $_SERVER['HTTP_X_FORWARDED_FOR']='[1:2:3:4]'; + $_SERVER['HTTP_CLIENT_IP']='5.6.7.8'; + $result = getUserRemoteIP(); + $this->assertEquals($result, '[1:2:3:4]'); + + return true; + } } diff --git a/test/phpunit/GetUrlLibTest.php b/test/phpunit/GetUrlLibTest.php index 268122c8d48..97878ef9589 100644 --- a/test/phpunit/GetUrlLibTest.php +++ b/test/phpunit/GetUrlLibTest.php @@ -30,11 +30,10 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/geturl.lib.php'; -if (empty($user->id)) -{ - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); +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; @@ -48,202 +47,202 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class GetUrlLibTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return FilesLibTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return FilesLibTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testGetRootURLFromURL - * - * @return int - */ - public function testGetRootURLFromURL() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testGetRootURLFromURL + * + * @return int + */ + public function testGetRootURLFromURL() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=getRootURLFromURL('http://www.dolimed.com/screenshots/afile'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('http://www.dolimed.com', $result, 'Test 1'); + $result=getRootURLFromURL('http://www.dolimed.com/screenshots/afile'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('http://www.dolimed.com', $result, 'Test 1'); - $result=getRootURLFromURL('https://www.dolimed.com/screenshots/afile'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('https://www.dolimed.com', $result, 'Test 2'); + $result=getRootURLFromURL('https://www.dolimed.com/screenshots/afile'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('https://www.dolimed.com', $result, 'Test 2'); - $result=getRootURLFromURL('http://www.dolimed.com/screenshots'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('http://www.dolimed.com', $result); + $result=getRootURLFromURL('http://www.dolimed.com/screenshots'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('http://www.dolimed.com', $result); - $result=getRootURLFromURL('https://www.dolimed.com/screenshots'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('https://www.dolimed.com', $result); + $result=getRootURLFromURL('https://www.dolimed.com/screenshots'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('https://www.dolimed.com', $result); - $result=getRootURLFromURL('http://www.dolimed.com/'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('http://www.dolimed.com', $result); + $result=getRootURLFromURL('http://www.dolimed.com/'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('http://www.dolimed.com', $result); - $result=getRootURLFromURL('https://www.dolimed.com/'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('https://www.dolimed.com', $result); + $result=getRootURLFromURL('https://www.dolimed.com/'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('https://www.dolimed.com', $result); - $result=getRootURLFromURL('http://www.dolimed.com'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('http://www.dolimed.com', $result); + $result=getRootURLFromURL('http://www.dolimed.com'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('http://www.dolimed.com', $result); - $result=getRootURLFromURL('https://www.dolimed.com'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('https://www.dolimed.com', $result); + $result=getRootURLFromURL('https://www.dolimed.com'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('https://www.dolimed.com', $result); - return 1; - } + return 1; + } - /** - * testGetDomainFromURL - * - * @return int - */ - public function testGetDomainFromURL() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testGetDomainFromURL + * + * @return int + */ + public function testGetDomainFromURL() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=getDomainFromURL('http://localhost'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('localhost', $result, 'Test 0a'); + $result=getDomainFromURL('http://localhost'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('localhost', $result, 'Test 0a'); - $result=getDomainFromURL('http://localhost', 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('localhost', $result, 'Test 0b'); + $result=getDomainFromURL('http://localhost', 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('localhost', $result, 'Test 0b'); - $result=getDomainFromURL('https://dolimed.com'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('dolimed', $result, 'Test 1'); + $result=getDomainFromURL('https://dolimed.com'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('dolimed', $result, 'Test 1'); - $result=getDomainFromURL('http://www.dolimed.com/screenshots/afile'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('dolimed', $result, 'Test 2'); + $result=getDomainFromURL('http://www.dolimed.com/screenshots/afile'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('dolimed', $result, 'Test 2'); - $result=getDomainFromURL('http://www.with.dolimed.com/screenshots/afile'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('dolimed', $result, 'Test 3'); + $result=getDomainFromURL('http://www.with.dolimed.com/screenshots/afile'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('dolimed', $result, 'Test 3'); - $result=getDomainFromURL('https://dolimed.com', 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('dolimed.com', $result, 'Test 4'); + $result=getDomainFromURL('https://dolimed.com', 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('dolimed.com', $result, 'Test 4'); - $result=getDomainFromURL('http://www.dolimed.com/screenshots/afile', 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('dolimed.com', $result, 'Test 5'); + $result=getDomainFromURL('http://www.dolimed.com/screenshots/afile', 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('dolimed.com', $result, 'Test 5'); - $result=getDomainFromURL('http://www.with.dolimed.com/screenshots/afile', 1); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('dolimed.com', $result, 'Test 6'); + $result=getDomainFromURL('http://www.with.dolimed.com/screenshots/afile', 1); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('dolimed.com', $result, 'Test 6'); - return 1; - } + return 1; + } - /** - * testRemoveHtmlComment - * - * @return int - */ - public function testRemoveHtmlComment() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testRemoveHtmlComment + * + * @return int + */ + public function testRemoveHtmlComment() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result=removeHtmlComment('abcdef'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('abcdef', $result, 'Test 1'); + $result=removeHtmlComment('abcdef'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('abcdef', $result, 'Test 1'); - $result=removeHtmlComment('abcbbdef'); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('abcbbdef', $result, 'Test 1'); + $result=removeHtmlComment('abcbbdef'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('abcbbdef', $result, 'Test 1'); - return 1; - } + return 1; + } } diff --git a/test/phpunit/HolidayTest.php b/test/phpunit/HolidayTest.php index e7ad436b586..bba5d68c41e 100644 --- a/test/phpunit/HolidayTest.php +++ b/test/phpunit/HolidayTest.php @@ -30,11 +30,10 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/holiday/class/holiday.class.php'; $langs->load("dict"); -if (empty($user->id)) -{ - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); +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; @@ -49,324 +48,324 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class HolidayTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return HolidayTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return HolidayTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + /** + * setUpBeforeClass + * + * @return void + */ + 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. + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testHolidayCreate - * - * @return int - */ - public function testHolidayCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testHolidayCreate + * + * @return int + */ + public function testHolidayCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Holiday($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user); + $localobject=new Holiday($this->savdb); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $result; - } + return $result; + } - /** - * testHolidayFetch - * - * @param int $id Id of Holiday - * @return int - * @depends testHolidayCreate - * The depends says test is run only if previous is ok - */ - public function testHolidayFetch($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testHolidayFetch + * + * @param int $id Id of Holiday + * @return int + * @depends testHolidayCreate + * The depends says test is run only if previous is ok + */ + public function testHolidayFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Holiday($this->savdb); - $result=$localobject->fetch($id); + $localobject=new Holiday($this->savdb); + $result=$localobject->fetch($id); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject; - } + return $localobject; + } - /** - * testHolidayUpdate - * - * @param Holiday $localobject Holiday - * @return int - * - * @depends testHolidayFetch - * The depends says test is run only if previous is ok - */ - public function testHolidayUpdate($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testHolidayUpdate + * + * @param Holiday $localobject Holiday + * @return int + * + * @depends testHolidayFetch + * The depends says test is run only if previous is ok + */ + public function testHolidayUpdate($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject->oldcopy = clone $localobject; + $localobject->oldcopy = clone $localobject; - $localobject->note_private='New private note after update'; - $localobject->note_public='New public note after update'; - $localobject->lastname='New name'; - $localobject->firstname='New firstname'; - $localobject->address='New address'; - $localobject->zip='New zip'; - $localobject->town='New town'; - $localobject->country_id=2; - //$localobject->status=0; - $localobject->phone_pro='New tel pro'; - $localobject->phone_perso='New tel perso'; - $localobject->phone_mobile='New tel mobile'; - $localobject->fax='New fax'; - $localobject->email='newemail@newemail.com'; - $localobject->jabberid='New im id'; - $localobject->default_lang='es_ES'; + $localobject->note_private='New private note after update'; + $localobject->note_public='New public note after update'; + $localobject->lastname='New name'; + $localobject->firstname='New firstname'; + $localobject->address='New address'; + $localobject->zip='New zip'; + $localobject->town='New town'; + $localobject->country_id=2; + //$localobject->status=0; + $localobject->phone_pro='New tel pro'; + $localobject->phone_perso='New tel perso'; + $localobject->phone_mobile='New tel mobile'; + $localobject->fax='New fax'; + $localobject->email='newemail@newemail.com'; + $localobject->jabberid='New im id'; + $localobject->default_lang='es_ES'; - $result=$localobject->update($localobject->id, $user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0, 'Holiday::update error'); + $result=$localobject->update($localobject->id, $user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0, 'Holiday::update error'); - $result=$localobject->update_note($localobject->note_private, '_private'); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0, 'Holiday::update_note (private) error'); + $result=$localobject->update_note($localobject->note_private, '_private'); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0, 'Holiday::update_note (private) error'); - $result=$localobject->update_note($localobject->note_public, '_public'); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0, 'Holiday::update_note (public) error'); + $result=$localobject->update_note($localobject->note_public, '_public'); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0, 'Holiday::update_note (public) error'); - $newobject=new Holiday($this->savdb); - $result=$newobject->fetch($localobject->id); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0, 'Holiday::fetch error'); + $newobject=new Holiday($this->savdb); + $result=$newobject->fetch($localobject->id); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0, 'Holiday::fetch error'); - print __METHOD__." old=".$localobject->note." new=".$newobject->note."\n"; - $this->assertEquals($localobject->note, $newobject->note, 'Holiday::update_note error compare note'); - //print __METHOD__." old=".$localobject->note_public." new=".$newobject->note_public."\n"; - //$this->assertEquals($localobject->note_public, $newobject->note_public); + print __METHOD__." old=".$localobject->note." new=".$newobject->note."\n"; + $this->assertEquals($localobject->note, $newobject->note, 'Holiday::update_note error compare note'); + //print __METHOD__." old=".$localobject->note_public." new=".$newobject->note_public."\n"; + //$this->assertEquals($localobject->note_public, $newobject->note_public); - return $localobject; - } + return $localobject; + } - /** - * testHolidayOther - * - * @param Holiday $localobject Holiday - * @return void - * - * @depends testHolidayUpdate - * The depends says test is run only if previous is ok - */ - public function testHolidayOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testHolidayOther + * + * @param Holiday $localobject Holiday + * @return void + * + * @depends testHolidayUpdate + * The depends says test is run only if previous is ok + */ + public function testHolidayOther($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $result = $localobject->fetchUsers(true, true, ''); - $this->assertNotEquals($result, -1); + $result = $localobject->fetchUsers(true, true, ''); + $this->assertNotEquals($result, -1); - $result = $localobject->fetchUsers(true, false, ''); - $this->assertNotEquals($result, -1); + $result = $localobject->fetchUsers(true, false, ''); + $this->assertNotEquals($result, -1); - $result = $localobject->fetchUsers(false, true, ''); - $this->assertNotEquals($result, -1); + $result = $localobject->fetchUsers(false, true, ''); + $this->assertNotEquals($result, -1); - $result = $localobject->fetchUsers(false, false, ''); - $this->assertNotEquals($result, -1); + $result = $localobject->fetchUsers(false, false, ''); + $this->assertNotEquals($result, -1); - return $localobject->id; - } + return $localobject->id; + } - /** - * testHolidayDelete - * - * @param int $id Id of Holiday - * @return void - * - * @depends testHolidayOther - * The depends says test is run only if previous is ok - */ - public function testHolidayDelete($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testHolidayDelete + * + * @param int $id Id of Holiday + * @return void + * + * @depends testHolidayOther + * The depends says test is run only if previous is ok + */ + public function testHolidayDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Holiday($this->savdb); - $result=$localobject->fetch($id); + $localobject=new Holiday($this->savdb); + $result=$localobject->fetch($id); - $result=$localobject->delete(0); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $result=$localobject->delete(0); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $result; - } + return $result; + } - /** - * testVerifDateHolidayCP - * - * @return void - */ - public function testVerifDateHolidayCP() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testVerifDateHolidayCP + * + * @return void + */ + public function testVerifDateHolidayCP() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - // Create a leave request the 1st morning only - $localobjecta=new Holiday($this->savdb); - $localobjecta->initAsSpecimen(); - $localobjecta->date_debut = dol_mktime(0, 0, 0, 1, 1, 2020); - $localobjecta->date_fin = dol_mktime(0, 0, 0, 1, 1, 2020); - $localobjecta->halfday = 1; - $result=$localobjecta->create($user); + // Create a leave request the 1st morning only + $localobjecta=new Holiday($this->savdb); + $localobjecta->initAsSpecimen(); + $localobjecta->date_debut = dol_mktime(0, 0, 0, 1, 1, 2020); + $localobjecta->date_fin = dol_mktime(0, 0, 0, 1, 1, 2020); + $localobjecta->halfday = 1; + $result=$localobjecta->create($user); - // Create a leave request the 2 afternoon only - $localobjectb=new Holiday($this->savdb); - $localobjectb->initAsSpecimen(); - $localobjectb->date_debut = dol_mktime(0, 0, 0, 1, 2, 2020); - $localobjectb->date_fin = dol_mktime(0, 0, 0, 1, 2, 2020); - $localobjectb->halfday = -1; - $result=$localobjectb->create($user); + // Create a leave request the 2 afternoon only + $localobjectb=new Holiday($this->savdb); + $localobjectb->initAsSpecimen(); + $localobjectb->date_debut = dol_mktime(0, 0, 0, 1, 2, 2020); + $localobjectb->date_fin = dol_mktime(0, 0, 0, 1, 2, 2020); + $localobjectb->halfday = -1; + $result=$localobjectb->create($user); - $date_debut = dol_mktime(0, 0, 0, 1, 1, 2020); - $date_fin = dol_mktime(0, 0, 0, 1, 2, 2020); + $date_debut = dol_mktime(0, 0, 0, 1, 1, 2020); + $date_fin = dol_mktime(0, 0, 0, 1, 2, 2020); - $localobjectc=new Holiday($this->savdb); + $localobjectc=new Holiday($this->savdb); - $result=$localobjectc->verifDateHolidayCP($user->id, $date_debut, $date_debut, 0); - $this->assertFalse($result, 'result should be false, there is overlapping, full day is not available.'); - $result=$localobjectc->verifDateHolidayCP($user->id, $date_debut, $date_fin, 0); - $this->assertFalse($result, 'result should be false, there is overlapping, full day is not available.'); - $result=$localobjectc->verifDateHolidayCP($user->id, $date_fin, $date_fin, 0); - $this->assertFalse($result, 'result should be false, there is overlapping, full day is not available.'); + $result=$localobjectc->verifDateHolidayCP($user->id, $date_debut, $date_debut, 0); + $this->assertFalse($result, 'result should be false, there is overlapping, full day is not available.'); + $result=$localobjectc->verifDateHolidayCP($user->id, $date_debut, $date_fin, 0); + $this->assertFalse($result, 'result should be false, there is overlapping, full day is not available.'); + $result=$localobjectc->verifDateHolidayCP($user->id, $date_fin, $date_fin, 0); + $this->assertFalse($result, 'result should be false, there is overlapping, full day is not available.'); - $result=$localobjectc->verifDateHolidayCP($user->id, $date_debut, $date_debut, 1); - $this->assertFalse($result, 'result should be false, there is overlapping, morning of first day is not available.'); - $result=$localobjectc->verifDateHolidayCP($user->id, $date_debut, $date_fin, 1); - $this->assertFalse($result, 'result should be false, there is overlapping, morning of first day is not available.'); - $result=$localobjectc->verifDateHolidayCP($user->id, $date_fin, $date_fin, 1); - $this->assertTrue($result, 'result should be true, there is no overlapping'); + $result=$localobjectc->verifDateHolidayCP($user->id, $date_debut, $date_debut, 1); + $this->assertFalse($result, 'result should be false, there is overlapping, morning of first day is not available.'); + $result=$localobjectc->verifDateHolidayCP($user->id, $date_debut, $date_fin, 1); + $this->assertFalse($result, 'result should be false, there is overlapping, morning of first day is not available.'); + $result=$localobjectc->verifDateHolidayCP($user->id, $date_fin, $date_fin, 1); + $this->assertTrue($result, 'result should be true, there is no overlapping'); - $result=$localobjectc->verifDateHolidayCP($user->id, $date_debut, $date_debut, -1); - $this->assertTrue($result, 'result should be true, there is no overlapping'); - $result=$localobjectc->verifDateHolidayCP($user->id, $date_debut, $date_fin, -1); - $this->assertFalse($result, 'result should be false, there is overlapping, afternoon of second day is not available'); - $result=$localobjectc->verifDateHolidayCP($user->id, $date_fin, $date_fin, -1); - $this->assertFalse($result, 'result should be false, there is overlapping, afternoon of second day is not available'); + $result=$localobjectc->verifDateHolidayCP($user->id, $date_debut, $date_debut, -1); + $this->assertTrue($result, 'result should be true, there is no overlapping'); + $result=$localobjectc->verifDateHolidayCP($user->id, $date_debut, $date_fin, -1); + $this->assertFalse($result, 'result should be false, there is overlapping, afternoon of second day is not available'); + $result=$localobjectc->verifDateHolidayCP($user->id, $date_fin, $date_fin, -1); + $this->assertFalse($result, 'result should be false, there is overlapping, afternoon of second day is not available'); - $result=$localobjectc->verifDateHolidayCP($user->id, $date_debut, $date_fin, 2); // start afternoon and end morning - $this->assertTrue($result, 'result should be true, there is no overlapping'); - } + $result=$localobjectc->verifDateHolidayCP($user->id, $date_debut, $date_fin, 2); // start afternoon and end morning + $this->assertTrue($result, 'result should be true, there is no overlapping'); + } - /** - * testUpdateBalance - * - * @return void - */ - public function testUpdateBalance() - { - $localobjecta=new Holiday($this->savdb); + /** + * testUpdateBalance + * + * @return void + */ + public function testUpdateBalance() + { + $localobjecta=new Holiday($this->savdb); - $localobjecta->updateConfCP('lastUpdate', '20100101120000'); - $result = $localobjecta->updateBalance(); - $this->assertEquals($result, 1); - } + $localobjecta->updateConfCP('lastUpdate', '20100101120000'); + $result = $localobjecta->updateBalance(); + $this->assertEquals($result, 1); + } } diff --git a/test/phpunit/ImagesLibTest.php b/test/phpunit/ImagesLibTest.php index 3bfb676f3be..d50d90b9069 100644 --- a/test/phpunit/ImagesLibTest.php +++ b/test/phpunit/ImagesLibTest.php @@ -30,8 +30,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/images.lib.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -76,81 +75,81 @@ class ImagesLibTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testDolCountNbOfLine - * - * @return int - */ - public function testgetImageSize() - { + /** + * testDolCountNbOfLine + * + * @return int + */ + public function testgetImageSize() + { $file=dirname(__FILE__).'/img250x50.jpg'; $tmp=dol_getImageSize($file); - print __METHOD__." result=".$tmp['width'].'/'.$tmp['height']."\n"; + print __METHOD__." result=".$tmp['width'].'/'.$tmp['height']."\n"; $this->assertEquals($tmp['width'], 250); $this->assertEquals($tmp['height'], 50); $file=dirname(__FILE__).'/img250x20.png'; $tmp=dol_getImageSize($file); - print __METHOD__." result=".$tmp['width'].'/'.$tmp['height']."\n"; + print __METHOD__." result=".$tmp['width'].'/'.$tmp['height']."\n"; $this->assertEquals($tmp['width'], 250); $this->assertEquals($tmp['height'], 20); /*$file=dirname(__FILE__).'/filenotfound.png'; $tmp=dol_getImageSize($file); - print __METHOD__." result=".$tmp['width'].'/'.$tmp['height']."\n"; + print __METHOD__." result=".$tmp['width'].'/'.$tmp['height']."\n"; $this->assertEquals($tmp['width'],250); $this->assertEquals($tmp['height'],20);*/ return 1; - } + } } diff --git a/test/phpunit/ImportTest.php b/test/phpunit/ImportTest.php index e9bf019740c..1dd0853829c 100644 --- a/test/phpunit/ImportTest.php +++ b/test/phpunit/ImportTest.php @@ -28,16 +28,36 @@ global $conf,$user,$langs,$db; //require_once 'PHPUnit/Autoload.php'; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); -if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +if (! defined('NOREQUIREUSER')) { + define('NOREQUIREUSER', '1'); +} +if (! defined('NOREQUIREDB')) { + define('NOREQUIREDB', '1'); +} +if (! defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (! defined('NOREQUIRETRAN')) { + define('NOREQUIRETRAN', '1'); +} +if (! defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (! defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (! defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); // If there is no menu to show +} +if (! defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +} +if (! defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (! defined("NOLOGIN")) { + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +} /** @@ -77,71 +97,71 @@ class ImportTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testImportSample1 - * - * @return boolean - */ - public function testImportSample1() - { - $file=dirname(__FILE__).'/Example_import_company_1.csv'; + /** + * testImportSample1 + * + * @return boolean + */ + public function testImportSample1() + { + $file=dirname(__FILE__).'/Example_import_company_1.csv'; - // TODO - // Run import on file and check the record with field "auto" are filled - // according to option - $this->assertEquals(0, 0); + // TODO + // Run import on file and check the record with field "auto" are filled + // according to option + $this->assertEquals(0, 0); return true; - } + } } diff --git a/test/phpunit/JsonLibTest.php b/test/phpunit/JsonLibTest.php index 7d2678b0ec7..ddb62a90204 100644 --- a/test/phpunit/JsonLibTest.php +++ b/test/phpunit/JsonLibTest.php @@ -28,16 +28,36 @@ global $conf,$user,$langs,$db; //require_once 'PHPUnit/Autoload.php'; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); -if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +if (! defined('NOREQUIREUSER')) { + define('NOREQUIREUSER', '1'); +} +if (! defined('NOREQUIREDB')) { + define('NOREQUIREDB', '1'); +} +if (! defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (! defined('NOREQUIRETRAN')) { + define('NOREQUIRETRAN', '1'); +} +if (! defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (! defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (! defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); // If there is no menu to show +} +if (! defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +} +if (! defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (! defined("NOLOGIN")) { + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +} /** @@ -49,133 +69,133 @@ if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page i */ class JsonLibTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return CoreTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return CoreTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - //$db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + //$db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testJsonEncode - * - * @return void - */ - public function testJsonEncode() - { - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + /** + * testJsonEncode + * + * @return void + */ + public function testJsonEncode() + { + //$this->sharedFixture + global $conf,$user,$langs,$db; + $this->savconf=$conf; + $this->savuser=$user; + $this->savlangs=$langs; + $this->savdb=$db; - // Do a test with an array starting with 0 - $arraytotest=array(0=>array('key'=>1,'value'=>'PRODREF','label'=>'Product ref with é and special chars \\ \' "')); - $arrayencodedexpected='[{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}]'; + // Do a test with an array starting with 0 + $arraytotest=array(0=>array('key'=>1,'value'=>'PRODREF','label'=>'Product ref with é and special chars \\ \' "')); + $arrayencodedexpected='[{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}]'; - $encoded=json_encode($arraytotest); - $this->assertEquals($arrayencodedexpected, $encoded); - $decoded=json_decode($encoded, true); - $this->assertEquals($arraytotest, $decoded, 'test for json_xxx'); + $encoded=json_encode($arraytotest); + $this->assertEquals($arrayencodedexpected, $encoded); + $decoded=json_decode($encoded, true); + $this->assertEquals($arraytotest, $decoded, 'test for json_xxx'); - $encoded=dol_json_encode($arraytotest); - $this->assertEquals($arrayencodedexpected, $encoded); - $decoded=dol_json_decode($encoded, true); - $this->assertEquals($arraytotest, $decoded, 'test for dol_json_xxx'); + $encoded=dol_json_encode($arraytotest); + $this->assertEquals($arrayencodedexpected, $encoded); + $decoded=dol_json_decode($encoded, true); + $this->assertEquals($arraytotest, $decoded, 'test for dol_json_xxx'); - // Same test but array start with 2 instead of 0 - $arraytotest=array(2=>array('key'=>1,'value'=>'PRODREF','label'=>'Product ref with é and special chars \\ \' "')); - $arrayencodedexpected='{"2":{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}}'; + // Same test but array start with 2 instead of 0 + $arraytotest=array(2=>array('key'=>1,'value'=>'PRODREF','label'=>'Product ref with é and special chars \\ \' "')); + $arrayencodedexpected='{"2":{"key":1,"value":"PRODREF","label":"Product ref with \u00e9 and special chars \\\\ \' \""}}'; - $encoded=json_encode($arraytotest); - $this->assertEquals($arrayencodedexpected, $encoded); - $decoded=json_decode($encoded, true); - $this->assertEquals($arraytotest, $decoded, 'test for json_xxx'); + $encoded=json_encode($arraytotest); + $this->assertEquals($arrayencodedexpected, $encoded); + $decoded=json_decode($encoded, true); + $this->assertEquals($arraytotest, $decoded, 'test for json_xxx'); - $encoded=dol_json_encode($arraytotest); - $this->assertEquals($arrayencodedexpected, $encoded); - $decoded=dol_json_decode($encoded, true); - $this->assertEquals($arraytotest, $decoded, 'test for dol_json_xxx'); + $encoded=dol_json_encode($arraytotest); + $this->assertEquals($arrayencodedexpected, $encoded); + $decoded=dol_json_decode($encoded, true); + $this->assertEquals($arraytotest, $decoded, 'test for dol_json_xxx'); - // Test with object - $now=gmmktime(12, 0, 0, 1, 1, 1970); - $objecttotest=new stdClass(); - $objecttotest->property1='abc'; - $objecttotest->property2=1234; - $objecttotest->property3=$now; - $encoded=dol_json_encode($objecttotest); - $this->assertEquals('{"property1":"abc","property2":1234,"property3":43200}', $encoded); - } + // Test with object + $now=gmmktime(12, 0, 0, 1, 1, 1970); + $objecttotest=new stdClass(); + $objecttotest->property1='abc'; + $objecttotest->property2=1234; + $objecttotest->property3=$now; + $encoded=dol_json_encode($objecttotest); + $this->assertEquals('{"property1":"abc","property2":1234,"property3":43200}', $encoded); + } } diff --git a/test/phpunit/LangTest.php b/test/phpunit/LangTest.php index 1c1f8ed0e8a..ad76667d560 100644 --- a/test/phpunit/LangTest.php +++ b/test/phpunit/LangTest.php @@ -30,22 +30,41 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/security.lib.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/security2.lib.php'; -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); -if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +if (! defined('NOREQUIREUSER')) { + define('NOREQUIREUSER', '1'); +} +if (! defined('NOREQUIREDB')) { + define('NOREQUIREDB', '1'); +} +if (! defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (! defined('NOREQUIRETRAN')) { + define('NOREQUIRETRAN', '1'); +} +if (! defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (! defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (! defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); // If there is no menu to show +} +if (! defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +} +if (! defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (! defined("NOLOGIN")) { + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +} -if (empty($user->id)) -{ - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); +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; @@ -87,81 +106,82 @@ class LangTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testLang - * - * @return string - */ - public function testLang() - { - global $conf,$user,$langs,$db; + /** + * testLang + * + * @return string + */ + public function testLang() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - include_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php'; + include_once DOL_DOCUMENT_ROOT.'/core/class/translate.class.php'; $filesarray = scandir(DOL_DOCUMENT_ROOT.'/langs'); - foreach ($filesarray as $key => $code) - { - if (! preg_match('/^[a-z]+_[A-Z]+$/', $code)) continue; + foreach ($filesarray as $key => $code) { + if (! preg_match('/^[a-z]+_[A-Z]+$/', $code)) { + continue; + } print 'Check language file for lang code='.$code."\n"; $tmplangs=new Translate('', $conf); - $langcode=$code; - $tmplangs->setDefaultLang($langcode); + $langcode=$code; + $tmplangs->setDefaultLang($langcode); $tmplangs->load("main"); $result=$tmplangs->transnoentitiesnoconv("SeparatorDecimal"); @@ -201,29 +221,29 @@ class LangTest extends PHPUnit\Framework\TestCase } } - return; - } + return; + } - /** - * testTrans - * - * @return string - */ - public function testTrans() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testTrans + * + * @return string + */ + public function testTrans() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $tmplangs=new Translate('', $conf); - $langcode='en_US'; - $tmplangs->setDefaultLang($langcode); - $tmplangs->load("main"); + $tmplangs=new Translate('', $conf); + $langcode='en_US'; + $tmplangs->setDefaultLang($langcode); + $tmplangs->load("main"); - $result = $tmplangs->trans("FilterOnInto", "assertEquals($result, "Search criteria '<input autofocus onfocus='alert(1337)' <--!' into fields ", 'Result of lang->trans must have original translation string with its original HTML tag, but inserted values must be fully encoded.'); - } + $result = $tmplangs->trans("FilterOnInto", "assertEquals($result, "Search criteria '<input autofocus onfocus='alert(1337)' <--!' into fields ", 'Result of lang->trans must have original translation string with its original HTML tag, but inserted values must be fully encoded.'); + } } diff --git a/test/phpunit/LesscTest.php b/test/phpunit/LesscTest.php index a4ce302c540..691d413d020 100644 --- a/test/phpunit/LesscTest.php +++ b/test/phpunit/LesscTest.php @@ -30,22 +30,41 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/security.lib.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/security2.lib.php'; -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); -if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +if (! defined('NOREQUIREUSER')) { + define('NOREQUIREUSER', '1'); +} +if (! defined('NOREQUIREDB')) { + define('NOREQUIREDB', '1'); +} +if (! defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (! defined('NOREQUIRETRAN')) { + define('NOREQUIRETRAN', '1'); +} +if (! defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (! defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (! defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); // If there is no menu to show +} +if (! defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +} +if (! defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (! defined("NOLOGIN")) { + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +} -if (empty($user->id)) -{ - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); +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; @@ -87,92 +106,92 @@ class LesscTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testLess - * - * @return string - */ - public function testLessc() - { - global $conf,$user,$langs,$db; + /** + * testLess + * + * @return string + */ + public function testLessc() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - include_once DOL_DOCUMENT_ROOT.'/core/class/lessc.class.php'; + include_once DOL_DOCUMENT_ROOT.'/core/class/lessc.class.php'; - $lesscobj = new Lessc(); + $lesscobj = new Lessc(); - $cssfile = " + $cssfile = " a { font-size: 10px; } b .test { font-size: 10px; } "; - try { - $contentforlessc = ".bodywebsite {\n".$cssfile."\n}\n"; - //print '
    '.$contentforlessc.'
    '; - $result = $lesscobj->compile($contentforlessc); - //var_dump($contentforlessc); exit; - } catch (exception $e) { - //echo "failed to compile lessc"; - dol_syslog("Failed to compile the CSS with lessc: ".$e->getMessage(), LOG_WARNING); - } + try { + $contentforlessc = ".bodywebsite {\n".$cssfile."\n}\n"; + //print '
    '.$contentforlessc.'
    '; + $result = $lesscobj->compile($contentforlessc); + //var_dump($contentforlessc); exit; + } catch (exception $e) { + //echo "failed to compile lessc"; + dol_syslog("Failed to compile the CSS with lessc: ".$e->getMessage(), LOG_WARNING); + } - $cssexpected = " + $cssexpected = " .bodywebsite a { font-size: 10px; } @@ -184,6 +203,6 @@ class LesscTest extends PHPUnit\Framework\TestCase print __METHOD__." SeparatorDecimal=".$result."\n"; $this->assertEquals(trim($result), trim($cssexpected)); - return; - } + return; + } } diff --git a/test/phpunit/LoanTest.php b/test/phpunit/LoanTest.php index 253e779ac03..653af07bc2b 100644 --- a/test/phpunit/LoanTest.php +++ b/test/phpunit/LoanTest.php @@ -29,8 +29,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/loan/class/loan.class.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -75,39 +74,39 @@ class LoanTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + protected function setUp() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -115,111 +114,111 @@ class LoanTest extends PHPUnit\Framework\TestCase print __METHOD__."\n"; //print $db->getVersion()."\n"; - } + } /** * End phpunit tests * * @return void */ - protected function tearDown() - { - print __METHOD__."\n"; - } - - /** - * testLoanCreate - * - * @return void - */ - public function testLoanCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; - - $localobject=new Loan($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user); - - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; - return $result; - } - - /** - * testLoanFetch - * - * @param int $id Id of object - * @return void - * - * @depends testLoanCreate - * The depends says test is run only if previous is ok - */ - public function testLoanFetch($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; - - $localobject=new Loan($this->savdb); - $result=$localobject->fetch($id); - - $this->assertLessThan($result, 0); - print __METHOD__." id=".$id." result=".$result."\n"; - return $localobject; - } + protected function tearDown() + { + print __METHOD__."\n"; + } /** - * testLoanOther - * - * @param Loan $localobject Loan - * @return int - * - * @depends testLoanFetch - * The depends says test is run only if previous is ok - */ - public function testLoanOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; - - $result=$localobject->set_paid($user); - - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject->id; - } - - /** - * testLoanDelete - * - * @param int $id Id of loan - * @return void - * - * @depends testLoanCreate - * The depends says test is run only if previous is ok - */ - public function testLoanDelete($id) - { - global $conf,$user,$langs,$db; + * testLoanCreate + * + * @return void + */ + public function testLoanCreate() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Loan($this->savdb); - $result=$localobject->fetch($id); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); + + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + return $result; + } + + /** + * testLoanFetch + * + * @param int $id Id of object + * @return void + * + * @depends testLoanCreate + * The depends says test is run only if previous is ok + */ + public function testLoanFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new Loan($this->savdb); + $result=$localobject->fetch($id); + + $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + return $localobject; + } + + /** + * testLoanOther + * + * @param Loan $localobject Loan + * @return int + * + * @depends testLoanFetch + * The depends says test is run only if previous is ok + */ + public function testLoanOther($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $result=$localobject->set_paid($user); + + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject->id; + } + + /** + * testLoanDelete + * + * @param int $id Id of loan + * @return void + * + * @depends testLoanCreate + * The depends says test is run only if previous is ok + */ + public function testLoanDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new Loan($this->savdb); + $result=$localobject->fetch($id); $result=$localobject->delete($user); print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $result; - } + $this->assertLessThan($result, 0); + return $result; + } } diff --git a/test/phpunit/MarginsLibTest.php b/test/phpunit/MarginsLibTest.php index e451262546d..1c7553eb76f 100644 --- a/test/phpunit/MarginsLibTest.php +++ b/test/phpunit/MarginsLibTest.php @@ -29,8 +29,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/margin/lib/margins.lib.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -74,65 +73,65 @@ class MarginsLibTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testGetMarginInfos - * - * @return void - */ - public function testGetMarginInfos() - { - global $conf,$user,$langs,$db; + /** + * testGetMarginInfos + * + * @return void + */ + public function testGetMarginInfos() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -156,5 +155,5 @@ class MarginsLibTest extends PHPUnit\Framework\TestCase $this->assertEquals(1/9*100, $result[2]); return 0; - } + } } diff --git a/test/phpunit/ModulesTest.php b/test/phpunit/ModulesTest.php index 32652200c2c..79e3013ae11 100755 --- a/test/phpunit/ModulesTest.php +++ b/test/phpunit/ModulesTest.php @@ -28,8 +28,7 @@ global $conf,$user,$langs,$db; //require_once 'PHPUnit/Autoload.php'; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -74,64 +73,64 @@ class ModulesTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testModulesInit - * - * @return int - */ - public function testModulesInit() - { - global $conf,$user,$langs,$db; + /** + * testModulesInit + * + * @return int + */ + public function testModulesInit() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -144,22 +143,20 @@ class ModulesTest extends PHPUnit\Framework\TestCase 'Mailing','MailmanSpip','Margin','ModuleBuilder','MultiCurrency', 'Notification','Oauth','OpenSurvey','Paybox','Paypal','Prelevement','Printing','Product','ProductBatch','Projet','Propale','ReceiptPrinter','Resource', 'Salaries','Service','SocialNetworks','Societe','Stock','Stripe','SupplierProposal','Syslog','TakePos','Tax','Ticket','User','Variants','WebServices','WebServicesClient','Website','Workflow'); - foreach ($modulelist as $modlabel) - { - require_once DOL_DOCUMENT_ROOT.'/core/modules/mod'.$modlabel.'.class.php'; - $class='mod'.$modlabel; - $mod=new $class($db); - $result=$mod->remove(); - $result=$mod->init(); - $this->assertLessThan($result, 0, $modlabel); - print __METHOD__." test remove/init for module ".$modlabel.", result=".$result."\n"; + foreach ($modulelist as $modlabel) { + require_once DOL_DOCUMENT_ROOT.'/core/modules/mod'.$modlabel.'.class.php'; + $class='mod'.$modlabel; + $mod=new $class($db); + $result=$mod->remove(); + $result=$mod->init(); + $this->assertLessThan($result, 0, $modlabel); + print __METHOD__." test remove/init for module ".$modlabel.", result=".$result."\n"; - if (in_array($modlabel, array('Ldap', 'MailmanSpip'))) - { - $result=$mod->remove(); - } + if (in_array($modlabel, array('Ldap', 'MailmanSpip'))) { + $result=$mod->remove(); + } } - return 0; - } + return 0; + } } diff --git a/test/phpunit/MouvementStockTest.php b/test/phpunit/MouvementStockTest.php index 1f27b4c71de..b68a8c90d0a 100644 --- a/test/phpunit/MouvementStockTest.php +++ b/test/phpunit/MouvementStockTest.php @@ -31,8 +31,7 @@ require_once dirname(__FILE__).'/../../htdocs/product/stock/class/mouvementstock require_once dirname(__FILE__).'/../../htdocs/product/stock/class/entrepot.class.php'; require_once dirname(__FILE__).'/../../htdocs/product/class/product.class.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -77,66 +76,68 @@ class MouvementStockTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + protected function setUp() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - if (empty($conf->productbatch->enabled)) { print "\n".__METHOD__." module Lot/Serial must be enabled.\n"; die(); } + if (empty($conf->productbatch->enabled)) { + print "\n".__METHOD__." module Lot/Serial must be enabled.\n"; die(); + } print __METHOD__."\n"; - } + } /** * End phpunit tests * * @return void */ - protected function tearDown() - { - print __METHOD__."\n"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testMouvementCreate - * - * @return MouvementStock - */ - public function testMouvementCreate() - { - global $conf,$user,$langs,$db; + /** + * testMouvementCreate + * + * @return MouvementStock + */ + public function testMouvementCreate() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -201,76 +202,76 @@ class MouvementStockTest extends PHPUnit\Framework\TestCase print __METHOD__." result=".$result."\n"; $this->assertEquals(-3, $result, 'Test to check we can t create a movement for a lot with a different eatby date'); - // Do a list of movement into warehouse 1 + // Do a list of movement into warehouse 1 - // Create an input movement (type = 3) of price 9.9 -> should update PMP to 9.9 + // Create an input movement (type = 3) of price 9.9 -> should update PMP to 9.9 $result=$localobject->reception($user, $product1id, $warehouse1id, 10, 9.9, 'Movement for unit test 1', '', '', '', '', 0, 'Inventory Code Test'); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result, 'Return code of 0 was expected for the reception test 1'); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result, 'Return code of 0 was expected for the reception test 1'); - // Create an input movement (type = 3) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 - $result=$localobject->reception($user, $product1id, $warehouse1id, 10, 9.7, 'Movement for unit test 2', '', '', '', '', 0, 'Inventory Code Test'); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + // Create an input movement (type = 3) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 + $result=$localobject->reception($user, $product1id, $warehouse1id, 10, 9.7, 'Movement for unit test 2', '', '', '', '', 0, 'Inventory Code Test'); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); - // Create an output movement (type = 2) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 - $result=$localobject->livraison($user, $product1id, $warehouse1id, 5, 999, 'Movement for unit test 3', '', '', '', '', 0, 'Inventory Code Test'); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + // Create an output movement (type = 2) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 + $result=$localobject->livraison($user, $product1id, $warehouse1id, 5, 999, 'Movement for unit test 3', '', '', '', '', 0, 'Inventory Code Test'); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); - // Create an output movement (type = 1) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 - $result=$localobject->_create($user, $product1id, $warehouse1id, 1, 0, 0, 'Input from transfer', 'Transfert X'); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + // Create an output movement (type = 1) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 + $result=$localobject->_create($user, $product1id, $warehouse1id, 1, 0, 0, 'Input from transfer', 'Transfert X'); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); - // Create an output movement (type = 1) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 - $result=$localobject->_create($user, $product1id, $warehouse1id, -2, 1, 0, 'Output from transfer', 'Transfert Y'); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + // Create an output movement (type = 1) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 + $result=$localobject->_create($user, $product1id, $warehouse1id, -2, 1, 0, 'Output from transfer', 'Transfert Y'); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); - // Do same but into warehouse 2 + // Do same but into warehouse 2 - // Create an input movement (type = 3) of price 9.9 -> should update PMP to 9.9 - $result=$localobject->reception($user, $product1id, $warehouse2id, 10, 9.9, 'Movement for unit test 1 wh 2', '', '', '', '', 0, 'Inventory Code Test 2'); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + // Create an input movement (type = 3) of price 9.9 -> should update PMP to 9.9 + $result=$localobject->reception($user, $product1id, $warehouse2id, 10, 9.9, 'Movement for unit test 1 wh 2', '', '', '', '', 0, 'Inventory Code Test 2'); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); - // Create an input movement (type = 3) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 - $result=$localobject->reception($user, $product1id, $warehouse2id, 10, 9.7, 'Movement for unit test 2 wh 2', '', '', '', '', 0, 'Inventory Code Test 2'); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + // Create an input movement (type = 3) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 + $result=$localobject->reception($user, $product1id, $warehouse2id, 10, 9.7, 'Movement for unit test 2 wh 2', '', '', '', '', 0, 'Inventory Code Test 2'); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); - // Create an output movement (type = 2) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 - $result=$localobject->livraison($user, $product1id, $warehouse2id, 5, 999, 'Movement for unit test 3 wh 2', '', '', '', '', 0, 'Inventory Code Test 2'); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + // Create an output movement (type = 2) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 + $result=$localobject->livraison($user, $product1id, $warehouse2id, 5, 999, 'Movement for unit test 3 wh 2', '', '', '', '', 0, 'Inventory Code Test 2'); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); - // Create an output movement (type = 1) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 - $result=$localobject->_create($user, $product1id, $warehouse2id, 1, 0, 0, 'Input from transfer wh 2', 'Transfert X 2'); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + // Create an output movement (type = 1) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 + $result=$localobject->_create($user, $product1id, $warehouse2id, 1, 0, 0, 'Input from transfer wh 2', 'Transfert X 2'); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); - // Create an output movement (type = 1) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 - $result=$localobject->_create($user, $product1id, $warehouse2id, -2, 1, 0, 'Output from transfer wh 2', 'Transfert Y 2'); - print __METHOD__." result=".$result."\n"; - $this->assertGreaterThan(0, $result); + // Create an output movement (type = 1) of price 9.7 -> should update PMP to 9.9/9.7 = 9.8 + $result=$localobject->_create($user, $product1id, $warehouse2id, -2, 1, 0, 'Output from transfer wh 2', 'Transfert Y 2'); + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); - return $localobject; - } + return $localobject; + } - /** - * testMouvementCheck - * - * @param MouvementStock $localobject Movement object we created - * @return MouvementStock - * - * @depends testMouvementCreate - * The depends says test is run only if previous is ok - */ - public function testMouvementCheck($localobject) - { - global $conf,$user,$langs,$db; + /** + * testMouvementCheck + * + * @param MouvementStock $localobject Movement object we created + * @return MouvementStock + * + * @depends testMouvementCreate + * The depends says test is run only if previous is ok + */ + public function testMouvementCheck($localobject) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -284,12 +285,12 @@ class MouvementStockTest extends PHPUnit\Framework\TestCase $producttotest = new Product($db); $producttotest->fetch($productid); - print __METHOD__." producttotest->stock_reel=".$producttotest->stock_reel."\n"; - $this->assertEquals($producttotest->stock_reel, 28); // 28 is result of stock movement defined into testMouvementCreate + print __METHOD__." producttotest->stock_reel=".$producttotest->stock_reel."\n"; + $this->assertEquals($producttotest->stock_reel, 28); // 28 is result of stock movement defined into testMouvementCreate - print __METHOD__." producttotest->pmp=".$producttotest->pmp."\n"; - $this->assertEquals($producttotest->pmp, 9.8); + print __METHOD__." producttotest->pmp=".$producttotest->pmp."\n"; + $this->assertEquals($producttotest->pmp, 9.8); - return $localobject; - } + return $localobject; + } } diff --git a/test/phpunit/NumberingModulesTest.php b/test/phpunit/NumberingModulesTest.php index 089a2c2f4cf..a34d3b28d1c 100644 --- a/test/phpunit/NumberingModulesTest.php +++ b/test/phpunit/NumberingModulesTest.php @@ -28,8 +28,7 @@ global $conf,$user,$langs,$db; //require_once 'PHPUnit/Autoload.php'; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -74,66 +73,66 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase } /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + * setUpBeforeClass + * + * @return void + */ + 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. + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testFactureMercure - * - * @return int - */ - public function testFactureMercure() - { - global $conf,$user,$langs,$db,$mysoc; + /** + * testFactureMercure + * + * @return int + */ + public function testFactureMercure() + { + global $conf,$user,$langs,$db,$mysoc; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -237,13 +236,13 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $result2=$localobject2->create($user, 1); $result3=$localobject2->validate($user, $result); print __METHOD__." result=".$result."\n"; - $this->assertEquals('192101-0001', $result); // counter must be reseted to 1 - $result=$localobject2->is_erasable(); - print __METHOD__." is_erasable=".$result."\n"; - $this->assertGreaterThanOrEqual(1, $result); // Can be deleted - $result=$localobject->is_erasable(); - print __METHOD__." is_erasable=".$result."\n"; - $this->assertGreaterThanOrEqual(1, $result); // Case 1 can be deleted (because there was a reset for case 2) + $this->assertEquals('192101-0001', $result); // counter must be reseted to 1 + $result=$localobject2->is_erasable(); + print __METHOD__." is_erasable=".$result."\n"; + $this->assertGreaterThanOrEqual(1, $result); // Can be deleted + $result=$localobject->is_erasable(); + print __METHOD__." is_erasable=".$result."\n"; + $this->assertGreaterThanOrEqual(1, $result); // Case 1 can be deleted (because there was a reset for case 2) // Same but we add month before year and use a year on 2 digits $conf->global->FACTURE_MERCURE_MASK_CREDIT='[mm}{yy}-{0000@1}'; @@ -268,319 +267,319 @@ class NumberingModulesTest extends PHPUnit\Framework\TestCase $result2=$localobject2->create($user, 1); $result3=$localobject2->validate($user, $result); print __METHOD__." result=".$result."\n"; - $this->assertEquals('0125-0002', $result, 'Test for {mm}{yy}-{0000@1} 2st invoice'); // counter must be now 2 - $result=$localobject2->is_erasable(); - print __METHOD__." is_erasable=".$result."\n"; - $this->assertGreaterThanOrEqual(1, $result); // Can be deleted - $result=$localobject->is_erasable(); - print __METHOD__." is_erasable=".$result."\n"; - $this->assertLessThanOrEqual(0, $result); // Case 1 can not be deleted (because there is an invoice 2) + $this->assertEquals('0125-0002', $result, 'Test for {mm}{yy}-{0000@1} 2st invoice'); // counter must be now 2 + $result=$localobject2->is_erasable(); + print __METHOD__." is_erasable=".$result."\n"; + $this->assertGreaterThanOrEqual(1, $result); // Can be deleted + $result=$localobject->is_erasable(); + print __METHOD__." is_erasable=".$result."\n"; + $this->assertLessThanOrEqual(0, $result); // Case 1 can not be deleted (because there is an invoice 2) $localobject3=new Facture($this->savdb); $localobject3->initAsSpecimen(); $localobject3->date=dol_mktime(12, 0, 0, 1, 1, 1926); // we use following year for third invoice (and there is a reset required) $numbering=new mod_facture_mercure(); $result=$numbering->getNextValue($mysoc, $localobject3); print __METHOD__." result=".$result."\n"; - $this->assertEquals('0126-0001', $result, 'Test for {mm}{yy}-{0000@1} 3rd invoice'); // counter must be now 1 + $this->assertEquals('0126-0001', $result, 'Test for {mm}{yy}-{0000@1} 3rd invoice'); // counter must be now 1 - // Try an offset when an invoice already exists - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000+9990}'; - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000+9990}'; - $result=$numbering->getNextValue($mysoc, $localobject2); + // Try an offset when an invoice already exists + $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000+9990}'; + $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000+9990}'; + $result=$numbering->getNextValue($mysoc, $localobject2); // Now we try with a different fiscal month (forced by mask) - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@6}'; - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@6}'; + $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@6}'; + $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@6}'; - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1930); // we use year 1930 to be sure to not have existing invoice for this year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject, 'last'); - print __METHOD__." result for last=".$result."\n"; - $this->assertEquals('', $result); // no existing ref into reset range - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('193001-0001', $result); // counter must start to 1 - $result=$numbering->getNextValue($mysoc, $localobject, 'last'); - print __METHOD__." result for last=".$result."\n"; - $this->assertEquals('193001-0001', $result); // last ref into reset range should be same than last created + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1930); // we use year 1930 to be sure to not have existing invoice for this year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject, 'last'); + print __METHOD__." result for last=".$result."\n"; + $this->assertEquals('', $result); // no existing ref into reset range + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('193001-0001', $result); // counter must start to 1 + $result=$numbering->getNextValue($mysoc, $localobject, 'last'); + print __METHOD__." result for last=".$result."\n"; + $this->assertEquals('193001-0001', $result); // last ref into reset range should be same than last created - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1930); // we use same year but fiscal month after - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject, 'last'); - print __METHOD__." result for last=".$result."\n"; - $this->assertEquals('', $result); // last ref into reset range should be '' - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('193012-0001', $result); // counter must be reset to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1930); // we use same year but fiscal month after + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject, 'last'); + print __METHOD__." result for last=".$result."\n"; + $this->assertEquals('', $result); // last ref into reset range should be '' + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('193012-0001', $result); // counter must be reset to 1 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1931); // we use same fiscal year but different year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('193101-0002', $result); // counter must be 2 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1931); // we use same fiscal year but different year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('193101-0002', $result); // counter must be 2 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1931); // we use different fiscal year but same year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('193112-0001', $result); // counter must be reset to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1931); // we use different fiscal year but same year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('193112-0001', $result); // counter must be reset to 1 - // Now we try with a different fiscal month (defined by SOCIETE_FISCAL_MONTH_START) - $conf->global->SOCIETE_FISCAL_MONTH_START=6; - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@0}'; - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@0}'; + // Now we try with a different fiscal month (defined by SOCIETE_FISCAL_MONTH_START) + $conf->global->SOCIETE_FISCAL_MONTH_START=6; + $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@0}'; + $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@0}'; - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1940); // we use year 1940 to be sure to not have existing invoice for this year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('194001-0001', $result); // counter must start to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1940); // we use year 1940 to be sure to not have existing invoice for this year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('194001-0001', $result); // counter must start to 1 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1940); // we use same year but fiscal month after - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('194012-0001', $result); // counter must be reset to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1940); // we use same year but fiscal month after + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('194012-0001', $result); // counter must be reset to 1 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1941); // we use same fiscal year but different year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('194101-0002', $result); // counter must be 2 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1941); // we use same fiscal year but different year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('194101-0002', $result); // counter must be 2 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1941); // we use different discal year but same year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('194112-0001', $result); // counter must be reset to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1941); // we use different discal year but same year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('194112-0001', $result); // counter must be reset to 1 - // Now we try with a different fiscal month (defined by SOCIETE_FISCAL_MONTH_START) and we always want year of element - $conf->global->SOCIETE_FISCAL_MONTH_START=6; - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@=}'; - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@=}'; + // Now we try with a different fiscal month (defined by SOCIETE_FISCAL_MONTH_START) and we always want year of element + $conf->global->SOCIETE_FISCAL_MONTH_START=6; + $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@=}'; + $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@=}'; - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1950); // we use year 1950 to be sure to not have existing invoice for this year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('195001-0001', $result); // counter must start to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1950); // we use year 1950 to be sure to not have existing invoice for this year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('195001-0001', $result); // counter must start to 1 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1950); // we use same year but fiscal month after - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('195012-0001', $result); // counter must be reset to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1950); // we use same year but fiscal month after + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('195012-0001', $result); // counter must be reset to 1 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1951); // we use same fiscal year but different year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('195101-0002', $result); // counter must be 2 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1951); // we use same fiscal year but different year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('195101-0002', $result); // counter must be 2 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1951); // we use different discal year but same year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('195112-0001', $result); // counter must be reset to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1951); // we use different discal year but same year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('195112-0001', $result); // counter must be reset to 1 - // Now we try with a different fiscal month (defined by SOCIETE_FISCAL_MONTH_START) and we always want start year - $conf->global->SOCIETE_FISCAL_MONTH_START=6; - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@-}'; - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@-}'; + // Now we try with a different fiscal month (defined by SOCIETE_FISCAL_MONTH_START) and we always want start year + $conf->global->SOCIETE_FISCAL_MONTH_START=6; + $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@-}'; + $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@-}'; - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1960); // we use year 1960 to be sure to not have existing invoice for this year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('195901-0001', $result); // counter must start to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1960); // we use year 1960 to be sure to not have existing invoice for this year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('195901-0001', $result); // counter must start to 1 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1960); // we use same year but fiscal month after - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('196012-0001', $result); // counter must be reset to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1960); // we use same year but fiscal month after + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('196012-0001', $result); // counter must be reset to 1 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1961); // we use same fiscal year but different year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('196001-0002', $result); // counter must be 2 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1961); // we use same fiscal year but different year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('196001-0002', $result); // counter must be 2 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1961); // we use different discal year but same year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('196112-0001', $result); // counter must be reset to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1961); // we use different discal year but same year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('196112-0001', $result); // counter must be reset to 1 - // Now we try with a different fiscal month (defined by SOCIETE_FISCAL_MONTH_START) and we always want end year - $conf->global->SOCIETE_FISCAL_MONTH_START=6; - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@+}'; - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@+}'; + // Now we try with a different fiscal month (defined by SOCIETE_FISCAL_MONTH_START) and we always want end year + $conf->global->SOCIETE_FISCAL_MONTH_START=6; + $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@+}'; + $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@+}'; - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1970); // we use year 1970 to be sure to not have existing invoice for this year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('197001-0001', $result); // counter must start to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1970); // we use year 1970 to be sure to not have existing invoice for this year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('197001-0001', $result); // counter must start to 1 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1970); // we use same year but fiscal month after - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('197112-0001', $result); // counter must be reset to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1970); // we use same year but fiscal month after + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('197112-0001', $result); // counter must be reset to 1 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1971); // we use same fiscal year but different year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('197101-0002', $result); // counter must be 2 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1971); // we use same fiscal year but different year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('197101-0002', $result); // counter must be 2 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1971); // we use different fiscal year but same year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('197212-0001', $result); // counter must be reset to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 12, 1, 1971); // we use different fiscal year but same year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('197212-0001', $result); // counter must be reset to 1 - // Now we try with a reset every month (@99) - $conf->global->SOCIETE_FISCAL_MONTH_START=6; - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@99}'; - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@99}'; + // Now we try with a reset every month (@99) + $conf->global->SOCIETE_FISCAL_MONTH_START=6; + $conf->global->FACTURE_MERCURE_MASK_CREDIT='{yyyy}{mm}-{0000@99}'; + $conf->global->FACTURE_MERCURE_MASK_INVOICE='{yyyy}{mm}-{0000@99}'; - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('198001-0001', $result); // counter must start to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('198001-0001', $result); // counter must start to 1 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('198001-0002', $result); // counter must start to 2 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('198001-0002', $result); // counter must start to 2 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 2, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('198002-0001', $result); // counter must start to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 2, 1, 1980); // we use year 1980 to be sure to not have existing invoice for this year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('198002-0001', $result); // counter must start to 1 - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1981); // we use year 1981 to be sure to not have existing invoice for this year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($mysoc, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('198101-0001', $result); // counter must start to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1981); // we use year 1981 to be sure to not have existing invoice for this year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($mysoc, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('198101-0001', $result); // counter must start to 1 - // Test with {t} tag - $conf->global->SOCIETE_FISCAL_MONTH_START=1; - $conf->global->FACTURE_MERCURE_MASK_CREDIT='{t}{yyyy}{mm}-{0000}'; - $conf->global->FACTURE_MERCURE_MASK_INVOICE='{t}{yyyy}{mm}-{0000}'; + // Test with {t} tag + $conf->global->SOCIETE_FISCAL_MONTH_START=1; + $conf->global->FACTURE_MERCURE_MASK_CREDIT='{t}{yyyy}{mm}-{0000}'; + $conf->global->FACTURE_MERCURE_MASK_INVOICE='{t}{yyyy}{mm}-{0000}'; - $tmpthirdparty=new Societe($this->savdb); - $tmpthirdparty->initAsSpecimen(); - $tmpthirdparty->typent_code = 'TE_ABC'; + $tmpthirdparty=new Societe($this->savdb); + $tmpthirdparty->initAsSpecimen(); + $tmpthirdparty->typent_code = 'TE_ABC'; - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen(); - $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1982); // we use year 1982 to be sure to not have existing invoice for this year - $numbering=new mod_facture_mercure(); - $result=$numbering->getNextValue($tmpthirdparty, $localobject); - $result2=$localobject->create($user, 1); - $result3=$localobject->validate($user, $result); - print __METHOD__." result=".$result."\n"; - $this->assertEquals('A198201-0001', $result); // counter must start to 1 + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen(); + $localobject->date=dol_mktime(12, 0, 0, 1, 1, 1982); // we use year 1982 to be sure to not have existing invoice for this year + $numbering=new mod_facture_mercure(); + $result=$numbering->getNextValue($tmpthirdparty, $localobject); + $result2=$localobject->create($user, 1); + $result3=$localobject->validate($user, $result); + print __METHOD__." result=".$result."\n"; + $this->assertEquals('A198201-0001', $result); // counter must start to 1 - return $result; - } + return $result; + } } diff --git a/test/phpunit/PaypalTest.php b/test/phpunit/PaypalTest.php index 7a2e31cbdad..3177e5555ed 100644 --- a/test/phpunit/PaypalTest.php +++ b/test/phpunit/PaypalTest.php @@ -30,8 +30,7 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/geturl.lib.php'; require_once dirname(__FILE__).'/../../htdocs/paypal/lib/paypal.lib.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -75,69 +74,71 @@ class PaypalTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + /** + * setUpBeforeClass + * + * @return void + */ + public static function setUpBeforeClass() + { + global $conf,$user,$langs,$db; - if (empty($conf->paypal->enabled)) { print __METHOD__." Module Paypal must be enabled.\n"; die(); } + if (empty($conf->paypal->enabled)) { + print __METHOD__." Module Paypal must be enabled.\n"; die(); + } - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testPaypalOk - * - * @return void - */ - public function testPaypalOk() - { - global $conf,$user,$langs,$db; + /** + * testPaypalOk + * + * @return void + */ + public function testPaypalOk() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -148,9 +149,9 @@ class PaypalTest extends PHPUnit\Framework\TestCase $result=getURLContent($urltotest, 'GET', '', 1, array(), array('http', 'https'), 2); - print __METHOD__." result=".$result['http_code']."\n"; - $this->assertEquals(200, $result['http_code']); + print __METHOD__." result=".$result['http_code']."\n"; + $this->assertEquals(200, $result['http_code']); - return $result; - } + return $result; + } } diff --git a/test/phpunit/PdfDocTest.php b/test/phpunit/PdfDocTest.php index c323c2bb6f8..4c07f970c24 100644 --- a/test/phpunit/PdfDocTest.php +++ b/test/phpunit/PdfDocTest.php @@ -32,8 +32,7 @@ require_once dirname(__FILE__).'/../../htdocs/product/class/product.class.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/pdf.lib.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/doc.lib.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -77,65 +76,65 @@ class PdfDocTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testPdfDocGetLineDesc - * - * @return void - */ - public function testPdfDocGetLineDesc() - { - global $conf,$user,$langs,$db; + /** + * testPdfDocGetLineDesc + * + * @return void + */ + public function testPdfDocGetLineDesc() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -144,7 +143,9 @@ class PdfDocTest extends PHPUnit\Framework\TestCase $localproduct=new Product($this->savdb); $localproduct->fetch(0, 'PIDRESS'); $product_id=$localproduct->id; - if ($product_id <= 0) { print "\n".__METHOD__." A product with ref PIDRESS must exists into database"; die(); } + if ($product_id <= 0) { + print "\n".__METHOD__." A product with ref PIDRESS must exists into database"; die(); + } $localobject=new Facture($this->savdb); $localobject->initAsSpecimen(); @@ -154,29 +155,29 @@ class PdfDocTest extends PHPUnit\Framework\TestCase $localobject->lines[0]->label='Label 1'; $localobject->lines[0]->desc="This is a description with a é accent\n(Country of origin: France)"; - $result=pdf_getlinedesc($localobject, 0, $langs); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, "PIDRESS - Label 1
    This is a description with a é accent
    (Country of origin: France)"); + $result=pdf_getlinedesc($localobject, 0, $langs); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, "PIDRESS - Label 1
    This is a description with a é accent
    (Country of origin: France)"); - $result=doc_getlinedesc($localobject->lines[0], $langs); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, "PIDRESS - Label 1\nThis is a description with a é accent\n(Country of origin: France)"); - } + $result=doc_getlinedesc($localobject->lines[0], $langs); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, "PIDRESS - Label 1\nThis is a description with a é accent\n(Country of origin: France)"); + } - /** - * testPdfGetHeightForLogo - * - * @return void - */ - public function testPdfGetHeightForLogo() - { - $file=dirname(__FILE__).'/img250x50.jpg'; - $result=pdf_getHeightForLogo($file); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, 20); - $file=dirname(__FILE__).'/img250x20.png'; - $result=pdf_getHeightForLogo($file); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, 10.4); - } + /** + * testPdfGetHeightForLogo + * + * @return void + */ + public function testPdfGetHeightForLogo() + { + $file=dirname(__FILE__).'/img250x50.jpg'; + $result=pdf_getHeightForLogo($file); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 20); + $file=dirname(__FILE__).'/img250x20.png'; + $result=pdf_getHeightForLogo($file); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, 10.4); + } } diff --git a/test/phpunit/PgsqlTest.php b/test/phpunit/PgsqlTest.php index 5a09e7fc55a..044d4576067 100644 --- a/test/phpunit/PgsqlTest.php +++ b/test/phpunit/PgsqlTest.php @@ -30,8 +30,7 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/db/pgsql.class.php'; $langs->load("dict"); -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -76,114 +75,114 @@ class PgsqlTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + /** + * setUpBeforeClass + * + * @return void + */ + 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. + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testConvertSQLFromMysql - * - * @return int - */ - public function testConvertSQLFromMysql() - { - global $conf,$user,$langs,$db; + /** + * testConvertSQLFromMysql + * + * @return int + */ + public function testConvertSQLFromMysql() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - $sql="ALTER TABLE llx_table RENAME TO llx_table_new;"; - $result=DoliDBPgsql::convertSQLFromMysql($sql); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, "ALTER TABLE llx_table RENAME TO llx_table_new;"); + $sql="ALTER TABLE llx_table RENAME TO llx_table_new;"; + $result=DoliDBPgsql::convertSQLFromMysql($sql); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, "ALTER TABLE llx_table RENAME TO llx_table_new;"); - $sql="ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol;"; - $result=DoliDBPgsql::convertSQLFromMysql($sql); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, "ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0';"); + $sql="ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol;"; + $result=DoliDBPgsql::convertSQLFromMysql($sql); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, "ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0';"); - $sql="ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60);"; - $result=DoliDBPgsql::convertSQLFromMysql($sql); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, "-- ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60); replaced by --\nALTER TABLE llx_table RENAME COLUMN oldname TO newname"); + $sql="ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60);"; + $result=DoliDBPgsql::convertSQLFromMysql($sql); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, "-- ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60); replaced by --\nALTER TABLE llx_table RENAME COLUMN oldname TO newname"); - $sql="ALTER TABLE llx_table DROP COLUMN oldname;"; - $result=DoliDBPgsql::convertSQLFromMysql($sql); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, $sql); + $sql="ALTER TABLE llx_table DROP COLUMN oldname;"; + $result=DoliDBPgsql::convertSQLFromMysql($sql); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, $sql); - $sql="ALTER TABLE llx_table MODIFY name varchar(60);"; - $result=DoliDBPgsql::convertSQLFromMysql($sql); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, "-- ALTER TABLE llx_table MODIFY name varchar(60); replaced by --\nALTER TABLE llx_table ALTER COLUMN name TYPE varchar(60);"); + $sql="ALTER TABLE llx_table MODIFY name varchar(60);"; + $result=DoliDBPgsql::convertSQLFromMysql($sql); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, "-- ALTER TABLE llx_table MODIFY name varchar(60); replaced by --\nALTER TABLE llx_table ALTER COLUMN name TYPE varchar(60);"); - // Create a constraint + // Create a constraint $sql='ALTER TABLE llx_tablechild ADD CONSTRAINT fk_tablechild_fk_fieldparent FOREIGN KEY (fk_fieldparent) REFERENCES llx_tableparent (rowid)'; $result=DoliDBPgsql::convertSQLFromMysql($sql); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, $sql.' DEFERRABLE INITIALLY IMMEDIATE;'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, $sql.' DEFERRABLE INITIALLY IMMEDIATE;'); - // Test GROUP_CONCAT (without SEPARATOR) + // Test GROUP_CONCAT (without SEPARATOR) $sql="SELECT a.b, GROUP_CONCAT(a.c) FROM table GROUP BY a.b"; $result=DoliDBPgsql::convertSQLFromMysql($sql); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, "SELECT a.b, STRING_AGG(a.c, ',') FROM table GROUP BY a.b", 'Test GROUP_CONCAT (without SEPARATOR)'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, "SELECT a.b, STRING_AGG(a.c, ',') FROM table GROUP BY a.b", 'Test GROUP_CONCAT (without SEPARATOR)'); - // Test GROUP_CONCAT (with SEPARATOR) + // Test GROUP_CONCAT (with SEPARATOR) $sql="SELECT a.b, GROUP_CONCAT(a.c SEPARATOR ',') FROM table GROUP BY a.b"; $result=DoliDBPgsql::convertSQLFromMysql($sql); - print __METHOD__." result=".$result."\n"; - $this->assertEquals($result, "SELECT a.b, STRING_AGG(a.c, ',') FROM table GROUP BY a.b", 'Test GROUP_CONCAT (with SEPARATOR)'); + print __METHOD__." result=".$result."\n"; + $this->assertEquals($result, "SELECT a.b, STRING_AGG(a.c, ',') FROM table GROUP BY a.b", 'Test GROUP_CONCAT (with SEPARATOR)'); - return $result; - } + return $result; + } } diff --git a/test/phpunit/PricesTest.php b/test/phpunit/PricesTest.php index 0c47ec4f275..1845bf05149 100755 --- a/test/phpunit/PricesTest.php +++ b/test/phpunit/PricesTest.php @@ -31,18 +31,16 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/price.lib.php'; require_once dirname(__FILE__).'/../../htdocs/compta/facture/class/facture.class.php'; -if (empty($user->id)) -{ - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); +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; -if (! empty($conf->global->MAIN_ROUNDING_RULE_TOT)) -{ - print "Parameter MAIN_ROUNDING_RULE_TOT must be set to 0 or not set.\n"; - exit(1); +if (! empty($conf->global->MAIN_ROUNDING_RULE_TOT)) { + print "Parameter MAIN_ROUNDING_RULE_TOT must be set to 0 or not set.\n"; + exit(1); } /** @@ -54,311 +52,311 @@ if (! empty($conf->global->MAIN_ROUNDING_RULE_TOT)) */ class PricesTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return CoreTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return CoreTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - //$db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + //$db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } - /** - * End phpunit tests - * - * @return void - */ - protected function tearDown() - { - print __METHOD__."\n"; - } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * Test function calcul_price_total - * - * @return boolean - * @see http://wiki.dolibarr.org/index.php/Draft:VAT_calculation_and_rounding#Standard_usage - */ - public function testCalculPriceTotal() - { - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + /** + * Test function calcul_price_total + * + * @return boolean + * @see http://wiki.dolibarr.org/index.php/Draft:VAT_calculation_and_rounding#Standard_usage + */ + public function testCalculPriceTotal() + { + global $conf,$user,$langs,$db; + $this->savconf=$conf; + $this->savuser=$user; + $this->savlangs=$langs; + $this->savdb=$db; - global $mysoc; - $mysoc=new Societe($db); + global $mysoc; + $mysoc=new Societe($db); - // To force status that say module multicompany is on - //$conf->multicurrency=new stdClass(); - //$conf->multicurrency->enabled = 0; + // To force status that say module multicompany is on + //$conf->multicurrency=new stdClass(); + //$conf->multicurrency->enabled = 0; - /* - * Country France - */ + /* + * Country France + */ - // qty=1, unit_price=1.24, discount_line=0, vat_rate=10, price_base_type='HT' (method we provide value) - $mysoc->country_code='FR'; - $mysoc->country_id=1; - $result1=calcul_price_total(1, 1.24, 0, 10, 0, 0, 0, 'HT', 0, 0); - print __METHOD__." result1=".join(', ', $result1)."\n"; - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(1.24, 0.12, 1.36, 1.24, 0.124, 1.364, 1.24, 0.12, 1.36, 0, 0, 0, 0, 0, 0, 0, 1.24, 0.12, 1.36, 1.24, 0.124, 1.364, 1.24, 0.12, 1.36, 0, 0), $result1, 'Test1 FR'); + // qty=1, unit_price=1.24, discount_line=0, vat_rate=10, price_base_type='HT' (method we provide value) + $mysoc->country_code='FR'; + $mysoc->country_id=1; + $result1=calcul_price_total(1, 1.24, 0, 10, 0, 0, 0, 'HT', 0, 0); + print __METHOD__." result1=".join(', ', $result1)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(1.24, 0.12, 1.36, 1.24, 0.124, 1.364, 1.24, 0.12, 1.36, 0, 0, 0, 0, 0, 0, 0, 1.24, 0.12, 1.36, 1.24, 0.124, 1.364, 1.24, 0.12, 1.36, 0, 0), $result1, 'Test1 FR'); - // qty=1, unit_price=1.24, discount_line=0, vat_rate=10, price_base_type='HT', multicurrency_tx=1.09205 (method we provide value) - $mysoc->country_code='FR'; - $mysoc->country_id=1; - $result1=calcul_price_total(2, 8.56, 0, 10, 0, 0, 0, 'HT', 0, 0, '', '', 100, 1.09205); - print __METHOD__." result1=".join(', ', $result1)."\n"; - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(17.12, 1.71, 18.83, 8.56, 0.856, 9.416, 17.12, 1.71, 18.83, 0, 0, 0, 0, 0, 0, 0, 18.7, 1.87, 20.57, 9.34795, 0.93479, 10.28274, 18.7, 1.87, 20.57, 0, 0), $result1, 'Test1b FR'); + // qty=1, unit_price=1.24, discount_line=0, vat_rate=10, price_base_type='HT', multicurrency_tx=1.09205 (method we provide value) + $mysoc->country_code='FR'; + $mysoc->country_id=1; + $result1=calcul_price_total(2, 8.56, 0, 10, 0, 0, 0, 'HT', 0, 0, '', '', 100, 1.09205); + print __METHOD__." result1=".join(', ', $result1)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(17.12, 1.71, 18.83, 8.56, 0.856, 9.416, 17.12, 1.71, 18.83, 0, 0, 0, 0, 0, 0, 0, 18.7, 1.87, 20.57, 9.34795, 0.93479, 10.28274, 18.7, 1.87, 20.57, 0, 0), $result1, 'Test1b FR'); - // qty=2, unit_price=0, discount_line=0, vat_rate=10, price_base_type='HT', multicurrency_tx=1.09205 (method we provide value), pu_ht_devise=100 - $mysoc->country_code='FR'; - $mysoc->country_id=1; - $result1=calcul_price_total(2, 0, 0, 10, 0, 0, 0, 'HT', 0, 0, '', '', 100, 1.09205, 20); - print __METHOD__." result1=".join(', ', $result1)."\n"; - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(36.63, 3.66, 40.29, 18.31418, 1.83142, 20.1456, 36.63, 3.66, 40.29, 0, 0, 0, 0, 0, 0, 0, 40, 4, 44, 20, 2, 22, 40, 4, 44, 0, 0), $result1, 'Test1c FR'); + // qty=2, unit_price=0, discount_line=0, vat_rate=10, price_base_type='HT', multicurrency_tx=1.09205 (method we provide value), pu_ht_devise=100 + $mysoc->country_code='FR'; + $mysoc->country_id=1; + $result1=calcul_price_total(2, 0, 0, 10, 0, 0, 0, 'HT', 0, 0, '', '', 100, 1.09205, 20); + print __METHOD__." result1=".join(', ', $result1)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(36.63, 3.66, 40.29, 18.31418, 1.83142, 20.1456, 36.63, 3.66, 40.29, 0, 0, 0, 0, 0, 0, 0, 40, 4, 44, 20, 2, 22, 40, 4, 44, 0, 0), $result1, 'Test1c FR'); - /* - * Country Spain - */ + /* + * Country Spain + */ - // 10 * 10 HT - 0% discount with 10% vat, seller not using localtax1, not localtax2 (method we provide value) - $mysoc->country_code='ES'; - $mysoc->country_id=4; - $mysoc->localtax1_assuj=0; - $mysoc->localtax2_assuj=0; - $result2=calcul_price_total(10, 10, 0, 10, 0, 0, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1, 0% localtax2 - print __METHOD__." result2=".join(', ', $result2)."\n"; - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0, 100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0), $result2, 'Test1 ES'); + // 10 * 10 HT - 0% discount with 10% vat, seller not using localtax1, not localtax2 (method we provide value) + $mysoc->country_code='ES'; + $mysoc->country_id=4; + $mysoc->localtax1_assuj=0; + $mysoc->localtax2_assuj=0; + $result2=calcul_price_total(10, 10, 0, 10, 0, 0, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1, 0% localtax2 + print __METHOD__." result2=".join(', ', $result2)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0, 100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0), $result2, 'Test1 ES'); - // 10 * 10 HT - 0% discount with 10% vat, seller not using localtax1, not localtax2 (other method autodetect) - $mysoc->country_code='ES'; - $mysoc->country_id=4; - $mysoc->localtax1_assuj=0; - $mysoc->localtax2_assuj=0; - $result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1, 0% localtax2 - print __METHOD__." result2=".join(', ', $result2)."\n"; - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0, 100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0), $result2, 'Test2 ES'); + // 10 * 10 HT - 0% discount with 10% vat, seller not using localtax1, not localtax2 (other method autodetect) + $mysoc->country_code='ES'; + $mysoc->country_id=4; + $mysoc->localtax1_assuj=0; + $mysoc->localtax2_assuj=0; + $result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1, 0% localtax2 + print __METHOD__." result2=".join(', ', $result2)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0, 100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0), $result2, 'Test2 ES'); - // -------------------------------------------------------- + // -------------------------------------------------------- - // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1 type 3, 0% localtax2 type 5 (method we provide value) - $mysoc->country_code='ES'; - $mysoc->country_id=4; - $mysoc->localtax1_assuj=1; - $mysoc->localtax2_assuj=0; - $result2=calcul_price_total(10, 10, 0, 10, 1.4, 0, 0, 'HT', 0, 0); - print __METHOD__." result2=".join(', ', $result2)."\n"; - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0, 100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0), $result2, 'Test3 ES'); + // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1 type 3, 0% localtax2 type 5 (method we provide value) + $mysoc->country_code='ES'; + $mysoc->country_id=4; + $mysoc->localtax1_assuj=1; + $mysoc->localtax2_assuj=0; + $result2=calcul_price_total(10, 10, 0, 10, 1.4, 0, 0, 'HT', 0, 0); + print __METHOD__." result2=".join(', ', $result2)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0, 100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0), $result2, 'Test3 ES'); - // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1 type 3, 0% localtax2 type 5 (other method autodetect) - $mysoc->country_code='ES'; - $mysoc->country_id=4; - $mysoc->localtax1_assuj=1; - $mysoc->localtax2_assuj=0; - $result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 0); - print __METHOD__." result2=".join(', ', $result2)."\n"; - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0, 100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0), $result2, 'Test4 ES'); + // 10 * 10 HT - 0% discount with 10% vat and 1.4% localtax1 type 3, 0% localtax2 type 5 (other method autodetect) + $mysoc->country_code='ES'; + $mysoc->country_id=4; + $mysoc->localtax1_assuj=1; + $mysoc->localtax2_assuj=0; + $result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 0); + print __METHOD__." result2=".join(', ', $result2)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0, 0.14, 0, 0, 1.4, 0, 100, 10, 111.4, 10, 1, 11.14, 100, 10, 111.4, 1.4, 0), $result2, 'Test4 ES'); - // -------------------------------------------------------- + // -------------------------------------------------------- - // 10 * 10 HT - 0% discount with 10% vat and 0% localtax1 type 3, 19% localtax2 type 5 (method we provide value), we provide a service and not a product - $mysoc->country_code='ES'; - $mysoc->country_id=4; - $mysoc->localtax1_assuj=0; - $mysoc->localtax2_assuj=1; - $result2=calcul_price_total(10, 10, 0, 10, 0, -19, 0, 'HT', 0, 1); - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(100, 10, 91, 10, 1, 9.1, 100, 10, 91, 0, -19, 0, -1.90, 0, 0, -19, 100, 10, 91, 10, 1, 9.1, 100, 10, 91, 0, -19), $result2, 'Test5 ES for service'); + // 10 * 10 HT - 0% discount with 10% vat and 0% localtax1 type 3, 19% localtax2 type 5 (method we provide value), we provide a service and not a product + $mysoc->country_code='ES'; + $mysoc->country_id=4; + $mysoc->localtax1_assuj=0; + $mysoc->localtax2_assuj=1; + $result2=calcul_price_total(10, 10, 0, 10, 0, -19, 0, 'HT', 0, 1); + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 10, 91, 10, 1, 9.1, 100, 10, 91, 0, -19, 0, -1.90, 0, 0, -19, 100, 10, 91, 10, 1, 9.1, 100, 10, 91, 0, -19), $result2, 'Test5 ES for service'); - // 10 * 10 HT - 0% discount with 10% vat and 0% localtax1 type 3, 21% localtax2 type 5 (other method autodetect), we provide a service and not a product - $mysoc->country_code='ES'; - $mysoc->country_id=4; - $mysoc->localtax1_assuj=0; - $mysoc->localtax2_assuj=1; - $result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 0); - print __METHOD__." result2=".join(', ', $result2)."\n"; - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0, 100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0), $result2, 'Test6 ES for product'); + // 10 * 10 HT - 0% discount with 10% vat and 0% localtax1 type 3, 21% localtax2 type 5 (other method autodetect), we provide a service and not a product + $mysoc->country_code='ES'; + $mysoc->country_id=4; + $mysoc->localtax1_assuj=0; + $mysoc->localtax2_assuj=1; + $result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 0); + print __METHOD__." result2=".join(', ', $result2)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0, 0, 0, 0, 0, 0, 100, 10, 110, 10, 1, 11, 100, 10, 110, 0, 0), $result2, 'Test6 ES for product'); - // 10 * 10 HT - 0% discount with 10% vat and 0% localtax1 type 3, 21% localtax2 type 5 (other method autodetect), we provide a product and not a service - $mysoc->country_code='ES'; - $mysoc->country_id=4; - $mysoc->localtax1_assuj=0; - $mysoc->localtax2_assuj=1; - $result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 1); - print __METHOD__." result2=".join(', ', $result2)."\n"; - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(100, 10, 91, 10, 1, 9.1, 100, 10, 91, 0, -19, 0, -1.90, 0, 0, -19, 100, 10, 91, 10, 1, 9.1, 100, 10, 91, 0, -19), $result2, 'Test6 ES for service'); + // 10 * 10 HT - 0% discount with 10% vat and 0% localtax1 type 3, 21% localtax2 type 5 (other method autodetect), we provide a product and not a service + $mysoc->country_code='ES'; + $mysoc->country_id=4; + $mysoc->localtax1_assuj=0; + $mysoc->localtax2_assuj=1; + $result2=calcul_price_total(10, 10, 0, 10, -1, -1, 0, 'HT', 0, 1); + print __METHOD__." result2=".join(', ', $result2)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 10, 91, 10, 1, 9.1, 100, 10, 91, 0, -19, 0, -1.90, 0, 0, -19, 100, 10, 91, 10, 1, 9.1, 100, 10, 91, 0, -19), $result2, 'Test6 ES for service'); - // -------------------------------------------------------- + // -------------------------------------------------------- - // Credit Note: 10 * -10 HT - 0% discount with 10% vat and 0% localtax1 type 3, 19% localtax2 type 5 (method we provide value), we provide a product and not a service - $mysoc->country_code='ES'; - $mysoc->country_id=4; - $mysoc->localtax1_assuj=0; - $mysoc->localtax2_assuj=1; - $result2=calcul_price_total(10, -10, 0, 10, 0, 19, 0, 'HT', 0, 0); - print __METHOD__." result2=".join(', ', $result2)."\n"; - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(-100, -10, -110, -10, -1, -11, -100, -10, -110, 0, 0, 0, 0, 0, 0, 0, -100, -10, -110, -10, -1, -11, -100, -10, -110, 0, 0), $result2, 'Test7 ES for product'); + // Credit Note: 10 * -10 HT - 0% discount with 10% vat and 0% localtax1 type 3, 19% localtax2 type 5 (method we provide value), we provide a product and not a service + $mysoc->country_code='ES'; + $mysoc->country_id=4; + $mysoc->localtax1_assuj=0; + $mysoc->localtax2_assuj=1; + $result2=calcul_price_total(10, -10, 0, 10, 0, 19, 0, 'HT', 0, 0); + print __METHOD__." result2=".join(', ', $result2)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(-100, -10, -110, -10, -1, -11, -100, -10, -110, 0, 0, 0, 0, 0, 0, 0, -100, -10, -110, -10, -1, -11, -100, -10, -110, 0, 0), $result2, 'Test7 ES for product'); - // Credit Note: 10 * -10 HT - 0% discount with 10% vat and 1.4% localtax1 type 3, 0% localtax2 type 5 (other method autodetect), we provide a service and not a product - $mysoc->country_code='ES'; - $mysoc->country_id=4; - $mysoc->localtax1_assuj=0; - $mysoc->localtax2_assuj=1; - $result2=calcul_price_total(10, -10, 0, 10, -1, -1, 0, 'HT', 0, 1); - print __METHOD__." result2=".join(', ', $result2)."\n"; - $this->assertEquals(array(-100, -10, -91, -10, -1, -9.1, -100, -10, -91, 0, 19, 0, 1.90, 0, 0, 19, -100, -10, -91, -10, -1, -9.1, -100, -10, -91, 0, 19), $result2, 'Test8 ES for service'); + // Credit Note: 10 * -10 HT - 0% discount with 10% vat and 1.4% localtax1 type 3, 0% localtax2 type 5 (other method autodetect), we provide a service and not a product + $mysoc->country_code='ES'; + $mysoc->country_id=4; + $mysoc->localtax1_assuj=0; + $mysoc->localtax2_assuj=1; + $result2=calcul_price_total(10, -10, 0, 10, -1, -1, 0, 'HT', 0, 1); + print __METHOD__." result2=".join(', ', $result2)."\n"; + $this->assertEquals(array(-100, -10, -91, -10, -1, -9.1, -100, -10, -91, 0, 19, 0, 1.90, 0, 0, 19, -100, -10, -91, -10, -1, -9.1, -100, -10, -91, 0, 19), $result2, 'Test8 ES for service'); - /* - * Country Côte d'Ivoire - */ + /* + * Country Côte d'Ivoire + */ - // 10 * 10 HT - 0% discount with 18% vat, seller using localtax1 type 2, not localtax2 (method we provide value) - $mysoc->country_code='CI'; - $mysoc->country_id=21; - $mysoc->localtax1_assuj=1; - $mysoc->localtax2_assuj=0; - //$localtaxes=getLocalTaxesFromRate(18, 0, null, $mysoc); - //var_dump($locataxes); - $result3=calcul_price_total(10, 10, 0, 18, 7.5, 0, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 18% vat and 7.5% localtax1, 0% localtax2 - print __METHOD__." result3=".join(', ', $result3)."\n"; - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0, 0.885, 0, 0, 8.85, 0, 100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0), $result3, 'Test9 CI'); + // 10 * 10 HT - 0% discount with 18% vat, seller using localtax1 type 2, not localtax2 (method we provide value) + $mysoc->country_code='CI'; + $mysoc->country_id=21; + $mysoc->localtax1_assuj=1; + $mysoc->localtax2_assuj=0; + //$localtaxes=getLocalTaxesFromRate(18, 0, null, $mysoc); + //var_dump($locataxes); + $result3=calcul_price_total(10, 10, 0, 18, 7.5, 0, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 18% vat and 7.5% localtax1, 0% localtax2 + print __METHOD__." result3=".join(', ', $result3)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0, 0.885, 0, 0, 8.85, 0, 100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0), $result3, 'Test9 CI'); - // 10 * 10 HT - 0% discount with 18% vat, seller using localtax1 type 2, not localtax2 (other method autodetect) - $mysoc->country_code='CI'; - $mysoc->country_id=21; - $mysoc->localtax1_assuj=1; - $mysoc->localtax2_assuj=0; - $result3=calcul_price_total(10, 10, 0, 18, -1, -1, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 18% vat and 7.5% localtax1, 0% localtax2 - print __METHOD__." result3=".join(', ', $result3)."\n"; - // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) - $this->assertEquals(array(100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0, 0.885, 0, 0, 8.85, 0, 100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0), $result3, 'Test10 CI'); + // 10 * 10 HT - 0% discount with 18% vat, seller using localtax1 type 2, not localtax2 (other method autodetect) + $mysoc->country_code='CI'; + $mysoc->country_id=21; + $mysoc->localtax1_assuj=1; + $mysoc->localtax2_assuj=0; + $result3=calcul_price_total(10, 10, 0, 18, -1, -1, 0, 'HT', 0, 0); // 10 * 10 HT - 0% discount with 18% vat and 7.5% localtax1, 0% localtax2 + print __METHOD__." result3=".join(', ', $result3)."\n"; + // result[0,1,2,3,4,5,6,7,8] (total_ht, total_vat, total_ttc, pu_ht, pu_tva, pu_ttc, total_ht_without_discount, total_vat_without_discount, total_ttc_without_discount) + $this->assertEquals(array(100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0, 0.885, 0, 0, 8.85, 0, 100, 18, 126.85, 10, 1.8, 12.685, 100, 18, 126.85, 8.85, 0), $result3, 'Test10 CI'); - return true; - } + return true; + } - /** - * Test function addline and update_price - * - * @return boolean - * @see http://wiki.dolibarr.org/index.php/Draft:VAT_calculation_and_rounding#Standard_usage - */ - public function testUpdatePrice() - { - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + /** + * Test function addline and update_price + * + * @return boolean + * @see http://wiki.dolibarr.org/index.php/Draft:VAT_calculation_and_rounding#Standard_usage + */ + public function testUpdatePrice() + { + //$this->sharedFixture + global $conf,$user,$langs,$db; + $this->savconf=$conf; + $this->savuser=$user; + $this->savlangs=$langs; + $this->savdb=$db; - $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=0; + $conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND=0; - // Two lines of 1.24 give 2.48 HT and 2.72 TTC with standard vat rounding mode - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen('nolines'); - $invoiceid=$localobject->create($user); + // Two lines of 1.24 give 2.48 HT and 2.72 TTC with standard vat rounding mode + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen('nolines'); + $invoiceid=$localobject->create($user); - $localobject->addline('Desc', 1.24, 1, 10, 0, 0, 0, 0, '', '', 0, 0, 0, 'HT'); - $localobject->addline('Desc', 1.24, 1, 10, 0, 0, 0, 0, '', '', 0, 0, 0, 'HT'); + $localobject->addline('Desc', 1.24, 1, 10, 0, 0, 0, 0, '', '', 0, 0, 0, 'HT'); + $localobject->addline('Desc', 1.24, 1, 10, 0, 0, 0, 0, '', '', 0, 0, 0, 'HT'); - $newlocalobject=new Facture($this->savdb); - $newlocalobject->fetch($invoiceid); + $newlocalobject=new Facture($this->savdb); + $newlocalobject->fetch($invoiceid); - $this->assertEquals(2.48, $newlocalobject->total_ht, "testUpdatePrice test1"); - $this->assertEquals(0.24, $newlocalobject->total_tva, "testUpdatePrice test2"); - $this->assertEquals(2.72, $newlocalobject->total_ttc, "testUpdatePrice test3"); + $this->assertEquals(2.48, $newlocalobject->total_ht, "testUpdatePrice test1"); + $this->assertEquals(0.24, $newlocalobject->total_tva, "testUpdatePrice test2"); + $this->assertEquals(2.72, $newlocalobject->total_ttc, "testUpdatePrice test3"); - // Two lines of 1.24 give 2.48 HT and 2.73 TTC with global vat rounding mode - $localobject=new Facture($this->savdb); - $localobject->initAsSpecimen('nolines'); - $invoiceid=$localobject->create($user); + // Two lines of 1.24 give 2.48 HT and 2.73 TTC with global vat rounding mode + $localobject=new Facture($this->savdb); + $localobject->initAsSpecimen('nolines'); + $invoiceid=$localobject->create($user); - $localobject->addline('Desc', 1.24, 1, 10, 0, 0, 0, 0, '', '', 0, 0, 0, 'HT'); - $localobject->addline('Desc', 1.24, 1, 10, 0, 0, 0, 0, '', '', 0, 0, 0, 'HT'); + $localobject->addline('Desc', 1.24, 1, 10, 0, 0, 0, 0, '', '', 0, 0, 0, 'HT'); + $localobject->addline('Desc', 1.24, 1, 10, 0, 0, 0, 0, '', '', 0, 0, 0, 'HT'); - $newlocalobject=new Facture($this->savdb); - $newlocalobject->fetch($invoiceid); + $newlocalobject=new Facture($this->savdb); + $newlocalobject->fetch($invoiceid); - $this->assertEquals(2.48, $newlocalobject->total_ht, "testUpdatePrice test4"); - //$this->assertEquals(0.25,$newlocalobject->total_tva); - //$this->assertEquals(2.73,$newlocalobject->total_ttc); - } + $this->assertEquals(2.48, $newlocalobject->total_ht, "testUpdatePrice test4"); + //$this->assertEquals(0.25,$newlocalobject->total_tva); + //$this->assertEquals(2.73,$newlocalobject->total_ttc); + } } diff --git a/test/phpunit/ProductTest.php b/test/phpunit/ProductTest.php index e574d3e1d20..a7267251ed0 100644 --- a/test/phpunit/ProductTest.php +++ b/test/phpunit/ProductTest.php @@ -29,11 +29,10 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/product/class/product.class.php'; -if (empty($user->id)) -{ - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); +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; @@ -47,208 +46,210 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1; */ class ProductTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; - /** - * Constructor - * We save global variables into local variables - * - * @return ProductTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return ProductTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$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"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + /** + * setUpBeforeClass + * + * @return void + */ + public static function setUpBeforeClass() + { + global $conf,$user,$langs,$db; - if (empty($conf->produit->enabled)) { print __METHOD__." Module Product must be enabled.\n"; die(); } + if (empty($conf->produit->enabled)) { + print __METHOD__." Module Product must be enabled.\n"; die(); + } - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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"; - } + print __METHOD__."\n"; + } - /** - * End phpunit tests - * - * @return void - */ - protected function tearDown() - { - print __METHOD__."\n"; - } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testProductCreate - * - * @return void - */ - public function testProductCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testProductCreate + * + * @return void + */ + public function testProductCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Product($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user); + $localobject=new Product($this->savdb); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); - print __METHOD__." result=".$result."\n"; - $this->assertLessThanOrEqual($result, 0, "Creation of product"); + print __METHOD__." result=".$result."\n"; + $this->assertLessThanOrEqual($result, 0, "Creation of product"); - return $result; - } + return $result; + } - /** - * testProductFetch - * - * @param int $id Id product - * @return Product - * - * @depends testProductCreate - * The depends says test is run only if previous is ok - */ - public function testProductFetch($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testProductFetch + * + * @param int $id Id product + * @return Product + * + * @depends testProductCreate + * The depends says test is run only if previous is ok + */ + public function testProductFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Product($this->savdb); - $result=$localobject->fetch($id); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $localobject=new Product($this->savdb); + $result=$localobject->fetch($id); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject; - } + return $localobject; + } - /** - * testProductUpdate - * - * @param Product $localobject Product - * @return void - * - * @depends testProductFetch - * The depends says test is run only if previous is ok - */ - public function testProductUpdate($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testProductUpdate + * + * @param Product $localobject Product + * @return void + * + * @depends testProductFetch + * The depends says test is run only if previous is ok + */ + public function testProductUpdate($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject->note_public = 'New public note after update'; - $localobject->note_private = 'New private note after update'; - $result=$localobject->update($localobject->id, $user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $localobject->note_public = 'New public note after update'; + $localobject->note_private = 'New private note after update'; + $result=$localobject->update($localobject->id, $user); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $localobject; - } + return $localobject; + } - /** - * testProductOther - * - * @param Product $localobject Product - * @return void - * - * @depends testProductUpdate - * The depends says test is run only if previous is ok - */ - public function testProductOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testProductOther + * + * @param Product $localobject Product + * @return void + * + * @depends testProductUpdate + * The depends says test is run only if previous is ok + */ + public function testProductOther($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $this->assertEquals(0, 0); + $this->assertEquals(0, 0); - return $localobject->id; - } + return $localobject->id; + } - /** - * testProductDelete - * - * @param int $id Id of product - * @return void - * - * @depends testProductOther - * The depends says test is run only if previous is ok - */ - public function testProductDelete($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testProductDelete + * + * @param int $id Id of product + * @return void + * + * @depends testProductOther + * The depends says test is run only if previous is ok + */ + public function testProductDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $localobject=new Product($this->savdb); - $result=$localobject->fetch($id); + $localobject=new Product($this->savdb); + $result=$localobject->fetch($id); - $result=$localobject->delete($user); - print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); + $result=$localobject->delete($user); + print __METHOD__." id=".$id." result=".$result."\n"; + $this->assertLessThan($result, 0); - return $result; - } + return $result; + } } diff --git a/test/phpunit/ProjectTest.php b/test/phpunit/ProjectTest.php index 8a7e0540b9a..d9f76f26635 100644 --- a/test/phpunit/ProjectTest.php +++ b/test/phpunit/ProjectTest.php @@ -30,8 +30,7 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/projet/class/project.class.php'; require_once dirname(__FILE__).'/../../htdocs/projet/class/task.class.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -75,40 +74,40 @@ class ProjectTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + protected function setUp() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -116,135 +115,135 @@ class ProjectTest extends PHPUnit\Framework\TestCase print __METHOD__."\n"; //print $db->getVersion()."\n"; - } + } /** * End phpunit tests * * @return void */ - protected function tearDown() - { - print __METHOD__."\n"; - } - - /** - * testProjectCreate - * - * @return void - */ - public function testProjectCreate() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; - - $localobject=new Project($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user); - - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; - return $result; - } - - /** - * testProjectFetch - * - * @param int $id Id of object - * @return void - * - * @depends testProjectCreate - * The depends says test is run only if previous is ok - */ - public function testProjectFetch($id) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; - - $localobject=new Project($this->savdb); - $result=$localobject->fetch($id); - - $this->assertLessThan($result, 0); - print __METHOD__." id=".$id." result=".$result."\n"; - return $localobject; - } - - /** - * testProjectValid - * - * @param Project $localobject Project - * @return Project - * - * @depends testProjectFetch - * The depends says test is run only if previous is ok - */ - public function testProjectValid($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; - - $result=$localobject->setValid($user); - - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + protected function tearDown() + { + print __METHOD__."\n"; + } /** - * testProjectClose - * - * @param Project $localobject Project - * @return int - * - * @depends testProjectValid - * The depends says test is run only if previous is ok - */ - public function testProjectOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; - - $result=$localobject->setClose($user); - - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject->id; - } - - /** - * testProjectDelete - * - * @param int $id Id of project - * @return void - * - * @depends testProjectClose - * The depends says test is run only if previous is ok - */ - public function testProjectDelete($id) - { - global $conf,$user,$langs,$db; + * testProjectCreate + * + * @return void + */ + public function testProjectCreate() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Project($this->savdb); - $result=$localobject->fetch($id); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); + + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + return $result; + } + + /** + * testProjectFetch + * + * @param int $id Id of object + * @return void + * + * @depends testProjectCreate + * The depends says test is run only if previous is ok + */ + public function testProjectFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new Project($this->savdb); + $result=$localobject->fetch($id); + + $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + return $localobject; + } + + /** + * testProjectValid + * + * @param Project $localobject Project + * @return Project + * + * @depends testProjectFetch + * The depends says test is run only if previous is ok + */ + public function testProjectValid($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $result=$localobject->setValid($user); + + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } + + /** + * testProjectClose + * + * @param Project $localobject Project + * @return int + * + * @depends testProjectValid + * The depends says test is run only if previous is ok + */ + public function testProjectOther($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $result=$localobject->setClose($user); + + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject->id; + } + + /** + * testProjectDelete + * + * @param int $id Id of project + * @return void + * + * @depends testProjectClose + * The depends says test is run only if previous is ok + */ + public function testProjectDelete($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new Project($this->savdb); + $result=$localobject->fetch($id); $result=$localobject->delete($user); print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $result; - } + $this->assertLessThan($result, 0); + return $result; + } } diff --git a/test/phpunit/PropalTest.php b/test/phpunit/PropalTest.php index ea678e8df34..235cc81e10c 100644 --- a/test/phpunit/PropalTest.php +++ b/test/phpunit/PropalTest.php @@ -29,8 +29,7 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/comm/propal/class/propal.class.php'; -if (empty($user->id)) -{ +if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; $user->fetch(1); $user->getrights(); @@ -74,40 +73,40 @@ class PropalTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + protected function setUp() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -115,190 +114,190 @@ class PropalTest extends PHPUnit\Framework\TestCase print __METHOD__."\n"; //print $db->getVersion()."\n"; - } + } /** * End phpunit tests * * @return void */ - protected function tearDown() - { - print __METHOD__."\n"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testPropalCreate - * - * @return void - */ - public function testPropalCreate() - { - global $conf,$user,$langs,$db; + /** + * testPropalCreate + * + * @return void + */ + public function testPropalCreate() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Propal($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user); + $localobject->initAsSpecimen(); + $result=$localobject->create($user); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; - return $result; - } + $this->assertLessThan($result, 0); + print __METHOD__." result=".$result."\n"; + return $result; + } - /** - * testPropalFetch - * - * @param int $id Id of object - * @return Propal - * - * @depends testPropalCreate - * The depends says test is run only if previous is ok - */ - public function testPropalFetch($id) - { - global $conf,$user,$langs,$db; + /** + * testPropalFetch + * + * @param int $id Id of object + * @return Propal + * + * @depends testPropalCreate + * The depends says test is run only if previous is ok + */ + public function testPropalFetch($id) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Propal($this->savdb); - $result=$localobject->fetch($id); + $result=$localobject->fetch($id); - $this->assertLessThan($result, 0); - print __METHOD__." id=".$id." result=".$result."\n"; - return $localobject; - } + $this->assertLessThan($result, 0); + print __METHOD__." id=".$id." result=".$result."\n"; + return $localobject; + } - /** - * testPropalUpdate - * - * @param Propal $localobject Proposal - * @return Propal - * - * @depends testPropalFetch - * The depends says test is run only if previous is ok - */ - public function testPropalUpdate($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; - - $localobject->note_private = 'New note private after update'; - $result = $localobject->update($user); - - $this->assertLessThan($result, 0); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - return $localobject; - } - - /** - * testPropalAddLine - * - * @param Propal $localobject Proposal - * @return Propal - * - * @depends testPropalUpdate - * The depends says test is run only if previous is ok - */ - public function testPropalAddLine($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; - - $localobject->fetch_thirdparty(); - $result=$localobject->addline('Added line', 10, 2, 19.6); - - $this->assertLessThan($result, 0); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - return $localobject; - } - - /** - * testPropalValid - * - * @param Propal $localobject Proposal - * @return Propal - * - * @depends testPropalAddLine - * The depends says test is run only if previous is ok - */ - public function testPropalValid($localobject) - { - global $conf,$user,$langs,$db; + /** + * testPropalUpdate + * + * @param Propal $localobject Proposal + * @return Propal + * + * @depends testPropalFetch + * The depends says test is run only if previous is ok + */ + public function testPropalUpdate($localobject) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - $result=$localobject->valid($user); + $localobject->note_private = 'New note private after update'; + $result = $localobject->update($user); - print __METHOD__." id=".$localobject->id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $localobject; - } + $this->assertLessThan($result, 0); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + return $localobject; + } - /** - * testPropalOther - * - * @param Propal $localobject Proposal - * @return int - * - * @depends testPropalValid - * The depends says test is run only if previous is ok - */ - public function testPropalOther($localobject) - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testPropalAddLine + * + * @param Propal $localobject Proposal + * @return Propal + * + * @depends testPropalUpdate + * The depends says test is run only if previous is ok + */ + public function testPropalAddLine($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->fetch_thirdparty(); + $result=$localobject->addline('Added line', 10, 2, 19.6); - $localobject->info($localobject->id); - print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n"; - $this->assertNotEquals($localobject->date_creation, ''); + $this->assertLessThan($result, 0); + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + return $localobject; + } - return $localobject->id; - } + /** + * testPropalValid + * + * @param Propal $localobject Proposal + * @return Propal + * + * @depends testPropalAddLine + * The depends says test is run only if previous is ok + */ + public function testPropalValid($localobject) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - /** - * testPropalDelete - * - * @param int $id Id of proposal - * @return void - * - * @depends testPropalOther - * The depends says test is run only if previous is ok - */ - public function testPropalDelete($id) - { - global $conf,$user,$langs,$db; + $result=$localobject->valid($user); + + print __METHOD__." id=".$localobject->id." result=".$result."\n"; + $this->assertLessThan($result, 0); + return $localobject; + } + + /** + * testPropalOther + * + * @param Propal $localobject Proposal + * @return int + * + * @depends testPropalValid + * The depends says test is run only if previous is ok + */ + public function testPropalOther($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; + } + + /** + * testPropalDelete + * + * @param int $id Id of proposal + * @return void + * + * @depends testPropalOther + * The depends says test is run only if previous is ok + */ + public function testPropalDelete($id) + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Propal($this->savdb); - $result=$localobject->fetch($id); + $result=$localobject->fetch($id); $result=$localobject->delete($user); print __METHOD__." id=".$id." result=".$result."\n"; - $this->assertLessThan($result, 0); - return $result; - } + $this->assertLessThan($result, 0); + return $result; + } } diff --git a/test/phpunit/RestAPIDocumentTest.php b/test/phpunit/RestAPIDocumentTest.php index e38f1fbae12..c71ef7bcf63 100644 --- a/test/phpunit/RestAPIDocumentTest.php +++ b/test/phpunit/RestAPIDocumentTest.php @@ -31,9 +31,9 @@ require_once dirname(__FILE__).'/../../htdocs/core/lib/geturl.lib.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/files.lib.php'; if (empty($user->id)) { - echo "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + echo "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS = 1; $conf->global->MAIN_UMASK = '0666'; @@ -47,204 +47,204 @@ $conf->global->MAIN_UMASK = '0666'; */ class RestAPIDocumentTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; - protected $api_url; - protected $api_key; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; + protected $api_url; + protected $api_key; - /** - * Constructor - * We save global variables into local variables. - * - * @return DateLibTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables. + * + * @return DateLibTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf = $conf; - $this->savuser = $user; - $this->savlangs = $langs; - $this->savdb = $db; + //$this->sharedFixture + global $conf,$user,$langs,$db; + $this->savconf = $conf; + $this->savuser = $user; + $this->savlangs = $langs; + $this->savdb = $db; - echo __METHOD__.' db->type='.$db->type.' user->id='.$user->id; - //print " - db ".$db->db; - echo "\n"; - } + echo __METHOD__.' db->type='.$db->type.' user->id='.$user->id; + //print " - db ".$db->db; + echo "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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. - echo __METHOD__."\n"; - } + echo __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - echo __METHOD__."\n"; - } + echo __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; + /** + * 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; - $this->api_url = DOL_MAIN_URL_ROOT.'/api/index.php'; + $this->api_url = DOL_MAIN_URL_ROOT.'/api/index.php'; - $login = 'admin'; - $password = 'admin'; - $url = $this->api_url.'/login?login='.$login.'&password='.$password; - // Call the API login method to save api_key for this test class - $result = getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); - echo __METHOD__.' result = '.var_export($result, true)."\n"; - echo __METHOD__.' curl_error_no: '.$result['curl_error_no']."\n"; - $this->assertEquals($result['curl_error_no'], ''); - $object = json_decode($result['content'], true); - $this->assertNotNull($object, 'Parsing of json result must no be null'); - $this->assertEquals('200', $object['success']['code']); + $login = 'admin'; + $password = 'admin'; + $url = $this->api_url.'/login?login='.$login.'&password='.$password; + // Call the API login method to save api_key for this test class + $result = getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); + echo __METHOD__.' result = '.var_export($result, true)."\n"; + echo __METHOD__.' curl_error_no: '.$result['curl_error_no']."\n"; + $this->assertEquals($result['curl_error_no'], ''); + $object = json_decode($result['content'], true); + $this->assertNotNull($object, 'Parsing of json result must no be null'); + $this->assertEquals('200', $object['success']['code']); - $this->api_key = $object['success']['token']; - echo __METHOD__." api_key: $this->api_key \n"; + $this->api_key = $object['success']['token']; + echo __METHOD__." api_key: $this->api_key \n"; - echo __METHOD__."\n"; - } + echo __METHOD__."\n"; + } - /** - * End phpunit tests. - * @return void - */ - protected function tearDown() - { - echo __METHOD__."\n"; - } + /** + * End phpunit tests. + * @return void + */ + protected function tearDown() + { + echo __METHOD__."\n"; + } - /** - * testPushDocument. - * - * @return int - */ - public function testPushDocument() - { - global $conf,$user,$langs,$db; + /** + * testPushDocument. + * + * @return int + */ + public function testPushDocument() + { + global $conf,$user,$langs,$db; - $url = $this->api_url.'/documents/upload?api_key='.$this->api_key; + $url = $this->api_url.'/documents/upload?api_key='.$this->api_key; - echo __METHOD__.' Request POST url='.$url."\n"; + echo __METHOD__.' Request POST url='.$url."\n"; - // Send to non existent directory + // Send to non existent directory - dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit/tmpphpunit1'); + dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit/tmpphpunit1'); - //$data = '{ "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "mysubdir1/mysubdir2", "filecontent": "content text", "fileencoding": "" }'; - $data = array( - 'filename'=>"mynewfile.txt", - 'modulepart'=>"medias", - 'subdir'=>"tmpphpunit/tmpphpunit1", - 'filecontent'=>"content text", - 'fileencoding'=>"", - 'overwriteifexists'=>0, - 'createdirifnotexists'=>0 - ); + //$data = '{ "filename": "mynewfile.txt", "modulepart": "medias", "ref": "", "subdir": "mysubdir1/mysubdir2", "filecontent": "content text", "fileencoding": "" }'; + $data = array( + 'filename'=>"mynewfile.txt", + 'modulepart'=>"medias", + 'subdir'=>"tmpphpunit/tmpphpunit1", + 'filecontent'=>"content text", + 'fileencoding'=>"", + 'overwriteifexists'=>0, + 'createdirifnotexists'=>0 + ); - $param = ''; - foreach ($data as $key => $val) { - $param .= '&'.$key.'='.urlencode($val); - } + $param = ''; + foreach ($data as $key => $val) { + $param .= '&'.$key.'='.urlencode($val); + } - $result = getURLContent($url, 'POST', $param, 1, array(), array('http', 'https'), 2); - echo __METHOD__.' Result for sending document: '.var_export($result, true)."\n"; - echo __METHOD__.' curl_error_no: '.$result['curl_error_no']."\n"; - $object = json_decode($result['content'], true); - $this->assertNotNull($object, 'Parsing of json result must not be null'); - $this->assertEquals('401', $result['http_code'], 'Return code is not 401'); - $this->assertEquals('401', empty($object['error']['code']) ? '' : $object['error']['code'], 'Error code is not 401'); + $result = getURLContent($url, 'POST', $param, 1, array(), array('http', 'https'), 2); + echo __METHOD__.' Result for sending document: '.var_export($result, true)."\n"; + echo __METHOD__.' curl_error_no: '.$result['curl_error_no']."\n"; + $object = json_decode($result['content'], true); + $this->assertNotNull($object, 'Parsing of json result must not be null'); + $this->assertEquals('401', $result['http_code'], 'Return code is not 401'); + $this->assertEquals('401', empty($object['error']['code']) ? '' : $object['error']['code'], 'Error code is not 401'); - // Send to existent directory + // Send to existent directory - dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit/tmpphpunit2'); - dol_mkdir(DOL_DATA_ROOT.'/medias/tmpphpunit/tmpphpunit2'); + dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit/tmpphpunit2'); + dol_mkdir(DOL_DATA_ROOT.'/medias/tmpphpunit/tmpphpunit2'); - $data = array( - 'filename'=>"mynewfile.txt", - 'modulepart'=>"medias", - 'ref'=>"", - 'subdir'=>"tmpphpunit/tmpphpunit2", - 'filecontent'=>"content text", - 'fileencoding'=>"", - 'overwriteifexists'=>0, - 'createdirifnotexists'=>0 - ); + $data = array( + 'filename'=>"mynewfile.txt", + 'modulepart'=>"medias", + 'ref'=>"", + 'subdir'=>"tmpphpunit/tmpphpunit2", + 'filecontent'=>"content text", + 'fileencoding'=>"", + 'overwriteifexists'=>0, + 'createdirifnotexists'=>0 + ); - $param = ''; - foreach ($data as $key => $val) { - $param .= '&'.$key.'='.urlencode($val); - } + $param = ''; + foreach ($data as $key => $val) { + $param .= '&'.$key.'='.urlencode($val); + } - $result2 = getURLContent($url, 'POST', $param, 1, array(), array('http', 'https'), 2); - echo __METHOD__.' Result for sending document: '.var_export($result2, true)."\n"; - echo __METHOD__.' curl_error_no: '.$result2['curl_error_no']."\n"; - $object2 = json_decode($result2['content'], true); - //$this->assertNotNull($object2, 'Parsing of json result must not be null'); - $this->assertEquals('200', $result2['http_code'], 'Return code must be 200'); - $this->assertEquals($result2['curl_error_no'], ''); - $this->assertEquals($object2, 'mynewfile.txt', 'Must contains basename of file'); + $result2 = getURLContent($url, 'POST', $param, 1, array(), array('http', 'https'), 2); + echo __METHOD__.' Result for sending document: '.var_export($result2, true)."\n"; + echo __METHOD__.' curl_error_no: '.$result2['curl_error_no']."\n"; + $object2 = json_decode($result2['content'], true); + //$this->assertNotNull($object2, 'Parsing of json result must not be null'); + $this->assertEquals('200', $result2['http_code'], 'Return code must be 200'); + $this->assertEquals($result2['curl_error_no'], ''); + $this->assertEquals($object2, 'mynewfile.txt', 'Must contains basename of file'); - dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit/tmpphpunit3'); + dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit/tmpphpunit3'); - $data = array( - 'filename'=>"mynewfile.txt", - 'modulepart'=>"medias", - 'ref'=>"", - 'subdir'=>"tmpphpunit/tmpphpunit3", - 'filecontent'=>"content text", - 'fileencoding'=>"", - 'overwriteifexists'=>0, - 'createdirifnotexists'=>1 - ); + $data = array( + 'filename'=>"mynewfile.txt", + 'modulepart'=>"medias", + 'ref'=>"", + 'subdir'=>"tmpphpunit/tmpphpunit3", + 'filecontent'=>"content text", + 'fileencoding'=>"", + 'overwriteifexists'=>0, + 'createdirifnotexists'=>1 + ); - $param = ''; - foreach ($data as $key => $val) { - $param .= '&'.$key.'='.urlencode($val); - } + $param = ''; + foreach ($data as $key => $val) { + $param .= '&'.$key.'='.urlencode($val); + } - $result3 = getURLContent($url, 'POST', $param, 1, array(), array('http', 'https'), 2); - echo __METHOD__.' Result for sending document: '.var_export($result3, true)."\n"; - echo __METHOD__.' curl_error_no: '.$result3['curl_error_no']."\n"; - $object3 = json_decode($result3['content'], true); - //$this->assertNotNull($object2, 'Parsing of json result must not be null'); - $this->assertEquals('200', $result3['http_code'], 'Return code must be 200'); - $this->assertEquals($result3['curl_error_no'], ''); - $this->assertEquals($object3, 'mynewfile.txt', 'Must contains basename of file'); + $result3 = getURLContent($url, 'POST', $param, 1, array(), array('http', 'https'), 2); + echo __METHOD__.' Result for sending document: '.var_export($result3, true)."\n"; + echo __METHOD__.' curl_error_no: '.$result3['curl_error_no']."\n"; + $object3 = json_decode($result3['content'], true); + //$this->assertNotNull($object2, 'Parsing of json result must not be null'); + $this->assertEquals('200', $result3['http_code'], 'Return code must be 200'); + $this->assertEquals($result3['curl_error_no'], ''); + $this->assertEquals($object3, 'mynewfile.txt', 'Must contains basename of file'); - dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit'); - } + dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit'); + } } diff --git a/test/phpunit/RestAPIUserTest.php b/test/phpunit/RestAPIUserTest.php index 6222f7fcaf7..a534c5f5910 100644 --- a/test/phpunit/RestAPIUserTest.php +++ b/test/phpunit/RestAPIUserTest.php @@ -32,9 +32,9 @@ require_once dirname(__FILE__).'/../../htdocs/core/lib/geturl.lib.php'; if (empty($user->id)) { - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); + print "Load permissions for admin user nb 1\n"; + $user->fetch(1); + $user->getrights(); } $conf->global->MAIN_DISABLE_ALL_MAILS=1; $conf->global->MAIN_UMASK='0666'; @@ -49,193 +49,195 @@ $conf->global->MAIN_UMASK='0666'; */ class RestAPIUserTest extends PHPUnit\Framework\TestCase { - protected $savconf; - protected $savuser; - protected $savlangs; - protected $savdb; - protected $api_url; - protected $api_key; + protected $savconf; + protected $savuser; + protected $savlangs; + protected $savdb; + protected $api_url; + protected $api_key; - /** - * Constructor - * We save global variables into local variables - * - * @return DateLibTest - */ - public function __construct() - { - parent::__construct(); + /** + * Constructor + * We save global variables into local variables + * + * @return DateLibTest + */ + public function __construct() + { + parent::__construct(); - //$this->sharedFixture - global $conf,$user,$langs,$db; - $this->savconf=$conf; - $this->savuser=$user; - $this->savlangs=$langs; - $this->savdb=$db; + //$this->sharedFixture + global $conf,$user,$langs,$db; + $this->savconf=$conf; + $this->savuser=$user; + $this->savlangs=$langs; + $this->savdb=$db; - if (empty($conf->api->enabled)) { print __METHOD__." module api must be enabled.\n"; die(); } + if (empty($conf->api->enabled)) { + print __METHOD__." module api must be enabled.\n"; die(); + } - print __METHOD__." db->type=".$db->type." user->id=".$user->id; - //print " - db ".$db->db; - print "\n"; - } + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; - $db->rollback(); + /** + * tearDownAfterClass + * + * @return void + */ + public static function tearDownAfterClass() + { + global $conf,$user,$langs,$db; + $db->rollback(); - print __METHOD__."\n"; - } + 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; + /** + * 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; - $this->api_url=DOL_MAIN_URL_ROOT.'/api/index.php'; + $this->api_url=DOL_MAIN_URL_ROOT.'/api/index.php'; - $login='admin'; - $password='admin'; - $url=$this->api_url.'/login?login='.$login.'&password='.$password; - // Call the API login method to save api_key for this test class - $result=getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); - print __METHOD__." result = ".var_export($result, true)."\n"; - print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; - $this->assertEquals($result['curl_error_no'], ''); - $object=json_decode($result['content'], true); - $this->assertNotNull($object, "Parsing of json result must not be null"); - $this->assertEquals('200', $object['success']['code']); + $login='admin'; + $password='admin'; + $url=$this->api_url.'/login?login='.$login.'&password='.$password; + // Call the API login method to save api_key for this test class + $result=getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); + print __METHOD__." result = ".var_export($result, true)."\n"; + print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; + $this->assertEquals($result['curl_error_no'], ''); + $object=json_decode($result['content'], true); + $this->assertNotNull($object, "Parsing of json result must not be null"); + $this->assertEquals('200', $object['success']['code']); - $this->api_key = $object['success']['token']; - print __METHOD__." api_key: $this->api_key \n"; + $this->api_key = $object['success']['token']; + print __METHOD__." api_key: $this->api_key \n"; - print __METHOD__."\n"; - } + print __METHOD__."\n"; + } - /** - * End phpunit tests - * - * @return void - */ - protected function tearDown() - { - print __METHOD__."\n"; - } + /** + * End phpunit tests + * + * @return void + */ + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testRestGetUser - * - * @return int - */ - public function testRestGetUser() - { - global $conf,$user,$langs,$db; + /** + * testRestGetUser + * + * @return int + */ + public function testRestGetUser() + { + global $conf,$user,$langs,$db; - $url = $this->api_url.'/users/123456789?api_key='.$this->api_key; - //$addheaders=array('Content-Type: application/json'); + $url = $this->api_url.'/users/123456789?api_key='.$this->api_key; + //$addheaders=array('Content-Type: application/json'); - print __METHOD__." Request GET url=".$url."\n"; - $result=getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); - //print __METHOD__." result for get on unexisting user: ".var_export($result, true)."\n"; - print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; - $this->assertEquals($result['curl_error_no'], ''); - $object=json_decode($result['content'], true); - $this->assertNotNull($object, "Parsing of json result must not be null"); - $this->assertEquals(404, $object['error']['code'], 'Error code is not 404'); + print __METHOD__." Request GET url=".$url."\n"; + $result=getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); + //print __METHOD__." result for get on unexisting user: ".var_export($result, true)."\n"; + print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; + $this->assertEquals($result['curl_error_no'], ''); + $object=json_decode($result['content'], true); + $this->assertNotNull($object, "Parsing of json result must not be null"); + $this->assertEquals(404, $object['error']['code'], 'Error code is not 404'); - $url = $this->api_url.'/users/1?api_key='.$this->api_key; + $url = $this->api_url.'/users/1?api_key='.$this->api_key; - print __METHOD__." Request GET url=".$url."\n"; - $result=getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); - print __METHOD__." result for get on an existing user: ".var_export($result, true)."\n"; - print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; - $this->assertEquals($result['curl_error_no'], ''); - $object=json_decode($result['content'], true); - $this->assertNotNull($object, "Parsing of json result must not be null"); - $this->assertEquals(1, $object['statut']); - } + print __METHOD__." Request GET url=".$url."\n"; + $result=getURLContent($url, 'GET', '', 1, array(), array('http', 'https'), 2); + print __METHOD__." result for get on an existing user: ".var_export($result, true)."\n"; + print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; + $this->assertEquals($result['curl_error_no'], ''); + $object=json_decode($result['content'], true); + $this->assertNotNull($object, "Parsing of json result must not be null"); + $this->assertEquals(1, $object['statut']); + } - /** - * testRestCreateUser - * - * @return void - */ - public function testRestCreateUser() - { - // attemp to create without mandatory fields : - $url = $this->api_url.'/users?api_key='.$this->api_key; - $addheaders=array('Content-Type: application/json'); + /** + * testRestCreateUser + * + * @return void + */ + public function testRestCreateUser() + { + // attemp to create without mandatory fields : + $url = $this->api_url.'/users?api_key='.$this->api_key; + $addheaders=array('Content-Type: application/json'); - $bodyobj = array( - "lastname"=>"testRestUser", - "password"=>"testRestPassword", - "email"=>"test@restuser.com" - ); - $body = json_encode($bodyobj); + $bodyobj = array( + "lastname"=>"testRestUser", + "password"=>"testRestPassword", + "email"=>"test@restuser.com" + ); + $body = json_encode($bodyobj); - print __METHOD__." Request POST url=".$url."\n"; - $result=getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); - //print __METHOD__." Result for creating incomplete user".var_export($result, true)."\n"; - print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; - $this->assertEquals($result['curl_error_no'], ''); - $object=json_decode($result['content'], true); - $this->assertNotNull($object, "Parsing of json result must no be null"); - $this->assertEquals(500, $object['error']['code'], $object['error']['code'].' '.$object['error']['message']); + print __METHOD__." Request POST url=".$url."\n"; + $result=getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); + //print __METHOD__." Result for creating incomplete user".var_export($result, true)."\n"; + print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; + $this->assertEquals($result['curl_error_no'], ''); + $object=json_decode($result['content'], true); + $this->assertNotNull($object, "Parsing of json result must no be null"); + $this->assertEquals(500, $object['error']['code'], $object['error']['code'].' '.$object['error']['message']); - // create regular user - unset($result); - $bodyobj = array( - "login"=>"testRestLogin".mt_rand(), - "lastname"=>"testRestUser", - "password"=>"testRestPassword", - "email"=>"test@restuser.com" - ); - $body = json_encode($bodyobj); - print __METHOD__." Request POST url=".$url."\n"; - $result=getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); - print __METHOD__." rclsesult code for creating user ".var_export($result, true)."\n"; - print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; - $this->assertEquals($result['curl_error_no'], ''); - $resid=json_decode($result['content'], true); - $this->assertNotNull($resid, "Parsing of json result must no be null"); - $this->assertGreaterThan(0, $resid, $object['error']['code'].' '.$object['error']['message']); + // create regular user + unset($result); + $bodyobj = array( + "login"=>"testRestLogin".mt_rand(), + "lastname"=>"testRestUser", + "password"=>"testRestPassword", + "email"=>"test@restuser.com" + ); + $body = json_encode($bodyobj); + print __METHOD__." Request POST url=".$url."\n"; + $result=getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); + print __METHOD__." rclsesult code for creating user ".var_export($result, true)."\n"; + print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; + $this->assertEquals($result['curl_error_no'], ''); + $resid=json_decode($result['content'], true); + $this->assertNotNull($resid, "Parsing of json result must no be null"); + $this->assertGreaterThan(0, $resid, $object['error']['code'].' '.$object['error']['message']); - // attempt to create duplicated user - print __METHOD__." Request POST url=".$url."\n"; - $result=getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); - //print __METHOD__." Result for creating duplicate user".var_export($result, true)."\n"; - print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; - $this->assertEquals($result['curl_error_no'], ''); - $object=json_decode($result['content'], true); - $this->assertNotNull($object, "Parsing of json result must no be null"); - $this->assertEquals(500, $object['error']['code'], $object['error']['code'].' '.$object['error']['message']); - } + // attempt to create duplicated user + print __METHOD__." Request POST url=".$url."\n"; + $result=getURLContent($url, 'POST', $body, 1, $addheaders, array('http', 'https'), 2); + //print __METHOD__." Result for creating duplicate user".var_export($result, true)."\n"; + print __METHOD__." curl_error_no: ".$result['curl_error_no']."\n"; + $this->assertEquals($result['curl_error_no'], ''); + $object=json_decode($result['content'], true); + $this->assertNotNull($object, "Parsing of json result must no be null"); + $this->assertEquals(500, $object['error']['code'], $object['error']['code'].' '.$object['error']['message']); + } } diff --git a/test/phpunit/ScriptsTest.php b/test/phpunit/ScriptsTest.php index 82d1ee28e39..fa0a4a9d72b 100644 --- a/test/phpunit/ScriptsTest.php +++ b/test/phpunit/ScriptsTest.php @@ -30,22 +30,41 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/security.lib.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/security2.lib.php'; -if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); -if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +if (! defined('NOREQUIREUSER')) { + define('NOREQUIREUSER', '1'); +} +if (! defined('NOREQUIREDB')) { + define('NOREQUIREDB', '1'); +} +if (! defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (! defined('NOREQUIRETRAN')) { + define('NOREQUIRETRAN', '1'); +} +if (! defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (! defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (! defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); // If there is no menu to show +} +if (! defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +} +if (! defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (! defined("NOLOGIN")) { + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +} -if (empty($user->id)) -{ - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); +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; @@ -86,66 +105,66 @@ class ScriptsTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - 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. + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testBank - * - * @return string - */ - public function testBank() - { - global $conf,$user,$langs,$db; + /** + * testBank + * + * @return string + */ + public function testBank() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -164,18 +183,18 @@ class ScriptsTest extends PHPUnit\Framework\TestCase $this->assertEquals($result, 'Failed to find bank account with ref BANKDUMMY.'); $this->assertEquals($returnvar, 255); - return $result; - } + return $result; + } - /** - * testCompany - * - * @depends testBank - * @return string - */ - public function testCompany() - { - global $conf,$user,$langs,$db; + /** + * testCompany + * + * @depends testBank + * @return string + */ + public function testCompany() + { + global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -193,88 +212,88 @@ class ScriptsTest extends PHPUnit\Framework\TestCase */ $this->assertEquals(0, 0); - return ''; - } + return ''; + } - /** - * testContracts - * - * @depends testCompany - * @return string - */ - public function testContracts() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testContracts + * + * @depends testCompany + * @return string + */ + public function testContracts() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $returnvar = 0; - $output = array(); + $returnvar = 0; + $output = array(); - $script=dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_customers.php test thirdparties'; - $result=exec($script, $output, $returnvar); - print __METHOD__." result=".$result."\n"; - print __METHOD__." output=".join("\n", $output)."\n"; - print __METHOD__." returnvar=".$returnvar."\n"; - $this->assertEquals($returnvar, 0, 'email_expire_services_to_customers.php thirdparties'); + $script=dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_customers.php test thirdparties'; + $result=exec($script, $output, $returnvar); + print __METHOD__." result=".$result."\n"; + print __METHOD__." output=".join("\n", $output)."\n"; + print __METHOD__." returnvar=".$returnvar."\n"; + $this->assertEquals($returnvar, 0, 'email_expire_services_to_customers.php thirdparties'); - $script=dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_customers.php test contacts -30'; - $result=exec($script, $output, $returnvar); - print __METHOD__." result=".$result."\n"; - print __METHOD__." output=".join("\n", $output)."\n"; - print __METHOD__." returnvar=".$returnvar."\n"; - $this->assertEquals($returnvar, 0, 'email_expire_services_to_customers.php contacts'); + $script=dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_customers.php test contacts -30'; + $result=exec($script, $output, $returnvar); + print __METHOD__." result=".$result."\n"; + print __METHOD__." output=".join("\n", $output)."\n"; + print __METHOD__." returnvar=".$returnvar."\n"; + $this->assertEquals($returnvar, 0, 'email_expire_services_to_customers.php contacts'); - $script=dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_representatives.php test -30'; - $result=exec($script, $output, $returnvar); - print __METHOD__." result=".$result."\n"; - print __METHOD__." output=".join("\n", $output)."\n"; - print __METHOD__." returnvar=".$returnvar."\n"; - $this->assertEquals($returnvar, 0, 'email_expire_services_to_representatives.php'); + $script=dirname(__FILE__).'/../../scripts/contracts/email_expire_services_to_representatives.php test -30'; + $result=exec($script, $output, $returnvar); + print __METHOD__." result=".$result."\n"; + print __METHOD__." output=".join("\n", $output)."\n"; + print __METHOD__." returnvar=".$returnvar."\n"; + $this->assertEquals($returnvar, 0, 'email_expire_services_to_representatives.php'); - return $result; - } + return $result; + } - /** - * testInvoices - * - * @depends testContracts - * @return string - */ - public function testInvoices() - { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + /** + * testInvoices + * + * @depends testContracts + * @return string + */ + public function testInvoices() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; - $returnvar = 0; - $output = array(); + $returnvar = 0; + $output = array(); - $script=dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_customers.php test thirdparties'; - $result=exec($script, $output, $returnvar); - print __METHOD__." result=".$result."\n"; - print __METHOD__." output=".join("\n", $output)."\n"; - print __METHOD__." returnvar=".$returnvar."\n"; - $this->assertEquals($returnvar, 0, 'email_unpaid_invoices_to_customers.php thirdparties'); + $script=dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_customers.php test thirdparties'; + $result=exec($script, $output, $returnvar); + print __METHOD__." result=".$result."\n"; + print __METHOD__." output=".join("\n", $output)."\n"; + print __METHOD__." returnvar=".$returnvar."\n"; + $this->assertEquals($returnvar, 0, 'email_unpaid_invoices_to_customers.php thirdparties'); - $script=dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_customers.php test contacts -30'; - $result=exec($script, $output, $returnvar); - print __METHOD__." result=".$result."\n"; - print __METHOD__." output=".join("\n", $output)."\n"; - print __METHOD__." returnvar=".$returnvar."\n"; - $this->assertEquals($returnvar, 0, 'email_unpaid_invoices_to_customers.php contacts'); + $script=dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_customers.php test contacts -30'; + $result=exec($script, $output, $returnvar); + print __METHOD__." result=".$result."\n"; + print __METHOD__." output=".join("\n", $output)."\n"; + print __METHOD__." returnvar=".$returnvar."\n"; + $this->assertEquals($returnvar, 0, 'email_unpaid_invoices_to_customers.php contacts'); - $script=dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_representatives.php test thirdparties'; - $result=exec($script, $output, $returnvar); - print __METHOD__." result=".$result."\n"; - print __METHOD__." output=".join("\n", $output)."\n"; - print __METHOD__." returnvar=".$returnvar."\n"; - $this->assertEquals($returnvar, 0, 'email_unpaid_invoices_to_customers.php thirdparties'); + $script=dirname(__FILE__).'/../../scripts/invoices/email_unpaid_invoices_to_representatives.php test thirdparties'; + $result=exec($script, $output, $returnvar); + print __METHOD__." result=".$result."\n"; + print __METHOD__." output=".join("\n", $output)."\n"; + print __METHOD__." returnvar=".$returnvar."\n"; + $this->assertEquals($returnvar, 0, 'email_unpaid_invoices_to_customers.php thirdparties'); - return $result; - } + return $result; + } } diff --git a/test/phpunit/SecurityTest.php b/test/phpunit/SecurityTest.php index d2405e9609d..0e08227b96a 100644 --- a/test/phpunit/SecurityTest.php +++ b/test/phpunit/SecurityTest.php @@ -27,25 +27,40 @@ global $conf,$user,$langs,$db; //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver //require_once 'PHPUnit/Autoload.php'; -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no menu to show -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); -if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) -if (! defined("NOSESSION")) define("NOSESSION", '1'); +if (! defined('NOREQUIRESOC')) { + define('NOREQUIRESOC', '1'); +} +if (! defined('NOCSRFCHECK')) { + define('NOCSRFCHECK', '1'); +} +if (! defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); +} +if (! defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); // If there is no menu to show +} +if (! defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +} +if (! defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} +if (! defined("NOLOGIN")) { + define("NOLOGIN", '1'); // If this page is public (can be called outside logged session) +} +if (! defined("NOSESSION")) { + define("NOSESSION", '1'); +} require_once dirname(__FILE__).'/../../htdocs/main.inc.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/security.lib.php'; require_once dirname(__FILE__).'/../../htdocs/core/lib/security2.lib.php'; -if (empty($user->id)) -{ - print "Load permissions for admin user nb 1\n"; - $user->fetch(1); - $user->getrights(); +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; @@ -86,141 +101,141 @@ class SecurityTest extends PHPUnit\Framework\TestCase print "\n"; } - /** - * setUpBeforeClass - * - * @return void - */ - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; + /** + * setUpBeforeClass + * + * @return void + */ + 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"; - } + print __METHOD__."\n"; + } - /** - * tearDownAfterClass - * - * @return void - */ - public static function tearDownAfterClass() - { - global $conf,$user,$langs,$db; + /** + * tearDownAfterClass + * + * @return void + */ + 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; + 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"; - } + protected function tearDown() + { + print __METHOD__."\n"; + } - /** - * testSetLang - * - * @return string - */ - public function testSetLang() - { - global $conf; - $conf=$this->savconf; + /** + * testSetLang + * + * @return string + */ + public function testSetLang() + { + global $conf; + $conf=$this->savconf; - $tmplangs = new Translate('', $conf); + $tmplangs = new Translate('', $conf); - $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "' malicious text with quote"; - $tmplangs->setDefaultLang('auto'); - print __METHOD__.' $tmplangs->defaultlang='.$tmplangs->defaultlang."\n"; - $this->assertEquals($tmplangs->defaultlang, 'malicioustextwithquote_MALICIOUSTEXTWITHQUOTE'); - } + $_SERVER['HTTP_ACCEPT_LANGUAGE'] = "' malicious text with quote"; + $tmplangs->setDefaultLang('auto'); + print __METHOD__.' $tmplangs->defaultlang='.$tmplangs->defaultlang."\n"; + $this->assertEquals($tmplangs->defaultlang, 'malicioustextwithquote_MALICIOUSTEXTWITHQUOTE'); + } - /** - * testSqlAndScriptInjectWithPHPUnit - * - * @return void - */ - public function testSqlAndScriptInjectWithPHPUnit() - { - // Run tests - // More on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet + /** + * testSqlAndScriptInjectWithPHPUnit + * + * @return void + */ + public function testSqlAndScriptInjectWithPHPUnit() + { + // Run tests + // More on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet - // Should be OK - $expectedresult=0; + // Should be OK + $expectedresult=0; - $_SERVER["PHP_SELF"]='/DIR WITH SPACE/htdocs/admin/index.php?mainmenu=home&leftmenu=setup&username=weservices'; - $result=testSqlAndScriptInject($_SERVER["PHP_SELF"], 2); - $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject 1a'); + $_SERVER["PHP_SELF"]='/DIR WITH SPACE/htdocs/admin/index.php?mainmenu=home&leftmenu=setup&username=weservices'; + $result=testSqlAndScriptInject($_SERVER["PHP_SELF"], 2); + $this->assertEquals($expectedresult, $result, 'Error on testSqlAndScriptInject 1a'); - // Should detect XSS - $expectedresult=1; + // Should detect XSS + $expectedresult=1; - $_SERVER["PHP_SELF"]='/DIR WITH SPACE/htdocs/admin/index.php?mainmenu=home&leftmenu=setup&username=weservices;badaction'; - $result=testSqlAndScriptInject($_SERVER["PHP_SELF"], 2); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject 1b'); + $_SERVER["PHP_SELF"]='/DIR WITH SPACE/htdocs/admin/index.php?mainmenu=home&leftmenu=setup&username=weservices;badaction'; + $result=testSqlAndScriptInject($_SERVER["PHP_SELF"], 2); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject 1b'); - $test=""; - $result=testSqlAndScriptInject($test, 0); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa'); + $test=""; + $result=testSqlAndScriptInject($test, 0); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa'); - $test=""; - $result=testSqlAndScriptInject($test, 2); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa2'); + $test=""; + $result=testSqlAndScriptInject($test, 2); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa2'); - $test=''; - $result=testSqlAndScriptInject($test, 0); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa3'); - $test=''; - $result=testSqlAndScriptInject($test, 0); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa4'); - $test=''; - $result=testSqlAndScriptInject($test, 0); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa5'); - $test=''; - $result=testSqlAndScriptInject($test, 0); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa6'); - $test=''; - $result=testSqlAndScriptInject($test, 0); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa7'); + $test=''; + $result=testSqlAndScriptInject($test, 0); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa3'); + $test=''; + $result=testSqlAndScriptInject($test, 0); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa4'); + $test=''; + $result=testSqlAndScriptInject($test, 0); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa5'); + $test=''; + $result=testSqlAndScriptInject($test, 0); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa6'); + $test=''; + $result=testSqlAndScriptInject($test, 0); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa7'); - $test=''; - $result=testSqlAndScriptInject($test, 0); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject bbb'); + $test=''; + $result=testSqlAndScriptInject($test, 0); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject bbb'); - $test=''; - $result=testSqlAndScriptInject($test, 0); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ccc'); + $test=''; + $result=testSqlAndScriptInject($test, 0); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ccc'); - $test=''; - $result=testSqlAndScriptInject($test, 1); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ddd'); + $test=''; + $result=testSqlAndScriptInject($test, 1); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ddd'); - $test='">'; - $result=testSqlAndScriptInject($test, 0); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject eee'); + $test='">'; + $result=testSqlAndScriptInject($test, 0); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject eee'); - $test=' + $test=' '; - $result=testSqlAndScriptInject($test, 0); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject eee'); + $result=testSqlAndScriptInject($test, 0); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject eee'); - $test=""; // Is locked by some browser like chrome because the default directive no-referrer-when-downgrade is sent when requesting the SRC and then refused because of browser protection on img src load without referrer. - $test=""; // Same + $test=""; // Is locked by some browser like chrome because the default directive no-referrer-when-downgrade is sent when requesting the SRC and then refused because of browser protection on img src load without referrer. + $test=""; // Same - $test=''; - $result=testSqlAndScriptInject($test, 0); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff1'); - $test=''; - $result=testSqlAndScriptInject($test, 0); - $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff2'); + $test=''; + $result=testSqlAndScriptInject($test, 0); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff1'); + $test=''; + $result=testSqlAndScriptInject($test, 0); + $this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff2'); - // This case seems to be filtered by browsers now. - $test=''; - //$result=testSqlAndScriptInject($test, 0); - //$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ggg'); + // This case seems to be filtered by browsers now. + $test=''; + //$result=testSqlAndScriptInject($test, 0); + //$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ggg'); - $test='
    '.$langs->trans("Search").'
    '.$langs->trans("Search").'
    :
    '.$obj->office_phone.'".dol_print_phone($obj->office_phone, $obj->country_code, 0, $obj->rowid, 'AC_TEL')."'.$obj->user_mobile.'".dol_print_phone($obj->user_mobile, $obj->country_code, 0, $obj->rowid, 'AC_TEL')."'.$obj->email.''.dol_print_email($obj->email, $obj->rowid, $obj->socid, 'AC_EMAIL', 0, 0, 1)."".dol_print_phone($obj->office_phone, $obj->country_code, 0, $obj->rowid, 'AC_TEL')."".dol_print_phone($obj->office_phone, $obj->country_code, 0, $obj->rowid, 'AC_TEL', ' ', 'phone')."".dol_print_phone($obj->user_mobile, $obj->country_code, 0, $obj->rowid, 'AC_TEL')."".dol_print_phone($obj->user_mobile, $obj->country_code, 0, $obj->rowid, 'AC_TEL', ' ', 'mobile')."'.dol_print_phone($obj->phone_pro, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL').''.dol_print_phone($obj->phone_pro, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'phone').''.dol_print_phone($obj->phone_perso, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL').''.dol_print_phone($obj->phone_perso, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'phone').''.dol_print_phone($obj->phone_mobile, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL').''.dol_print_phone($obj->phone_mobile, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'mobile').''.dol_print_phone($obj->fax, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL').''.dol_print_phone($obj->fax, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'fax').''.dol_print_email($obj->email, $obj->rowid, $obj->socid, 'AC_EMAIL', 18).''.dol_print_email($obj->email, $obj->rowid, $obj->socid, 'AC_EMAIL', 18, 0, 1).'".dol_print_phone($obj->phone, $obj->country_code, 0, $obj->rowid, 'AC_TEL')."".dol_print_phone($obj->phone, $obj->country_code, 0, $obj->rowid, 'AC_TEL', ' ', 'phone')."".dol_print_phone($obj->fax, $obj->country_code, 0, $obj->rowid, 'AC_TEL')."".dol_print_phone($obj->fax, $obj->country_code, 0, $obj->rowid, 'AC_TEL', ' ', 'fax')."".$obj->url."".dol_print_url($obj->url, '', '', 1)."
    '.$langs->trans("RemainderToPay").''.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
    '.$langs->trans("Date").''; + $empty=1; + $datepayment=''; if (GETPOSTISSET('remonth')) { $datepayment = dol_mktime(12, 0, 0, GETPOST("remonth", 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); + $empty=0; } elseif (!empty($conf->global->MAIN_AUTOFILL_DATE)) { $datepayment = dol_mktime(12, 0, 0, dol_print_date(dol_now(), '%m'), dol_print_date(dol_now(), '%d'), dol_print_date(dol_now(), '%Y')); - } else { - $datepayment = '' ; + $empty=0; } - print $form->selectDate($datepayment, '', '', '', '', "add_payment", 1, 1); + print $form->selectDate($datepayment, '', '', '', $empty, "add_payment", 1, 1); print "
    '; $object->id = $line->id; $object->piece_num = $line->piece_num; print $object->getNomUrl(1, '', 0, '', 1); print ''; - $object->id = $line->id; - $object->piece_num = $line->piece_num; - print $object->getNomUrl(1, '', 0, '', 1); - print '