2
0
forked from Wavyzz/dolibarr

New: Implement same rule for return value of all command line scripts (0

when success, <>0 if error).
This commit is contained in:
Laurent Destailleur
2013-06-09 14:40:33 +02:00
parent e6155ebfd8
commit 89ee79f5cf
21 changed files with 295 additions and 95 deletions

View File

@@ -18,6 +18,7 @@ For users:
- New: Module mailman can subscribe/unsubscribe to ML according to categories or type of member.
- New: Add object_hour as substitution tag for opendocument generation.
- New: Add option MEMBER_PAYONLINE_SENDEMAIL to send email when paypal or paybox payment is done.
- New: Implement same rule for return value of all command line scripts (0 when success, <>0 if error).
For translators:
- Normalized sort order of all languages files with english ref file.

View File

@@ -31,7 +31,7 @@ $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;
exit(-1);
}
// Global variables
@@ -60,7 +60,7 @@ $user->getrights();
print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n";
if (! isset($argv[1])) { // Check parameters
print "Usage: ".$script_file." param1 param2 ...\n";
exit;
exit(-1);
}
print '--- start'."\n";
print 'Argument 1='.$argv[1]."\n";
@@ -163,5 +163,5 @@ else
$db->close(); // Close $db database opened handler
return $error;
exit($error);
?>

View File

@@ -30,7 +30,7 @@ $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;
exit(-1);
}
require_once($path."../../htdocs/master.inc.php");
@@ -62,8 +62,8 @@ $error=0;
print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n";
if (! isset($argv[3]) || ! $argv[3]) {
print "Usage: $script_file bank_ref bank_receipt_number (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
exit;
print "Usage: ".$script_file." bank_ref bank_receipt_number (csv|tsv|excel|excel2007) [lang=xx_XX]\n";
exit(-1);
}
$bankref=$argv[1];
$num=$argv[2];
@@ -120,7 +120,7 @@ $result=$acct->fetch('',$bankref);
if ($result <= 0)
{
print "Failed to find bank account with ref ".$bankref.".\n";
exit;
exit(-1);
}
else
{
@@ -135,7 +135,7 @@ $classname = "Export".$model;
if (! dol_is_file($dir.$file))
{
print "No driver to export with format ".$model."\n";
exit;
exit(-1);
}
require_once $dir.$file;
$objmodel = new $classname($db);
@@ -247,7 +247,7 @@ if ($resql)
else
{
dol_print_error($db);
exit;
exit(-1);
}
$total = $balancebefore[$objp->num_releve];
@@ -439,5 +439,5 @@ else
$db->close();
return $ret;
exit($ret);
?>

View File

@@ -31,12 +31,12 @@ $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;
exit(-1);
}
if (! isset($argv[1]) || ! $argv[1]) {
print "Usage: $script_file now\n";
exit;
exit(-1);
}
$now=$argv[1];
@@ -120,4 +120,5 @@ $objWriter->save($fname);
print 'File '.$fname.' was generated.'."\n";
exit(0);
?>

View File

@@ -31,12 +31,12 @@ $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;
exit(-1);
}
if (! isset($argv[1]) || ! $argv[1]) {
print "Usage: $script_file now\n";
exit;
exit(-1);
}
$now=$argv[1];
@@ -87,7 +87,7 @@ $input = trim(fgets(STDIN));
if (! $conf->global->LDAP_CONTACT_ACTIVE)
{
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
exit 1;
exit(-1);
}
*/
@@ -147,5 +147,5 @@ else
dol_print_error($db);
}
return $error;
exit($error);
?>

View File

@@ -33,7 +33,7 @@ $path=dirname(__FILE__).'/';
$sapi_type = php_sapi_name();
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;
exit(-1);
}
if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')))
@@ -43,7 +43,7 @@ if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm
print "Send an email to customers to remind all all contracts services to expire.\n";
print "If you choose 'test' mode, no emails are sent.\n";
print "If you add a delay (nb of days), only services with expired date < today + delay are included.\n";
exit;
exit(-1);
}
$mode=$argv[1];
@@ -157,11 +157,15 @@ if ($resql)
{
print "No unpaid invoices found\n";
}
exit(0);
}
else
{
dol_print_error($db);
dol_syslog("email_expire_services_to_customers.php: Error");
exit(-1);
}
@@ -269,5 +273,4 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldcustomer,$dura
}
}
?>

