Browse Source

code syntax

Frédéric FRANCE 4 years ago
parent
commit
b1a1cd4be6
83 changed files with 15700 additions and 15464 deletions
  1. 11 9
      dev/examples/code/create_invoice.php
  2. 11 9
      dev/examples/code/create_order.php
  3. 8 7
      dev/examples/code/create_product.php
  4. 13 12
      dev/examples/code/create_user.php
  5. 8 5
      dev/examples/code/get_contracts.php
  6. 195 193
      test/phpunit/AccountingAccountTest.php
  7. 211 209
      test/phpunit/ActionCommTest.php
  8. 536 532
      test/phpunit/AdherentTest.php
  9. 119 119
      test/phpunit/AdminLibTest.php
  10. 209 214
      test/phpunit/AllTests.php
  11. 10 10
      test/phpunit/BOMTest.php
  12. 188 188
      test/phpunit/BankAccountTest.php
  13. 67 68
      test/phpunit/BonPrelevementTest.php
  14. 378 364
      test/phpunit/BuildDocTest.php
  15. 162 162
      test/phpunit/CMailFileTest.php
  16. 302 302
      test/phpunit/CategorieTest.php
  17. 206 207
      test/phpunit/ChargeSocialesTest.php
  18. 337 325
      test/phpunit/CodingPhpTest.php
  19. 232 217
      test/phpunit/CodingSqlTest.php
  20. 352 350
      test/phpunit/CommandeFournisseurTest.php
  21. 261 259
      test/phpunit/CommandeTest.php
  22. 109 109
      test/phpunit/CommonInvoiceTest.php
  23. 149 149
      test/phpunit/CommonObjectTest.php
  24. 131 132
      test/phpunit/CompanyBankAccountTest.php
  25. 107 107
      test/phpunit/CompanyLibTest.php
  26. 236 238
      test/phpunit/ContactTest.php
  27. 185 186
      test/phpunit/ContratTest.php
  28. 216 197
      test/phpunit/CoreTest.php
  29. 313 314
      test/phpunit/DateLibTest.php
  30. 116 117
      test/phpunit/DateLibTzFranceTest.php
  31. 80 81
      test/phpunit/DiscountTest.php
  32. 124 123
      test/phpunit/EntrepotTest.php
  33. 269 269
      test/phpunit/ExpenseReportTest.php
  34. 276 258
      test/phpunit/ExportTest.php
  35. 146 147
      test/phpunit/FactureFournisseurTest.php
  36. 87 86
      test/phpunit/FactureRecTest.php
  37. 330 324
      test/phpunit/FactureTest.php
  38. 241 244
      test/phpunit/FactureTestRounding.php
  39. 130 131
      test/phpunit/FichinterTest.php
  40. 370 371
      test/phpunit/FilesLibTest.php
  41. 44 45
      test/phpunit/FormAdminTest.php
  42. 45 46
      test/phpunit/FormTest.php
  43. 231 211
      test/phpunit/Functions2LibTest.php
  44. 1473 1451
      test/phpunit/FunctionsLibTest.php
  45. 202 203
      test/phpunit/GetUrlLibTest.php
  46. 324 325
      test/phpunit/HolidayTest.php
  47. 40 41
      test/phpunit/ImagesLibTest.php
  48. 73 53
      test/phpunit/ImportTest.php
  49. 159 139
      test/phpunit/JsonLibTest.php
  50. 103 83
      test/phpunit/LangTest.php
  51. 87 68
      test/phpunit/LesscTest.php
  52. 101 102
      test/phpunit/LoanTest.php
  53. 41 42
      test/phpunit/MarginsLibTest.php
  54. 51 54
      test/phpunit/ModulesTest.php
  55. 114 113
      test/phpunit/MouvementStockTest.php
  56. 353 354
      test/phpunit/NumberingModulesTest.php
  57. 49 48
      test/phpunit/PaypalTest.php
  58. 66 65
      test/phpunit/PdfDocTest.php
  59. 72 73
      test/phpunit/PgsqlTest.php
  60. 314 316
      test/phpunit/PricesTest.php
  61. 210 209
      test/phpunit/ProductTest.php
  62. 123 124
      test/phpunit/ProjectTest.php
  63. 181 182
      test/phpunit/PropalTest.php
  64. 203 203
      test/phpunit/RestAPIDocumentTest.php
  65. 194 192
      test/phpunit/RestAPIUserTest.php
  66. 170 151
      test/phpunit/ScriptsTest.php
  67. 462 447
      test/phpunit/SecurityTest.php
  68. 397 393
      test/phpunit/SocieteTest.php
  69. 49 48
      test/phpunit/StripeTest.php
  70. 154 153
      test/phpunit/SupplierProposalTest.php
  71. 10 10
      test/phpunit/TicketTest.php
  72. 245 245
      test/phpunit/UserGroupTest.php
  73. 312 308
      test/phpunit/UserTest.php
  74. 109 109
      test/phpunit/UtilsTest.php
  75. 195 203
      test/phpunit/WebservicesInvoicesTest.php
  76. 141 141
      test/phpunit/WebservicesOrdersTest.php
  77. 170 170
      test/phpunit/WebservicesOtherTest.php
  78. 283 284
      test/phpunit/WebservicesProductsTest.php
  79. 358 358
      test/phpunit/WebservicesThirdpartyTest.php
  80. 171 171
      test/phpunit/WebservicesUserTest.php
  81. 104 104
      test/phpunit/XCalLibTest.php
  82. 75 75
      test/phpunit/functional/InstallTest.php
  83. 11 8
      test/phpunit/functional/TakePosFunctionalTest.php

+ 11 - 9
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 {

+ 11 - 9
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 {

+ 8 - 7
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 {

+ 13 - 12
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 {

+ 8 - 5
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";

+ 195 - 193
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;
-
-    /**
-     * 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;
-
-        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 (empty($conf->accounting->enabled)) { print __METHOD__." module accouting must be enabled.\n"; exit(-1); }
-
-        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";
-        //print $db->getVersion()."\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;
-
-        $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);
-
-        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;
-
-        $localobject=new AccountingAccount($this->savdb);
-        $result=$localobject->fetch($id);
-
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        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;
-
-        $localobject->label='New label';
-        $result=$localobject->update($user);
-
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        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;
-
-        $localobject=new AccountingAccount($this->savdb);
-        $result=$localobject->fetch($id);
-        $result=$localobject->delete($user);
-
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        return $result;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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 (empty($conf->accounting->enabled)) {
+			print __METHOD__." module accouting must be enabled.\n"; exit(-1);
+		}
+
+		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";
+		//print $db->getVersion()."\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;
+
+		$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);
+
+		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;
+
+		$localobject=new AccountingAccount($this->savdb);
+		$result=$localobject->fetch($id);
+
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
+
+		$localobject->label='New label';
+		$result=$localobject->update($user);
+
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
+
+		$localobject=new AccountingAccount($this->savdb);
+		$result=$localobject->fetch($id);
+		$result=$localobject->delete($user);
+
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		return $result;
+	}
 }

+ 211 - 209
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;
-
-    /**
-     * 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;
-
-        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 (empty($conf->agenda->enabled)) { print __METHOD__." module agenda 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";
-        //print $db->getVersion()."\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;
-
-        $now = dol_now();
-
-        $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';
-
-        $result = $localobject->create($user);
-
-        $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;
-
-        $localobject=new ActionComm($this->savdb);
-        $result=$localobject->fetch($id);
-
-        $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;
-
-    	$localobject->label='New label';
-    	$result=$localobject->update($user);
-
-    	$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;
-
-        $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;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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 (empty($conf->agenda->enabled)) {
+			print __METHOD__." module agenda 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";
+		//print $db->getVersion()."\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;
+
+		$now = dol_now();
+
+		$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';
+
+		$result = $localobject->create($user);
+
+		$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;
+
+		$localobject=new ActionComm($this->savdb);
+		$result=$localobject->fetch($id);
+
+		$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;
+
+		$localobject->label='New label';
+		$result=$localobject->update($user);
+
+		$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;
+
+		$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;
+	}
 }

+ 536 - 532
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;
-
-    /**
-     * 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;
-
-        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 (! 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";
-    }
-
-    /**
-     * 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";
-    }
-
-    /**
-     * 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);
-
-        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;
-
-        $localobject=new Adherent($this->savdb);
-        $localobject->initAsSpecimen();
-        $localobject->typeid=$fk_adherent_type;
-        $result=$localobject->create($user);
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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 (! 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";
+	}
+
+	/**
+	 * 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";
+	}
+
+	/**
+	 * 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);
+
+		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;
+
+		$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);
-
-        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;
-
-        $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;
-
-        $newobject = new Adherent($this->savdb);
-        $result = $newobject->fetch_login($localobject->login);
-
-        $this->assertEquals($newobject, $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;
-
-        $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);
+		$this->assertLessThan($result, 0);
+
+		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;
+
+		$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;
+
+		$newobject = new Adherent($this->savdb);
+		$result = $newobject->fetch_login($localobject->login);
+
+		$this->assertEquals($newobject, $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;
+
+		$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);
 		$result=$localobject->update_note($localobject->note_public, '_public');
-        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);
-
-        //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;
-
-        $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__';
-
-        // 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);
-
-        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;
-
-        //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";
-
-        $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 update user object
-        $user->fetch($user->id);
-        print __METHOD__." user id=".$user->id." fk_member=".$user->fk_member."\n";
-
-        $this->assertNull($user->fk_member);
-
-        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;
-
-        //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";
-
-        //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');
-
-        //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');
-
-        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;
-
-        $result=$localobject->validate($user);
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        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;
-
-        /*$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;
-    }
-
-    /**
-     * 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);
-
-        //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);
-
-        //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;
-    }
-
-    /**
-     * 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);
-
-        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;
-
-        $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;
-    }
+		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);
+
+		//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;
+
+		$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__';
+
+		// 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);
+
+		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;
+
+		//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";
+
+		$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 update user object
+		$user->fetch($user->id);
+		print __METHOD__." user id=".$user->id." fk_member=".$user->fk_member."\n";
+
+		$this->assertNull($user->fk_member);
+
+		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;
+
+		//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";
+
+		//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');
+
+		//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');
+
+		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;
+
+		$result=$localobject->validate($user);
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
+
+		/*$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;
+	}
+
+	/**
+	 * 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);
+
+		//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);
+
+		//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;
+	}
+
+	/**
+	 * 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);
+
+		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;
+
+		$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;
+	}
 }

+ 119 - 119
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;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-    /**
-     * 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);
-
-        return $result;
-    }
-
-    /**
-     * testEnableModule
-     *
-     * @return  void
-     */
-    public function testEnableModule()
-    {
-    	global $conf, $db, $langs, $user;
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+	/**
+	 * 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);
+
+		return $result;
+	}
+
+	/**
+	 * 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);
-    }
+	}
 }

+ 209 - 214
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()
-    {
-
-        $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');
-
-        // 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__).'/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__).'/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__).'/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__).'/BOMTest.php';
-        $suite->addTestSuite('BOMTest');
-
-        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__).'/PropalTest.php';
-        $suite->addTestSuite('PropalTest');
-
-        require_once dirname(__FILE__).'/SupplierProposalTest.php';
-        $suite->addTestSuite('SupplierProposalTest');
-
-        require_once dirname(__FILE__).'/CommandeTest.php';
-        $suite->addTestSuite('CommandeTest');
-
-        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__).'/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__).'/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__).'/AccountingAccountTest.php';
-        $suite->addTestSuite('AccountingAccountTest');
-
-        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');
-        //}
-
-        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__).'/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');
-
-
-        // Payment services
-        require_once dirname(__FILE__).'/PaypalTest.php';
-        $suite->addTestSuite('PaypalTest');
-        require_once dirname(__FILE__).'/StripeTest.php';
-        $suite->addTestSuite('StripeTest');
-
-        return $suite;
-    }
+	/**
+	 * Function suite to make all PHPUnit tests
+	 *
+	 * @return	void
+	 */
+	public static function suite()
+	{
+
+		$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');
+
+		// 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__).'/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__).'/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__).'/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__).'/BOMTest.php';
+		$suite->addTestSuite('BOMTest');
+
+		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__).'/PropalTest.php';
+		$suite->addTestSuite('PropalTest');
+
+		require_once dirname(__FILE__).'/SupplierProposalTest.php';
+		$suite->addTestSuite('SupplierProposalTest');
+
+		require_once dirname(__FILE__).'/CommandeTest.php';
+		$suite->addTestSuite('CommandeTest');
+
+		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__).'/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__).'/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__).'/AccountingAccountTest.php';
+		$suite->addTestSuite('AccountingAccountTest');
+
+		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');
+		//}
+
+		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__).'/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');
+
+
+		// Payment services
+		require_once dirname(__FILE__).'/PaypalTest.php';
+		$suite->addTestSuite('PaypalTest');
+		require_once dirname(__FILE__).'/StripeTest.php';
+		$suite->addTestSuite('StripeTest');
+
+		return $suite;
+	}
 }

+ 10 - 10
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()
 	{

+ 188 - 188
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;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-    /**
-     * 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);
-
-        print __METHOD__." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        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;
-
-        $localobject=new Account($this->savdb);
-        $result=$localobject->fetch($id);
-
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        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;
-
-        /*$result=$localobject->setstatus(0);
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-        */
-
-        $localobject->info($localobject->id);
-
-        $result = $localobject->needIBAN();
-        //print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n";
-        $this->assertEquals(1, $result);
-
-        return $localobject->id;
-    }
-
-    /**
-     * testBankAccountDelete
-     *
-     * @param   int $id     Id of contract
-     * @return  int
-     *
-     * @depends testBankAccountOther
-     * The depends says test is run only if previous is ok
-     */
-    public function testBankAccountDelete($id)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $localobject=new Account($this->savdb);
-        $result=$localobject->fetch($id);
-        $result=$localobject->delete($user);
-
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-        return $result;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+	/**
+	 * 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);
+
+		print __METHOD__." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
+
+		$localobject=new Account($this->savdb);
+		$result=$localobject->fetch($id);
+
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
+
+		/*$result=$localobject->setstatus(0);
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+		*/
+
+		$localobject->info($localobject->id);
+
+		$result = $localobject->needIBAN();
+		//print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n";
+		$this->assertEquals(1, $result);
+
+		return $localobject->id;
+	}
+
+	/**
+	 * testBankAccountDelete
+	 *
+	 * @param   int $id     Id of contract
+	 * @return  int
+	 *
+	 * @depends testBankAccountOther
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testBankAccountDelete($id)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$localobject=new Account($this->savdb);
+		$result=$localobject->fetch($id);
+		$result=$localobject->delete($user);
+
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+		return $result;
+	}
 }

+ 67 - 68
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-    /**
-     * testBonPrevelementCreate
-     *
-     * @return	int
-     */
-    public function testBonPrelevementCreate()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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');
-
-    	print __METHOD__." result=".$result."\n";
-    	$this->assertEquals($result, 0);
-
-    	// Test SEPA file
-
-
-    	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;
+		//$localobject->date_solde=dol_now();
+		$result=$localobject->Create(0, 0, 'simu');
+
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, 0);
+
+		// Test SEPA file
+
+
+		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;
 		$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;
+	}
+	*/
 }

+ 378 - 364
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;
-
-    /**
-     * 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;
-
-        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;
-
-        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.
-
-        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";
-    }
-
-    /**
-     * 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';
-
-        $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;
-
-        // 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 (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 (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 (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;
-    }
-
-    /**
-    * 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();
-
-        // Canelle
-        $localobject->modelpdf='canelle';
-        $result = $localobject->generateDocument($localobject->modelpdf, $langs);
-
-        $this->assertLessThan($result, 0);
-        print __METHOD__." result=".$result."\n";
-
-        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;
-
-        $conf->commande->dir_output.='/temp';
-        $localobject=new Commande($this->savdb);
-        $localobject->initAsSpecimen();
-
-        // Einstein
-        $localobject->modelpdf='einstein';
-        $result = $localobject->generateDocument($localobject->modelpdf, $langs);
-
-        $this->assertLessThan($result, 0);
-        print __METHOD__." result=".$result."\n";
-
-        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;
-
-        $conf->fournisseur->commande->dir_output.='/temp';
-        $localobject=new CommandeFournisseur($this->savdb);
-        $localobject->initAsSpecimen();
-
-        // Muscadet
-        $localobject->modelpdf='muscadet';
-        $result= $localobject->generateDocument($localobject->modelpdf, $langs);
-
-        $this->assertLessThan($result, 0);
-        print __METHOD__." result=".$result."\n";
-
-        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;
-
-        $conf->propal->dir_output.='/temp';
-        $localobject=new Propal($this->savdb);
-        $localobject->initAsSpecimen();
-
-        // Azur
-        $localobject->modelpdf='azur';
-        $result = $localobject->generateDocument($localobject->modelpdf, $langs);
-
-        $this->assertLessThan($result, 0);
-        print __METHOD__." result=".$result."\n";
-
-        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();
-
-        // Baleine
-        $localobject->modelpdf='baleine';
-        $result = $localobject->generateDocument($localobject->modelpdf, $langs);
-
-        $this->assertLessThan($result, 0);
-        print __METHOD__." result=".$result."\n";
-
-        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;
-
-        $conf->ficheinter->dir_output.='/temp';
-        $localobject=new Fichinter($this->savdb);
-        $localobject->initAsSpecimen();
-
-        // Soleil
-        $localobject->modelpdf='soleil';
-        $result=fichinter_create($db, $localobject, $localobject->modelpdf, $langs);
-
-        $this->assertLessThan($result, 0);
-        print __METHOD__." result=".$result."\n";
-
-        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;
-
-        $conf->expedition->dir_output.='/temp';
-        $localobject=new Expedition($this->savdb);
-        $localobject->initAsSpecimen();
-
-        // Merou
-        $localobject->modelpdf='merou';
-        $result= $localobject->generateDocument($localobject->modelpdf, $langs);
-
-        $this->assertLessThan($result, 0);
-        print __METHOD__." result=".$result."\n";
-
-        // Rouget
-        $localobject->modelpdf='rouget';
-        $result= $localobject->generateDocument($localobject->modelpdf, $langs);
-
-        $this->assertLessThan($result, 0);
-        print __METHOD__." result=".$result."\n";
-
-        return 0;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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;
+
+		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.
+
+		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";
+	}
+
+	/**
+	 * 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';
+
+		$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;
+
+		// 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 (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 (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 (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;
+	}
+
+	/**
+	* 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();
+
+		// Canelle
+		$localobject->modelpdf='canelle';
+		$result = $localobject->generateDocument($localobject->modelpdf, $langs);
+
+		$this->assertLessThan($result, 0);
+		print __METHOD__." result=".$result."\n";
+
+		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;
+
+		$conf->commande->dir_output.='/temp';
+		$localobject=new Commande($this->savdb);
+		$localobject->initAsSpecimen();
+
+		// Einstein
+		$localobject->modelpdf='einstein';
+		$result = $localobject->generateDocument($localobject->modelpdf, $langs);
+
+		$this->assertLessThan($result, 0);
+		print __METHOD__." result=".$result."\n";
+
+		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;
+
+		$conf->fournisseur->commande->dir_output.='/temp';
+		$localobject=new CommandeFournisseur($this->savdb);
+		$localobject->initAsSpecimen();
+
+		// Muscadet
+		$localobject->modelpdf='muscadet';
+		$result= $localobject->generateDocument($localobject->modelpdf, $langs);
+
+		$this->assertLessThan($result, 0);
+		print __METHOD__." result=".$result."\n";
+
+		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;
+
+		$conf->propal->dir_output.='/temp';
+		$localobject=new Propal($this->savdb);
+		$localobject->initAsSpecimen();
+
+		// Azur
+		$localobject->modelpdf='azur';
+		$result = $localobject->generateDocument($localobject->modelpdf, $langs);
+
+		$this->assertLessThan($result, 0);
+		print __METHOD__." result=".$result."\n";
+
+		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();
+
+		// Baleine
+		$localobject->modelpdf='baleine';
+		$result = $localobject->generateDocument($localobject->modelpdf, $langs);
+
+		$this->assertLessThan($result, 0);
+		print __METHOD__." result=".$result."\n";
+
+		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;
+
+		$conf->ficheinter->dir_output.='/temp';
+		$localobject=new Fichinter($this->savdb);
+		$localobject->initAsSpecimen();
+
+		// Soleil
+		$localobject->modelpdf='soleil';
+		$result=fichinter_create($db, $localobject, $localobject->modelpdf, $langs);
+
+		$this->assertLessThan($result, 0);
+		print __METHOD__." result=".$result."\n";
+
+		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;
+
+		$conf->expedition->dir_output.='/temp';
+		$localobject=new Expedition($this->savdb);
+		$localobject->initAsSpecimen();
+
+		// Merou
+		$localobject->modelpdf='merou';
+		$result= $localobject->generateDocument($localobject->modelpdf, $langs);
+
+		$this->assertLessThan($result, 0);
+		print __METHOD__." result=".$result."\n";
+
+		// Rouget
+		$localobject->modelpdf='rouget';
+		$result= $localobject->generateDocument($localobject->modelpdf, $langs);
+
+		$this->assertLessThan($result, 0);
+		print __METHOD__." result=".$result."\n";
+
+		return 0;
+	}
 }

+ 162 - 162
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;
-
-    /**
-     * 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;
-
-        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.
-
-        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;
-
-        $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";
-    }
-
-    /**
-     * 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);
-
-        $result=$localobject->sendfile();
-        print __METHOD__." result=".$result."\n";
-        $this->assertFalse($result);   // False because mail send disabled
-
-        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;
-
-        $localobject=new CMailFile('', '', '', '');
-
-        $src='John Doe <john@doe.com>';
-        $result=$localobject->getValidAddress($src, 0);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, 'John Doe <john@doe.com>');
-
-        $src='John Doe <john@doe.com>';
-        $result=$localobject->getValidAddress($src, 1);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, '<john@doe.com>');
-
-        $src='John Doe <john@doe.com>';
-        $result=$localobject->getValidAddress($src, 2);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, 'john@doe.com');
-
-        $src='John Doe <john@doe.com>';
-        $result=$localobject->getValidAddress($src, 3, 0);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, '"John Doe" <john@doe.com>');
-
-        $src='John Doe <john@doe.com>';
-        $result=$localobject->getValidAddress($src, 3, 1);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, '"=?UTF-8?B?Sm9obiBEb2U=?=" <john@doe.com>');
-
-        $src='John Doe <john@doe.com>';
-        $result=$localobject->getValidAddress($src, 4);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, 'John Doe');
-
-        $src='John Doe <john@doe.com>, John Doe2 <john@doe3.com>, John Doe3 <john@doe2.com>';
-        $result=$localobject->getValidAddress($src, 4);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, 'John Doe,John Doe2,John Doe3');
-
-        $src='John Doe <john@doe.com>, John Doe2 <john@doe3.com>, John Doe3 <john@doe2.com>';
-        $result=$localobject->getValidAddress($src, 4, 0, 2);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, 'John Doe,John Doe2...');
-
-        return $result;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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;
+
+		$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";
+	}
+
+	/**
+	 * 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);
+
+		$result=$localobject->sendfile();
+		print __METHOD__." result=".$result."\n";
+		$this->assertFalse($result);   // False because mail send disabled
+
+		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;
+
+		$localobject=new CMailFile('', '', '', '');
+
+		$src='John Doe <john@doe.com>';
+		$result=$localobject->getValidAddress($src, 0);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, 'John Doe <john@doe.com>');
+
+		$src='John Doe <john@doe.com>';
+		$result=$localobject->getValidAddress($src, 1);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, '<john@doe.com>');
+
+		$src='John Doe <john@doe.com>';
+		$result=$localobject->getValidAddress($src, 2);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, 'john@doe.com');
+
+		$src='John Doe <john@doe.com>';
+		$result=$localobject->getValidAddress($src, 3, 0);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, '"John Doe" <john@doe.com>');
+
+		$src='John Doe <john@doe.com>';
+		$result=$localobject->getValidAddress($src, 3, 1);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, '"=?UTF-8?B?Sm9obiBEb2U=?=" <john@doe.com>');
+
+		$src='John Doe <john@doe.com>';
+		$result=$localobject->getValidAddress($src, 4);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, 'John Doe');
+
+		$src='John Doe <john@doe.com>, John Doe2 <john@doe3.com>, John Doe3 <john@doe2.com>';
+		$result=$localobject->getValidAddress($src, 4);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, 'John Doe,John Doe2,John Doe3');
+
+		$src='John Doe <john@doe.com>, John Doe2 <john@doe3.com>, John Doe3 <john@doe2.com>';
+		$result=$localobject->getValidAddress($src, 4, 0, 2);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, 'John Doe,John Doe2...');
+
+		return $result;
+	}
 }

+ 302 - 302
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;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-    /**
-     * 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();
-
-        // 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);
-
-        // 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);
-
-        $resultSecondCreate=$localobject2->create($user);
-        print __METHOD__." result=".$resultSecondCreate."\n";
-        $this->assertEquals(-4, $resultSecondCreate);
-
-        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;
-
-        $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);
-
-        // 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);
-
-        // 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;
-    }
-
-    /**
-     * 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);
-
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertGreaterThan(0, $result);
-        return $localobject;
-    }
-
-    /**
-     * 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;
-
-        $localobject->note='New note after update';
-        $result=$localobject->update($user);
-
-        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;
-
-        /*$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));
-
-        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;
-
-        $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;
-    }
-
-    /**
-     * 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);
-
-        print __METHOD__." retarray size=".count($retarray)."\n";
-        $this->assertTrue(is_array($retarray));
-        return $retarray;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+	/**
+	 * 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();
+
+		// 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);
+
+		// 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);
+
+		$resultSecondCreate=$localobject2->create($user);
+		print __METHOD__." result=".$resultSecondCreate."\n";
+		$this->assertEquals(-4, $resultSecondCreate);
+
+		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;
+
+		$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);
+
+		// 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);
+
+		// 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;
+	}
+
+	/**
+	 * 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);
+
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertGreaterThan(0, $result);
+		return $localobject;
+	}
+
+	/**
+	 * 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;
+
+		$localobject->note='New note after update';
+		$result=$localobject->update($user);
+
+		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;
+
+		/*$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));
+
+		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;
+
+		$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;
+	}
+
+	/**
+	 * 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);
+
+		print __METHOD__." retarray size=".count($retarray)."\n";
+		$this->assertTrue(is_array($retarray));
+		return $retarray;
+	}
 }

+ 206 - 207
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;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-    /**
-     * 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";
-
-        $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;
-
-        $localobject=new ChargeSociales($this->savdb);
-        $result=$localobject->fetch($id);
-        print __METHOD__." id=".$id." result=".$result."\n";
-
-        $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;
-
-        $result=$localobject->set_paid($user);
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-
-        $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;
-
-        $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);
-
-        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;
-
-        $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;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+	/**
+	 * 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";
+
+		$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;
+
+		$localobject=new ChargeSociales($this->savdb);
+		$result=$localobject->fetch($id);
+		print __METHOD__." id=".$id." result=".$result."\n";
+
+		$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;
+
+		$result=$localobject->set_paid($user);
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+
+		$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;
+
+		$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);
+
+		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;
+
+		$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;
+	}
 }

+ 337 - 325
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 (empty($user->id))
-{
-    print "Load permissions for admin user nb 1\n";
-    $user->fetch(1);
-    $user->getrights();
+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;
 
@@ -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;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-    /**
-     * 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');
-
-        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']);
-
-            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 $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->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;
-
-
-            // 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 we don't have <br />
-            $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('/<br \/>/', $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 <br /> that is for xml in file '.$file['relativename'].'. You must use html syntax <br> 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 @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;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+	/**
+	 * 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');
+
+		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']);
+
+			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 $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->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;
+
+
+			// 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 we don't have <br />
+			$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('/<br \/>/', $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 <br /> that is for xml in file '.$file['relativename'].'. You must use html syntax <br> 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 @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;
+	}
 }

+ 232 - 217
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 (empty($user->id))
-{
-    print "Load permissions for admin user nb 1\n";
-    $user->fetch(1);
-    $user->getrights();
+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;
 
@@ -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;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-    /**
-     * 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');
-
-        foreach ($listofsqldir as $dir)
-        {
-            print 'Process dir '.$dir."\n";
-            $filesarray = scandir($dir);
-
-            foreach ($filesarray as $key => $file)
-            {
-                if (! preg_match('/\.sql$/', $file))
-                    continue;
-
-                print 'Check sql file '.$file."\n";
-                $filecontent = file_get_contents($dir.'/'.$file);
-
-                // 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, '"');
-                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, '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 '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.');
-
-                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.');
-                    }
-                }
-            }
-        }
-
-        return;
-    }
-
-    /**
-     * 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;
-
-            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, '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;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+	/**
+	 * 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');
+
+		foreach ($listofsqldir as $dir) {
+			print 'Process dir '.$dir."\n";
+			$filesarray = scandir($dir);
+
+			foreach ($filesarray as $key => $file) {
+				if (! preg_match('/\.sql$/', $file)) {
+					continue;
+				}
+
+				print 'Check sql file '.$file."\n";
+				$filecontent = file_get_contents($dir.'/'.$file);
+
+				// 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, '"');
+				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, '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 '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.');
+
+				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.');
+					}
+				}
+			}
+		}
+
+		return;
+	}
+
+	/**
+	 * 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;
+			}
+
+			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, '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;
+	}
 }

+ 352 - 350
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;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-        //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;
-
-        // 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;
-
-        // 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 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;
-
-        $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);
-
-        // 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);
-
-
-        // 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;
-
-        $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);
-
-        // 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');
-
-        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;
-
-        $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;
-    }
-
-    /**
-     * 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);
-
-        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;
-
-        $result=$localobject->approve($user);
-
-        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;
-
-        $result=$localobject->cancel($user);
-
-        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;
-
-        /*$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);
-
-        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;
-
-        $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;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+		//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;
+
+		// 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;
+
+		// 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 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;
+
+		$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);
+
+		// 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);
+
+
+		// 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;
+
+		$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);
+
+		// 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');
+
+		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;
+
+		$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;
+	}
+
+	/**
+	 * 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);
+
+		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;
+
+		$result=$localobject->approve($user);
+
+		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;
+
+		$result=$localobject->cancel($user);
+
+		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;
+
+		/*$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);
+
+		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;
+
+		$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;
+	}
 }

+ 261 - 259
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;
-
-    /**
-     * 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;
-
-        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 (empty($conf->commande->enabled)) { print __METHOD__." module customer order 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";
-        //print $db->getVersion()."\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;
-
-        $localobject=new Commande($this->savdb);
-        $localobject->initAsSpecimen();
-        $result=$localobject->create($user);
-
-        $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;
-
-        $localobject=new Commande($this->savdb);
-        $result=$localobject->fetch($id);
-
-        $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;
-
-    	$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;
-    }
-
-    /**
-     * 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);
-
-        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;
-
-        $result=$localobject->cancel();
-
-        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;
-
-        /*$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;
-    }
-
-    /**
-     * 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);
-
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-        return $result;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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 (empty($conf->commande->enabled)) {
+			print __METHOD__." module customer order 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";
+		//print $db->getVersion()."\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;
+
+		$localobject=new Commande($this->savdb);
+		$localobject->initAsSpecimen();
+		$result=$localobject->create($user);
+
+		$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;
+
+		$localobject=new Commande($this->savdb);
+		$result=$localobject->fetch($id);
+
+		$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;
+
+		$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;
+	}
+
+	/**
+	 * 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);
+
+		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;
+
+		$result=$localobject->cancel();
+
+		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;
+
+		/*$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;
+	}
+
+	/**
+	 * 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);
+
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+		return $result;
+	}
 }

+ 109 - 109
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;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-
-    /**
-     *  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);
-
-        $result = 0;
-
-        // TODO Insert payment terms
-
-
-        //$result=$localobject->calculate_date_lim_reglement(1);
-        //print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, 0);
-        return $result;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+
+	/**
+	 *  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);
+
+		$result = 0;
+
+		// TODO Insert payment terms
+
+
+		//$result=$localobject->calculate_date_lim_reglement(1);
+		//print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, 0);
+		return $result;
+	}
 }

+ 149 - 149
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;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-
-    /**
-     *  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);
-
-        $result=$localobject->fetch_user(1);
-
-        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;
-
-        $localobject=new Commande($this->savdb);
-        $localobject->fetch(1);
-        $result=$localobject->fetch_projet();
-
-        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;
-
-        $localobject=new Commande($this->savdb);
-        $localobject->fetch(1);
-
-        $result=$localobject->fetch_thirdparty();
-
-        print __METHOD__." result=".$result."\n";
-        $this->assertLessThanOrEqual($result, 0);
-        return $result;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+
+	/**
+	 *  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);
+
+		$result=$localobject->fetch_user(1);
+
+		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;
+
+		$localobject=new Commande($this->savdb);
+		$localobject->fetch(1);
+		$result=$localobject->fetch_projet();
+
+		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;
+
+		$localobject=new Commande($this->savdb);
+		$localobject->fetch(1);
+
+		$result=$localobject->fetch_thirdparty();
+
+		print __METHOD__." result=".$result."\n";
+		$this->assertLessThanOrEqual($result, 0);
+		return $result;
+	}
 }

+ 131 - 132
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.
-
-        print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	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";
+	}
+
+	/**
+	 * 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";
-    }
-
-    /**
-     * testCompanyBankAccountCreate
-     *
-     * @return	int
-     */
-    public function testCompanyBankAccountCreate()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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);
-
-    	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;
+		$localobject->initAsSpecimen();
+		$result=$localobject->create($user);
+
+		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;
 		$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;