View File

@@ -33,7 +33,7 @@ $path=dirname(__FILE__).'/';
$sapi_type = php_sapi_name();
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;
exit(-1);
}
if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')))
@@ -43,7 +43,7 @@ if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm
print "Send an email to remind all contracts services to expire, to users that are sale representative for.\n";
print "If you choose 'test' mode, no emails are sent.\n";
print "If you add a delay (nb of days), only services with expired date < today + delay are included.\n";
exit;
exit(-1);
}
$mode=$argv[1];
@@ -157,11 +157,15 @@ if ($resql)
{
print "No services to expire (for companies linked to a particular commercial dolibarr user) found\n";
}
exit(0);
}
else
{
dol_print_error($db);
dol_syslog("email_expire_services_to_representatives.php: Error");
exit(-1);
}
@@ -268,5 +272,4 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta
}
}
?>

View File

@@ -1,7 +1,8 @@
#!/usr/bin/php
<?php
/* Copyright (C) 2012 Nicolas Villa aka Boyquotes http://informetic.fr
* Copyright (C) 2013 Florian Henry <forian.henry@open-cocnept.pro
* Copyright (C) 2013 Florian Henry <forian.henry@open-concept.pro
* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -38,18 +39,18 @@ $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;
exit(-1);
}
if (! isset($argv[1]) || ! $argv[1]) {
print "Usage: ".$script_file." securitykey userlogin cronjobid(optional)\n";
exit;
exit(-1);
}
$key=$argv[1];
if (! isset($argv[2]) || ! $argv[2]) {
print "Usage: ".$script_file." securitykey userlogin cronjobid(optional)\n";
exit;
exit(-1);
} else {
$userlogin=$argv[2];
}
@@ -75,7 +76,7 @@ print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n";
if ($key != $conf->global->CRON_KEY)
{
print "Error: securitykey is wrong\n";
exit;
exit(-1);
}
// Check user login
@@ -85,7 +86,7 @@ if ($result < 0)
{
echo "User Error: ".$user->error;
dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR);
exit;
exit(-1);
}
else
{
@@ -93,7 +94,7 @@ else
{
echo " User user login: ".$userlogin." do not exists";
dol_syslog(" User user login:".$userlogin." do not exists", LOG_ERR);
exit;
exit(-1);
}
}
@@ -116,7 +117,7 @@ if ($result<0)
{
echo "Error: ".$object->error;
dol_syslog("cron_run_jobs.php:: fetch Error ".$object->error, LOG_ERR);
exit;
exit(-1);
}
// current date
@@ -135,14 +136,14 @@ if(is_array($object->lines) && (count($object->lines)>0))
if ($result<0) {
echo "Error:".$cronjob->error;
dol_syslog("cron_run_jobs.php:: fetch Error".$cronjob->error, LOG_ERR);
exit;
exit(-1);
}
// execute methode
$result=$cronjob->run_jobs($userlogin);
if ($result<0) {
echo "Error:".$cronjob->error;
dol_syslog("cron_run_jobs.php:: run_jobs Error".$cronjob->error, LOG_ERR);
exit;
exit(-1);
}
// we re-program the next execution and stores the last execution time for this job
@@ -150,7 +151,7 @@ if(is_array($object->lines) && (count($object->lines)>0))
if ($result<0) {
echo "Error:".$cronjob->error;
dol_syslog("cron_run_jobs.php:: reprogram_jobs Error".$cronjob->error, LOG_ERR);
exit;
exit(-1);
}
}
@@ -158,4 +159,6 @@ if(is_array($object->lines) && (count($object->lines)>0))
}
$db->close();
exit(0);
?>

View File

@@ -32,12 +32,12 @@ $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;
exit(-1);
}
if (! isset($argv[1]) || ! $argv[1]) {
print "Usage: ".$script_file." (ID_MAILING|all)\n";
exit;
exit(-1);
}
$id=$argv[1];

View File

@@ -33,7 +33,7 @@ $path=dirname(__FILE__).'/';
$sapi_type = php_sapi_name();
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;
exit(-1);
}
if (! isset($argv[2]) || ! $argv[2] || ! in_array($argv[1],array('test','confirm')) || ! in_array($argv[2],array('thirdparties','contacts')))
@@ -43,7 +43,7 @@ if (! isset($argv[2]) || ! $argv[2] || ! in_array($argv[1],array('test','confirm
print "Send an email to customers to remind all unpaid customer invoices.\n";
print "If you choose 'test' mode, no emails are sent.\n";
print "If you add a delay (nb of days), only invoice with due date < today + delay are included.\n";
exit;
exit(-1);
}
$mode=$argv[1];
$targettype=$argv[2];
@@ -190,11 +190,15 @@ if ($resql)
{
print "No unpaid invoices found\n";
}
exit(0);
}
else
{
dol_print_error($db);
dol_syslog("email_unpaid_invoices_to_customers.php: Error");
exit(-1);
}
@@ -297,5 +301,4 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldtarget)
}
}
?>

View File

@@ -33,7 +33,7 @@ $path=dirname(__FILE__).'/';
$sapi_type = php_sapi_name();
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;
exit(-1);
}
if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm')))
@@ -43,7 +43,7 @@ if (! isset($argv[1]) || ! $argv[1] || ! in_array($argv[1],array('test','confirm
print "Send an email to users to remind all unpaid customer invoices user is sale representative for.\n";
print "If you choose 'test' mode, no emails are sent.\n";
print "If you add a delay (nb of days), only invoice with due date < today + delay are included.\n";
exit;
exit(-1);
}
$mode=$argv[1];
@@ -167,11 +167,15 @@ if ($resql)
{
print "No unpaid invoices (for companies linked to a particular commercial dolibarr user) found\n";
}
exit(0);
}
else
{
dol_print_error($db);
dol_syslog("email_unpaid_invoices_to_representatives.php: Error");
exit(-1);
}
@@ -272,5 +276,4 @@ function envoi_mail($mode,$oldemail,$message,$total,$userlang,$oldsalerepresenta
}
}
?>

View File

@@ -30,7 +30,7 @@ $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;
exit(-1);
}
// Include Dolibarr environment
@@ -62,7 +62,7 @@ print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n";
if (! isset($argv[1]))
{
usage();
exit;
exit(-1);
}
$diroutputpdf=$conf->facture->dir_output . '/temp';
@@ -125,7 +125,7 @@ foreach ($argv as $key => $value)
if (empty($paymentdateafter) || empty($paymentdatebefore))
{
print 'Error: Bad date format'."\n";
exit;
exit(-1);
}
print 'Rebuild PDF for invoices with at least one payment between '.dol_print_date($paymentdateafter,'day')." and ".dol_print_date($paymentdatebefore,'day').".\n";
}
@@ -151,7 +151,7 @@ foreach ($argv as $key => $value)
if ($result <= 0)
{
print 'Error: Bank account with ref "'.$paymentonbankref.'" not found'."\n";
exit;
exit(-1);
}
$paymentonbankid=$bankaccount->id;
print 'Rebuild PDF for invoices with at least one payment on financial account '.$bankaccount->ref."\n";
@@ -185,7 +185,7 @@ foreach ($argv as $key => $value)
if (! $found && preg_match('/filter=/i',$value))
{
usage();
exit;
exit(-1);
}
}
@@ -193,18 +193,18 @@ foreach ($argv as $key => $value)
if (empty($option) && count($filter) <= 0)
{
usage();
exit;
exit(-1);
}
// Check if there is no uncompatible choice
if (in_array('payments',$filter) && in_array('nopayment',$filter))
{
usage();
exit;
exit(-1);
}
if (in_array('bank',$filter) && in_array('nopayment',$filter))
{
usage();
exit;
exit(-1);
}
@@ -229,7 +229,7 @@ else
$db->close();
return $error;
exit($error);

View File

@@ -31,7 +31,7 @@ $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;
exit(-1);
}
require_once($path."../../htdocs/master.inc.php");
@@ -55,7 +55,7 @@ print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n";
if (! isset($argv[1]) || ! $argv[1]) {
print "Usage: $script_file now\n";
exit;
exit(-1);
}
$now=$argv[1];
@@ -88,7 +88,7 @@ $input = trim(fgets(STDIN));
if (! $conf->global->LDAP_MEMBER_ACTIVE)
{
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
exit 1;
exit(-1);
}
*/
@@ -115,13 +115,13 @@ if ($resql)
if ($result < 0)
{
dol_print_error($db,$member->error);
exit;
exit(-1);
}
$result=$member->fetch_subscriptions();
if ($result < 0)
{
dol_print_error($db,$member->error);
exit;
exit(-1);
}
print $langs->transnoentities("UpdateMember")." rowid=".$member->id." ".$member->getFullName($langs);
@@ -158,5 +158,5 @@ else
dol_print_error($db);
}
return $error;
exit($error);
?>