-    }
-
-    /**
-     * 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;
-    }
-
-    /**
-     * 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;
+		$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;
+
+		$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;
 		$conf=$this->savconf;
 		$user=$this->savuser;
 		$langs=$this->savlangs;
 		$db=$this->savdb;
 
 		$localobject->owner='New owner';
-    	$result=$localobject->update($user);
-
-	   	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;
-
-        $localobject->owner='New owner';
-        $result=$localobject->update($user);
-
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-        return $localobject->id;
-    }
+		$result=$localobject->update($user);
+
+		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;
+
+		$localobject->owner='New owner';
+		$result=$localobject->update($user);
+
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+		return $localobject->id;
+	}
 }

+ 107 - 107
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;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-    /**
-     * 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);
-
-        $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());
-
-        return $result;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+	/**
+	 * 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);
+
+		$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());
+
+		return $result;
+	}
 }

+ 236 - 238
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;
-
-        $db->begin();	// This is to have all actions inside a transaction even if test launched without suite.
-
-        print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	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";
+	}
+
+	/**
+	 * 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";
-    }
-
-    /**
-     * testContactCreate
-     *
-     * @return	int
-     */
-    public function testContactCreate()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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);
-
-        print __METHOD__." result=".$result."\n";
-    	$this->assertLessThan($result, 0);
-
-    	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;
+		$localobject->initAsSpecimen();
+		$result=$localobject->create($user);
+
+		print __METHOD__." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
 		$conf=$this->savconf;
 		$user=$this->savuser;
 		$langs=$this->savlangs;
 		$db=$this->savdb;
 
 		$localobject=new Contact($this->savdb);
-    	$result=$localobject->fetch($id);
-
-        print __METHOD__." id=".$id." result=".$result."\n";
-    	$this->assertLessThan($result, 0);
-
-    	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;
+		$result=$localobject->fetch($id);
+
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
 		$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');
-
-    	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;
-    }
-
-    /**
-     * 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;
+		$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);
+
+		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;
 		$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->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, '');
-
-        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;
+		$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);
+
+		$localobject->info($localobject->id);
+		print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n";
+		$this->assertNotEquals($localobject->date_creation, '');
+
+		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;
 		$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);
-
-    	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;
-
-        $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);
-
-        // 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);
-
-        // 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;
-    }
+		$this->assertLessThan($result, 0);
+
+		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;
+
+		$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);
+
+		// 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);
+
+		// 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;
+	}
 }

+ 185 - 186
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;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-    /**
-     * 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);
-
-        print __METHOD__." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        return $result;
-    }
-
-    /**
-     * testContratFetch
-     *
-     * @param	int		$id		Id of contract
-     * @return	int
-     *
-     * @depends	testContratCreate
-     * The depends says test is run only if previous is ok
-     */
-    public function 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);
-
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        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;
-
-        /*$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;
-    }
-
-    /**
-     * 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);
-
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-        return $result;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+	/**
+	 * 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);
+
+		print __METHOD__." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		return $result;
+	}
+
+	/**
+	 * testContratFetch
+	 *
+	 * @param	int		$id		Id of contract
+	 * @return	int
+	 *
+	 * @depends	testContratCreate
+	 * The depends says test is run only if previous is ok
+	 */
+	public function 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);
+
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
+
+		/*$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;
+	}
+
+	/**
+	 * 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);
+
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+		return $result;
+	}
 }

+ 216 - 197
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;
-
-    /**
-     * 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.
-
-        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";
-    }
-
-
-    /**
-     * 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;
-
-        $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 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 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';
-        }
-
-        // 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);
-        }
-
-        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.
+
+		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";
+	}
+
+
+	/**
+	 * 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;
+
+		$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 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 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';
+		}
+
+		// 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);
+		}
+
+		return true;
+	}
 }

+ 313 - 314
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.
-
-        print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	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";
+	}
+
+	/**
+	 * 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";
-    }
-
-    /**
-     * testNumBetweenDay
-     *
-     * @return	void
-     */
-    public function testNumBetweenDay()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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;
-
-        // 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, '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
-
-        // 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, '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);
-
-        $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, 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, '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;
-
-        // 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, '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
-
-        // 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, '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;
+	}
+
+	/**
+	 * 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);
+
+		$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($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);
+
+		$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)
+
+		// 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, 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, 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)
+	}
+
+	/**
+	 * 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);
+
+		$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($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);
+
+		$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)
+	}
+
+	/**
+	 * 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;
-
-    	// 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(-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);
-
-    	// 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");
-
-    	$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 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);
-
-    	// 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;
-    }
-
-    /**
-     * 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");
-
-        $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;
-    }
-
-    /**
-     * testDolStringToTime
-     *
-     * @return int
-     */
-    public function testDolStringToTime()
-    {
-        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(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(-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);
+
+		// 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);
+
+		// 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");
+
+		$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);
+
+		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;
+
+		// 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);
+
+		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;
 
 		$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;
-    }
-
-    /**
-     * 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);
+		return $result;
+	}
+
+	/**
+	 * 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);
 		$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
-    }
+	}
 }

+ 116 - 117
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;
-
-    	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.
-
-    	print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	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();
+		}
+
+		$db->begin();	// This is to have all actions inside a transaction even if test launched without suite.
+
+		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;
+	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";
-    }
-
-    /**
-     * 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(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
-
-    	// 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
-
-    	// 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);
-
-    	// 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");
-
-    	$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");
-
-    	$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);
-
-    	return $result;
-    }
+	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;
+
+		// 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(-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
+
+		// 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
+
+		// 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);
+
+		// 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);
+
+		// 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);
+
+		// 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;
+	}
 }

+ 80 - 81
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-    /**
-     * testDiscountCreate
-     *
-     * @return	int
-     */
-    public function testDiscountCreate()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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);
-
-    	$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;
+		$localobject->initAsSpecimen();
+		$result=$localobject->create($user);
+
+		$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;
 		$conf=$this->savconf;
 		$user=$this->savuser;
 		$langs=$this->savlangs;
 		$db=$this->savdb;
 
 		$localobject=new DiscountAbsolute($this->savdb);
-    	$result=$localobject->fetch($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;
+		$result=$localobject->fetch($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;
 		$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;
+	}
 }

+ 124 - 123
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;
-
-    	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.
-
-    	print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	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();
+		}
+
+		$db->begin();	// This is to have all actions inside a transaction even if test launched without suite.
+
+		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;
+	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";
-    }
-
-    /**
-     * testEntrepotCreate
-     *
-     * @return	void
-     */
-    public function testEntrepotCreate()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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);
-
-        print __METHOD__." result=".$result."\n";
-        $this->assertGreaterThan(0, $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;
+		$localobject->initAsSpecimen();
+		$result=$localobject->create($user);
+
+		print __METHOD__." result=".$result."\n";
+		$this->assertGreaterThan(0, $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;
 		$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);
-
-    	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;
+		$result=$localobject->fetch($id);
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
 		$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);
-
-    	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;
+		$result=$localobject->update($localobject->id, $user);
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
 		$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;
-    }
-
-    /**
-     * 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;
+		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;
 		$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;
+	}
 }

+ 269 - 269
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;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-        //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;
-
-        // 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
-
-        $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;
-
-        $result=$localobject2->create($user);
-        print __METHOD__." result=".$result."\n";
-        $this->assertGreaterThanOrEqual(0, $result, "Error on test ExpenseReport create 2 : ".$localobject2->error);
-
-        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;
-
-        $localobject=new ExpenseReport($this->savdb);
-        $result=$localobject->fetch($id);
-
-        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;
-
-        $result=$localobject->setValidate($user);
-
-        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;
-
-        $result=$localobject->setApproved($user);
-
-        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;
-
-        $result=$localobject->set_cancel($user, 'Because...');
-
-        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;
-
-        $result=$localobject->getSumPayments();
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-        $this->assertGreaterThanOrEqual(0, $result);
-
-        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;
-
-        $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;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+		//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;
+
+		// 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
+
+		$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;
+
+		$result=$localobject2->create($user);
+		print __METHOD__." result=".$result."\n";
+		$this->assertGreaterThanOrEqual(0, $result, "Error on test ExpenseReport create 2 : ".$localobject2->error);
+
+		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;
+
+		$localobject=new ExpenseReport($this->savdb);
+		$result=$localobject->fetch($id);
+
+		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;
+
+		$result=$localobject->setValidate($user);
+
+		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;
+
+		$result=$localobject->setApproved($user);
+
+		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;
+
+		$result=$localobject->set_cancel($user, 'Because...');
+
+		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;
+
+		$result=$localobject->getSumPayments();
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertGreaterThanOrEqual(0, $result);
+
+		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;
+
+		$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;
+	}
 }

+ 276 - 258
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-
-    /**
-     * 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 <a href="aaa"><strong>html<br>content</strong></a> inside<br>'."\n";
-        print __METHOD__." valtotest=".$valtotest."\n";
-        $result = $objmodel->csvClean($valtotest, $langs->charset_output);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, '"A string with <a href=""aaa""><strong>html<br>content</strong></a> 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 <a href="aaa"><strong>html<br>content</strong></a> inside<br>'."\n";
-        print __METHOD__." valtotest=".$valtotest."\n";
-        $result = $objmodel->csvClean($valtotest, $langs->charset_output);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, '"A string with <a href=""aaa""><strong>html<br>content</strong></a> inside"');
-    }
-
-    /**
-     * Test export function for a personalized dataset
-     *
-     * @depends	testExportOther
+	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 <a href="aaa"><strong>html<br>content</strong></a> inside<br>'."\n";
+		print __METHOD__." valtotest=".$valtotest."\n";
+		$result = $objmodel->csvClean($valtotest, $langs->charset_output);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, '"A string with <a href=""aaa""><strong>html<br>content</strong></a> 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 <a href="aaa"><strong>html<br>content</strong></a> inside<br>'."\n";
+		print __METHOD__." valtotest=".$valtotest."\n";
+		$result = $objmodel->csvClean($valtotest, $langs->charset_output);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, '"A string with <a href=""aaa""><strong>html<br>content</strong></a> inside"');
+	}
+
+	/**
+	 * Test export function for a personalized dataset
+	 *
+	 * @depends	testExportOther
 	 * @return void
-     */
-    public function testExportPersonalizedExport()
-    {
-        global $conf,$user,$langs,$db;
+	 */
+	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";
+		$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);
+		$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;
+		// 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);
+		dol_mkdir($conf->export->dir_temp);
 
-        $model='csv';
+		$model='csv';
 
-        // 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 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');
-
-
-        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
+		$this->assertEquals($expectedresult, $result, 'Error in Excel2007new export');
+
+
+		return true;
+	}
+
+	/**
+	 * Test export function for a personalized dataset with filters
+	 *
+	 * @depends	testExportPersonalizedExport
 	 * @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)
-			{
+	 */
+	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
+	 * @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;
+	}
 }

+ 146 - 147
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-    /**
-     * testFactureFournisseurCreate
-     *
-     * @return int
-     */
-    public function testFactureFournisseurCreate()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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);
-
-    	$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;
+		$localobject->initAsSpecimen();
+		$result=$localobject->create($user);
+
+		$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;
 		$conf=$this->savconf;
 		$user=$this->savuser;
 		$langs=$this->savlangs;
 		$db=$this->savdb;
 
 		$localobject=new FactureFournisseur($this->savdb);
-    	$result=$localobject->fetch($id);
-
-    	$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;
+		$result=$localobject->fetch($id);
+
+		$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;
 		$conf=$this->savconf;
 		$user=$this->savuser;
 		$langs=$this->savlangs;
 		$db=$this->savdb;
 
 		$localobject->note='New note after update';
-    	$result=$localobject->update($user);
-
-    	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;
+		$result=$localobject->update($user);
+
+		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;
+		$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, $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;
 
-    	$result=$localobject->validate($user);
-    	print __METHOD__." id=".$localobject->id." result=".$result."\n";
-
-    	$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;
-
-        /*$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;
-    }
-
-    /**
-     * 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;
+		/*$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;
+	}
+
+	/**
+	 * 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;
+	}
 }

+ 87 - 86
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-    /**
-     * testFactureCreate
-     *
-     * @return int
-     */
-    public function testFactureRecCreate()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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();
-
-        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;
-    }
+	 */
+	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;
+	}
 }

+ 330 - 324
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;
-
-    /**
-     * 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;
-
-        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;
-
-        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.
-
-        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";
-    }
-
-    /**
-     * 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;
-    }
-
-    /**
-     * 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);
-
-        $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;
-
-        $this->changeProperties($localobject);
-        $result=$localobject->update($user);
-
-        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;
-
-        $result=$localobject->validate($user);
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-
-        $this->assertLessThan($result, 0);
-
-        // 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']);
-
-        $arraywithdiff = $this->objCompare(
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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;
+
+		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.
+
+		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";
+	}
+
+	/**
+	 * 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;
+	}
+
+	/**
+	 * 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);
+
+		$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;
+
+		$this->changeProperties($localobject);
+		$result=$localobject->update($user);
+
+		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;
+
+		$result=$localobject->validate($user);
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+
+		$this->assertLessThan($result, 0);
+
+		// 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']);
+
+		$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
-
-        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;
-
-        /*$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, '');
-
-        $result=$localobject->demande_prelevement($user);
-        print __METHOD__." result=".$result."\n";
-       	$this->assertLessThan($result, 0);
-
-        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;
-
-        // 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);
-
-        // Create another invoice and validate it after $localobject
-        $localobject2=new Facture($this->savdb);
-        $result=$localobject2->initAsSpecimen();
-        $result=$localobject2->create($user);
-        $result=$localobject2->validate($user);
+		$this->assertEquals($arraywithdiff, array());    // Actual, Expected
+
+		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;
+
+		/*$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, '');
+
+		$result=$localobject->demande_prelevement($user);
+		print __METHOD__." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
+
+		// 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);
+
+		// 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";
-
-        $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');
-
-        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=$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');
-
-        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';
-    }
-
-    /**
-     * 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;
-    }
+		print 'Invoice $localobject2 created with ref = '.$localobject2->ref."\n";
+
+		$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');
+
+		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=$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');
+
+		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';
+	}
+
+	/**
+	 * 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;
+	}
 }

+ 241 - 244
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-
-
-    /**
-     * 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;
+	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;
+
+		$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);
+
+		// 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);
+
+		$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;
+
+		$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);
+
+		// 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);
+
+		$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;
 
+		// With option 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_tva);
-        $result=$localobject->create($user);
-
-        // 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);
-
-        $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;
-
-        $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);
-
-        // 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);
-
-        $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;
-
-    	// 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);
-
-    	// 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');
-    }
-
-    /**
-     * 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;
-
-    	$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;
-
-    	$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;
-
-    	// 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);
-
-    	// 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);
-    }
+		$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;
+
+		$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;
+
+		// 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);
+
+		// 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);
+	}
+
+	/**
+	 * 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;
+
+		$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;
+
+		$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);
+	}
 }

+ 130 - 131
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-    /**
-     * testFichinterCreate
-     *
-     * @return	int
-     */
-    public function testFichinterCreate()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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);
-
-    	print __METHOD__." result=".$result."\n";
-    	$this->assertLessThan($result, 0);
-
-    	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;
+		$localobject->initAsSpecimen();
+		$result=$localobject->create($user);
+
+		print __METHOD__." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
 		$conf=$this->savconf;
 		$user=$this->savuser;
 		$langs=$this->savlangs;
 		$db=$this->savdb;
 
 		$localobject=new Fichinter($this->savdb);
-    	$result=$localobject->fetch($id);
-
-    	print __METHOD__." id=".$id." result=".$result."\n";
-    	$this->assertLessThan($result, 0);
-
-    	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;
+		$result=$localobject->fetch($id);
+
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
+		$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;
+	}
+
+	/**
+	 * 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->setValid($user);
-    	print __METHOD__." id=".$localobject->id." result=".$result."\n";
-
-    	$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;
-
-        /*$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;
-    }
-
-    /**
-     * 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;
+		/*$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;
+	}
+
+	/**
+	 * 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;
+	}
 }

+ 370 - 371
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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;
-
-        $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='file://www.dolibarr.org/download/file.zip';
-        $result=dol_is_url($url);
-        print __METHOD__." result=".$result."\n";
-        $this->assertTrue($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;
-
-    	// 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;
-
-    	$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;
-    	$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);
-    }
-
-
-    /**
-     * 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';
-
-        $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
-
-        // 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
-
-        // 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 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 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
-
-        // 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;
-
-        $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);
-
-        $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();
-
-        $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);
-    }
-
-    /**
-     * 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));
-    }
-
-
-    /**
-     * 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');
-
-        // We save user properties
-        $savpermlire = $user->rights->facture->lire;
-        $savpermcreer = $user->rights->facture->creer;
+	}
+
+	/**
+	 * 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='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);
+
+		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;
+
+		// 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;
+
+		$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;
+		$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);
+	}
+
+
+	/**
+	 * 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';
+
+		$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
+
+		// 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
+
+		// 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 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 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
+
+		// 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;
+
+		$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);
+
+		$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();
+
+		$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);
+	}
+
+	/**
+	 * 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));
+	}
+
+
+	/**
+	 * 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');
+
+		// 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']);
-
-
-        // 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']);
-
-        // 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 = 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;
-    }
+		$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']);
+
+		$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']);
+
+		$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']);
+
+
+		// We restore user properties
+		$user->rights->facture->lire = $savpermlire;
+		$user->rights->facture->creer = $savpermcreer;
+	}
 }

+ 44 - 45
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-    /**
-     * testSelectPaperFormat
-     *
-     * @return int
-     */
-    public function testSelectPaperFormat()
-    {
-    	global $conf,$user,$langs,$db;
+	 * @return	void
+	 */
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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, '<select class="flat" id="paperformat_id" name="paperformat_id"><option value="EUA4">Format A4 - 210x297 mm</option></select>');
-    	print __METHOD__." result=".$result."\n";
-    	return $result;
-    }
+		$this->assertEquals($result, '<select class="flat" id="paperformat_id" name="paperformat_id"><option value="EUA4">Format A4 - 210x297 mm</option></select>');
+		print __METHOD__." result=".$result."\n";
+		return $result;
+	}
 }

+ 45 - 46
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-    /**
-     * testSelectProduitsList
-     *
-     * @return int
-     */
-    public function testSelectProduitsList()
-    {
-    	global $conf,$user,$langs,$db;
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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;
+	}
 }