View File

@@ -31,7 +31,7 @@ $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;
exit(-1);
}
require_once($path."../../htdocs/master.inc.php");
@@ -98,7 +98,7 @@ print "***** $script_file ($version) *****\n";
if (! isset($argv[2]) || ! is_numeric($argv[2])) {
print "Usage: $script_file (nocommitiferror|commitiferror) id_member_type [ldapserverhost]\n";
exit;
exit(-1);
}
$typeid=$argv[2];
if ($argv[1] == 'commitiferror') $forcecommit=1;
@@ -128,12 +128,12 @@ print "\n";
if (empty($conf->global->LDAP_MEMBER_DN))
{
print $langs->trans("Error").': '.$langs->trans("LDAP setup for members not defined inside Dolibarr")."\n";
exit(1);
exit(-1);
}
if ($typeid <= 0)
{
print $langs->trans("Error").': Parameter id_member_type is not a valid ref of an existing member type'."\n";
exit(2);
exit(-2);
}
@@ -173,7 +173,7 @@ if ($resql)
else
{
dol_print_error($db);
exit;
exit(-1);
}
@@ -326,7 +326,7 @@ else
}
return $error;
exit($error);
/**

View File

@@ -31,12 +31,12 @@ $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;
exit(-1);
}
if (! isset($argv[1]) || ! $argv[1]) {
print "Usage: $script_file now\n";
exit;
print "Usage: ".$script_file." now\n";
exit(-1);
}
$now=$argv[1];
@@ -60,7 +60,7 @@ print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n";
if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
{
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
exit 1;
exit(-1);
}
*/
@@ -120,5 +120,5 @@ else
dol_print_error($db);
}
return $error;
exit($error);
?>