+ 231 - 211
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;
-
-    /**
-     * 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.
-
-        print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-        global $conf,$user,$langs,$db;
-        //$db->rollback();
-
-        print __METHOD__."\n";
-    }
+	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.
+
+		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";
-    }
+	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";
-    }
-
-
-    /**
-     * 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);
-
-    	$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);
-
-	    $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);
-
-	    $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 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);
-
-	    //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);
-
-	    //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);
-
-	    //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);
-
-	    $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);
-
-	    $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);
-
-    	// 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);
-
-    	// 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='192.168.0.0';
-        $result=is_ip($ip);
-        print __METHOD__." for ".$ip." result=".$result."\n";
-        $this->assertEquals(2, $result, $ip);
-    }
+	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);
+	}
+
+	/**
+	 * 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);
+	}
+
+	/**
+	 * 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);
+
+		//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);
+
+		//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);
+
+		$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);
+
+		$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);
+
+		$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?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);
+
+		//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);
+	}
+
+	/**
+	 * 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
+
+		$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);
+
+		$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);
+	}
 }

+ 1473 - 1451
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 <test@yahoo.com>";
-    	$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<br>bbbbbbbbbbbb<br>";
-        $result=dolGetFirstLineOfText($input, 2);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals("aaaa<br>\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<br>bbbbbbbbbbbb<br>cccccc<br>";
-        $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<br>bbbbbbbbbbbb<br>cccccc<br>";
-        $result=dolGetFirstLineOfText($input, 2);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals("aaaa<br>\nbbbbbbbbbbbb...", $result);
-
-        // Nb of line is higher
-
-        $input="aaaa<br>bbbbbbbbbbbb<br>cccccc";
-        $result=dolGetFirstLineOfText($input, 100);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals("aaaa<br>\nbbbbbbbbbbbb<br>\ncccccc", $result, 'dolGetFirstLineOfText with nb 100 a');
-
-        $input="aaaa<br>bbbbbbbbbbbb<br>cccccc<br>";
-        $result=dolGetFirstLineOfText($input, 100);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals("aaaa<br>\nbbbbbbbbbbbb<br>\ncccccc", $result, 'dolGetFirstLineOfText with nb 100 b');
-
-        $input="aaaa<br>bbbbbbbbbbbb<br>cccccc<br>\n";
-        $result=dolGetFirstLineOfText($input, 100);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals("aaaa<br>\nbbbbbbbbbbbb<br>\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='<html>xxx</html>';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with html tag');
-        $input='<body>xxx</body>';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with body tag');
-        $input='xxx <b>yyy</b> zzz';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with b tag');
-        $input='xxx <u>yyy</u> zzz';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with u tag');
-        $input='text with <div>some div</div>';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with div tag');
-        $input='text with HTML &nbsp; entities';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with entities tag');
-        $input='xxx<br>';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with entities br');
-        $input='xxx<br >';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with entities br');
-        $input='xxx<br style="eee">';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with entities br and attributes');
-        $input='xxx<br style="eee" >';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with entities br and attributes bis');
-        $input='<h2>abc</h2>';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with entities h2');
-        $input='<img id="abc" src="https://xxx.com/aaa/image.png" />';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with img tag');
-        $input='<a class="azerty" href="https://xxx.com/aaa/image.png" />';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with a tag');
-        $input='This is a text with&nbsp;html spaces';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with a &nbsp;');
-        $input='This is a text with accent &eacute;';
-        $after=dol_textishtml($input);
-        $this->assertTrue($after, 'Test with a &eacute;');
-
-        // False
-        $input='xxx < br>';
-        $after=dol_textishtml($input);
-        $this->assertFalse($after);
-        $input='xxx <email@email.com>';	// <em> is html, <em... is not
-        $after=dol_textishtml($input);
-        $this->assertFalse($after);
-        $input='xxx <brstyle="ee">';
-        $after=dol_textishtml($input);
-        $this->assertFalse($after);
-        $input='This is a text with html comments <!-- comment -->';	// 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<br>";
-        $after=dol_htmlcleanlastbr($input);
-        $this->assertEquals("A string", $after);
-
-        $input="A string first<br>\nA string second<br>";
-        $after=dol_htmlcleanlastbr($input);
-        $this->assertEquals("A string first<br>\nA string second", $after);
-
-        $input="A string\n<br type=\"_moz\" />\n";
-        $after=dol_htmlcleanlastbr($input);
-        $this->assertEquals("A string", $after);
-
-        $input="A string\n<br><br />\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<br>string 1"; $text2="A string 2";	// text 1 is html, concat need <br>\n
-        $after=dol_concatdesc($text1, $text2);
-        $this->assertEquals("A<br>string 1<br>\nA string 2", $after);
-
-        $text1="A string 1"; $text2="A <b>string</b> 2";	// text 2 is html, concat need <br>\n
-        $after=dol_concatdesc($text1, $text2);
-        $this->assertEquals("A string 1<br>\nA <b>string</b> 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 <b>string<b><br>\n<br>\n\nwith html tag<br>\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 <b>string<b><br>\n<br>\n\nwith html tag<br>\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 <b>string<b><br>\n<br>\n\nwith html tag<br>\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 <b>string<b><br>\r\n<br>\r\n\r\nwith html tag<br>\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<br>Another string";
-        $after=dol_string_nohtmltag($text, 0);
-        $this->assertEquals("A string\nAnother string", $after, "test4");
-
-        $text="A string<br>Another string";
-        $after=dol_string_nohtmltag($text, 1);
-        $this->assertEquals("A string Another string", $after, "test5");
-
-        $text='<a href="/myurl" title="<u>Afficher projet</u>">ABC</a>';
-        $after=dol_string_nohtmltag($text, 1);
-        $this->assertEquals("ABC", $after, "test6");
-
-        $text='<a href="/myurl" title="&lt;u&gt;Afficher projet&lt;/u&gt;">DEF</a>';
-        $after=dol_string_nohtmltag($text, 1);
-        $this->assertEquals("DEF", $after, "test7");
-
-        $text='<a href="/myurl" title="<u>A title</u>">HIJ</a>';
-        $after=dol_string_nohtmltag($text, 0);
-        $this->assertEquals("HIJ", $after, "test8");
-
-        $text="A <b>string<b>\n\nwith html tag and '<' chars<br>\n";
-        $after=dol_string_nohtmltag($text, 0);
-        $this->assertEquals("A string\n\nwith html tag and '<' chars", $after, "test9");
-
-        $text="A <b>string<b>\n\nwith tag with < chars<br>\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 <br> before \n
-        $this->assertEquals("A string<br>\nwith a &eacute;, &amp;, &lt; and &gt;.", $after);
-
-        $input="A string\nwith a é, &, < and >.";
-        $after=dol_htmlentitiesbr($input, 1);    // Replace \n with <br>
-        $this->assertEquals("A string<br>with a &eacute;, &amp;, &lt; and &gt;.", $after);
-
-        $input="A string\nwith a é, &, < and >.\n\n";	// With some \n at end that should be cleaned
-        $after=dol_htmlentitiesbr($input, 0);    // Add <br> before \n
-        $this->assertEquals("A string<br>\nwith a &eacute;, &amp;, &lt; and &gt;.", $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 <br>
-        $this->assertEquals("A string<br>with a &eacute;, &amp;, &lt; and &gt;.", $after);
-
-        // Text already HTML, so &,<,> should not be converted
-
-        $input="A string<br>\nwith a é, &, < and >.";
-        $after=dol_htmlentitiesbr($input);
-        $this->assertEquals("A string<br>\nwith a &eacute;, &, < and >.", $after);
-
-        $input="<li>\nA string with a é, &, < and >.</li>\nAnother string";
-        $after=dol_htmlentitiesbr($input);
-        $this->assertEquals("<li>\nA string with a &eacute;, &, < and >.</li>\nAnother string", $after);
-
-        $input="A string<br>\nwith a é, &, < and >.<br>";	// With some <br> at end that should be cleaned
-        $after=dol_htmlentitiesbr($input);
-        $this->assertEquals("A string<br>\nwith a &eacute;, &, < and >.", $after);
-
-        $input="<li>\nA string with a é, &, < and >.</li>\nAnother string<br>";	// With some <br> at end that should be cleaned
-        $after=dol_htmlentitiesbr($input);
-        $this->assertEquals("<li>\nA string with a &eacute;, &, < and >.</li>\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 <br>
-        $input="A string\nwith a é, &, < and > and <b>bold</b> tag.\nThird line";
-        $after=dol_nboflines_bis($input, 0);
-        $this->assertEquals($after, 1);
-
-        // This is a html string so nb of lines depends on <br>
-        $input="A string<br>with a é, &, < and > and <b>bold</b> tag.<br>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&<b>#</b>,\"'";    // " will be converted into '
-        $result=dol_escape_js($input);
-        $this->assertEquals("x&<b>#</b>,\'\'", $result, "Test mode=0");
-
-        $result=dol_escape_js($input, 1);
-        $this->assertEquals("x&<b>#</b>,\"\'", $result, "Test mode=1");
-
-        $result=dol_escape_js($input, 2);
-        $this->assertEquals("x&<b>#</b>,\\\"'", $result, "Test mode=2");
-    }
-
-
-    /**
-    * testDolEscapeHtmlTag
-    *
-    * @return	void
-    */
-    public function testDolEscapeHtmlTag()
-    {
-        $input='x&<b>#</b>,"';    // & and " are converted into html entities, <b> are removed
-        $result=dol_escape_htmltag($input);
-        $this->assertEquals('x&amp;#,&quot;', $result);
-
-        $input='x&<b>#</b>,"';    // & and " are converted into html entities, <b> are not removed
-        $result=dol_escape_htmltag($input, 1);
-        $this->assertEquals('x&amp;&lt;b&gt;#&lt;/b&gt;,&quot;', $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('<span style="margin-right: 10px;">12&nbsp;34&nbsp;56&nbsp;78&nbsp;90</span>', $phone, 'Phone for FR 1');
-
-        $object->country_code='FR';
-        $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, '');
-        $this->assertEquals('<span style="margin-right: 10px;">1234567890</span>', $phone, 'Phone for FR 2');
-
-        $object->country_code='FR';
-        $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ' ');
-        $this->assertEquals('<span style="margin-right: 10px;">12 34 56 78 90</span>', $phone, 'Phone for FR 3');
-
-        $object->country_code='CA';
-        $phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ' ');
-        $this->assertEquals('<span style="margin-right: 10px;">(123) 456-7890</span>', $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('<img src="/fullpath/img.png" alt="" title="title" class="inline-block">', $s, 'testImgPicto3');
-
-        $s=img_picto('title', '/fullpath/img.png', '', true);
-        print __METHOD__." s=".$s."\n";
-        $this->assertEquals('<img src="/fullpath/img.png" alt="" title="title" class="inline-block">', $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<br>\na");
-
-        //With $forxml parameter
-        $this->assertEquals(dol_nl2br($string, 0, 1), "a<br />\na");
-
-        //Replacing \n by br
-        $this->assertEquals(dol_nl2br($string, 1), "a<br>a");
-
-        //With $forxml parameter
-        $this->assertEquals(dol_nl2br($string, 1, 1), "a<br />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<corrupted>';
-    	$_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 <test@yahoo.com>";
+		$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<br>bbbbbbbbbbbb<br>";
+		$result=dolGetFirstLineOfText($input, 2);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals("aaaa<br>\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<br>bbbbbbbbbbbb<br>cccccc<br>";
+		$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<br>bbbbbbbbbbbb<br>cccccc<br>";
+		$result=dolGetFirstLineOfText($input, 2);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals("aaaa<br>\nbbbbbbbbbbbb...", $result);
+
+		// Nb of line is higher
+
+		$input="aaaa<br>bbbbbbbbbbbb<br>cccccc";
+		$result=dolGetFirstLineOfText($input, 100);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals("aaaa<br>\nbbbbbbbbbbbb<br>\ncccccc", $result, 'dolGetFirstLineOfText with nb 100 a');
+
+		$input="aaaa<br>bbbbbbbbbbbb<br>cccccc<br>";
+		$result=dolGetFirstLineOfText($input, 100);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals("aaaa<br>\nbbbbbbbbbbbb<br>\ncccccc", $result, 'dolGetFirstLineOfText with nb 100 b');
+
+		$input="aaaa<br>bbbbbbbbbbbb<br>cccccc<br>\n";
+		$result=dolGetFirstLineOfText($input, 100);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals("aaaa<br>\nbbbbbbbbbbbb<br>\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='<html>xxx</html>';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with html tag');
+		$input='<body>xxx</body>';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with body tag');
+		$input='xxx <b>yyy</b> zzz';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with b tag');
+		$input='xxx <u>yyy</u> zzz';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with u tag');
+		$input='text with <div>some div</div>';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with div tag');
+		$input='text with HTML &nbsp; entities';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with entities tag');
+		$input='xxx<br>';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with entities br');
+		$input='xxx<br >';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with entities br');
+		$input='xxx<br style="eee">';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with entities br and attributes');
+		$input='xxx<br style="eee" >';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with entities br and attributes bis');
+		$input='<h2>abc</h2>';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with entities h2');
+		$input='<img id="abc" src="https://xxx.com/aaa/image.png" />';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with img tag');
+		$input='<a class="azerty" href="https://xxx.com/aaa/image.png" />';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with a tag');
+		$input='This is a text with&nbsp;html spaces';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with a &nbsp;');
+		$input='This is a text with accent &eacute;';
+		$after=dol_textishtml($input);
+		$this->assertTrue($after, 'Test with a &eacute;');
+
+		// False
+		$input='xxx < br>';
+		$after=dol_textishtml($input);
+		$this->assertFalse($after);
+		$input='xxx <email@email.com>';	// <em> is html, <em... is not
+		$after=dol_textishtml($input);
+		$this->assertFalse($after);
+		$input='xxx <brstyle="ee">';
+		$after=dol_textishtml($input);
+		$this->assertFalse($after);
+		$input='This is a text with html comments <!-- comment -->';	// 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<br>";
+		$after=dol_htmlcleanlastbr($input);
+		$this->assertEquals("A string", $after);
+
+		$input="A string first<br>\nA string second<br>";
+		$after=dol_htmlcleanlastbr($input);
+		$this->assertEquals("A string first<br>\nA string second", $after);
+
+		$input="A string\n<br type=\"_moz\" />\n";
+		$after=dol_htmlcleanlastbr($input);
+		$this->assertEquals("A string", $after);
+
+		$input="A string\n<br><br />\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<br>string 1"; $text2="A string 2";	// text 1 is html, concat need <br>\n
+		$after=dol_concatdesc($text1, $text2);
+		$this->assertEquals("A<br>string 1<br>\nA string 2", $after);
+
+		$text1="A string 1"; $text2="A <b>string</b> 2";	// text 2 is html, concat need <br>\n
+		$after=dol_concatdesc($text1, $text2);
+		$this->assertEquals("A string 1<br>\nA <b>string</b> 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 <b>string<b><br>\n<br>\n\nwith html tag<br>\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 <b>string<b><br>\n<br>\n\nwith html tag<br>\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 <b>string<b><br>\n<br>\n\nwith html tag<br>\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 <b>string<b><br>\r\n<br>\r\n\r\nwith html tag<br>\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<br>Another string";
+		$after=dol_string_nohtmltag($text, 0);
+		$this->assertEquals("A string\nAnother string", $after, "test4");
+
+		$text="A string<br>Another string";
+		$after=dol_string_nohtmltag($text, 1);
+		$this->assertEquals("A string Another string", $after, "test5");
+
+		$text='<a href="/myurl" title="<u>Afficher projet</u>">ABC</a>';
+		$after=dol_string_nohtmltag($text, 1);
+		$this->assertEquals("ABC", $after, "test6");
+
+		$text='<a href="/myurl" title="&lt;u&gt;Afficher projet&lt;/u&gt;">DEF</a>';
+		$after=dol_string_nohtmltag($text, 1);
+		$this->assertEquals("DEF", $after, "test7");
+
+		$text='<a href="/myurl" title="<u>A title</u>">HIJ</a>';
+		$after=dol_string_nohtmltag($text, 0);
+		$this->assertEquals("HIJ", $after, "test8");
+
+		$text="A <b>string<b>\n\nwith html tag and '<' chars<br>\n";
+		$after=dol_string_nohtmltag($text, 0);
+		$this->assertEquals("A string\n\nwith html tag and '<' chars", $after, "test9");
+
+		$text="A <b>string<b>\n\nwith tag with < chars<br>\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 <br> before \n
+		$this->assertEquals("A string<br>\nwith a &eacute;, &amp;, &lt; and &gt;.", $after);
+
+		$input="A string\nwith a é, &, < and >.";
+		$after=dol_htmlentitiesbr($input, 1);    // Replace \n with <br>
+		$this->assertEquals("A string<br>with a &eacute;, &amp;, &lt; and &gt;.", $after);
+
+		$input="A string\nwith a é, &, < and >.\n\n";	// With some \n at end that should be cleaned
+		$after=dol_htmlentitiesbr($input, 0);    // Add <br> before \n
+		$this->assertEquals("A string<br>\nwith a &eacute;, &amp;, &lt; and &gt;.", $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 <br>
+		$this->assertEquals("A string<br>with a &eacute;, &amp;, &lt; and &gt;.", $after);
+
+		// Text already HTML, so &,<,> should not be converted
+
+		$input="A string<br>\nwith a é, &, < and >.";
+		$after=dol_htmlentitiesbr($input);
+		$this->assertEquals("A string<br>\nwith a &eacute;, &, < and >.", $after);
+
+		$input="<li>\nA string with a é, &, < and >.</li>\nAnother string";
+		$after=dol_htmlentitiesbr($input);
+		$this->assertEquals("<li>\nA string with a &eacute;, &, < and >.</li>\nAnother string", $after);
+
+		$input="A string<br>\nwith a é, &, < and >.<br>";	// With some <br> at end that should be cleaned
+		$after=dol_htmlentitiesbr($input);
+		$this->assertEquals("A string<br>\nwith a &eacute;, &, < and >.", $after);
+
+		$input="<li>\nA string with a é, &, < and >.</li>\nAnother string<br>";	// With some <br> at end that should be cleaned
+		$after=dol_htmlentitiesbr($input);
+		$this->assertEquals("<li>\nA string with a &eacute;, &, < and >.</li>\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 <br>
+		$input="A string\nwith a é, &, < and > and <b>bold</b> tag.\nThird line";
+		$after=dol_nboflines_bis($input, 0);
+		$this->assertEquals($after, 1);
+
+		// This is a html string so nb of lines depends on <br>
+		$input="A string<br>with a é, &, < and > and <b>bold</b> tag.<br>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&<b>#</b>,\"'";    // " will be converted into '
+		$result=dol_escape_js($input);
+		$this->assertEquals("x&<b>#</b>,\'\'", $result, "Test mode=0");
+
+		$result=dol_escape_js($input, 1);
+		$this->assertEquals("x&<b>#</b>,\"\'", $result, "Test mode=1");
+
+		$result=dol_escape_js($input, 2);
+		$this->assertEquals("x&<b>#</b>,\\\"'", $result, "Test mode=2");
+	}
+
+
+	/**
+	* testDolEscapeHtmlTag
+	*
+	* @return	void
+	*/
+	public function testDolEscapeHtmlTag()
+	{
+		$input='x&<b>#</b>,"';    // & and " are converted into html entities, <b> are removed
+		$result=dol_escape_htmltag($input);
+		$this->assertEquals('x&amp;#,&quot;', $result);
+
+		$input='x&<b>#</b>,"';    // & and " are converted into html entities, <b> are not removed
+		$result=dol_escape_htmltag($input, 1);
+		$this->assertEquals('x&amp;&lt;b&gt;#&lt;/b&gt;,&quot;', $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('<span style="margin-right: 10px;">12&nbsp;34&nbsp;56&nbsp;78&nbsp;90</span>', $phone, 'Phone for FR 1');
+
+		$object->country_code='FR';
+		$phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, '');
+		$this->assertEquals('<span style="margin-right: 10px;">1234567890</span>', $phone, 'Phone for FR 2');
+
+		$object->country_code='FR';
+		$phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ' ');
+		$this->assertEquals('<span style="margin-right: 10px;">12 34 56 78 90</span>', $phone, 'Phone for FR 3');
+
+		$object->country_code='CA';
+		$phone=dol_print_phone('1234567890', $object->country_code, 0, 0, 0, ' ');
+		$this->assertEquals('<span style="margin-right: 10px;">(123) 456-7890</span>', $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('<img src="/fullpath/img.png" alt="" title="title" class="inline-block">', $s, 'testImgPicto3');
+
+		$s=img_picto('title', '/fullpath/img.png', '', true);
+		print __METHOD__." s=".$s."\n";
+		$this->assertEquals('<img src="/fullpath/img.png" alt="" title="title" class="inline-block">', $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<br>\na");
+
+		//With $forxml parameter
+		$this->assertEquals(dol_nl2br($string, 0, 1), "a<br />\na");
+
+		//Replacing \n by br
+		$this->assertEquals(dol_nl2br($string, 1), "a<br>a");
+
+		//With $forxml parameter
+		$this->assertEquals(dol_nl2br($string, 1, 1), "a<br />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<corrupted>';
+		$_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;
+	}
 }

+ 202 - 203
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;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-
-    /**
-     * 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('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('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('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('https://www.dolimed.com');
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals('https://www.dolimed.com', $result);
-
-        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;
-
-    	$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('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.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('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');
-
-    	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;
-
-        $result=removeHtmlComment('abc<!--[if lt IE 8]>aaaa<![endif]-->def');
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals('abcdef', $result, 'Test 1');
-
-        $result=removeHtmlComment('abc<!--[if lt IE 8]>aa-->bb<!--aa<![endif]-->def');
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals('abcbbdef', $result, 'Test 1');
-
-        return 1;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+
+	/**
+	 * 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('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('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('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('https://www.dolimed.com');
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals('https://www.dolimed.com', $result);
+
+		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;
+
+		$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('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.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('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');
+
+		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;
+
+		$result=removeHtmlComment('abc<!--[if lt IE 8]>aaaa<![endif]-->def');
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals('abcdef', $result, 'Test 1');
+
+		$result=removeHtmlComment('abc<!--[if lt IE 8]>aa-->bb<!--aa<![endif]-->def');
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals('abcbbdef', $result, 'Test 1');
+
+		return 1;
+	}
 }

+ 324 - 325
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;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-    /**
-     * 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);
-
-        print __METHOD__." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        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;
-
-        $localobject=new Holiday($this->savdb);
-        $result=$localobject->fetch($id);
-
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        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;
-
-        $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';
-
-        $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_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');
-
-        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;
-    }
-
-    /**
-     * 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, false, '');
-        $this->assertNotEquals($result, -1);
-
-        $result = $localobject->fetchUsers(false, true, '');
-        $this->assertNotEquals($result, -1);
-
-        $result = $localobject->fetchUsers(false, false, '');
-        $this->assertNotEquals($result, -1);
-
-        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;
-
-        $localobject=new Holiday($this->savdb);
-        $result=$localobject->fetch($id);
-
-        $result=$localobject->delete(0);
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        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;
-
-        // 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);
-
-        $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);
-
-        $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->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');
-    }
-
-    /**
-     * testUpdateBalance
-     *
-     * @return void
-     */
-    public function testUpdateBalance()
-    {
-    	$localobjecta=new Holiday($this->savdb);
-
-    	$localobjecta->updateConfCP('lastUpdate', '20100101120000');
-    	$result = $localobjecta->updateBalance();
-    	$this->assertEquals($result, 1);
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+	/**
+	 * 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);
+
+		print __METHOD__." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
+
+		$localobject=new Holiday($this->savdb);
+		$result=$localobject->fetch($id);
+
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
+
+		$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';
+
+		$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_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');
+
+		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;
+	}
+
+	/**
+	 * 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, false, '');
+		$this->assertNotEquals($result, -1);
+
+		$result = $localobject->fetchUsers(false, true, '');
+		$this->assertNotEquals($result, -1);
+
+		$result = $localobject->fetchUsers(false, false, '');
+		$this->assertNotEquals($result, -1);
+
+		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;
+
+		$localobject=new Holiday($this->savdb);
+		$result=$localobject->fetch($id);
+
+		$result=$localobject->delete(0);
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
+
+		// 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);
+
+		$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);
+
+		$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->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');
+	}
+
+	/**
+	 * testUpdateBalance
+	 *
+	 * @return void
+	 */
+	public function testUpdateBalance()
+	{
+		$localobjecta=new Holiday($this->savdb);
+
+		$localobjecta->updateConfCP('lastUpdate', '20100101120000');
+		$result = $localobjecta->updateBalance();
+		$this->assertEquals($result, 1);
+	}
 }

+ 40 - 41
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-    /**
-     * testDolCountNbOfLine
-     *
-     * @return	int
-     */
-    public function testgetImageSize()
-    {
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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;
-    }
+	}
 }

+ 73 - 53
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-
-    /**
-     * 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);
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+
+	/**
+	 * 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);
 
 		return true;
-    }
+	}
 }

+ 159 - 139
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;
-
-    /**
-     * 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.
-
-        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";
-    }
-
-    /**
-     * 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 \\\\ \' \""}]';
-
-        $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');
-
-        // 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=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);
-    }
+	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.
+
+		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";
+	}
+
+	/**
+	 * 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 \\\\ \' \""}]';
+
+		$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');
+
+		// 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=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);
+	}
 }

+ 103 - 83
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 (empty($user->id))
-{
-    print "Load permissions for admin user nb 1\n";
-    $user->fetch(1);
-    $user->getrights();
+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;
 
@@ -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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-    /**
-     * testLang
-     *
-     * @return string
-     */
-    public function testLang()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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;
-    }
-
-    /**
-     * 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");
-
-    	$result = $tmplangs->trans("FilterOnInto", "<input autofocus onfocus='alert(1337)' <--!");
-    	print __METHOD__." result trans FilterOnInto = ".$result."\n";
-    	$this->assertEquals($result, "Search criteria '<b>&lt;input autofocus onfocus='alert(1337)' &lt;--!</b>' into fields ", 'Result of lang->trans must have original translation string with its original HTML tag, but inserted values must be fully encoded.');
-    }
+		return;
+	}
+
+	/**
+	 * 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");
+
+		$result = $tmplangs->trans("FilterOnInto", "<input autofocus onfocus='alert(1337)' <--!");
+		print __METHOD__." result trans FilterOnInto = ".$result."\n";
+		$this->assertEquals($result, "Search criteria '<b>&lt;input autofocus onfocus='alert(1337)' &lt;--!</b>' into fields ", 'Result of lang->trans must have original translation string with its original HTML tag, but inserted values must be fully encoded.');
+	}
 }

+ 87 - 68
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 (empty($user->id))
-{
-    print "Load permissions for admin user nb 1\n";
-    $user->fetch(1);
-    $user->getrights();
+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;
 
@@ -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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-    /**
-     * testLess
-     *
-     * @return string
-     */
-    public function testLessc()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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 '<pre>'.$contentforlessc.'</pre>';
-        	$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 = "
+		try {
+			$contentforlessc = ".bodywebsite {\n".$cssfile."\n}\n";
+			//print '<pre>'.$contentforlessc.'</pre>';
+			$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 = "
 .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;
+	}
 }

+ 101 - 102
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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;
+	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;
+		$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);
+		$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;
 
-    	$this->assertLessThan($result, 0);
-    	print __METHOD__." id=".$id." result=".$result."\n";
-    	return $localobject;
-    }
+		$result=$localobject->set_paid($user);
+
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+		return $localobject->id;
+	}
 
 	/**
-     * 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;
+	 * 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->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;
+	}
 }

+ 41 - 42
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.
-
-        print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	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";
+	}
+
+	/**
+	 * 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";
-    }
-
-    /**
-     * testGetMarginInfos
-     *
-     * @return	void
-     */
-    public function testGetMarginInfos()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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;
-    }
+	}
 }

+ 51 - 54
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-    /**
-     * testModulesInit
-     *
-     * @return int
-     */
-    public function testModulesInit()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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";
-
-        	if (in_array($modlabel, array('Ldap', 'MailmanSpip')))
-        	{
-        	    $result=$mod->remove();
-        	}
+		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();
+			}
 		}
 
-        return 0;
-    }
+		return 0;
+	}
 }

+ 114 - 113
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-    /**
-     * testMouvementCreate
-     *
-     * @return	MouvementStock
-     */
-    public function testMouvementCreate()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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');
-
-    	// 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 = 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);
-
-
-    	// 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.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 = 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);
-
-    	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;
+		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 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, -2, 1, 0, 'Output from transfer', 'Transfert Y');
+		print __METHOD__." result=".$result."\n";
+		$this->assertGreaterThan(0, $result);
+
+
+		// 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.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 = 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);
+
+		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;
 		$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;
+	}
 }

+ 353 - 354
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;
-
-    	$db->begin();	// This is to have all actions inside a transaction even if test launched without suite.
-
-    	print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	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";
+	}
+
+	/**
+	 * 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";
-    }
-
-    /**
-     * testFactureMercure
-     *
-     * @return int
-     */
-    public function testFactureMercure()
-    {
-    	global $conf,$user,$langs,$db,$mysoc;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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}';
-
-    	$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, 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
-
-
-    	// 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, 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, 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@=}';
-
-    	$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, 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
-
-
-    	// 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, 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, 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@+}';
-
-    	$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, 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
-
-    	// 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-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, 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}';
-
-    	$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
-
-
-
-    	return $result;
-    }
+		$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, 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, 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}';
+
+		$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, 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
+
+
+		// 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, 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, 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@-}';
+
+		$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, 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
+
+
+		// 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, 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, 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}';
+
+		$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, 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
+
+		// 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';
+
+		$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;
+	}
 }

+ 49 - 48
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;
-
-    	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.
-
-    	print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	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();
+		}
+
+		$db->begin();	// This is to have all actions inside a transaction even if test launched without suite.
+
+		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;
+	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";
-    }
-
-    /**
-     * testPaypalOk
-     *
-     * @return	void
-     */
-    public function testPaypalOk()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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;
+	}
 }

+ 66 - 65
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-    /**
-     * testPdfDocGetLineDesc
-     *
-     * @return void
-     */
-    public function testPdfDocGetLineDesc()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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<br>This is a description with a &eacute; accent<br>(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);
-    }
+		$result=pdf_getlinedesc($localobject, 0, $langs);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, "PIDRESS - Label 1<br>This is a description with a &eacute; accent<br>(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);
+	}
 }

+ 72 - 73
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;
-
-        $db->begin();	// This is to have all actions inside a transaction even if test launched without suite.
-
-    	print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	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";
+	}
+
+	/**
+	 * 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";
-    }
-
-    /**
-     * testConvertSQLFromMysql
-     *
-     * @return	int
-     */
-    public function testConvertSQLFromMysql()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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;
+	}
 }

+ 314 - 316
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;
-
-    /**
-     * 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.
-
-        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";
-    }
-
-
-    /**
-     * 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);
-
-        // To force status that say module multicompany is on
-        //$conf->multicurrency=new stdClass();
-        //$conf->multicurrency->enabled = 0;
-
-
-        /*
-         *  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', 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');
-
-        /*
-         *  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 (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 (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, 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');
-
-        // --------------------------------------------------------
-
-        // 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');
-
-
-        /*
-         * 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 (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;
-    }
-
-
-    /**
-     * 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;
-
-        // 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');
-
-        $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");
-
-
-        // 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');
-
-        $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);
-    }
+	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.
+
+		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";
+	}
+
+
+	/**
+	 * 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);
+
+		// To force status that say module multicompany is on
+		//$conf->multicurrency=new stdClass();
+		//$conf->multicurrency->enabled = 0;
+
+
+		/*
+		 *  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', 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');
+
+		/*
+		 *  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 (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 (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, 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');
+
+		// --------------------------------------------------------
+
+		// 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');
+
+
+		/*
+		 * 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 (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;
+	}
+
+
+	/**
+	 * 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;
+
+		// 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');
+
+		$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");
+
+
+		// 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');
+
+		$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);
+	}
 }

+ 210 - 209
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;
-
-    /**
-     * 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;
-
-        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;
-
-        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.
-
-        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";
-    }
-
-    /**
-     * 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);
-
-        print __METHOD__." result=".$result."\n";
-        $this->assertLessThanOrEqual($result, 0, "Creation of product");
-
-        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;
-
-        $localobject=new Product($this->savdb);
-        $result=$localobject->fetch($id);
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        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;
-
-        $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;
-    }
-
-    /**
-     * 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);
-
-        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;
-
-        $localobject=new Product($this->savdb);
-        $result=$localobject->fetch($id);
-
-        $result=$localobject->delete($user);
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        return $result;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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;
+
+		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.
+
+		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";
+	}
+
+	/**
+	 * 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);
+
+		print __METHOD__." result=".$result."\n";
+		$this->assertLessThanOrEqual($result, 0, "Creation of product");
+
+		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;
+
+		$localobject=new Product($this->savdb);
+		$result=$localobject->fetch($id);
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		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;
+
+		$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;
+	}
+
+	/**
+	 * 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);
+
+		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;
+
+		$localobject=new Product($this->savdb);
+		$result=$localobject->fetch($id);
+
+		$result=$localobject->delete($user);
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		return $result;
+	}
 }

+ 123 - 124
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.
-
-        print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	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";
+	}
+
+	/**
+	 * 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;
+	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;
+		$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;
+		$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->setValid($user);
+		$result=$localobject->setClose($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->id;
+	}
 
 	/**
-     * 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;
+	 * 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->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;
+	}
 }

+ 181 - 182
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.
-
-        print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	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";
+	}
+
+	/**
+	 * 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";
-    }
-
-    /**
-     * testPropalCreate
-     *
-     * @return	void
-     */
-    public function testPropalCreate()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * 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);
-
-    	$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;
+		$localobject->initAsSpecimen();
+		$result=$localobject->create($user);
+
+		$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;
 		$conf=$this->savconf;
 		$user=$this->savuser;
 		$langs=$this->savlangs;
 		$db=$this->savdb;
 
 		$localobject=new Propal($this->savdb);
-    	$result=$localobject->fetch($id);
-
-    	$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;
+		$result=$localobject->fetch($id);
+
+		$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;
 
-    	$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;
+		$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;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$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;
+	}
 }

+ 203 - 203
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;
-
-    /**
-     * 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;
-
-        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.
-
-        echo __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-        global $conf,$user,$langs,$db;
-        $db->rollback();
-
-        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;
-
-        $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']);
-
-        $this->api_key = $object['success']['token'];
-        echo __METHOD__." api_key: $this->api_key \n";
-
-        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;
-
-        $url = $this->api_url.'/documents/upload?api_key='.$this->api_key;
-
-        echo __METHOD__.' Request POST url='.$url."\n";
-
-
-        // Send to non existent directory
-
-        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
-        );
-
-        $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');
-
-
-        // Send to existent directory
-
-        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
-        );
-
-        $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');
-
-
-        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
-        );
-
-        $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');
-
-
-        dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit');
-    }
+	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();
+
+		//$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";
+	}
+
+	/**
+	 * 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";
+	}
+
+	/**
+	 * tearDownAfterClass
+	 *
+	 * @return	void
+	 */
+	public static function tearDownAfterClass()
+	{
+		global $conf,$user,$langs,$db;
+		$db->rollback();
+
+		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;
+
+		$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']);
+
+		$this->api_key = $object['success']['token'];
+		echo __METHOD__." api_key: $this->api_key \n";
+
+		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;
+
+		$url = $this->api_url.'/documents/upload?api_key='.$this->api_key;
+
+		echo __METHOD__.' Request POST url='.$url."\n";
+
+
+		// Send to non existent directory
+
+		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
+		);
+
+		$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');
+
+
+		// Send to existent directory
+
+		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
+		);
+
+		$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');
+
+
+		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
+		);
+
+		$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');
+
+
+		dol_delete_dir_recursive(DOL_DATA_ROOT.'/medias/tmpphpunit');
+	}
 }

+ 194 - 192
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;
-
-    /**
-     * 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;
-
-        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";
-    }
-
-    /**
-     * 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";
-    }
-
-    /**
-     * 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;
-
-        $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']);
-
-        $this->api_key = $object['success']['token'];
-        print __METHOD__." api_key: $this->api_key \n";
-
-        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;
-
-        $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');
-
-        $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']);
-    }
-
-    /**
-     * 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);
-
-        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']);
-
-        // 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']);
-    }
+	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();
+
+		//$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();
+		}
+
+		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.
+
+		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;
+
+		$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']);
+
+		$this->api_key = $object['success']['token'];
+		print __METHOD__." api_key: $this->api_key \n";
+
+		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;
+
+		$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');
+
+		$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']);
+	}
+
+	/**
+	 * 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);
+
+		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']);
+
+		// 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']);
+	}
 }

+ 170 - 151
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 (empty($user->id))
-{
-    print "Load permissions for admin user nb 1\n";
-    $user->fetch(1);
-    $user->getrights();
+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;
 
@@ -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.
-
-        print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	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";
+	}
+
+	/**
+	 * 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";
-    }
-
-    /**
-     * testBank
-     *
-     * @return string
-     */
-    public function testBank()
-    {
-    	global $conf,$user,$langs,$db;
+	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;
@@ -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;
-    }
-
-    /**
-     * testCompany
-     *
-     * @depends	testBank
-     * @return string
-     */
-    public function testCompany()
-    {
-    	global $conf,$user,$langs,$db;
+		return $result;
+	}
+
+	/**
+	 * 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 '';
-    }
-
-    /**
-     * 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();
-
-    	$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_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;
-    }
-
-    /**
-     * 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();
-
-    	$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_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 '';
+	}
+
+	/**
+	 * 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();
+
+		$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_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;
+	}
+
+	/**
+	 * 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();
+
+		$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_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;
+	}
 }

+ 462 - 447
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";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-    /**
-     * testSetLang
-     *
-     * @return string
-     */
-    public function testSetLang()
-    {
-    	global $conf;
-    	$conf=$this->savconf;
-
-    	$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');
-    }
-
-    /**
-     * 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;
-
-    	$_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;
-
-    	$_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="<img src='1.jpg' onerror =javascript:alert('XSS')>";
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa');
-
-    	$test="<img src='1.jpg' onerror =javascript:alert('XSS')>";
-    	$result=testSqlAndScriptInject($test, 2);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa2');
-
-    	$test='<IMG SRC=# onmouseover="alert(1)">';
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa3');
-    	$test='<IMG SRC onmouseover="alert(1)">';
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa4');
-    	$test='<IMG onmouseover="alert(1)">';
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa5');
-    	$test='<IMG SRC=/ onerror="alert(1)">';
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa6');
-    	$test='<IMG SRC=" &#14;  javascript:alert(1);">';
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa7');
-
-    	$test='<IMG SRC=&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;&#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;>';
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject bbb');
-
-    	$test='<SCRIPT SRC=http://xss.rocks/xss.js></SCRIPT>';
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ccc');
-
-    	$test='<IMG SRC="javascript:alert(\'XSS\');">';
-    	$result=testSqlAndScriptInject($test, 1);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ddd');
-
-    	$test='<IMG """><SCRIPT>alert("XSS")</SCRIPT>">';
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject eee');
-
-    	$test='<!-- Google analytics -->
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * testSetLang
+	 *
+	 * @return string
+	 */
+	public function testSetLang()
+	{
+		global $conf;
+		$conf=$this->savconf;
+
+		$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');
+	}
+
+	/**
+	 * 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;
+
+		$_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;
+
+		$_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="<img src='1.jpg' onerror =javascript:alert('XSS')>";
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa');
+
+		$test="<img src='1.jpg' onerror =javascript:alert('XSS')>";
+		$result=testSqlAndScriptInject($test, 2);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa2');
+
+		$test='<IMG SRC=# onmouseover="alert(1)">';
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa3');
+		$test='<IMG SRC onmouseover="alert(1)">';
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa4');
+		$test='<IMG onmouseover="alert(1)">';
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa5');
+		$test='<IMG SRC=/ onerror="alert(1)">';
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa6');
+		$test='<IMG SRC=" &#14;  javascript:alert(1);">';
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject aaa7');
+
+		$test='<IMG SRC=&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;&#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;>';
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject bbb');
+
+		$test='<SCRIPT SRC=http://xss.rocks/xss.js></SCRIPT>';
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ccc');
+
+		$test='<IMG SRC="javascript:alert(\'XSS\');">';
+		$result=testSqlAndScriptInject($test, 1);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ddd');
+
+		$test='<IMG """><SCRIPT>alert("XSS")</SCRIPT>">';
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject eee');
+
+		$test='<!-- Google analytics -->
 			<script>
 			  (function(i,s,o,g,r,a,m){i[\'GoogleAnalyticsObject\']=r;i[r]=i[r]||function(){
 			  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
@@ -231,262 +246,262 @@ class SecurityTest extends PHPUnit\Framework\TestCase
 			  ga(\'send\', \'pageview\');
 
 			</script>';
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject eee');
-
-    	$test="<IMG SRC=\"jav\tascript:alert('XSS');\">";		// 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="<IMG SRC=\"jav&#x0D;ascript:alert('XSS');\">";	// Same
-
-    	$test='<SCRIPT/XSS SRC="http://xss.rocks/xss.js"></SCRIPT>';
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff1');
-    	$test='<SCRIPT/SRC="http://xss.rocks/xss.js"></SCRIPT>';
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff2');
-
-    	// This case seems to be filtered by browsers now.
-    	$test='<BODY onload!#$%&()*~+-_.,:;?@[/|\]^`=alert(1)>';
-    	//$result=testSqlAndScriptInject($test, 0);
-    	//$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ggg');
-
-    	$test='<iframe src=http://xss.rocks/scriptlet.html <';
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject hhh');
-
-    	$test='Set.constructor`alert\x281\x29```';
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject iii');
-
-    	$test="on<!-- ab\nc -->error=alert(1)";
-    	$result=testSqlAndScriptInject($test, 0);
-    	$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject jjj');
-    }
-
-    /**
-     * testGETPOST
-     *
-     * @return string
-     */
-    public function testGETPOST()
-    {
-    	global $conf,$user,$langs,$db;
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject eee');
+
+		$test="<IMG SRC=\"jav\tascript:alert('XSS');\">";		// 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="<IMG SRC=\"jav&#x0D;ascript:alert('XSS');\">";	// Same
+
+		$test='<SCRIPT/XSS SRC="http://xss.rocks/xss.js"></SCRIPT>';
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff1');
+		$test='<SCRIPT/SRC="http://xss.rocks/xss.js"></SCRIPT>';
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject fff2');
+
+		// This case seems to be filtered by browsers now.
+		$test='<BODY onload!#$%&()*~+-_.,:;?@[/|\]^`=alert(1)>';
+		//$result=testSqlAndScriptInject($test, 0);
+		//$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject ggg');
+
+		$test='<iframe src=http://xss.rocks/scriptlet.html <';
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject hhh');
+
+		$test='Set.constructor`alert\x281\x29```';
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject iii');
+
+		$test="on<!-- ab\nc -->error=alert(1)";
+		$result=testSqlAndScriptInject($test, 0);
+		$this->assertGreaterThanOrEqual($expectedresult, $result, 'Error on testSqlAndScriptInject jjj');
+	}
+
+	/**
+	 * testGETPOST
+	 *
+	 * @return string
+	 */
+	public function testGETPOST()
+	{
+		global $conf,$user,$langs,$db;
 		$conf=$this->savconf;
 		$user=$this->savuser;
 		$langs=$this->savlangs;
 		$db=$this->savdb;
 
-        $_COOKIE["id"]=111;
+		$_COOKIE["id"]=111;
 		$_GET["param1"]="222";
-        $_POST["param1"]="333";
+		$_POST["param1"]="333";
 		$_GET["param2"]='a/b#e(pr)qq-rr\cc';
-        $_GET["param3"]='"&#110;a/b#e(pr)qq-rr\cc';    // Same than param2 + " and &#110;
-        $_GET["param4"]='../dir';
-        $_GET["param5"]="a_1-b";
-        $_POST["param6"]="&quot;&gt;<svg o&#110;load='console.log(&quot;123&quot;)'&gt;";
-        $_GET["param7"]='"c:\this is a path~1\aaa&#110;" abc<bad>def</bad>';
-        $_POST["param8"]="Hacker<svg o&#110;load='console.log(&quot;123&quot;)'";	// html tag is not closed so it is not detected as html tag but is still harmfull
+		$_GET["param3"]='"&#110;a/b#e(pr)qq-rr\cc';    // Same than param2 + " and &#110;
+		$_GET["param4"]='../dir';
+		$_GET["param5"]="a_1-b";
+		$_POST["param6"]="&quot;&gt;<svg o&#110;load='console.log(&quot;123&quot;)'&gt;";
+		$_GET["param7"]='"c:\this is a path~1\aaa&#110;" abc<bad>def</bad>';
+		$_POST["param8"]="Hacker<svg o&#110;load='console.log(&quot;123&quot;)'";	// html tag is not closed so it is not detected as html tag but is still harmfull
 		$_POST["param9"]='is_object($object) ? ($object->id < 10 ? round($object->id / 2, 2) : (2 * $user->id) * (int) substr($mysoc->zip, 1, 2)) : \'objnotdefined\'';
 		$_POST["param10"]='is_object($object) ? ($object->id < 10 ? round($object->id / 2, 2) : (2 * $user->id) * (int) substr($mysoc->zip, 1, 2)) : \'<abc>objnotdefined\'';
 
 		$result=GETPOST('id', 'int');              // Must return nothing
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, '');
-
-        $result=GETPOST("param1", 'int');
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, 222, 'Test on param1 with no 3rd param');
-
-        $result=GETPOST("param1", 'int', 2);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, 333, 'Test on param1 with 3rd param = 2');
-
-        // Test alpha
-        $result=GETPOST("param2", 'alpha');
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, $_GET["param2"], 'Test on param2');
-
-        $result=GETPOST("param3", 'alpha');  // Must return string sanitized from char "
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, '\'\'na/b#e(pr)qq-rr\cc', 'Test on param3');
-
-        $result=GETPOST("param4", 'alpha');  // Must return string sanitized from ../
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, 'dir');
-
-        // Test aZ09
-        $result=GETPOST("param1", 'aZ09');
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, $_GET["param1"]);
-
-        $result=GETPOST("param2", 'aZ09');  // Must return '' as string contains car not in aZ09 definition
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, '');
-
-        $result=GETPOST("param3", 'aZ09');  // Must return '' as string contains car not in aZ09 definition
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($result, '');
-
-        $result=GETPOST("param4", 'aZ09');  // Must return '' as string contains car not in aZ09 definition
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals('', $result);
-
-        $result=GETPOST("param5", 'aZ09');
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($_GET["param5"], $result);
-
-        $result=GETPOST("param6", 'nohtml');
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals('">', $result);
-
-        // With restricthtml we must remove html open/close tag and content but not htmlentities like &#110;
-        $result=GETPOST("param7", 'restricthtml');
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals('"c:\this is a path~1\aaa&#110;" abcdef', $result);
-
-        // With alphanohtml, we must convert the html entities like &#110;
-        $result=GETPOST("param8", 'alphanohtml');
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals("Hacker<svg onload='console.log(''123'')'", $result);
-
-        $result=GETPOST("param9", 'alphanohtml');
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($_POST["param9"], $result);
-
-        $result=GETPOST("param10", 'alphanohtml');
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals($_POST["param9"], $result, 'We should get param9 after processing param10');
-
-        return $result;
-    }
-
-    /**
-     * testCheckLoginPassEntity
-     *
-     * @return	void
-     */
-    public function testCheckLoginPassEntity()
-    {
-        $login=checkLoginPassEntity('loginbidon', 'passwordbidon', 1, array('dolibarr'));
-        print __METHOD__." login=".$login."\n";
-        $this->assertEquals($login, '');
-
-        $login=checkLoginPassEntity('admin', 'passwordbidon', 1, array('dolibarr'));
-        print __METHOD__." login=".$login."\n";
-        $this->assertEquals($login, '');
-
-        $login=checkLoginPassEntity('admin', 'admin', 1, array('dolibarr'));            // Should works because admin/admin exists
-        print __METHOD__." login=".$login."\n";
-        $this->assertEquals($login, 'admin', 'The test to check if pass of user "admin" is "admin" has failed');
-
-        $login=checkLoginPassEntity('admin', 'admin', 1, array('http','dolibarr'));    // Should work because of second authetntication method
-        print __METHOD__." login=".$login."\n";
-        $this->assertEquals($login, 'admin');
-
-        $login=checkLoginPassEntity('admin', 'admin', 1, array('forceuser'));
-        print __METHOD__." login=".$login."\n";
-        $this->assertEquals($login, '');    // Expected '' because should failed because login 'auto' does not exists
-    }
-
-    /**
-     * testEncodeDecode
-     *
-     * @return number
-     */
-    public function testEncodeDecode()
-    {
-        $stringtotest="This is a string to test encode/decode. This is a string to test encode/decode. This is a string to test encode/decode.";
-
-        $encodedstring=dol_encode($stringtotest);
-        $decodedstring=dol_decode($encodedstring);
-        print __METHOD__." encodedstring=".$encodedstring." ".base64_encode($stringtotest)."\n";
-        $this->assertEquals($stringtotest, $decodedstring, 'Use dol_encode/decode with no parameter');
-
-        $encodedstring=dol_encode($stringtotest, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
-        $decodedstring=dol_decode($encodedstring, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
-        print __METHOD__." encodedstring=".$encodedstring." ".base64_encode($stringtotest)."\n";
-        $this->assertEquals($stringtotest, $decodedstring, 'Use dol_encode/decode with a key parameter');
-
-        return 0;
-    }
-
-    /**
-     * testDolStringOnlyTheseHtmlTags
-     *
-     * @return number
-     */
-    public function testDolHTMLEntityDecode()
-    {
-    	$stringtotest = 'a &colon; b &quot; c &#039; d &apos; e &eacute;';
-    	$decodedstring = dol_html_entity_decode($stringtotest, ENT_QUOTES);
-    	$this->assertEquals('a &colon; b " c \' d &apos; e é', $decodedstring, 'Function did not sanitize correclty');
-
-    	$stringtotest = 'a &colon; b &quot; c &#039; d &apos; e &eacute;';
-    	$decodedstring = dol_html_entity_decode($stringtotest, ENT_QUOTES|ENT_HTML5);
-    	$this->assertEquals('a : b " c \' d \' e é', $decodedstring, 'Function did not sanitize correclty');
-
-    	return 0;
-    }
-
-    /**
-     * testDolStringOnlyTheseHtmlTags
-     *
-     * @return number
-     */
-    public function testDolStringOnlyTheseHtmlTags()
-    {
-    	$stringtotest = '<a href="javascript:aaa">bbbڴ';
-    	$decodedstring = dol_string_onlythesehtmltags($stringtotest, 1, 1, 1);
-        $this->assertEquals('<a href="aaa">bbbڴ', $decodedstring, 'Function did not sanitize correclty with test 1');
-
-        $stringtotest = '<a href="java'.chr(0).'script:aaa">bbbڴ';
-        $decodedstring = dol_string_onlythesehtmltags($stringtotest, 1, 1, 1);
-        $this->assertEquals('<a href="aaa">bbbڴ', $decodedstring, 'Function did not sanitize correclty with test 2');
-
-        $stringtotest = '<a href="javascript&colon;aaa">bbbڴ';
-        $decodedstring = dol_string_onlythesehtmltags($stringtotest, 1, 1, 1);
-        $this->assertEquals('<a href="aaa">bbbڴ', $decodedstring, 'Function did not sanitize correclty with test 3');
-
-        return 0;
-    }
-
-    /**
-     * testGetRandomPassword
-     *
-     * @return number
-     */
-    public function testGetRandomPassword()
-    {
-        global $conf;
-
-        $genpass1=getRandomPassword(true);				// Should be a string return by dol_hash (if no option set, will be md5)
-        print __METHOD__." genpass1=".$genpass1."\n";
-        $this->assertEquals(strlen($genpass1), 32);
-
-        $genpass1=getRandomPassword(true, array('I'));	// Should be a string return by dol_hash (if no option set, will be md5)
-        print __METHOD__." genpass1=".$genpass1."\n";
-        $this->assertEquals(strlen($genpass1), 32);
-
-        $conf->global->USER_PASSWORD_GENERATED='None';
-        $genpass2=getRandomPassword(false);				// Should return an empty string
-        print __METHOD__." genpass2=".$genpass2."\n";
-        $this->assertEquals($genpass2, '');
-
-        $conf->global->USER_PASSWORD_GENERATED='Standard';
-        $genpass3=getRandomPassword(false);				// Should return a password of 10 chars
-        print __METHOD__." genpass3=".$genpass3."\n";
-        $this->assertEquals(strlen($genpass3), 10);
-
-        return 0;
-    }
-
-    /**
-     * testRestrictedArea
-     *
-     * @return void
-     */
-    public function testRestrictedArea()
-    {
-    	global $conf,$user,$langs,$db;
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, '');
+
+		$result=GETPOST("param1", 'int');
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, 222, 'Test on param1 with no 3rd param');
+
+		$result=GETPOST("param1", 'int', 2);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, 333, 'Test on param1 with 3rd param = 2');
+
+		// Test alpha
+		$result=GETPOST("param2", 'alpha');
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, $_GET["param2"], 'Test on param2');
+
+		$result=GETPOST("param3", 'alpha');  // Must return string sanitized from char "
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, '\'\'na/b#e(pr)qq-rr\cc', 'Test on param3');
+
+		$result=GETPOST("param4", 'alpha');  // Must return string sanitized from ../
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, 'dir');
+
+		// Test aZ09
+		$result=GETPOST("param1", 'aZ09');
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, $_GET["param1"]);
+
+		$result=GETPOST("param2", 'aZ09');  // Must return '' as string contains car not in aZ09 definition
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, '');
+
+		$result=GETPOST("param3", 'aZ09');  // Must return '' as string contains car not in aZ09 definition
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($result, '');
+
+		$result=GETPOST("param4", 'aZ09');  // Must return '' as string contains car not in aZ09 definition
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals('', $result);
+
+		$result=GETPOST("param5", 'aZ09');
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($_GET["param5"], $result);
+
+		$result=GETPOST("param6", 'nohtml');
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals('">', $result);
+
+		// With restricthtml we must remove html open/close tag and content but not htmlentities like &#110;
+		$result=GETPOST("param7", 'restricthtml');
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals('"c:\this is a path~1\aaa&#110;" abcdef', $result);
+
+		// With alphanohtml, we must convert the html entities like &#110;
+		$result=GETPOST("param8", 'alphanohtml');
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals("Hacker<svg onload='console.log(''123'')'", $result);
+
+		$result=GETPOST("param9", 'alphanohtml');
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($_POST["param9"], $result);
+
+		$result=GETPOST("param10", 'alphanohtml');
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals($_POST["param9"], $result, 'We should get param9 after processing param10');
+
+		return $result;
+	}
+
+	/**
+	 * testCheckLoginPassEntity
+	 *
+	 * @return	void
+	 */
+	public function testCheckLoginPassEntity()
+	{
+		$login=checkLoginPassEntity('loginbidon', 'passwordbidon', 1, array('dolibarr'));
+		print __METHOD__." login=".$login."\n";
+		$this->assertEquals($login, '');
+
+		$login=checkLoginPassEntity('admin', 'passwordbidon', 1, array('dolibarr'));
+		print __METHOD__." login=".$login."\n";
+		$this->assertEquals($login, '');
+
+		$login=checkLoginPassEntity('admin', 'admin', 1, array('dolibarr'));            // Should works because admin/admin exists
+		print __METHOD__." login=".$login."\n";
+		$this->assertEquals($login, 'admin', 'The test to check if pass of user "admin" is "admin" has failed');
+
+		$login=checkLoginPassEntity('admin', 'admin', 1, array('http','dolibarr'));    // Should work because of second authetntication method
+		print __METHOD__." login=".$login."\n";
+		$this->assertEquals($login, 'admin');
+
+		$login=checkLoginPassEntity('admin', 'admin', 1, array('forceuser'));
+		print __METHOD__." login=".$login."\n";
+		$this->assertEquals($login, '');    // Expected '' because should failed because login 'auto' does not exists
+	}
+
+	/**
+	 * testEncodeDecode
+	 *
+	 * @return number
+	 */
+	public function testEncodeDecode()
+	{
+		$stringtotest="This is a string to test encode/decode. This is a string to test encode/decode. This is a string to test encode/decode.";
+
+		$encodedstring=dol_encode($stringtotest);
+		$decodedstring=dol_decode($encodedstring);
+		print __METHOD__." encodedstring=".$encodedstring." ".base64_encode($stringtotest)."\n";
+		$this->assertEquals($stringtotest, $decodedstring, 'Use dol_encode/decode with no parameter');
+
+		$encodedstring=dol_encode($stringtotest, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
+		$decodedstring=dol_decode($encodedstring, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
+		print __METHOD__." encodedstring=".$encodedstring." ".base64_encode($stringtotest)."\n";
+		$this->assertEquals($stringtotest, $decodedstring, 'Use dol_encode/decode with a key parameter');
+
+		return 0;
+	}
+
+	/**
+	 * testDolStringOnlyTheseHtmlTags
+	 *
+	 * @return number
+	 */
+	public function testDolHTMLEntityDecode()
+	{
+		$stringtotest = 'a &colon; b &quot; c &#039; d &apos; e &eacute;';
+		$decodedstring = dol_html_entity_decode($stringtotest, ENT_QUOTES);
+		$this->assertEquals('a &colon; b " c \' d &apos; e é', $decodedstring, 'Function did not sanitize correclty');
+
+		$stringtotest = 'a &colon; b &quot; c &#039; d &apos; e &eacute;';
+		$decodedstring = dol_html_entity_decode($stringtotest, ENT_QUOTES|ENT_HTML5);
+		$this->assertEquals('a : b " c \' d \' e é', $decodedstring, 'Function did not sanitize correclty');
+
+		return 0;
+	}
+
+	/**
+	 * testDolStringOnlyTheseHtmlTags
+	 *
+	 * @return number
+	 */
+	public function testDolStringOnlyTheseHtmlTags()
+	{
+		$stringtotest = '<a href="javascript:aaa">bbbڴ';
+		$decodedstring = dol_string_onlythesehtmltags($stringtotest, 1, 1, 1);
+		$this->assertEquals('<a href="aaa">bbbڴ', $decodedstring, 'Function did not sanitize correclty with test 1');
+
+		$stringtotest = '<a href="java'.chr(0).'script:aaa">bbbڴ';
+		$decodedstring = dol_string_onlythesehtmltags($stringtotest, 1, 1, 1);
+		$this->assertEquals('<a href="aaa">bbbڴ', $decodedstring, 'Function did not sanitize correclty with test 2');
+
+		$stringtotest = '<a href="javascript&colon;aaa">bbbڴ';
+		$decodedstring = dol_string_onlythesehtmltags($stringtotest, 1, 1, 1);
+		$this->assertEquals('<a href="aaa">bbbڴ', $decodedstring, 'Function did not sanitize correclty with test 3');
+
+		return 0;
+	}
+
+	/**
+	 * testGetRandomPassword
+	 *
+	 * @return number
+	 */
+	public function testGetRandomPassword()
+	{
+		global $conf;
+
+		$genpass1=getRandomPassword(true);				// Should be a string return by dol_hash (if no option set, will be md5)
+		print __METHOD__." genpass1=".$genpass1."\n";
+		$this->assertEquals(strlen($genpass1), 32);
+
+		$genpass1=getRandomPassword(true, array('I'));	// Should be a string return by dol_hash (if no option set, will be md5)
+		print __METHOD__." genpass1=".$genpass1."\n";
+		$this->assertEquals(strlen($genpass1), 32);
+
+		$conf->global->USER_PASSWORD_GENERATED='None';
+		$genpass2=getRandomPassword(false);				// Should return an empty string
+		print __METHOD__." genpass2=".$genpass2."\n";
+		$this->assertEquals($genpass2, '');
+
+		$conf->global->USER_PASSWORD_GENERATED='Standard';
+		$genpass3=getRandomPassword(false);				// Should return a password of 10 chars
+		print __METHOD__." genpass3=".$genpass3."\n";
+		$this->assertEquals(strlen($genpass3), 10);
+
+		return 0;
+	}
+
+	/**
+	 * testRestrictedArea
+	 *
+	 * @return void
+	 */
+	public function testRestrictedArea()
+	{
+		global $conf,$user,$langs,$db;
 		$conf=$this->savconf;
 		$user=$this->savuser;
 		$langs=$this->savlangs;
@@ -497,83 +512,83 @@ class SecurityTest extends PHPUnit\Framework\TestCase
 
 		$result=restrictedArea($user, 'societe');
 		$this->assertEquals(1, $result);
-    }
-
-
-    /**
-     * testGetRandomPassword
-     *
-     * @return number
-     */
-    public function testGetURLContent()
-    {
-    	global $conf;
-    	include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
-
-    	$url = 'ftp://mydomain.com';
-    	$tmp = getURLContent($url);
-    	print __METHOD__." url=".$url."\n";
-    	$this->assertGreaterThan(0, strpos($tmp['curl_error_msg'], 'not supported'));	// Test error if return does not contains 'not supported'
-
-    	$url = 'https://www.dolibarr.fr';	// This is a redirect 301 page
-    	$tmp = getURLContent($url, 'GET', '', 0);	// We do NOT follow
-    	print __METHOD__." url=".$url."\n";
-    	$this->assertEquals(301, $tmp['http_code'], 'GET url 301 without following -> 301');
-
-    	$url = 'https://www.dolibarr.fr';	// This is a redirect 301 page
-    	$tmp = getURLContent($url);		// We DO follow
-    	print __METHOD__." url=".$url."\n";
-    	$this->assertEquals(200, $tmp['http_code'], 'GET url 301 with following -> 200');	// Test error if return does not contains 'not supported'
-
-    	$url = 'http://localhost';
-    	$tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0);		// Only external URL
-    	print __METHOD__." url=".$url."\n";
-    	$this->assertEquals(400, $tmp['http_code'], 'GET url to '.$url.' that resolves to a local URL');	// Test we receive an error because localtest.me is not an external URL
-
-    	$url = 'http://127.0.0.1';
-    	$tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0);		// Only external URL
-    	print __METHOD__." url=".$url."\n";
-    	$this->assertEquals(400, $tmp['http_code'], 'GET url to '.$url.' that is a local URL');	// Test we receive an error because localtest.me is not an external URL
-
-    	$url = 'https://169.254.0.1';
-    	$tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0);		// Only external URL
-    	print __METHOD__." url=".$url."\n";
-    	$this->assertEquals(400, $tmp['http_code'], 'GET url to '.$url.' that is a local URL');	// Test we receive an error because localtest.me is not an external URL
-
-    	$url = 'http://[::1]';
-    	$tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0);		// Only external URL
-    	print __METHOD__." url=".$url."\n";
-    	$this->assertEquals(400, $tmp['http_code'], 'GET url to '.$url.' that is a local URL');	// Test we receive an error because localtest.me is not an external URL
-
-    	/*$url = 'localtest.me';
-    	$tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0);		// Only external URL
-    	print __METHOD__." url=".$url."\n";
-    	$this->assertEquals(400, $tmp['http_code'], 'GET url to '.$url.' that resolves to a local URL');	// Test we receive an error because localtest.me is not an external URL
+	}
+
+
+	/**
+	 * testGetRandomPassword
+	 *
+	 * @return number
+	 */
+	public function testGetURLContent()
+	{
+		global $conf;
+		include_once DOL_DOCUMENT_ROOT.'/core/lib/geturl.lib.php';
+
+		$url = 'ftp://mydomain.com';
+		$tmp = getURLContent($url);
+		print __METHOD__." url=".$url."\n";
+		$this->assertGreaterThan(0, strpos($tmp['curl_error_msg'], 'not supported'));	// Test error if return does not contains 'not supported'
+
+		$url = 'https://www.dolibarr.fr';	// This is a redirect 301 page
+		$tmp = getURLContent($url, 'GET', '', 0);	// We do NOT follow
+		print __METHOD__." url=".$url."\n";
+		$this->assertEquals(301, $tmp['http_code'], 'GET url 301 without following -> 301');
+
+		$url = 'https://www.dolibarr.fr';	// This is a redirect 301 page
+		$tmp = getURLContent($url);		// We DO follow
+		print __METHOD__." url=".$url."\n";
+		$this->assertEquals(200, $tmp['http_code'], 'GET url 301 with following -> 200');	// Test error if return does not contains 'not supported'
+
+		$url = 'http://localhost';
+		$tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0);		// Only external URL
+		print __METHOD__." url=".$url."\n";
+		$this->assertEquals(400, $tmp['http_code'], 'GET url to '.$url.' that resolves to a local URL');	// Test we receive an error because localtest.me is not an external URL
+
+		$url = 'http://127.0.0.1';
+		$tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0);		// Only external URL
+		print __METHOD__." url=".$url."\n";
+		$this->assertEquals(400, $tmp['http_code'], 'GET url to '.$url.' that is a local URL');	// Test we receive an error because localtest.me is not an external URL
+
+		$url = 'https://169.254.0.1';
+		$tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0);		// Only external URL
+		print __METHOD__." url=".$url."\n";
+		$this->assertEquals(400, $tmp['http_code'], 'GET url to '.$url.' that is a local URL');	// Test we receive an error because localtest.me is not an external URL
+
+		$url = 'http://[::1]';
+		$tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0);		// Only external URL
+		print __METHOD__." url=".$url."\n";
+		$this->assertEquals(400, $tmp['http_code'], 'GET url to '.$url.' that is a local URL');	// Test we receive an error because localtest.me is not an external URL
+
+		/*$url = 'localtest.me';
+		$tmp = getURLContent($url, 'GET', '', 0, array(), array('http', 'https'), 0);		// Only external URL
+		print __METHOD__." url=".$url."\n";
+		$this->assertEquals(400, $tmp['http_code'], 'GET url to '.$url.' that resolves to a local URL');	// Test we receive an error because localtest.me is not an external URL
 		*/
 