View File

@@ -32,7 +32,7 @@ $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;
exit(-1);
}
require_once($path."../../htdocs/master.inc.php");
@@ -77,7 +77,7 @@ print "***** $script_file ($version) *****\n";
if (! isset($argv[1])) {
//print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n";
print "Usage: $script_file (nocommitiferror|commitiferror) [ldapserverhost]\n";
exit;
exit(-1);
}
$groupid=$argv[3];
if ($argv[1] == 'commitiferror') $forcecommit=1;
@@ -112,7 +112,7 @@ $input = trim(fgets(STDIN));
if (empty($conf->global->LDAP_GROUP_DN))
{
print $langs->trans("Error").': '.$langs->trans("LDAP setup for groups not defined inside Dolibarr");
exit(1);
exit(-1);
}
@@ -242,7 +242,7 @@ else
}
return $error;
exit($error);
/**

View File

@@ -31,12 +31,12 @@ $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;
exit(-1);
}
if (! isset($argv[1]) || ! $argv[1]) {
print "Usage: $script_file now\n";
exit;
exit(-1);
}
$now=$argv[1];
@@ -60,7 +60,7 @@ print "***** ".$script_file." (".$version.") pid=".getmypid()." *****\n";
if (! $conf->global->LDAP_SYNCHRO_ACTIVE)
{
print $langs->trans("LDAPSynchronizationNotSetupInDolibarr");
exit 1;
exit(-1);
}
*/
@@ -119,5 +119,5 @@ else
dol_print_error($db);
}
return $error;
exit($error);
?>

View File