-    	return 0;
-    }
-
-    /**
-     * testDolSanitizeFileName
-     *
-     * @return void
-     */
-    public function testDolSanitizeFileName()
-    {
-    	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');
-
-    	$result=dol_sanitizeFileName('bad file | evilaction');
-    	$this->assertEquals('bad file _ evilaction', $result);
-
-    	$result=dol_sanitizeFileName('bad file --evilparam');
-    	$this->assertEquals('bad file _evilparam', $result);
-    }
+		return 0;
+	}
+
+	/**
+	 * testDolSanitizeFileName
+	 *
+	 * @return void
+	 */
+	public function testDolSanitizeFileName()
+	{
+		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');
+
+		$result=dol_sanitizeFileName('bad file | evilaction');
+		$this->assertEquals('bad file _ evilaction', $result);
+
+		$result=dol_sanitizeFileName('bad file --evilparam');
+		$this->assertEquals('bad file _evilparam', $result);
+	}
 }

+ 397 - 393
test/phpunit/SocieteTest.php

@@ -31,9 +31,9 @@ require_once dirname(__FILE__).'/../../htdocs/societe/class/societe.class.php';
 $langs->load("dict");
 
 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,179 +47,183 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
  */
 class SocieteTest extends PHPUnit\Framework\TestCase
 {
-    protected $savconf;
-    protected $savuser;
-    protected $savlangs;
-    protected $savdb;
-
-    /**
-     * Constructor
-     * We save global variables into local variables
-     *
-     * @return SocieteTest
-     */
-    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;
-
-        if ($conf->global->SOCIETE_CODECLIENT_ADDON != 'mod_codeclient_monkey') { print "\n".__METHOD__." third party ref checker must be setup to 'mod_codeclient_monkey' not to '".$conf->global->SOCIETE_CODECLIENT_ADDON."'.\n"; die(); }
-
-        if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) { print "\n".__METHOD__." constant MAIN_DISABLEPROFIDRULES must be empty (if a module set it, disable module).\n"; die(); }
-
-        $db->begin();	// This is to have all actions inside a transaction even if test launched without suite.
-
-        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";
-    }
-
-    /**
-     * testSocieteCreate
-     *
-     * @return int
-     */
-    public function testSocieteCreate()
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $localobject=new Societe($this->savdb);
-        $localobject->initAsSpecimen();
-        $result=$localobject->create($user);
-
-        print __METHOD__." result=".$result."\n";
-        $this->assertLessThanOrEqual($result, 0);
-
-        return $result;
-    }
-
-    /**
-     * testSocieteFetch
-     *
-     * @param   int     $id             Company id
-     * @return  Societe $localobject    Company
-     *
-     * @depends	testSocieteCreate
-     * The depends says test is run only if previous is ok
-     */
-    public function testSocieteFetch($id)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $localobject=new Societe($this->savdb);
-        $result=$localobject->fetch($id);
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        $result=$localobject->verify();
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertEquals($result, 0);
-
-        return $localobject;
-    }
-
-    /**
-     * testSocieteUpdate
-     *
-     * @param   Societe $localobject    Company
-     * @return  Societe $localobject    Company
-    *
-     * @depends testSocieteFetch
-     * The depends says test is run only if previous is ok
-     */
-    public function testSocieteUpdate($localobject)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $localobject->note_private='New private note after update';
-        $localobject->note_public='New public note after update';
-        $localobject->name='New name';
-        $localobject->address='New address';
-        $localobject->zip='New zip';
-        $localobject->town='New town';
-        $localobject->country_id=2;
-        $localobject->status=0;
-        $localobject->phone='New tel';
-        $localobject->fax='New fax';
-        $localobject->email='newemail@newemail.com';
-        $localobject->url='New url';
-        $localobject->idprof1='new idprof1';
-        $localobject->idprof2='new idprof2';
-        $localobject->idprof3='new idprof3';
-        $localobject->idprof4='new idprof4';
-
-        $result=$localobject->update($localobject->id, $user);
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * Constructor
+	 * We save global variables into local variables
+	 *
+	 * @return SocieteTest
+	 */
+	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;
+
+		if ($conf->global->SOCIETE_CODECLIENT_ADDON != 'mod_codeclient_monkey') {
+			print "\n".__METHOD__." third party ref checker must be setup to 'mod_codeclient_monkey' not to '".$conf->global->SOCIETE_CODECLIENT_ADDON."'.\n"; die();
+		}
+
+		if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
+			print "\n".__METHOD__." constant MAIN_DISABLEPROFIDRULES must be empty (if a module set it, disable module).\n"; die();
+		}
+
+		$db->begin();	// This is to have all actions inside a transaction even if test launched without suite.
+
+		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";
+	}
+
+	/**
+	 * testSocieteCreate
+	 *
+	 * @return int
+	 */
+	public function testSocieteCreate()
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$localobject=new Societe($this->savdb);
+		$localobject->initAsSpecimen();
+		$result=$localobject->create($user);
+
+		print __METHOD__." result=".$result."\n";
+		$this->assertLessThanOrEqual($result, 0);
+
+		return $result;
+	}
+
+	/**
+	 * testSocieteFetch
+	 *
+	 * @param   int     $id             Company id
+	 * @return  Societe $localobject    Company
+	 *
+	 * @depends	testSocieteCreate
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testSocieteFetch($id)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$localobject=new Societe($this->savdb);
+		$result=$localobject->fetch($id);
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		$result=$localobject->verify();
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertEquals($result, 0);
+
+		return $localobject;
+	}
+
+	/**
+	 * testSocieteUpdate
+	 *
+	 * @param   Societe $localobject    Company
+	 * @return  Societe $localobject    Company
+	*
+	 * @depends testSocieteFetch
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testSocieteUpdate($localobject)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$localobject->note_private='New private note after update';
+		$localobject->note_public='New public note after update';
+		$localobject->name='New name';
+		$localobject->address='New address';
+		$localobject->zip='New zip';
+		$localobject->town='New town';
+		$localobject->country_id=2;
+		$localobject->status=0;
+		$localobject->phone='New tel';
+		$localobject->fax='New fax';
+		$localobject->email='newemail@newemail.com';
+		$localobject->url='New url';
+		$localobject->idprof1='new idprof1';
+		$localobject->idprof2='new idprof2';
+		$localobject->idprof3='new idprof3';
+		$localobject->idprof4='new idprof4';
+
+		$result=$localobject->update($localobject->id, $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";
@@ -229,221 +233,221 @@ class SocieteTest extends PHPUnit\Framework\TestCase
 		print __METHOD__." id=".$localobject->id." result=".$result."\n";
 		$this->assertLessThan($result, 0, 'Holiday::update_note (public) error');
 
-        $newobject=new Societe($this->savdb);
-        $result=$newobject->fetch($localobject->id);
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        $this->assertEquals($localobject->note_private, $newobject->note_private);
-        //$this->assertEquals($localobject->note_public, $newobject->note_public);
-        $this->assertEquals($localobject->name, $newobject->name);
-        $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($localobject->status, $newobject->status);
-        $this->assertEquals($localobject->phone, $newobject->phone);
-        $this->assertEquals($localobject->fax, $newobject->fax);
-        $this->assertEquals($localobject->email, $newobject->email);
-        $this->assertEquals($localobject->url, $newobject->url);
-        $this->assertEquals($localobject->idprof1, $newobject->idprof1);
-        $this->assertEquals($localobject->idprof2, $newobject->idprof2);
-        $this->assertEquals($localobject->idprof3, $newobject->idprof3);
-        $this->assertEquals($localobject->idprof4, $newobject->idprof4);
-
-        return $localobject;
-    }
-
-    /**
-     * testIdProfCheck
-     *
-     * @param   Societe $localobject    Company
-     * @return  Societe $localobject    Company
-     *
-     * @depends testSocieteUpdate
-     * The depends says test is run only if previous is ok
-     */
-    public function testIdProfCheck($localobject)
-    {
-        // OK FR
-        $localobject->country_code='FR';
-        $localobject->idprof1=493861496;
-        $localobject->idprof2=49386149600021;
-        $result=$localobject->id_prof_check(1, $localobject);    // Must be > 0
-        print __METHOD__." OK FR idprof1 result=".$result."\n";
-        $this->assertGreaterThanOrEqual(1, $result);
-        $result=$localobject->id_prof_check(2, $localobject);    // Must be > 0
-        print __METHOD__." OK FR idprof2 result=".$result."\n";
-        $this->assertGreaterThanOrEqual(1, $result);
-
-        // KO FR
-        $localobject->country_code='FR';
-        $localobject->idprof1='id1ko';
-        $localobject->idprof2='id2ko';
-        $result=$localobject->id_prof_check(1, $localobject);    // Must be <= 0
-        print __METHOD__." KO FR idprof1 result=".$result."\n";
-        $this->assertLessThan(1, $result);
-        $result=$localobject->id_prof_check(2, $localobject);    // Must be <= 0
-        print __METHOD__." KO FR idprof2 result=".$result."\n";
-        $this->assertLessThan(1, $result);
-
-        // KO ES
-        $localobject->country_code='ES';
-        $localobject->idprof1='id1ko';
-        $result=$localobject->id_prof_check(1, $localobject);    // Must be <= 0
-        print __METHOD__." KO ES idprof1 result=".$result."\n";
-        $this->assertLessThan(1, $result);
-
-        // OK AR
-        $localobject->country_code='AR';
-        $localobject->idprof1='id1ko';
-        $localobject->idprof2='id2ko';
-        $result=$localobject->id_prof_check(1, $localobject);    // Must be > 0
-        print __METHOD__." OK AR idprof1 result=".$result."\n";
-        $this->assertGreaterThanOrEqual(0, $result);
-        $result=$localobject->id_prof_check(2, $localobject);    // Must be > 0
-        print __METHOD__." OK AR idprof2 result=".$result."\n";
-        $this->assertGreaterThanOrEqual(1, $result);
-
-        return $localobject;
-    }
-
-
-    /**
-     * testSocieteOther
-     *
-     * @param   Societe $localobject    Company
-     * @return  int     $id             Id of company
-     *
-     * @depends testIdProfCheck
-     * The depends says test is run only if previous is ok
-     */
-    public function testSocieteOther($localobject)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $result=$localobject->set_as_client();
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        $result=$localobject->set_price_level(1, $user);
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        $result=$localobject->set_remise_client(10, 'Gift', $user);
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        $result=$localobject->getNomUrl(1);
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-        $this->assertNotEquals($result, '');
-
-        $result=$localobject->isInEEC();
-        print __METHOD__." id=".$localobject->id." country_code=".$localobject->country_code." result=".$result."\n";
-        $this->assertTrue(true, $result);
-
-        $localobject->info($localobject->id);
-        print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n";
-        $this->assertNotEquals($localobject->date_creation, '');
-
-        return $localobject->id;
-    }
-
-
-    /**
-     * testSocieteDelete
-     *
-     * @param   int     $id     Id of company
-     * @return  int
-     *
-     * @depends testSocieteOther
-     * The depends says test is run only if previous is ok
-     */
-    public function testSocieteDelete($id)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $localobject=new Societe($this->savdb);
-        $result=$localobject->fetch($id);
-
-        $result=$localobject->delete($id, $user);
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        return $result;
-    }
-
-
-    /**
-     * testSocieteGetFullAddress
-     *
-     * @return  int     $id             Id of company
-     */
-    public function testSocieteGetFullAddress()
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $localobjectadd=new Societe($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);
-
-        // 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);
-
-        // 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';
-        $localobjectadd->state='New state';
-        $result=$localobjectadd->getFullAddress(1);
-        print __METHOD__." id=".$localobjectadd->id." result=".$result."\n";
-        $this->assertContains("New address\nNew town, New state, New zip\nUnited States", $result);
-
-        return $localobjectadd->id;
-    }
+		$newobject=new Societe($this->savdb);
+		$result=$newobject->fetch($localobject->id);
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		$this->assertEquals($localobject->note_private, $newobject->note_private);
+		//$this->assertEquals($localobject->note_public, $newobject->note_public);
+		$this->assertEquals($localobject->name, $newobject->name);
+		$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($localobject->status, $newobject->status);
+		$this->assertEquals($localobject->phone, $newobject->phone);
+		$this->assertEquals($localobject->fax, $newobject->fax);
+		$this->assertEquals($localobject->email, $newobject->email);
+		$this->assertEquals($localobject->url, $newobject->url);
+		$this->assertEquals($localobject->idprof1, $newobject->idprof1);
+		$this->assertEquals($localobject->idprof2, $newobject->idprof2);
+		$this->assertEquals($localobject->idprof3, $newobject->idprof3);
+		$this->assertEquals($localobject->idprof4, $newobject->idprof4);
+
+		return $localobject;
+	}
+
+	/**
+	 * testIdProfCheck
+	 *
+	 * @param   Societe $localobject    Company
+	 * @return  Societe $localobject    Company
+	 *
+	 * @depends testSocieteUpdate
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testIdProfCheck($localobject)
+	{
+		// OK FR
+		$localobject->country_code='FR';
+		$localobject->idprof1=493861496;
+		$localobject->idprof2=49386149600021;
+		$result=$localobject->id_prof_check(1, $localobject);    // Must be > 0
+		print __METHOD__." OK FR idprof1 result=".$result."\n";
+		$this->assertGreaterThanOrEqual(1, $result);
+		$result=$localobject->id_prof_check(2, $localobject);    // Must be > 0
+		print __METHOD__." OK FR idprof2 result=".$result."\n";
+		$this->assertGreaterThanOrEqual(1, $result);
+
+		// KO FR
+		$localobject->country_code='FR';
+		$localobject->idprof1='id1ko';
+		$localobject->idprof2='id2ko';
+		$result=$localobject->id_prof_check(1, $localobject);    // Must be <= 0
+		print __METHOD__." KO FR idprof1 result=".$result."\n";
+		$this->assertLessThan(1, $result);
+		$result=$localobject->id_prof_check(2, $localobject);    // Must be <= 0
+		print __METHOD__." KO FR idprof2 result=".$result."\n";
+		$this->assertLessThan(1, $result);
+
+		// KO ES
+		$localobject->country_code='ES';
+		$localobject->idprof1='id1ko';
+		$result=$localobject->id_prof_check(1, $localobject);    // Must be <= 0
+		print __METHOD__." KO ES idprof1 result=".$result."\n";
+		$this->assertLessThan(1, $result);
+
+		// OK AR
+		$localobject->country_code='AR';
+		$localobject->idprof1='id1ko';
+		$localobject->idprof2='id2ko';
+		$result=$localobject->id_prof_check(1, $localobject);    // Must be > 0
+		print __METHOD__." OK AR idprof1 result=".$result."\n";
+		$this->assertGreaterThanOrEqual(0, $result);
+		$result=$localobject->id_prof_check(2, $localobject);    // Must be > 0
+		print __METHOD__." OK AR idprof2 result=".$result."\n";
+		$this->assertGreaterThanOrEqual(1, $result);
+
+		return $localobject;
+	}
+
+
+	/**
+	 * testSocieteOther
+	 *
+	 * @param   Societe $localobject    Company
+	 * @return  int     $id             Id of company
+	 *
+	 * @depends testIdProfCheck
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testSocieteOther($localobject)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$result=$localobject->set_as_client();
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		$result=$localobject->set_price_level(1, $user);
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		$result=$localobject->set_remise_client(10, 'Gift', $user);
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		$result=$localobject->getNomUrl(1);
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertNotEquals($result, '');
+
+		$result=$localobject->isInEEC();
+		print __METHOD__." id=".$localobject->id." country_code=".$localobject->country_code." result=".$result."\n";
+		$this->assertTrue(true, $result);
+
+		$localobject->info($localobject->id);
+		print __METHOD__." localobject->date_creation=".$localobject->date_creation."\n";
+		$this->assertNotEquals($localobject->date_creation, '');
+
+		return $localobject->id;
+	}
+
+
+	/**
+	 * testSocieteDelete
+	 *
+	 * @param   int     $id     Id of company
+	 * @return  int
+	 *
+	 * @depends testSocieteOther
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testSocieteDelete($id)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$localobject=new Societe($this->savdb);
+		$result=$localobject->fetch($id);
+
+		$result=$localobject->delete($id, $user);
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		return $result;
+	}
+
+
+	/**
+	 * testSocieteGetFullAddress
+	 *
+	 * @return  int     $id             Id of company
+	 */
+	public function testSocieteGetFullAddress()
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$localobjectadd=new Societe($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);
+
+		// 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);
+
+		// 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';
+		$localobjectadd->state='New state';
+		$result=$localobjectadd->getFullAddress(1);
+		print __METHOD__." id=".$localobjectadd->id." result=".$result."\n";
+		$this->assertContains("New address\nNew town, New state, New zip\nUnited States", $result);
+
+		return $localobjectadd->id;
+	}
 }

+ 49 - 48
test/phpunit/StripeTest.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/stripe/lib/stripe.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 StripeTest extends PHPUnit\Framework\TestCase
 		print "\n";
 	}
 
-    /**
-     * setUpBeforeClass
-     *
-     * @return void
-     */
-    public static function setUpBeforeClass()
-    {
-    	global $conf,$user,$langs,$db;
-
-    	if (empty($conf->stripe->enabled)) { print __METHOD__." Module Stripe must be enabled.\n"; die(); }
-
-        $db->begin();	// This is to have all actions inside a transaction even if test launched without suite.
-
-    	print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+	/**
+	 * setUpBeforeClass
+	 *
+	 * @return void
+	 */
+	public static function setUpBeforeClass()
+	{
+		global $conf,$user,$langs,$db;
+
+		if (empty($conf->stripe->enabled)) {
+			print __METHOD__." Module Stripe must be enabled.\n"; die();
+		}
+
+		$db->begin();	// This is to have all actions inside a transaction even if test launched without suite.
+
+		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;
+	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";
-    }
-
-    /**
-     * testStripeOk
-     *
-     * @return	void
-     */
-    public function testStripeOk()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * testStripeOk
+	 *
+	 * @return	void
+	 */
+	public function testStripeOk()
+	{
+		global $conf,$user,$langs,$db;
 		$conf=$this->savconf;
 		$user=$this->savuser;
 		$langs=$this->savlangs;
@@ -148,9 +149,9 @@ class StripeTest 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;
+	}
 }

+ 154 - 153
test/phpunit/SupplierProposalTest.php

@@ -29,8 +29,7 @@ global $conf,$user,$langs,$db;
 require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
 require_once dirname(__FILE__).'/../../htdocs/supplier_proposal/class/supplier_proposal.class.php';
 
-if (empty($user->id))
-{
+if (empty($user->id)) {
 	print "Load permissions for user nb 1 (that should be admin)\n";
 	$user->fetch(1);
 
@@ -63,7 +62,7 @@ class SupplierProposalTest extends PHPUnit\Framework\TestCase
 	 */
 	public function __construct()
 	{
-        parent::__construct();
+		parent::__construct();
 
 		//$this->sharedFixture
 		global $conf,$user,$langs,$db;
@@ -78,41 +77,43 @@ class SupplierProposalTest 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.
 
-		if (empty($conf->global->MAIN_MODULE_SUPPLIERPROPOSAL)) { print "\n".__METHOD__." module Supplier proposal must be enabled.\n"; die(); }
+		if (empty($conf->global->MAIN_MODULE_SUPPLIERPROPOSAL)) {
+			print "\n".__METHOD__." module Supplier proposal must be enabled.\n"; die();
+		}
 
-    	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;
@@ -124,102 +125,102 @@ class SupplierProposalTest extends PHPUnit\Framework\TestCase
 		// Set permission not set by default sql sample
 		$user->addrights(0, 'supplier_proposal');
 		$user->getrights('supplier_proposal', 1);
-    }
+	}
 
 	/**
 	 * End phpunit tests
 	 *
 	 * @return	void
 	 */
-    protected function tearDown()
-    {
-    	print __METHOD__."\n";
-    }
-
-    /**
-     * testSupplierProposalCreate
-     *
-     * @return	void
-     */
-    public function testSupplierProposalCreate()
-    {
-    	global $conf,$user,$langs,$db;
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+	/**
+	 * testSupplierProposalCreate
+	 *
+	 * @return	void
+	 */
+	public function testSupplierProposalCreate()
+	{
+		global $conf,$user,$langs,$db;
 		$conf=$this->savconf;
 		$user=$this->savuser;
 		$langs=$this->savlangs;
 		$db=$this->savdb;
 
 		$localobject=new SupplierProposal($this->savdb);
-    	$localobject->initAsSpecimen();
-    	$result=$localobject->create($user);
-
-    	$this->assertLessThan($result, 0);
-    	print __METHOD__." result=".$result."\n";
-    	return $result;
-    }
-
-    /**
-     * testSupplierProposalFetch
-     *
-     * @param	int		$id		Id of object
-     * @return	void
-     *
-     * @depends	testSupplierProposalCreate
-     * The depends says test is run only if previous is ok
-     */
-    public function testSupplierProposalFetch($id)
-    {
-    	global $conf,$user,$langs,$db;
+		$localobject->initAsSpecimen();
+		$result=$localobject->create($user);
+
+		$this->assertLessThan($result, 0);
+		print __METHOD__." result=".$result."\n";
+		return $result;
+	}
+
+	/**
+	 * testSupplierProposalFetch
+	 *
+	 * @param	int		$id		Id of object
+	 * @return	void
+	 *
+	 * @depends	testSupplierProposalCreate
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testSupplierProposalFetch($id)
+	{
+		global $conf,$user,$langs,$db;
 		$conf=$this->savconf;
 		$user=$this->savuser;
 		$langs=$this->savlangs;
 		$db=$this->savdb;
 
 		$localobject=new SupplierProposal($this->savdb);
-    	$result=$localobject->fetch($id);
-
-    	$this->assertLessThan($result, 0);
-    	print __METHOD__." id=".$id." result=".$result."\n";
-    	return $localobject;
-    }
-
-    /**
-     * testSupplierProposalAddLine
-     *
-     * @param	int		$localobject	Proposal
-     * @return	void
-     *
-     * @depends	testSupplierProposalFetch
-     * The depends says test is run only if previous is ok
-     */
-    public function testSupplierProposalAddLine($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;
-    }
-
-    /**
-     * testSupplierProposalValid
-     *
-     * @param	SupplierProposal	$localobject	Proposal
-     * @return	SupplierProposal
-     *
-     * @depends	testSupplierProposalAddLine
-     * The depends says test is run only if previous is ok
-     */
-    public function testSupplierProposalValid($localobject)
-    {
-    	global $conf,$user,$langs,$db;
+		$result=$localobject->fetch($id);
+
+		$this->assertLessThan($result, 0);
+		print __METHOD__." id=".$id." result=".$result."\n";
+		return $localobject;
+	}
+
+	/**
+	 * testSupplierProposalAddLine
+	 *
+	 * @param	int		$localobject	Proposal
+	 * @return	void
+	 *
+	 * @depends	testSupplierProposalFetch
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testSupplierProposalAddLine($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;
+	}
+
+	/**
+	 * testSupplierProposalValid
+	 *
+	 * @param	SupplierProposal	$localobject	Proposal
+	 * @return	SupplierProposal
+	 *
+	 * @depends	testSupplierProposalAddLine
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testSupplierProposalValid($localobject)
+	{
+		global $conf,$user,$langs,$db;
 		$conf=$this->savconf;
 		$user=$this->savuser;
 		$langs=$this->savlangs;
@@ -234,63 +235,63 @@ class SupplierProposalTest extends PHPUnit\Framework\TestCase
 		$result=$localobject->valid($user);
 		$this->assertLessThan($result, 0);
 
-    	print __METHOD__." id=".$localobject->id." result=".$result."\n";
-    	$this->assertLessThan($result, 0);
-    	return $localobject;
-    }
-
-    /**
-     * testSupplierProposalOther
-     *
-     * @param	SupplierProposal	$localobject	Proposal
-     * @return	int
-     *
-     * @depends testSupplierProposalValid
-     * The depends says test is run only if previous is ok
-     */
-    public function testSupplierProposalOther($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;
-    }
-
-    /**
-     * testSupplierProposalDelete
-     *
-     * @param	int		$id		Id of proposal
-     * @return	void
-     *
-     * @depends	testSupplierProposalOther
-     * The depends says test is run only if previous is ok
-     */
-    public function testSupplierProposalDelete($id)
-    {
-    	global $conf,$user,$langs,$db;
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+		return $localobject;
+	}
+
+	/**
+	 * testSupplierProposalOther
+	 *
+	 * @param	SupplierProposal	$localobject	Proposal
+	 * @return	int
+	 *
+	 * @depends testSupplierProposalValid
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testSupplierProposalOther($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;
+	}
+
+	/**
+	 * testSupplierProposalDelete
+	 *
+	 * @param	int		$id		Id of proposal
+	 * @return	void
+	 *
+	 * @depends	testSupplierProposalOther
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testSupplierProposalDelete($id)
+	{
+		global $conf,$user,$langs,$db;
 		$conf=$this->savconf;
 		$user=$this->savuser;
 		$langs=$this->savlangs;
 		$db=$this->savdb;
 
 		$localobject=new SupplierProposal($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;
+	}
 }

+ 10 - 10
test/phpunit/TicketTest.php

@@ -75,10 +75,10 @@ class TicketTest extends PHPUnit\Framework\TestCase
 	}
 
 	/**
-     * setUpBeforeClass
-     *
-     * @return void
-     */
+	 * setUpBeforeClass
+	 *
+	 * @return void
+	 */
 	public static function setUpBeforeClass()
 	{
 		global $conf,$user,$langs,$db;
@@ -87,11 +87,11 @@ class TicketTest extends PHPUnit\Framework\TestCase
 		print __METHOD__."\n";
 	}
 
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
+	/**
+	 * tearDownAfterClass
+	 *
+	 * @return	void
+	 */
 	public static function tearDownAfterClass()
 	{
 		global $conf,$user,$langs,$db;
@@ -306,7 +306,7 @@ class TicketTest extends PHPUnit\Framework\TestCase
 		$user_id_to_assign = 1;
 
 		$result=$localobject->assignUser($user, $user_id_to_assign);
-        ;
+		;
 		print __METHOD__." id=".$localobject->id." result=".$result."\n";
 
 		$this->assertGreaterThan(0, $result);

+ 245 - 245
test/phpunit/UserGroupTest.php

@@ -30,9 +30,9 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
 require_once dirname(__FILE__).'/../../htdocs/user/class/usergroup.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,246 +46,246 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
  */
 class UserGroupTest extends PHPUnit\Framework\TestCase
 {
-    protected $savconf;
-    protected $savuser;
-    protected $savlangs;
-    protected $savdb;
-
-    /**
-     * Constructor
-     * We save global variables into local variables
-     *
-     * @return UserGroupTest
-     */
-    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.
-
-        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";
-    }
-
-    /**
-     * testUserGroupCreate
-     *
-     * @return	void
-     */
-    public function testUserGroupCreate()
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $localobject=new UserGroup($this->savdb);
-        $localobject->initAsSpecimen();
-        $result=$localobject->create($user);
-
-        $this->assertLessThan($result, 0);
-        print __METHOD__." result=".$result."\n";
-        return $result;
-    }
-
-    /**
-     * testUserGroupFetch
-     *
-     * @param   int $id             Id of group
-     * @return  void
-     * @depends testUserGroupCreate
-     * The depends says test is run only if previous is ok
-     */
-    public function testUserGroupFetch($id)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $localobject=new UserGroup($this->savdb);
-        $result=$localobject->fetch($id);
-
-        $this->assertLessThan($result, 0);
-        print __METHOD__." id=".$id." result=".$result."\n";
-        return $localobject;
-    }
-
-    /**
-     * testUserGroupUpdate
-     *
-     * @param   Object $localobject Group
-     * @return  void
-     * @depends testUserGroupFetch
-     * The depends says test is run only if previous is ok
-     */
-    public function testUserGroupUpdate($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);
-
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-        return $localobject;
-    }
-
-    /**
-     * testUserGroupAddRight
-     *
-     * @param   Object $localobject Object to show
-     * @return  void
-     * @depends testUserGroupUpdate
-     * The depends says test is run only if previous is ok
-     */
-    public function testUserGroupAddRight($localobject)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $result=$localobject->addrights(1, 'bookmarks');
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-
-        $this->assertLessThan($result, 0);
-        return $localobject;
-    }
-
-    /**
-     * testUserGroupDelRight
-     *
-     * @param   Object $localobject Object
-     * @return  void
-     * @depends testUserGroupAddRight
-     * The depends says test is run only if previous is ok
-     */
-    public function testUserGroupDelRight($localobject)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $result=$localobject->delrights(1, 'bookmarks');
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-
-        $this->assertLessThan($result, 0);
-        return $localobject;
-    }
-
-    /**
-     * testUserGroupOther
-     *
-     * @param   Object $localobject Object
-     * @return  void
-     * @depends testUserGroupDelRight
-     * The depends says test is run only if previous is ok
-     */
-    public function testUserGroupOther($localobject)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $result = $localobject->generateDocument('templatenamethadoesnotexist', $langs);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals(-1, $result, 'Calling generateDocument with a not existing template should return 0');
-
-        return $localobject->id;
-    }
-
-    /**
-     * testUserGroupDelete
-     *
-     * @param   int $id             Id of object
-     * @return  void
-     * @depends testUserGroupOther
-     * The depends says test is run only if previous is ok
-     */
-    public function testUserGroupDelete($id)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $localobject=new UserGroup($this->savdb);
-        $result=$localobject->fetch($id);
-        $result=$localobject->delete($user);
-
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-        return $result;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * Constructor
+	 * We save global variables into local variables
+	 *
+	 * @return UserGroupTest
+	 */
+	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.
+
+		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";
+	}
+
+	/**
+	 * testUserGroupCreate
+	 *
+	 * @return	void
+	 */
+	public function testUserGroupCreate()
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$localobject=new UserGroup($this->savdb);
+		$localobject->initAsSpecimen();
+		$result=$localobject->create($user);
+
+		$this->assertLessThan($result, 0);
+		print __METHOD__." result=".$result."\n";
+		return $result;
+	}
+
+	/**
+	 * testUserGroupFetch
+	 *
+	 * @param   int $id             Id of group
+	 * @return  void
+	 * @depends testUserGroupCreate
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testUserGroupFetch($id)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$localobject=new UserGroup($this->savdb);
+		$result=$localobject->fetch($id);
+
+		$this->assertLessThan($result, 0);
+		print __METHOD__." id=".$id." result=".$result."\n";
+		return $localobject;
+	}
+
+	/**
+	 * testUserGroupUpdate
+	 *
+	 * @param   Object $localobject Group
+	 * @return  void
+	 * @depends testUserGroupFetch
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testUserGroupUpdate($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);
+
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+		return $localobject;
+	}
+
+	/**
+	 * testUserGroupAddRight
+	 *
+	 * @param   Object $localobject Object to show
+	 * @return  void
+	 * @depends testUserGroupUpdate
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testUserGroupAddRight($localobject)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$result=$localobject->addrights(1, 'bookmarks');
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+
+		$this->assertLessThan($result, 0);
+		return $localobject;
+	}
+
+	/**
+	 * testUserGroupDelRight
+	 *
+	 * @param   Object $localobject Object
+	 * @return  void
+	 * @depends testUserGroupAddRight
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testUserGroupDelRight($localobject)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$result=$localobject->delrights(1, 'bookmarks');
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+
+		$this->assertLessThan($result, 0);
+		return $localobject;
+	}
+
+	/**
+	 * testUserGroupOther
+	 *
+	 * @param   Object $localobject Object
+	 * @return  void
+	 * @depends testUserGroupDelRight
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testUserGroupOther($localobject)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$result = $localobject->generateDocument('templatenamethadoesnotexist', $langs);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals(-1, $result, 'Calling generateDocument with a not existing template should return 0');
+
+		return $localobject->id;
+	}
+
+	/**
+	 * testUserGroupDelete
+	 *
+	 * @param   int $id             Id of object
+	 * @return  void
+	 * @depends testUserGroupOther
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testUserGroupDelete($id)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$localobject=new UserGroup($this->savdb);
+		$result=$localobject->fetch($id);
+		$result=$localobject->delete($user);
+
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+		return $result;
+	}
 }

+ 312 - 308
test/phpunit/UserTest.php

@@ -30,9 +30,9 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
 require_once dirname(__FILE__).'/../../htdocs/user/class/user.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,309 +46,313 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
  */
 class UserTest extends PHPUnit\Framework\TestCase
 {
-    protected $savconf;
-    protected $savuser;
-    protected $savlangs;
-    protected $savdb;
-
-    /**
-     * Constructor
-     * We save global variables into local variables
-     *
-     * @return UserTest
-     */
-    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;
-
-        if (! empty($conf->global->MAIN_MODULE_LDAP)) { print "\n".__METHOD__." module LDAP must be disabled.\n"; die(); }
-
-        $db->begin();	// This is to have all actions inside a transaction even if test launched without suite.
-
-        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";
-    }
-
-    /**
-     * testUserCreate
-     *
-     * @return  void
-     */
-    public function testUserCreate()
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $localobject=new User($this->savdb);
-        $localobject->initAsSpecimen();
-        $result=$localobject->create($user);
-
-        $this->assertLessThan($result, 0);
-        print __METHOD__." result=".$result."\n";
-        return $result;
-    }
-
-    /**
-     * testUserFetch
-     *
-     * @param   int $id             Id of user
-     * @return  void
-     * @depends testUserCreate
-     * The depends says test is run only if previous is ok
-     */
-    public function testUserFetch($id)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $localobject=new User($this->savdb);
-        $result=$localobject->fetch($id);
-
-        $this->assertLessThan($result, 0);
-        print __METHOD__." id=".$id." result=".$result."\n";
-        return $localobject;
-    }
-
-    /**
-     * testUserUpdate
-     *
-     * @param   Object  $localobject     User
-     * @return  void
-     * @depends testUserFetch
-     * The depends says test is run only if previous is ok
-     */
-    public function testUserUpdate($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);
-
-        print __METHOD__." id=".$localobject->id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-
-        // Test everything are still same than specimen
-        $newlocalobject=new User($this->savdb);
-        $newlocalobject->initAsSpecimen();
-        $this->changeProperties($newlocalobject);
-        $this->assertEquals($this->objCompare($localobject, $newlocalobject, true, array('id','socid','societe_id','specimen','note','ref','pass','pass_indatabase','pass_indatabase_crypted','pass_temp','datec','datem','datelastlogin','datepreviouslogin','trackid')), array());    // Actual, Expected
-
-        return $localobject;
-    }
-
-    /**
-     * testUserDisable
-     *
-     * @param   Object  $localobject     User
-     * @return  void
-     * @depends testUserUpdate
-     * The depends says test is run only if previous is ok
-     */
-    public function testUserDisable($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);
-
-        return $localobject;
-    }
-
-    /**
-     * testUserOther
-     *
-     * @param   Object  $localobject     User
-     * @return  void
-     * @depends testUserDisable
-     * The depends says test is run only if previous is ok
-     */
-    public function testUserOther($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;
-    }
-
-    /**
-     * testUserDelete
-     *
-     * @param   Object  $id      User
-     * @return  void
-     * @depends testUserOther
-     * The depends says test is run only if previous is ok
-     */
-    public function testUserDelete($id)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $localobject=new User($this->savdb);
-        $result=$localobject->fetch($id);
-        $result=$localobject->delete($user);
-
-        print __METHOD__." id=".$id." result=".$result."\n";
-        $this->assertLessThan($result, 0);
-        return $result;
-    }
-
-    /**
-     * testUserAddPermission
-     *
-     * @param   Object  $id      User
-     * @return  void
-     * @depends testUserDelete
-     * The depends says test is run only if previous is ok
-     */
-    public function testUserAddPermission($id)
-    {
-    	global $conf,$user,$langs,$db;
-    	$conf=$this->savconf;
-    	$user=$this->savuser;
-    	$langs=$this->savlangs;
-    	$db=$this->savdb;
-
-    	$localobject=new User($this->savdb);
-    	$result=$localobject->fetch(1);			// Other tests use the user id 1
-    	$result=$localobject->addrights(0, 'supplier_proposal');
-
-    	print __METHOD__." id=".$id." result=".$result."\n";
-    	$this->assertLessThan($result, 0);
-    	return $result;
-    }
-
-
-
-    /**
-     * Edit an object to test updates
-     *
-     * @param   mixed   $localobject        Object User
-     * @return  void
-     */
-    public function changeProperties(&$localobject)
-    {
-        $localobject->note_private='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();
-
-        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;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * Constructor
+	 * We save global variables into local variables
+	 *
+	 * @return UserTest
+	 */
+	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;
+
+		if (! empty($conf->global->MAIN_MODULE_LDAP)) {
+			print "\n".__METHOD__." module LDAP must be disabled.\n"; die();
+		}
+
+		$db->begin();	// This is to have all actions inside a transaction even if test launched without suite.
+
+		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";
+	}
+
+	/**
+	 * testUserCreate
+	 *
+	 * @return  void
+	 */
+	public function testUserCreate()
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$localobject=new User($this->savdb);
+		$localobject->initAsSpecimen();
+		$result=$localobject->create($user);
+
+		$this->assertLessThan($result, 0);
+		print __METHOD__." result=".$result."\n";
+		return $result;
+	}
+
+	/**
+	 * testUserFetch
+	 *
+	 * @param   int $id             Id of user
+	 * @return  void
+	 * @depends testUserCreate
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testUserFetch($id)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$localobject=new User($this->savdb);
+		$result=$localobject->fetch($id);
+
+		$this->assertLessThan($result, 0);
+		print __METHOD__." id=".$id." result=".$result."\n";
+		return $localobject;
+	}
+
+	/**
+	 * testUserUpdate
+	 *
+	 * @param   Object  $localobject     User
+	 * @return  void
+	 * @depends testUserFetch
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testUserUpdate($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);
+
+		print __METHOD__." id=".$localobject->id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+
+		// Test everything are still same than specimen
+		$newlocalobject=new User($this->savdb);
+		$newlocalobject->initAsSpecimen();
+		$this->changeProperties($newlocalobject);
+		$this->assertEquals($this->objCompare($localobject, $newlocalobject, true, array('id','socid','societe_id','specimen','note','ref','pass','pass_indatabase','pass_indatabase_crypted','pass_temp','datec','datem','datelastlogin','datepreviouslogin','trackid')), array());    // Actual, Expected
+
+		return $localobject;
+	}
+
+	/**
+	 * testUserDisable
+	 *
+	 * @param   Object  $localobject     User
+	 * @return  void
+	 * @depends testUserUpdate
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testUserDisable($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);
+
+		return $localobject;
+	}
+
+	/**
+	 * testUserOther
+	 *
+	 * @param   Object  $localobject     User
+	 * @return  void
+	 * @depends testUserDisable
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testUserOther($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;
+	}
+
+	/**
+	 * testUserDelete
+	 *
+	 * @param   Object  $id      User
+	 * @return  void
+	 * @depends testUserOther
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testUserDelete($id)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$localobject=new User($this->savdb);
+		$result=$localobject->fetch($id);
+		$result=$localobject->delete($user);
+
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+		return $result;
+	}
+
+	/**
+	 * testUserAddPermission
+	 *
+	 * @param   Object  $id      User
+	 * @return  void
+	 * @depends testUserDelete
+	 * The depends says test is run only if previous is ok
+	 */
+	public function testUserAddPermission($id)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$localobject=new User($this->savdb);
+		$result=$localobject->fetch(1);			// Other tests use the user id 1
+		$result=$localobject->addrights(0, 'supplier_proposal');
+
+		print __METHOD__." id=".$id." result=".$result."\n";
+		$this->assertLessThan($result, 0);
+		return $result;
+	}
+
+
+
+	/**
+	 * Edit an object to test updates
+	 *
+	 * @param   mixed   $localobject        Object User
+	 * @return  void
+	 */
+	public function changeProperties(&$localobject)
+	{
+		$localobject->note_private='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();
+
+		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;
+	}
 }

+ 109 - 109
test/phpunit/UtilsTest.php

@@ -30,9 +30,9 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
 require_once dirname(__FILE__).'/../../htdocs/core/class/utils.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,114 +46,114 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
  */
 class UtilsTest extends PHPUnit\Framework\TestCase
 {
-    protected $savconf;
-    protected $savuser;
-    protected $savlangs;
-    protected $savdb;
-
-    /**
-     * Constructor
-     * We save global variables into local variables
-     *
-     * @return UserTest
-     */
-    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.
-
-        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";
-    }
-
-    /**
-     * testExecuteCLI
-     *
-     * @return  void
-     */
-    public function testExecuteCLI()
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $localobject=new Utils($this->savdb);
-        $result = $localobject->executeCLI('ls', $conf->admin->dir_temp.'/out.tmp', 1);
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * Constructor
+	 * We save global variables into local variables
+	 *
+	 * @return UserTest
+	 */
+	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.
+
+		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";
+	}
+
+	/**
+	 * testExecuteCLI
+	 *
+	 * @return  void
+	 */
+	public function testExecuteCLI()
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$localobject=new Utils($this->savdb);
+		$result = $localobject->executeCLI('ls', $conf->admin->dir_temp.'/out.tmp', 1);
 		print var_export($result, true);
-        $this->assertEquals($result['result'], 0);
-        $this->assertEquals($result['error'], '');
-        //$this->assertEquals(preg_match('/phpunit/', $result['output']), 1);
+		$this->assertEquals($result['result'], 0);
+		$this->assertEquals($result['error'], '');
+		//$this->assertEquals(preg_match('/phpunit/', $result['output']), 1);
 
-        $localobject=new Utils($this->savdb);
-        $result = $localobject->executeCLI('ls', $conf->admin->dir_temp.'/out.tmp', 2);
+		$localobject=new Utils($this->savdb);
+		$result = $localobject->executeCLI('ls', $conf->admin->dir_temp.'/out.tmp', 2);
 		print var_export($result, true);
-        $this->assertEquals($result['result'], 0);
-        $this->assertEquals($result['error'], '');
-        //$this->assertEquals(preg_match('/phpunit/', $result['output']), 1);
+		$this->assertEquals($result['result'], 0);
+		$this->assertEquals($result['error'], '');
+		//$this->assertEquals(preg_match('/phpunit/', $result['output']), 1);
 
-        print __METHOD__." result=".$result['result']."\n";
-        return $result;
-    }
+		print __METHOD__." result=".$result['result']."\n";
+		return $result;
+	}
 }

+ 195 - 203
test/phpunit/WebservicesInvoicesTest.php

@@ -31,8 +31,7 @@ require_once dirname(__FILE__).'/../../htdocs/core/lib/date.lib.php';
 require_once NUSOAP_PATH.'/nusoap.php';        // Include SOAP
 
 