@@ -31,7 +31,7 @@ $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;
exit(-1);
}
require_once($path."../../htdocs/master.inc.php");
@@ -89,7 +89,7 @@ print "***** $script_file ($version) *****\n";
if (! isset($argv[1])) {
//print "Usage: $script_file (nocommitiferror|commitiferror) [id_group]\n";
print "Usage: $script_file (nocommitiferror|commitiferror) [ldapserverhost]\n";
exit;
exit(-1);
}
$groupid=$argv[3];
if ($argv[1] == 'commitiferror') $forcecommit=1;
@@ -124,7 +124,7 @@ $input = trim(fgets(STDIN));
if (empty($conf->global->LDAP_USER_DN))
{
print $langs->trans("Error").': '.$langs->trans("LDAP setup for users not defined inside Dolibarr");
exit(1);
exit(-1);
}
@@ -158,7 +158,7 @@ if ($resql)
else
{
dol_print_error($db);
exit;
exit(-1);
}
@@ -296,7 +296,7 @@ else
}
return $error;
exit($error);
/**

View File

@@ -31,7 +31,7 @@ $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;
exit(-1);
}
require_once($path."../../htdocs/master.inc.php");
@@ -66,7 +66,7 @@ if (! isset($argv[1])) { // Check parameters
print "This script check invoices with a withdrawal request and\n";
print "then create payment and build a withdraw file.\n";
print "Usage: ".$script_file." simu|real\n";
exit;
exit(-1);
}
@@ -75,4 +75,6 @@ $result=$withdrawreceipt->create($conf->global->PRELEVEMENT_CODE_BANQUE,$conf->g
$db->close();
exit(0);
?>

View File

@@ -159,6 +159,9 @@ class AllTests
require_once dirname(__FILE__).'/ImportTest.php';
$suite->addTestSuite('ImportTest');
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');

178
test/phpunit/ScriptsTest.php Executable file
View File

@@ -0,0 +1,178 @@
<?php
/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 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 <http://www.gnu.org/licenses/>.
* or see http://www.gnu.org/
*/
/**
* \file test/phpunit/ScriptsTest.php
* \ingroup test
* \brief PHPUnit test
* \remarks To run this script as CLI: phpunit filename.php
*/
global $conf,$user,$langs,$db;
//define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver
require_once 'PHPUnit/Autoload.php';
require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
require_once dirname(__FILE__).'/../../htdocs/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 (empty($user->id))
{
print "Load permissions for admin user nb 1\n";
$user->fetch(1);
$user->getrights();
}
$conf->global->MAIN_DISABLE_ALL_MAILS=1;
/**
* Class for PHPUnit tests
*
* @backupGlobals disabled
* @backupStaticAttributes enabled
* @remarks backupGlobals must be disabled to have db,conf,user and lang not erased.
*/
class ScriptsTest extends PHPUnit_Framework_TestCase
{
protected $savconf;
protected $savuser;
protected $savlangs;
protected $savdb;
/**
* Constructor
* We save global variables into local variables
*
* @return SecurityTest
*/
function __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";
}
// Static methods
public static function setUpBeforeClass()
{
global $conf,$user,$langs,$db;
$db->begin(); // This is to have all actions inside a transaction even if test launched without suite.
print __METHOD__."\n";
}
public static function tearDownAfterClass()
{
global $conf,$user,$langs,$db;
$db->rollback();
print __METHOD__."\n";
}
/**
* Init phpunit tests
*
* @return void
*/
protected function setUp()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
print __METHOD__."\n";
}
/**
* End phpunit tests
*
* @return void
*/
protected function tearDown()
{
print __METHOD__."\n";
}
/**
* testBank
*
* @return string
*/
public function testBank()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$script=dirname(__FILE__).'/../../scripts/bank/export-bank-receipts.php BANKDUMMY RECEIPTDUMMY excel2007 lang=fr_FR';
$result=exec($script, $output, $returnvar);
print __METHOD__." result=".$result."\n";
print __METHOD__." output=".join("\n",$output)."\n";
print __METHOD__." returnvar=".$returnvar."\n";
$this->assertEquals($result,'Failed to find bank account with ref BANKDUMMY.');
$this->assertEquals($returnvar,255);
return $result;
}
/**
* testInvoices
*
* @return string
*/
public function testInvoices()
{
global $conf,$user,$langs,$db;
$conf=$this->savconf;
$user=$this->savuser;
$langs=$this->savlangs;
$db=$this->savdb;
$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);
return $result;
}
}
?>