-if (empty($user->id))
-{
+if (empty($user->id)) {
 	print "Load permissions for admin user nb 1\n";
 	$user->fetch(1);
 	$user->getrights();
@@ -85,8 +84,7 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase
 		$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php';
 		print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
 		$this->soapclient = new nusoap_client($WS_DOL_URL);
-		if ($this->soapclient)
-		{
+		if ($this->soapclient) {
 			$this->soapclient->soap_defencoding='UTF-8';
 			$this->soapclient->decodeUTF8(false);
 		}
@@ -96,16 +94,16 @@ class WebservicesInvoicesTest 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;
 
-        $now = dol_now();
+		$now = dol_now();
 
 		// create a third_party, needed to create an invoice
 		//
@@ -134,8 +132,7 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase
 		$societe->particulier=0;
 
 		$societe->create($user);
-		if (empty($societe->id))
-		{
+		if (empty($societe->id)) {
 			// Create failed, may be the thirdparty already exists, we fetch it
 			$societe->fetch(0, 'name');
 		}
@@ -146,66 +143,66 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase
 
 		$db->begin();	// This is to have all actions inside a transaction even if test launched without suite.
 
-        print __METHOD__."\n";
-    }
-
-    /**
-     * tearDownAfterClass
-     *
-     * @return void
-     */
-    public static function tearDownAfterClass()
-    {
-    	global $conf,$user,$langs,$db;
+		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;
+	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";
-    }
-
-
-    /**
-     * testWSInvoicesCreateInvoice
-     *
-     * @return	int		invoice created
-     */
-    public function testWSInvoicesCreateInvoice()
-    {
-    	global $conf,$user,$langs,$db;
-    	$conf=$this->savconf;
-    	$user=$this->savuser;
-    	$langs=$this->savlangs;
-    	$db=$this->savdb;
-
-    	$WS_METHOD  = 'createInvoice';
-
-    	$body = array (
-    			"id" => null,
+	protected function tearDown()
+	{
+		print __METHOD__."\n";
+	}
+
+
+	/**
+	 * testWSInvoicesCreateInvoice
+	 *
+	 * @return	int		invoice created
+	 */
+	public function testWSInvoicesCreateInvoice()
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$WS_METHOD  = 'createInvoice';
+
+		$body = array (
+				"id" => null,
 				"ref" => null,
 				"ref_ext" => "ref-phpunit-2",
 				"thirdparty_id" => self::$socid,
@@ -246,120 +243,117 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase
 					"product_desc" => "" ))
 					);
 
-    	// Call the WebService method and store its result in $result.
-    	$authentication=array(
-    	'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
-    	'sourceapplication'=>'DEMO',
-    	'login'=>'admin',
-    	'password'=>$this->pass,
-    	'entity'=>'');
-
-    	// Test URL
-    	$result='';
-    	$parameters = array('authentication'=>$authentication,'invoice'=>$body);
-    	print __METHOD__." call method ".$WS_METHOD."\n";
-    	try {
-    		$result = $this->soapclient->call($WS_METHOD, $parameters, $this->ns, '');
-    	} catch (SoapFault $exception) {
-    		echo $exception;
-    		$result=0;
-    	}
-    	if (! $result || ! empty($result['faultstring']))
-    	{
-    		//var_dump($soapclient);
-    		print $this->soapclient->error_str;
-    		print "\n<br>\n";
-    		print $this->soapclient->request;
-    		print "\n<br>\n";
-    		print $this->soapclient->response;
-    		print "\n";
-    	}
-
-    	print __METHOD__." result=".$result['result']['result_code']." ".$result['result']['result_label']."\n";
-    	$this->assertEquals('OK', $result['result']['result_code']);
-    	$this->assertEquals('ref-phpunit-2', $result['ref_ext']);
-
-
-    	return $result;
-    }
-
-    /**
-     * testWSInvoicesGetInvoiceByRefExt
-     *
-     * Retrieve an invoice using ref_ext
-     * @depends testWSInvoicesCreateInvoice
-     *
-     * @param	array	$result		Invoice created by create method
-     * @return	array				Invoice
-     */
-    public function testWSInvoicesGetInvoiceByRefExt($result)
-    {
-    	global $conf,$user,$langs,$db;
-    	$conf=$this->savconf;
-    	$user=$this->savuser;
-    	$langs=$this->savlangs;
-    	$db=$this->savdb;
-
-    	$WS_METHOD  = 'getInvoice';
-
-    	// Call the WebService method and store its result in $result.
-    	$authentication=array(
-    	'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
-    	'sourceapplication'=>'DEMO',
-    	'login'=>'admin',
-    	'password'=>$this->pass,
-    	'entity'=>'');
-
-    	// Test URL
-    	$result='';
-    	$parameters = array('authentication'=>$authentication, 'id'=>null, 'ref'=>null, 'ref_ext'=>'ref-phpunit-2');
-    	print __METHOD__." call method ".$WS_METHOD."\n";
-    	try {
-    		$result = $this->soapclient->call($WS_METHOD, $parameters, $this->ns, '');
-    	} catch (SoapFault $exception)
-    	{
-    		echo $exception;
-    		$result=0;
-    	}
-    	if (! $result || ! empty($result['faultstring']))
-    	{
-    		print $this->soapclient->error_str;
-    		print "\n<br>\n";
-    		print $this->soapclient->request;
-    		print "\n<br>\n";
-    		print $this->soapclient->response;
-    		print "\n";
-    	}
-    	print __METHOD__." result=".$result['result']['result_code']."\n";
-    	$this->assertEquals('OK', $result['result']['result_code']);
-    	$this->assertEquals('ref-phpunit-2', $result['invoice']['ref_ext']);
-
-
-    	return $result;
-    }
-
-    /**
-     * testWSInvoicesUpdateInvoiceByRefExt
-     *
-     * Update an invoice using ref_ext
-     * @depends testWSInvoicesCreateInvoice
-     *
-     * @param	array	$result		invoice created by create method
-     * @return	array 				Invoice
-     */
-    public function testWSInvoicesUpdateInvoiceByRefExt($result)
-    {
-    	global $conf,$user,$langs,$db;
-    	$conf=$this->savconf;
-    	$user=$this->savuser;
-    	$langs=$this->savlangs;
-    	$db=$this->savdb;
-
-    	$WS_METHOD  = 'updateInvoice';
-
-    	// update status to 2
-    	$body = array (
-    		"id" => null,
+		// Call the WebService method and store its result in $result.
+		$authentication=array(
+		'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+		'sourceapplication'=>'DEMO',
+		'login'=>'admin',
+		'password'=>$this->pass,
+		'entity'=>'');
+
+		// Test URL
+		$result='';
+		$parameters = array('authentication'=>$authentication,'invoice'=>$body);
+		print __METHOD__." call method ".$WS_METHOD."\n";
+		try {
+			$result = $this->soapclient->call($WS_METHOD, $parameters, $this->ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		if (! $result || ! empty($result['faultstring'])) {
+			//var_dump($soapclient);
+			print $this->soapclient->error_str;
+			print "\n<br>\n";
+			print $this->soapclient->request;
+			print "\n<br>\n";
+			print $this->soapclient->response;
+			print "\n";
+		}
+
+		print __METHOD__." result=".$result['result']['result_code']." ".$result['result']['result_label']."\n";
+		$this->assertEquals('OK', $result['result']['result_code']);
+		$this->assertEquals('ref-phpunit-2', $result['ref_ext']);
+
+
+		return $result;
+	}
+
+	/**
+	 * testWSInvoicesGetInvoiceByRefExt
+	 *
+	 * Retrieve an invoice using ref_ext
+	 * @depends testWSInvoicesCreateInvoice
+	 *
+	 * @param	array	$result		Invoice created by create method
+	 * @return	array				Invoice
+	 */
+	public function testWSInvoicesGetInvoiceByRefExt($result)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$WS_METHOD  = 'getInvoice';
+
+		// Call the WebService method and store its result in $result.
+		$authentication=array(
+		'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+		'sourceapplication'=>'DEMO',
+		'login'=>'admin',
+		'password'=>$this->pass,
+		'entity'=>'');
+
+		// Test URL
+		$result='';
+		$parameters = array('authentication'=>$authentication, 'id'=>null, 'ref'=>null, 'ref_ext'=>'ref-phpunit-2');
+		print __METHOD__." call method ".$WS_METHOD."\n";
+		try {
+			$result = $this->soapclient->call($WS_METHOD, $parameters, $this->ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		if (! $result || ! empty($result['faultstring'])) {
+			print $this->soapclient->error_str;
+			print "\n<br>\n";
+			print $this->soapclient->request;
+			print "\n<br>\n";
+			print $this->soapclient->response;
+			print "\n";
+		}
+		print __METHOD__." result=".$result['result']['result_code']."\n";
+		$this->assertEquals('OK', $result['result']['result_code']);
+		$this->assertEquals('ref-phpunit-2', $result['invoice']['ref_ext']);
+
+
+		return $result;
+	}
+
+	/**
+	 * testWSInvoicesUpdateInvoiceByRefExt
+	 *
+	 * Update an invoice using ref_ext
+	 * @depends testWSInvoicesCreateInvoice
+	 *
+	 * @param	array	$result		invoice created by create method
+	 * @return	array 				Invoice
+	 */
+	public function testWSInvoicesUpdateInvoiceByRefExt($result)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$WS_METHOD  = 'updateInvoice';
+
+		// update status to 2
+		$body = array (
+			"id" => null,
 			"ref" => null,
 			"ref_ext" => "ref-phpunit-2",
 			"thirdparty_id" => self::$socid,
@@ -401,39 +395,37 @@ class WebservicesInvoicesTest extends PHPUnit\Framework\TestCase
 				"product_desc" => "" ))
 			);
 
-    	// Call the WebService method and store its result in $result.
-    	$authentication=array(
-    	'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
-    	'sourceapplication'=>'DEMO',
-    	'login'=>'admin',
-    	'password'=>$this->pass,
-    	'entity'=>'');
-
-    	// Test URL
-    	$result='';
-    	$parameters = array('authentication'=>$authentication,'invoice'=>$body);
-    	print __METHOD__." call method ".$WS_METHOD."\n";
-    	try {
-    		$result = $this->soapclient->call($WS_METHOD, $parameters, $this->ns, '');
-    	} catch (SoapFault $exception)
-    	{
-    		echo $exception;
-    		$result=0;
-    	}
-    	if (! $result || ! empty($result['faultstring']))
-    	{
-    		print $this->soapclient->error_str;
-    		print "\n<br>\n";
-    		print $this->soapclient->request;
-    		print "\n<br>\n";
-    		print $this->soapclient->response;
-    		print "\n";
-    	}
-
-    	print __METHOD__." result=".$result['result']['result_code'].$result['result']['result_label']."\n";
-    	$this->assertEquals('OK', $result['result']['result_code']);
-    	$this->assertEquals('ref-phpunit-2', $result['ref_ext']);
-
-    	return $result;
-    }
+		// Call the WebService method and store its result in $result.
+		$authentication=array(
+		'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+		'sourceapplication'=>'DEMO',
+		'login'=>'admin',
+		'password'=>$this->pass,
+		'entity'=>'');
+
+		// Test URL
+		$result='';
+		$parameters = array('authentication'=>$authentication,'invoice'=>$body);
+		print __METHOD__." call method ".$WS_METHOD."\n";
+		try {
+			$result = $this->soapclient->call($WS_METHOD, $parameters, $this->ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		if (! $result || ! empty($result['faultstring'])) {
+			print $this->soapclient->error_str;
+			print "\n<br>\n";
+			print $this->soapclient->request;
+			print "\n<br>\n";
+			print $this->soapclient->response;
+			print "\n";
+		}
+
+		print __METHOD__." result=".$result['result']['result_code'].$result['result']['result_label']."\n";
+		$this->assertEquals('OK', $result['result']['result_code']);
+		$this->assertEquals('ref-phpunit-2', $result['ref_ext']);
+
+		return $result;
+	}
 }

+ 141 - 141
test/phpunit/WebservicesOrdersTest.php

@@ -32,9 +32,9 @@ require_once NUSOAP_PATH.'/nusoap.php';        // Include SOAP
 
 
 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;
 
@@ -50,142 +50,142 @@ $conf->global->MAIN_UMASK='0666';
  */
 class WebservicesOrdersTest extends PHPUnit\Framework\TestCase
 {
-    protected $savconf;
-    protected $savuser;
-    protected $savlangs;
-    protected $savdb;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-
-    /**
-     * testWSOrderGetOrder
-     *
-     * @return int
-     */
-    public function testWSOrderGetOrder()
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_order.php';
-        $WS_METHOD  = 'getOrder';
-        $ns='http://www.dolibarr.org/ns/';
-
-        // Set the WebService URL
-        print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
-        $soapclient = new nusoap_client($WS_DOL_URL);
-        if ($soapclient) {
-            $soapclient->soap_defencoding='UTF-8';
-            $soapclient->decodeUTF8(false);
-        }
-
-        // Call the WebService method and store its result in $result.
-        $authentication=array(
-            'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
-            'sourceapplication'=>'DEMO',
-            'login'=>'admin',
-            'password'=>'admin',
-            'entity'=>''
-        );
-
-        // Test URL
-        $parameters = array('authentication'=>$authentication,'id'=>1);
-        print __METHOD__." call method ".$WS_METHOD."\n";
-        try {
-            $result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
-        } catch (SoapFault $exception) {
-            echo $exception;
-            $result=0;
-        }
-        if (! $result || ! empty($result['faultstring'])) {
-            //var_dump($soapclient);
-            print $soapclient->error_str;
-            print "\n<br>\n";
-            print $soapclient->request;
-            print "\n<br>\n";
-            print $soapclient->response;
-            print "\n";
-        }
-
-        print __METHOD__." count(result)=".count($result)."\n";
-        $this->assertEquals('OK', $result['result']['result_code']);
-
-        return $result;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+
+	/**
+	 * testWSOrderGetOrder
+	 *
+	 * @return int
+	 */
+	public function testWSOrderGetOrder()
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_order.php';
+		$WS_METHOD  = 'getOrder';
+		$ns='http://www.dolibarr.org/ns/';
+
+		// Set the WebService URL
+		print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
+		$soapclient = new nusoap_client($WS_DOL_URL);
+		if ($soapclient) {
+			$soapclient->soap_defencoding='UTF-8';
+			$soapclient->decodeUTF8(false);
+		}
+
+		// Call the WebService method and store its result in $result.
+		$authentication=array(
+			'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+			'sourceapplication'=>'DEMO',
+			'login'=>'admin',
+			'password'=>'admin',
+			'entity'=>''
+		);
+
+		// Test URL
+		$parameters = array('authentication'=>$authentication,'id'=>1);
+		print __METHOD__." call method ".$WS_METHOD."\n";
+		try {
+			$result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		if (! $result || ! empty($result['faultstring'])) {
+			//var_dump($soapclient);
+			print $soapclient->error_str;
+			print "\n<br>\n";
+			print $soapclient->request;
+			print "\n<br>\n";
+			print $soapclient->response;
+			print "\n";
+		}
+
+		print __METHOD__." count(result)=".count($result)."\n";
+		$this->assertEquals('OK', $result['result']['result_code']);
+
+		return $result;
+	}
 }

+ 170 - 170
test/phpunit/WebservicesOtherTest.php

@@ -32,9 +32,9 @@ require_once NUSOAP_PATH.'/nusoap.php';        // Include SOAP
 
 
 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;
 
@@ -50,171 +50,171 @@ $conf->global->MAIN_UMASK='0666';
  */
 class WebservicesOtherTest extends PHPUnit\Framework\TestCase
 {
-    protected $savconf;
-    protected $savuser;
-    protected $savlangs;
-    protected $savdb;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-
-    /**
-     * testWSOtherGetVersions
-     *
-     * @return int
-     */
-    public function testWSOtherGetVersions()
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_other.php';
-        $WS_METHOD  = 'getVersions';
-        $ns='http://www.dolibarr.org/ns/';
-
-        // Set the WebService URL
-        print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
-        $soapclient = new nusoap_client($WS_DOL_URL);
-        if ($soapclient) {
-            $soapclient->soap_defencoding='UTF-8';
-            $soapclient->decodeUTF8(false);
-        }
-
-        // Call the WebService method and store its result in $result.
-        $authentication=array(
-            'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
-            'sourceapplication'=>'DEMO',
-            'login'=>'admin',
-            'password'=>'admin',
-            'entity'=>''
-        );
-
-        // Test URL
-        $result='';
-        $parameters = array('authentication'=>$authentication);
-        print __METHOD__." call method ".$WS_METHOD."\n";
-        try {
-            $result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
-        } catch (SoapFault $exception) {
-            echo $exception;
-            $result=0;
-        }
-        if (! empty($result['faultstring'])) {
-            print $result['faultstring']."\n";
-            $result=0;
-        }
-        if (! $result) {
-            //var_dump($soapclient);
-            print $soapclient->error_str;
-            print "\n<br>\n";
-            print $soapclient->request;
-            print "\n<br>\n";
-            print $soapclient->response;
-            print "\n";
-        }
-
-        print __METHOD__." count(result)=".count($result)."\n";
-        $this->assertEquals('OK', $result['result']['result_code']);
-
-        // Test method that does not exists
-        $WS_METHOD='methodthatdoesnotexists';
-        $result='';
-        $parameters = array('authentication'=>$authentication);
-        print __METHOD__." call method ".$WS_METHOD."\n";
-        try {
-            $result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
-        } catch (SoapFault $exception) {
-            echo $exception;
-            $result=0;
-        }
-        if (! $result || ! empty($result['faultstring'])) {
-            //var_dump($soapclient);
-            print $soapclient->error_str;
-            print "\n<br>\n";
-            print $soapclient->request;
-            print "\n<br>\n";
-            print $soapclient->response;
-            print "\n";
-        }
-
-        print __METHOD__." count(result)=".count($result)."\n";
-        $this->assertEquals("SOAP-ENV:Client: Operation 'methodthatdoesnotexists' is not defined in the WSDL for this service", $soapclient->error_str);
-
-        return $result;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+
+	/**
+	 * testWSOtherGetVersions
+	 *
+	 * @return int
+	 */
+	public function testWSOtherGetVersions()
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_other.php';
+		$WS_METHOD  = 'getVersions';
+		$ns='http://www.dolibarr.org/ns/';
+
+		// Set the WebService URL
+		print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
+		$soapclient = new nusoap_client($WS_DOL_URL);
+		if ($soapclient) {
+			$soapclient->soap_defencoding='UTF-8';
+			$soapclient->decodeUTF8(false);
+		}
+
+		// Call the WebService method and store its result in $result.
+		$authentication=array(
+			'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+			'sourceapplication'=>'DEMO',
+			'login'=>'admin',
+			'password'=>'admin',
+			'entity'=>''
+		);
+
+		// Test URL
+		$result='';
+		$parameters = array('authentication'=>$authentication);
+		print __METHOD__." call method ".$WS_METHOD."\n";
+		try {
+			$result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		if (! empty($result['faultstring'])) {
+			print $result['faultstring']."\n";
+			$result=0;
+		}
+		if (! $result) {
+			//var_dump($soapclient);
+			print $soapclient->error_str;
+			print "\n<br>\n";
+			print $soapclient->request;
+			print "\n<br>\n";
+			print $soapclient->response;
+			print "\n";
+		}
+
+		print __METHOD__." count(result)=".count($result)."\n";
+		$this->assertEquals('OK', $result['result']['result_code']);
+
+		// Test method that does not exists
+		$WS_METHOD='methodthatdoesnotexists';
+		$result='';
+		$parameters = array('authentication'=>$authentication);
+		print __METHOD__." call method ".$WS_METHOD."\n";
+		try {
+			$result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		if (! $result || ! empty($result['faultstring'])) {
+			//var_dump($soapclient);
+			print $soapclient->error_str;
+			print "\n<br>\n";
+			print $soapclient->request;
+			print "\n<br>\n";
+			print $soapclient->response;
+			print "\n";
+		}
+
+		print __METHOD__." count(result)=".count($result)."\n";
+		$this->assertEquals("SOAP-ENV:Client: Operation 'methodthatdoesnotexists' is not defined in the WSDL for this service", $soapclient->error_str);
+
+		return $result;
+	}
 }

+ 283 - 284
test/phpunit/WebservicesProductsTest.php

@@ -34,16 +34,15 @@ require_once NUSOAP_PATH.'/nusoap.php';        // Include SOAP
 
 
 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';
 
-if (empty($conf->service->enabled))
-{
+if (empty($conf->service->enabled)) {
 	print "Error: Module service must be enabled.\n";
 	exit(1);
 }
@@ -57,283 +56,283 @@ if (empty($conf->service->enabled))
  */
 class WebservicesProductsTest extends PHPUnit\Framework\TestCase
 {
-    protected $savconf;
-    protected $savuser;
-    protected $savlangs;
-    protected $savdb;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-
-    /**
-     * testWSProductsCreateProductOrService
-     *
-     * @return int
-     */
-    public function testWSProductsCreateProductOrService()
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $datestring=dol_print_date(dol_now(), 'dayhourlog');
-
-        $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_productorservice.php';
-        $WS_METHOD  = 'createProductOrService';
-        $ns='http://www.dolibarr.org/ns/';
-
-        // Set the WebService URL
-        print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
-        $soapclient = new nusoap_client($WS_DOL_URL);
-        if ($soapclient) {
-            $soapclient->soap_defencoding='UTF-8';
-            $soapclient->decodeUTF8(false);
-        }
-
-        // Call the WebService method and store its result in $result.
-        $authentication=array(
-            'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
-            'sourceapplication'=>'DEMO',
-            'login'=>'admin',
-            'password'=>'admin',
-            'entity'=>''
-        );
-
-        // Test URL
-        $result='';
-        $parameters = array(
-            'authentication'=>$authentication,'product'=>array(
-                'ref'=>'NewProductFromWS'.$datestring,
-                'label'=>'New Product From WS '.$datestring,
-                'type'=>1,
-                'description'=>'This is a new product created from WS PHPUnit test case',
-                'barcode'=>'123456789012',
-                'barcode_type'=>2,
-            	'price_net'=>10,
-            	'status_tosell'=>1,
-            	'status_tobuy'=>1
-            )
-        );
-        print __METHOD__." call method ".$WS_METHOD."\n";
-        try {
-            $result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
-        } catch (SoapFault $exception) {
-            echo $exception;
-            $result=0;
-        }
-        if (! $result || ! empty($result['faultstring']) || $result['result']['result_code'] != 'OK') {
-            //var_dump($soapclient);
-            print $soapclient->error_str;
-            print "\n<br>\n";
-            print $soapclient->request;
-            print "\n<br>\n";
-            print $soapclient->response;
-            print "\n";
-        }
-        print var_export($result, true);
-        print __METHOD__." count(result)=".(is_array($result) ? count($result) : '')."\n";
-        $this->assertEquals('OK', $result['result']['result_code']);
-
-        return $result['id'];
-    }
-
-    /**
-     * testWSProductsGetProductOrService
-     *
-     * @param   int $id     Id of product or service
-     * @return  int         Id of product or service
-     *
-     * @depends	testWSProductsCreateProductOrService
-     */
-    public function testWSProductsGetProductOrService($id)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_productorservice.php';
-        $WS_METHOD  = 'getProductOrService';
-        $ns='http://www.dolibarr.org/ns/';
-
-        // Set the WebService URL
-        print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
-        $soapclient = new nusoap_client($WS_DOL_URL);
-        if ($soapclient) {
-            $soapclient->soap_defencoding='UTF-8';
-            $soapclient->decodeUTF8(false);
-        }
-
-        // Call the WebService method and store its result in $result.
-        $authentication=array(
-            'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
-            'sourceapplication'=>'DEMO',
-            'login'=>'admin',
-            'password'=>'admin',
-            'entity'=>''
-        );
-
-        // Test URL
-        $result='';
-        $parameters = array('authentication'=>$authentication,'id'=>$id,'ref'=>'');
-        print __METHOD__." call method ".$WS_METHOD."\n";
-        try {
-            $result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
-        } catch (SoapFault $exception) {
-            echo $exception;
-            $result=0;
-        }
-        if (! $result || ! empty($result['faultstring'])) {
-            //var_dump($soapclient);
-            print $soapclient->error_str;
-            print "\n<br>\n";
-            print $soapclient->request;
-            print "\n<br>\n";
-            print $soapclient->response;
-            print "\n";
-        }
-
-        print __METHOD__." count(result)=".count($result)."\n";
-        $this->assertEquals('OK', $result['result']['result_code']);
-
-        return $id;
-    }
-
-    /**
-     * testWSProductsDeleteProductOrService
-     *
-     * @param   int $id     Id of product or service
-     * @return  int         0
-     *
-     * @depends testWSProductsGetProductOrService
-     */
-    public function testWSProductsDeleteProductOrService($id)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_productorservice.php';
-        $WS_METHOD  = 'deleteProductOrService';
-        $ns='http://www.dolibarr.org/ns/';
-
-        // Set the WebService URL
-        print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
-        $soapclient = new nusoap_client($WS_DOL_URL);
-        if ($soapclient) {
-            $soapclient->soap_defencoding='UTF-8';
-            $soapclient->decodeUTF8(false);
-        }
-
-        // Call the WebService method and store its result in $result.
-        $authentication=array(
-            'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
-            'sourceapplication'=>'DEMO',
-            'login'=>'admin',
-            'password'=>'admin',
-            'entity'=>''
-        );
-
-        // Test URL
-        $result='';
-        $parameters = array('authentication'=>$authentication,'listofid'=>$id);
-        print __METHOD__." call method ".$WS_METHOD."\n";
-        try {
-            $result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
-        } catch (SoapFault $exception) {
-            echo $exception;
-            $result=0;
-        }
-        if (! $result || ! empty($result['faultstring']) || $result['result']['result_code'] != 'OK') {
-            //var_dump($soapclient);
-            print $soapclient->error_str;
-            print "\n<br>\n";
-            print $soapclient->request;
-            print "\n<br>\n";
-            print $soapclient->response;
-            print "\n";
-        }
-
-        print __METHOD__." count(result)=".count($result)."\n";
-        $this->assertEquals('OK', $result['result']['result_code']);
-
-        return 0;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+
+	/**
+	 * testWSProductsCreateProductOrService
+	 *
+	 * @return int
+	 */
+	public function testWSProductsCreateProductOrService()
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$datestring=dol_print_date(dol_now(), 'dayhourlog');
+
+		$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_productorservice.php';
+		$WS_METHOD  = 'createProductOrService';
+		$ns='http://www.dolibarr.org/ns/';
+
+		// Set the WebService URL
+		print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
+		$soapclient = new nusoap_client($WS_DOL_URL);
+		if ($soapclient) {
+			$soapclient->soap_defencoding='UTF-8';
+			$soapclient->decodeUTF8(false);
+		}
+
+		// Call the WebService method and store its result in $result.
+		$authentication=array(
+			'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+			'sourceapplication'=>'DEMO',
+			'login'=>'admin',
+			'password'=>'admin',
+			'entity'=>''
+		);
+
+		// Test URL
+		$result='';
+		$parameters = array(
+			'authentication'=>$authentication,'product'=>array(
+				'ref'=>'NewProductFromWS'.$datestring,
+				'label'=>'New Product From WS '.$datestring,
+				'type'=>1,
+				'description'=>'This is a new product created from WS PHPUnit test case',
+				'barcode'=>'123456789012',
+				'barcode_type'=>2,
+				'price_net'=>10,
+				'status_tosell'=>1,
+				'status_tobuy'=>1
+			)
+		);
+		print __METHOD__." call method ".$WS_METHOD."\n";
+		try {
+			$result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		if (! $result || ! empty($result['faultstring']) || $result['result']['result_code'] != 'OK') {
+			//var_dump($soapclient);
+			print $soapclient->error_str;
+			print "\n<br>\n";
+			print $soapclient->request;
+			print "\n<br>\n";
+			print $soapclient->response;
+			print "\n";
+		}
+		print var_export($result, true);
+		print __METHOD__." count(result)=".(is_array($result) ? count($result) : '')."\n";
+		$this->assertEquals('OK', $result['result']['result_code']);
+
+		return $result['id'];
+	}
+
+	/**
+	 * testWSProductsGetProductOrService
+	 *
+	 * @param   int $id     Id of product or service
+	 * @return  int         Id of product or service
+	 *
+	 * @depends	testWSProductsCreateProductOrService
+	 */
+	public function testWSProductsGetProductOrService($id)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_productorservice.php';
+		$WS_METHOD  = 'getProductOrService';
+		$ns='http://www.dolibarr.org/ns/';
+
+		// Set the WebService URL
+		print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
+		$soapclient = new nusoap_client($WS_DOL_URL);
+		if ($soapclient) {
+			$soapclient->soap_defencoding='UTF-8';
+			$soapclient->decodeUTF8(false);
+		}
+
+		// Call the WebService method and store its result in $result.
+		$authentication=array(
+			'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+			'sourceapplication'=>'DEMO',
+			'login'=>'admin',
+			'password'=>'admin',
+			'entity'=>''
+		);
+
+		// Test URL
+		$result='';
+		$parameters = array('authentication'=>$authentication,'id'=>$id,'ref'=>'');
+		print __METHOD__." call method ".$WS_METHOD."\n";
+		try {
+			$result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		if (! $result || ! empty($result['faultstring'])) {
+			//var_dump($soapclient);
+			print $soapclient->error_str;
+			print "\n<br>\n";
+			print $soapclient->request;
+			print "\n<br>\n";
+			print $soapclient->response;
+			print "\n";
+		}
+
+		print __METHOD__." count(result)=".count($result)."\n";
+		$this->assertEquals('OK', $result['result']['result_code']);
+
+		return $id;
+	}
+
+	/**
+	 * testWSProductsDeleteProductOrService
+	 *
+	 * @param   int $id     Id of product or service
+	 * @return  int         0
+	 *
+	 * @depends testWSProductsGetProductOrService
+	 */
+	public function testWSProductsDeleteProductOrService($id)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_productorservice.php';
+		$WS_METHOD  = 'deleteProductOrService';
+		$ns='http://www.dolibarr.org/ns/';
+
+		// Set the WebService URL
+		print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
+		$soapclient = new nusoap_client($WS_DOL_URL);
+		if ($soapclient) {
+			$soapclient->soap_defencoding='UTF-8';
+			$soapclient->decodeUTF8(false);
+		}
+
+		// Call the WebService method and store its result in $result.
+		$authentication=array(
+			'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+			'sourceapplication'=>'DEMO',
+			'login'=>'admin',
+			'password'=>'admin',
+			'entity'=>''
+		);
+
+		// Test URL
+		$result='';
+		$parameters = array('authentication'=>$authentication,'listofid'=>$id);
+		print __METHOD__." call method ".$WS_METHOD."\n";
+		try {
+			$result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		if (! $result || ! empty($result['faultstring']) || $result['result']['result_code'] != 'OK') {
+			//var_dump($soapclient);
+			print $soapclient->error_str;
+			print "\n<br>\n";
+			print $soapclient->request;
+			print "\n<br>\n";
+			print $soapclient->response;
+			print "\n";
+		}
+
+		print __METHOD__." count(result)=".count($result)."\n";
+		$this->assertEquals('OK', $result['result']['result_code']);
+
+		return 0;
+	}
 }

+ 358 - 358
test/phpunit/WebservicesThirdpartyTest.php

@@ -32,9 +32,9 @@ require_once NUSOAP_PATH.'/nusoap.php';        // Include SOAP
 
 
 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;
 
@@ -50,361 +50,361 @@ $conf->global->MAIN_UMASK='0666';
  */
 class WebservicesThirdpartyTest extends PHPUnit\Framework\TestCase
 {
-    protected $savconf;
-    protected $savuser;
-    protected $savlangs;
-    protected $savdb;
-    protected $soapclient;
-
-    private $ns='http://www.dolibarr.org/ns/';
-
-
-
-
-    /**
-     * 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;
-
-        $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php';
-
-        // Set the WebService URL
-        print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
-        $this->soapclient = new nusoap_client($WS_DOL_URL);
-        if ($this->soapclient) {
-        	$this->soapclient->soap_defencoding='UTF-8';
-        	$this->soapclient->decodeUTF8(false);
-        }
-
-        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.
-
-        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";
-    }
-
-    /**
-     * testWSThirdpartycreateThirdParty
-     *
-     * @return array thirdparty created
-     */
-    public function testWSThirdpartycreateThirdParty()
-    {
-    	global $conf,$user,$langs,$db;
-    	$conf=$this->savconf;
-    	$user=$this->savuser;
-    	$langs=$this->savlangs;
-    	$db=$this->savdb;
-
-    	$WS_METHOD  = 'createThirdParty';
-
-
-    	// Call the WebService method and store its result in $result.
-    	$authentication=array(
-    			'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
-    			'sourceapplication'=>'DEMO',
-    			'login'=>'admin',
-    			'password'=>'admin',
-    			'entity'=>'');
-
-    	$body = array (
-    			"id" => null,
-    			"ref" => "name",
-    			"ref_ext" => "12",
-    			"fk_user_author" => null,
-    			"status" => null,
-    			"client" => 1,
-    			"supplier" => 0,
-    			"customer_code" => "CU0901-5678",
-    			"supplier_code" => "SU0901-5678",
-    			"customer_code_accountancy" => "",
-    			"supplier_code_accountancy" => "",
-    			"date_creation" => "", // dateTime
-    			"date_modification" => "", // dateTime
-    			"note_private" => "",
-    			"note_public" => "",
-    			"address" => "",
-    			"zip" => "",
-    			"town" => "",
-    			"province_id" => "",
-    			"country_id" => "",
-    			"country_code" => "",
-    			"country" => "",
-    			"phone" => "",
-    			"fax" => "",
-    			"email" => "",
-    			"url" => "",
-    			"profid1" => "",
-    			"profid2" => "",
-    			"profid3" => "",
-    			"profid4" => "",
-    			"profid5" => "",
-    			"profid6" => "",
-    			"capital" => "",
-    			"vat_used" => "",
-    			"vat_number" => ""
-    	);
-
-    	// Test URL
-    	$result='';
-    	$parameters = array('authentication'=>$authentication, 'thirdparty'=>$body);
-    	print __METHOD__." call method ".$WS_METHOD."\n";
-    	try {
-    		$result = $this->soapclient->call($WS_METHOD, $parameters, $this->ns, '');
-    	} catch (SoapFault $exception) {
-    		echo $exception;
-    		$result=0;
-    	}
-    	if (! $result || ! empty($result['faultstring'])) {
-    		//var_dump($soapclient);
-    		print $this->soapclient->error_str;
-    		print "\n<br>\n";
-    		print $this->soapclient->request;
-    		print "\n<br>\n";
-    		print $this->soapclient->response;
-    		print "\n";
-    	}
-
-    	print __METHOD__." result=".$result['result']['result_code']."\n";
-    	$this->assertEquals('OK', $result['result']['result_code']);
-    	$this->assertEquals('name', $result['ref']);
-
-    	return $result;
-    }
-
-    /**
-     * testWSThirdpartygetThirdPartyById
-     *
-     * Use id to retrieve thirdparty
-     * @depends testWSThirdpartycreateThirdParty
-     *
-     * @param	array	$result		thirdparty created by create method
-     * @return	array				thirpdarty updated
-     */
-    public function testWSThirdpartygetThirdPartyById($result)
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-        $id = $result['id'];
-
-        $WS_METHOD  = 'getThirdParty';
-
-        // Call the WebService method and store its result in $result.
-        $authentication=array(
-        'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
-        'sourceapplication'=>'DEMO',
-        'login'=>'admin',
-        'password'=>'admin',
-        'entity'=>'');
-
-        $result='';
-        $parameters = array('authentication'=>$authentication, 'id'=>$id);
-        print __METHOD__." call method ".$WS_METHOD."\n";
-        try {
-            $result = $this->soapclient->call($WS_METHOD, $parameters, $this->ns, '');
-        } catch (SoapFault $exception) {
-            echo $exception;
-            $result=0;
-        }
-        if (! $result || ! empty($result['faultstring'])) {
-            //var_dump($soapclient);
-            print $this->soapclient->error_str;
-            print "\n<br>\n";
-            print $this->soapclient->request;
-            print "\n<br>\n";
-            print $this->soapclient->response;
-            print "\n";
-        }
-
-        print __METHOD__." result=".$result['result']['result_code']."\n";
-        $this->assertEquals('OK', $result['result']['result_code']);
-        $this->assertEquals($id, $result['thirdparty']['id']);
-        $this->assertEquals('name', $result['thirdparty']['ref']);
-        $this->assertEquals('12', $result['thirdparty']['ref_ext']);
-        $this->assertEquals('0', $result['thirdparty']['status']);
-        $this->assertEquals('1', $result['thirdparty']['client']);
-        $this->assertEquals('0', $result['thirdparty']['supplier']);
-
-
-        return $result;
-    }
-
-    /**
-     * testWSThirdpartygetThirdPartyByRefExt
-     *
-     * Use ref_ext to retrieve thirdparty
-     *
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+	protected $soapclient;
+
+	private $ns='http://www.dolibarr.org/ns/';
+
+
+
+
+	/**
+	 * 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;
+
+		$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php';
+
+		// Set the WebService URL
+		print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n";
+		$this->soapclient = new nusoap_client($WS_DOL_URL);
+		if ($this->soapclient) {
+			$this->soapclient->soap_defencoding='UTF-8';
+			$this->soapclient->decodeUTF8(false);
+		}
+
+		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.
+
+		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";
+	}
+
+	/**
+	 * testWSThirdpartycreateThirdParty
+	 *
+	 * @return array thirdparty created
+	 */
+	public function testWSThirdpartycreateThirdParty()
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$WS_METHOD  = 'createThirdParty';
+
+
+		// Call the WebService method and store its result in $result.
+		$authentication=array(
+				'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+				'sourceapplication'=>'DEMO',
+				'login'=>'admin',
+				'password'=>'admin',
+				'entity'=>'');
+
+		$body = array (
+				"id" => null,
+				"ref" => "name",
+				"ref_ext" => "12",
+				"fk_user_author" => null,
+				"status" => null,
+				"client" => 1,
+				"supplier" => 0,
+				"customer_code" => "CU0901-5678",
+				"supplier_code" => "SU0901-5678",
+				"customer_code_accountancy" => "",
+				"supplier_code_accountancy" => "",
+				"date_creation" => "", // dateTime
+				"date_modification" => "", // dateTime
+				"note_private" => "",
+				"note_public" => "",
+				"address" => "",
+				"zip" => "",
+				"town" => "",
+				"province_id" => "",
+				"country_id" => "",
+				"country_code" => "",
+				"country" => "",
+				"phone" => "",
+				"fax" => "",
+				"email" => "",
+				"url" => "",
+				"profid1" => "",
+				"profid2" => "",
+				"profid3" => "",
+				"profid4" => "",
+				"profid5" => "",
+				"profid6" => "",
+				"capital" => "",
+				"vat_used" => "",
+				"vat_number" => ""
+		);
+
+		// Test URL
+		$result='';
+		$parameters = array('authentication'=>$authentication, 'thirdparty'=>$body);
+		print __METHOD__." call method ".$WS_METHOD."\n";
+		try {
+			$result = $this->soapclient->call($WS_METHOD, $parameters, $this->ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		if (! $result || ! empty($result['faultstring'])) {
+			//var_dump($soapclient);
+			print $this->soapclient->error_str;
+			print "\n<br>\n";
+			print $this->soapclient->request;
+			print "\n<br>\n";
+			print $this->soapclient->response;
+			print "\n";
+		}
+
+		print __METHOD__." result=".$result['result']['result_code']."\n";
+		$this->assertEquals('OK', $result['result']['result_code']);
+		$this->assertEquals('name', $result['ref']);
+
+		return $result;
+	}
+
+	/**
+	 * testWSThirdpartygetThirdPartyById
+	 *
+	 * Use id to retrieve thirdparty
+	 * @depends testWSThirdpartycreateThirdParty
+	 *
+	 * @param	array	$result		thirdparty created by create method
+	 * @return	array				thirpdarty updated
+	 */
+	public function testWSThirdpartygetThirdPartyById($result)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+		$id = $result['id'];
+
+		$WS_METHOD  = 'getThirdParty';
+
+		// Call the WebService method and store its result in $result.
+		$authentication=array(
+		'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+		'sourceapplication'=>'DEMO',
+		'login'=>'admin',
+		'password'=>'admin',
+		'entity'=>'');
+
+		$result='';
+		$parameters = array('authentication'=>$authentication, 'id'=>$id);
+		print __METHOD__." call method ".$WS_METHOD."\n";
+		try {
+			$result = $this->soapclient->call($WS_METHOD, $parameters, $this->ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		if (! $result || ! empty($result['faultstring'])) {
+			//var_dump($soapclient);
+			print $this->soapclient->error_str;
+			print "\n<br>\n";
+			print $this->soapclient->request;
+			print "\n<br>\n";
+			print $this->soapclient->response;
+			print "\n";
+		}
+
+		print __METHOD__." result=".$result['result']['result_code']."\n";
+		$this->assertEquals('OK', $result['result']['result_code']);
+		$this->assertEquals($id, $result['thirdparty']['id']);
+		$this->assertEquals('name', $result['thirdparty']['ref']);
+		$this->assertEquals('12', $result['thirdparty']['ref_ext']);
+		$this->assertEquals('0', $result['thirdparty']['status']);
+		$this->assertEquals('1', $result['thirdparty']['client']);
+		$this->assertEquals('0', $result['thirdparty']['supplier']);
+
+
+		return $result;
+	}
+
+	/**
+	 * testWSThirdpartygetThirdPartyByRefExt
+	 *
+	 * Use ref_ext to retrieve thirdparty
+	 *
+	 * @depends testWSThirdpartycreateThirdParty
+	 *
+	 * @param	array	$result		thirdparty created by create method
+	 * @return	array				thirdparty
+	 */
+	public function testWSThirdpartygetThirdPartyByRefExt($result)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+		$id = $result['id'];
+
+		$WS_METHOD  = 'getThirdParty';
+
+		// Call the WebService method and store its result in $result.
+		$authentication=array(
+				'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+				'sourceapplication'=>'DEMO',
+				'login'=>'admin',
+				'password'=>'admin',
+				'entity'=>'');
+
+		// Test URL
+		$result='';
+		$parameters = array('authentication'=>$authentication, 'id'=>'', 'ref'=>'', 'ref_ext'=>'12');
+		print __METHOD__." call method ".$WS_METHOD."\n";
+		try {
+			$result = $this->soapclient->call($WS_METHOD, $parameters, $this->ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		print $this->soapclient->response;
+		if (! $result || ! empty($result['faultstring'])) {
+			//var_dump($soapclient);
+			print $this->soapclient->error_str;
+			print "\n<br>\n";
+			print $this->soapclient->request;
+			print "\n<br>\n";
+			print $this->soapclient->response;
+			print "\n";
+		}
+
+		print __METHOD__." result=".$result['result']['result_code']."\n";
+		$this->assertEquals('OK', $result['result']['result_code']);
+		$this->assertEquals($id, $result['thirdparty']['id']);
+		$this->assertEquals('name', $result['thirdparty']['ref']);
+		$this->assertEquals('12', $result['thirdparty']['ref_ext']);
+		$this->assertEquals('0', $result['thirdparty']['status']);
+		$this->assertEquals('1', $result['thirdparty']['client']);
+		$this->assertEquals('0', $result['thirdparty']['supplier']);
+
+
+		return $result;
+	}
+
+	/**
+	 * testWSThirdpartydeleteThirdParty
+	 *
 	 * @depends testWSThirdpartycreateThirdParty
 	 *
-     * @param	array	$result		thirdparty created by create method
-     * @return	array				thirdparty
-     */
-    public function testWSThirdpartygetThirdPartyByRefExt($result)
-    {
-    	global $conf,$user,$langs,$db;
-    	$conf=$this->savconf;
-    	$user=$this->savuser;
-    	$langs=$this->savlangs;
-    	$db=$this->savdb;
-    	$id = $result['id'];
-
-    	$WS_METHOD  = 'getThirdParty';
-
-    	// Call the WebService method and store its result in $result.
-    	$authentication=array(
-    			'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
-    			'sourceapplication'=>'DEMO',
-    			'login'=>'admin',
-    			'password'=>'admin',
-    			'entity'=>'');
-
-    	// Test URL
-    	$result='';
-    	$parameters = array('authentication'=>$authentication, 'id'=>'', 'ref'=>'', 'ref_ext'=>'12');
-    	print __METHOD__." call method ".$WS_METHOD."\n";
-    	try {
-    		$result = $this->soapclient->call($WS_METHOD, $parameters, $this->ns, '');
-    	} catch (SoapFault $exception) {
-    		echo $exception;
-    		$result=0;
-    	}
-    	print $this->soapclient->response;
-    	if (! $result || ! empty($result['faultstring'])) {
-    		//var_dump($soapclient);
-    		print $this->soapclient->error_str;
-    		print "\n<br>\n";
-    		print $this->soapclient->request;
-    		print "\n<br>\n";
-    		print $this->soapclient->response;
-    		print "\n";
-    	}
-
-    	print __METHOD__." result=".$result['result']['result_code']."\n";
-    	$this->assertEquals('OK', $result['result']['result_code']);
-    	$this->assertEquals($id, $result['thirdparty']['id']);
-    	$this->assertEquals('name', $result['thirdparty']['ref']);
-    	$this->assertEquals('12', $result['thirdparty']['ref_ext']);
-    	$this->assertEquals('0', $result['thirdparty']['status']);
-    	$this->assertEquals('1', $result['thirdparty']['client']);
-    	$this->assertEquals('0', $result['thirdparty']['supplier']);
-
-
-    	return $result;
-    }
-
-    /**
-     * testWSThirdpartydeleteThirdParty
-     *
-     * @depends testWSThirdpartycreateThirdParty
-     *
-     * @param	array	$result		thirdparty created by create method
-     * @return	array				thirdparty
-     */
-    public function testWSThirdpartydeleteThirdPartyById($result)
-    {
-    	global $conf,$user,$langs,$db;
-    	$conf=$this->savconf;
-    	$user=$this->savuser;
-    	$langs=$this->savlangs;
-    	$db=$this->savdb;
-    	$id = $result['id'];
-
-    	$WS_METHOD  = 'deleteThirdParty';
-
-    	// Call the WebService method and store its result in $result.
-    	$authentication=array(
-    			'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
-    			'sourceapplication'=>'DEMO',
-    			'login'=>'admin',
-    			'password'=>'admin',
-    			'entity'=>'');
-
-    	$result='';
-    	$parameters = array('authentication'=>$authentication, 'id'=>$id, 'ref'=>'', 'ref_ext'=>'');
-    	print __METHOD__." call method ".$WS_METHOD."\n";
-    	try {
-    		$result = $this->soapclient->call($WS_METHOD, $parameters, $this->ns, '');
-    	} catch (SoapFault $exception) {
-    		echo $exception;
-    		$result=0;
-    	}
-    	if (! $result || ! empty($result['faultstring'])) {
-    		print $this->soapclient->error_str;
-    		print "\n<br>\n";
-    		print $this->soapclient->request;
-    		print "\n<br>\n";
-    		print $this->soapclient->response;
-    		print "\n";
-    	}
-
-    	print __METHOD__." result=".$result['result']['result_code']."\n";
-    	$this->assertEquals('OK', $result['result']['result_code']);
-
-    	return $result;
-    }
+	 * @param	array	$result		thirdparty created by create method
+	 * @return	array				thirdparty
+	 */
+	public function testWSThirdpartydeleteThirdPartyById($result)
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+		$id = $result['id'];
+
+		$WS_METHOD  = 'deleteThirdParty';
+
+		// Call the WebService method and store its result in $result.
+		$authentication=array(
+				'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+				'sourceapplication'=>'DEMO',
+				'login'=>'admin',
+				'password'=>'admin',
+				'entity'=>'');
+
+		$result='';
+		$parameters = array('authentication'=>$authentication, 'id'=>$id, 'ref'=>'', 'ref_ext'=>'');
+		print __METHOD__." call method ".$WS_METHOD."\n";
+		try {
+			$result = $this->soapclient->call($WS_METHOD, $parameters, $this->ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		if (! $result || ! empty($result['faultstring'])) {
+			print $this->soapclient->error_str;
+			print "\n<br>\n";
+			print $this->soapclient->request;
+			print "\n<br>\n";
+			print $this->soapclient->response;
+			print "\n";
+		}
+
+		print __METHOD__." result=".$result['result']['result_code']."\n";
+		$this->assertEquals('OK', $result['result']['result_code']);
+
+		return $result;
+	}
 }

+ 171 - 171
test/phpunit/WebservicesUserTest.php

@@ -32,9 +32,9 @@ require_once NUSOAP_PATH.'/nusoap.php';        // Include SOAP
 
 
 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;
 
@@ -50,172 +50,172 @@ $conf->global->MAIN_UMASK='0666';
  */
 class WebservicesUserTest extends PHPUnit\Framework\TestCase
 {
-    protected $savconf;
-    protected $savuser;
-    protected $savlangs;
-    protected $savdb;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-
-    /**
-     * testWSUserGetUser
-     *
-     * @return int
-     */
-    public function testWSUserGetUser()
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_user.php';
-        $WS_METHOD  = 'getUser';
-        $ns='http://www.dolibarr.org/ns/';
-
-        // Set the WebService URL
-        print __METHOD__." Create nusoap_client for URL=".$WS_DOL_URL."\n";
-        $soapclient = new nusoap_client($WS_DOL_URL);
-        if ($soapclient) {
-            $soapclient->soap_defencoding='UTF-8';
-            $soapclient->decodeUTF8(false);
-        }
-
-        //$soapclient->setDebugLevel(5);
-
-        // Call the WebService method and store its result in $result.
-        $authentication=array(
-            'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
-            'sourceapplication'=>'DEMO',
-            'login'=>'admin',
-            'password'=>'admin',
-            'entity'=>''
-        );
-
-        // Test URL
-        $result='';
-        $parameters = array('authentication'=>$authentication,'id'=>0,'ref'=>'admin');
-        print __METHOD__." Call method ".$WS_METHOD."\n";
-        try {
-            $result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
-        } catch (SoapFault $exception) {
-            echo $exception;
-            $result=0;
-        }
-        if (! empty($result['faultstring'])) {
-            print $result['faultstring']."\n";
-            $result=0;
-        }
-        if (! $result) {
-            //var_dump($soapclient);
-            print $soapclient->error_str;
-            print "\n<br>\n";
-            print $soapclient->request;
-            print "\n<br>\n";
-            print $soapclient->response;
-            print "\n";
-        }
-
-        print __METHOD__." count(result)=".count($result)."\n";
-        $this->assertEquals('OK', empty($result['result']['result_code'])?'':$result['result']['result_code'], 'Test on ref admin');
-
-        // Test URL
-        $result='';
-        $parameters = array('authentication'=>$authentication,'id'=>0,'ref'=>'refthatdoesnotexists');
-        print __METHOD__."Call method ".$WS_METHOD."\n";
-        try {
-            $result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
-        } catch (SoapFault $exception) {
-            echo $exception;
-            $result=0;
-        }
-        if (! $result || ! empty($result['faultstring'])) {
-            //var_dump($soapclient);
-            print $soapclient->error_str;
-            print "\n<br>\n";
-            print $soapclient->request;
-            print "\n<br>\n";
-            print $soapclient->response;
-            print "\n";
-        }
-
-        print __METHOD__." count(result)=".count($result)."\n";
-        $this->assertEquals('NOT_FOUND', $result['result']['result_code'], 'Test on ref that does not exists');
-
-        return $result;
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+
+	/**
+	 * testWSUserGetUser
+	 *
+	 * @return int
+	 */
+	public function testWSUserGetUser()
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_user.php';
+		$WS_METHOD  = 'getUser';
+		$ns='http://www.dolibarr.org/ns/';
+
+		// Set the WebService URL
+		print __METHOD__." Create nusoap_client for URL=".$WS_DOL_URL."\n";
+		$soapclient = new nusoap_client($WS_DOL_URL);
+		if ($soapclient) {
+			$soapclient->soap_defencoding='UTF-8';
+			$soapclient->decodeUTF8(false);
+		}
+
+		//$soapclient->setDebugLevel(5);
+
+		// Call the WebService method and store its result in $result.
+		$authentication=array(
+			'dolibarrkey'=>$conf->global->WEBSERVICES_KEY,
+			'sourceapplication'=>'DEMO',
+			'login'=>'admin',
+			'password'=>'admin',
+			'entity'=>''
+		);
+
+		// Test URL
+		$result='';
+		$parameters = array('authentication'=>$authentication,'id'=>0,'ref'=>'admin');
+		print __METHOD__." Call method ".$WS_METHOD."\n";
+		try {
+			$result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		if (! empty($result['faultstring'])) {
+			print $result['faultstring']."\n";
+			$result=0;
+		}
+		if (! $result) {
+			//var_dump($soapclient);
+			print $soapclient->error_str;
+			print "\n<br>\n";
+			print $soapclient->request;
+			print "\n<br>\n";
+			print $soapclient->response;
+			print "\n";
+		}
+
+		print __METHOD__." count(result)=".count($result)."\n";
+		$this->assertEquals('OK', empty($result['result']['result_code'])?'':$result['result']['result_code'], 'Test on ref admin');
+
+		// Test URL
+		$result='';
+		$parameters = array('authentication'=>$authentication,'id'=>0,'ref'=>'refthatdoesnotexists');
+		print __METHOD__."Call method ".$WS_METHOD."\n";
+		try {
+			$result = $soapclient->call($WS_METHOD, $parameters, $ns, '');
+		} catch (SoapFault $exception) {
+			echo $exception;
+			$result=0;
+		}
+		if (! $result || ! empty($result['faultstring'])) {
+			//var_dump($soapclient);
+			print $soapclient->error_str;
+			print "\n<br>\n";
+			print $soapclient->request;
+			print "\n<br>\n";
+			print $soapclient->response;
+			print "\n";
+		}
+
+		print __METHOD__." count(result)=".count($result)."\n";
+		$this->assertEquals('NOT_FOUND', $result['result']['result_code'], 'Test on ref that does not exists');
+
+		return $result;
+	}
 }

+ 104 - 104
test/phpunit/XCalLibTest.php

@@ -30,9 +30,9 @@ require_once dirname(__FILE__).'/../../htdocs/master.inc.php';
 require_once dirname(__FILE__).'/../../htdocs/core/lib/xcal.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,105 +46,105 @@ $conf->global->MAIN_DISABLE_ALL_MAILS=1;
  */
 class XCalLibTest extends PHPUnit\Framework\TestCase
 {
-    protected $savconf;
-    protected $savuser;
-    protected $savlangs;
-    protected $savdb;
-
-    /**
-     * 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;
-
-        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.
-
-        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";
-    }
-
-
-    /**
-     * testQuotedPrintEncodeDecode
-     *
-     * @return  void
-     */
-    public function testQuotedPrintEncodeDecode()
-    {
-        global $conf,$user,$langs,$db;
-        $conf=$this->savconf;
-        $user=$this->savuser;
-        $langs=$this->savlangs;
-        $db=$this->savdb;
-
-        $stringtoencode='ABCD=1234;';
-        $result=quotedPrintEncode($stringtoencode);
-        print __METHOD__." result=".$result."\n";
-        $this->assertEquals('ABCD=3D1234;', $result);
-
-        $resultback=quotedPrintDecode($result);
-        print __METHOD__." result=".$resultback."\n";
-        $this->assertEquals($stringtoencode, $resultback);
-    }
+	protected $savconf;
+	protected $savuser;
+	protected $savlangs;
+	protected $savdb;
+
+	/**
+	 * 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;
+
+		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.
+
+		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";
+	}
+
+
+	/**
+	 * testQuotedPrintEncodeDecode
+	 *
+	 * @return  void
+	 */
+	public function testQuotedPrintEncodeDecode()
+	{
+		global $conf,$user,$langs,$db;
+		$conf=$this->savconf;
+		$user=$this->savuser;
+		$langs=$this->savlangs;
+		$db=$this->savdb;
+
+		$stringtoencode='ABCD=1234;';
+		$result=quotedPrintEncode($stringtoencode);
+		print __METHOD__." result=".$result."\n";
+		$this->assertEquals('ABCD=3D1234;', $result);
+
+		$resultback=quotedPrintDecode($result);
+		print __METHOD__." result=".$resultback."\n";
+		$this->assertEquals($stringtoencode, $resultback);
+	}
 }

+ 75 - 75
test/phpunit/functional/InstallTest.php

@@ -42,11 +42,11 @@ class InstallTest extends PHPUnit_Extensions_Selenium2TestCase
 		)
 	);
 
-    /**
-     * setUpBeforeClass
-     *
-     * @return	void
-     */
+	/**
+	 * setUpBeforeClass
+	 *
+	 * @return	void
+	 */
 	public static function setUpBeforeClass()
 	{
 		// Make sure we backup and remove the configuration file to force new install.
@@ -59,22 +59,22 @@ class InstallTest extends PHPUnit_Extensions_Selenium2TestCase
 		self::shareSession(true);
 	}
 
-    /**
-     * dropTestDatabase
-     *
-     * @return	void
-     */
+	/**
+	 * dropTestDatabase
+	 *
+	 * @return	void
+	 */
 	protected static function dropTestDatabase()
 	{
 		$mysqli = new mysqli(self::$db_host, self::$db_admin_user, self::$db_admin_pass);
 		$mysqli->query("DROP DATABASE " . self::$db_name);
 	}
 
-    /**
-     * tearDownAfterClass
-     *
-     * @return	void
-     */
+	/**
+	 * tearDownAfterClass
+	 *
+	 * @return	void
+	 */
 	public static function tearDownAfterClass()
 	{
 		// Remove the generated configuration and restore the backed up file.
@@ -85,11 +85,11 @@ class InstallTest extends PHPUnit_Extensions_Selenium2TestCase
 		self::dropTestDatabase();
 	}
 
-    /**
-     * setUp
-     *
-     * @return  void
-     */
+	/**
+	 * setUp
+	 *
+	 * @return  void
+	 */
 	public function setUp()
 	{
 		// Populating the database can take quite long.
@@ -97,32 +97,32 @@ class InstallTest extends PHPUnit_Extensions_Selenium2TestCase
 		$this->setBrowserUrl(self::$url);
 	}
 
-    /**
-     * testInstallRedirect
-     *
-     * @return  void
-     */
+	/**
+	 * testInstallRedirect
+	 *
+	 * @return  void
+	 */
 	public function testInstallRedirect()
 	{
 		$this->url('/');
 		$this->assertContains('/install/index.php', $this->url());
 	}
 
-    /**
-     * testInstallPageTitle
-     *
-     * @return  void
-     */
+	/**
+	 * testInstallPageTitle
+	 *
+	 * @return  void
+	 */
 	public function testInstallPageTitle()
 	{
 		$this->assertContains('Dolibarr', $this->title());
 	}
 
-    /**
-     * testInstallProcess
-     *
-     * @return  void
-     */
+	/**
+	 * testInstallProcess
+	 *
+	 * @return  void
+	 */
 	public function testInstallProcess()
 	{
 		// FIXME: the button itself should have an ID
@@ -130,11 +130,11 @@ class InstallTest extends PHPUnit_Extensions_Selenium2TestCase
 		$this->assertContains('/install/check.php', $this->url());
 	}
 
-    /**
-     * testCheckPage
-     *
-     * @return  void
-     */
+	/**
+	 * testCheckPage
+	 *
+	 * @return  void
+	 */
 	public function testCheckPage()
 	{
 		$unavailable_choices = $this->byId('navail_choices');
@@ -149,11 +149,11 @@ class InstallTest extends PHPUnit_Extensions_Selenium2TestCase
 		$this->assertContains('/install/fileconf.php', $this->url());
 	}
 
-    /**
-     * testForm
-     *
-     * @return  void
-     */
+	/**
+	 * testForm
+	 *
+	 * @return  void
+	 */
 	public function testForm()
 	{
 		$this->assertFalse($this->byClassName('hideroot')->displayed());
@@ -198,22 +198,22 @@ class InstallTest extends PHPUnit_Extensions_Selenium2TestCase
 		$this->byId('db_pass_root')->value('');
 	}
 
-    /**
-     * testFormSubmit
-     *
-     * @return  void
-     */
+	/**
+	 * testFormSubmit
+	 *
+	 * @return  void
+	 */
 	public function testFormSubmit()
 	{
 		$this->byName('forminstall')->submit();
 		$this->assertContains('/install/step1.php', $this->url());
 	}
 
-    /**
-     * testStep1
-     *
-     * @return  void
-     */
+	/**
+	 * testStep1
+	 *
+	 * @return  void
+	 */
 	public function testStep1()
 	{
 		$this->assertFalse($this->byId('pleasewait')->displayed());
@@ -225,11 +225,11 @@ class InstallTest extends PHPUnit_Extensions_Selenium2TestCase
 		$this->assertContains('/install/step2.php', $this->url());
 	}
 
-    /**
-     * testStep2
-     *
-     * @return  void
-     */
+	/**
+	 * testStep2
+	 *
+	 * @return  void
+	 */
 	public function testStep2()
 	{
 		$this->byName('forminstall')->submit();
@@ -238,11 +238,11 @@ class InstallTest extends PHPUnit_Extensions_Selenium2TestCase
 
 	// There is no step 3
 
-    /**
-     * testStep4
-     *
-     * @return  void
-     */
+	/**
+	 * testStep4
+	 *
+	 * @return  void
+	 */
 	public function testStep4()
 	{
 		// FIXME: should have an ID
@@ -256,11 +256,11 @@ class InstallTest extends PHPUnit_Extensions_Selenium2TestCase
 		$this->assertContains('/install/step5.php', $this->url());
 	}
 
-    /**
-     * testStep5
-     *
-     * @return  void
-     */
+	/**
+	 * testStep5
+	 *
+	 * @return  void
+	 */
 	public function testStep5()
 	{
 		// FIXME: this button should have an ID
@@ -268,11 +268,11 @@ class InstallTest extends PHPUnit_Extensions_Selenium2TestCase
 		$this->assertContains('/admin/index.php', $this->url());
 	}
 
-    /**
-     * testFirstLogin
-     *
-     * @return  void
-     */
+	/**
+	 * testFirstLogin
+	 *
+	 * @return  void
+	 */
 	public function testFirstLogin()
 	{
 		$this->assertEquals('login', $this->byTag('form')->attribute('id'));

+ 11 - 8
test/phpunit/functional/TakePosFunctionalTest.php

@@ -44,16 +44,19 @@ class TakePosFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
 	// TODO: move to a global configuration file?
 	/** @var string Base URL of the webserver under test */
 	protected static $base_url = 'http://dev.zenfusion.fr';
+
 	/**
 	 * @var string Dolibarr admin username
 	 * @see authenticate
 	 */
 	protected static $dol_admin_user = 'admin';
+
 	/**
 	 * @var string Dolibarr admin password
 	 * @see authenticate
 	 */
 	protected static $dol_admin_pass = 'admin';
+
 	/** @var int Dolibarr module ID */
 	private static $module_id = 500000; // TODO: autodetect?
 
@@ -67,14 +70,14 @@ class TakePosFunctionalTest extends \PHPUnit_Extensions_Selenium2TestCase
 		),
 		// Geckodriver does not keep the session at the moment?!
 		// XPath selectors also don't seem to work
-        //array(
-        //    'browser' => 'Mozilla Firefox on Linux',
-        //    'browserName' => 'firefox',
-        //    'sessionStrategy' => 'shared',
-        //    'desiredCapabilities' => array(
-        //        'marionette' => true
-        //    )
-        //)
+		//array(
+		//    'browser' => 'Mozilla Firefox on Linux',
+		//    'browserName' => 'firefox',
+		//    'sessionStrategy' => 'shared',
+		//    'desiredCapabilities' => array(
+		//        'marionette' => true
+		//    )
+		//)
 	);
 
 	/**