From 67052933ca1cc9fbdcb713ae30a0c7a85c181c8f Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Sun, 14 Apr 2013 23:42:24 +0200
Subject: [PATCH] Fix: PHPUnit

---
 htdocs/compta/facture/class/facture.class.php |  3 ++-
 htdocs/core/class/commonobject.class.php      |  7 ++++++-
 test/phpunit/BuildDocTest.php                 |  4 ++--
 test/phpunit/ContactTest.php                  |  8 ++++----
 test/phpunit/FilesLibTest.php                 | 16 ++++++++--------
 test/phpunit/HolidayTest.php                  |  4 ++--
 test/phpunit/PdfDocTest.php                   |  1 +
 test/phpunit/SocieteTest.php                  |  4 ++--
 8 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 614ed7e2823..272e2d313b5 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -3002,7 +3002,8 @@ class Facture extends CommonInvoice
         		$this->total_tva      += $line->total_tva;
         		$this->total_ttc      += $line->total_ttc;
             }
-
+            $this->revenuestamp = 0;
+            
             // Add a line "offered"
             $line=new FactureLigne($this->db);
             $line->desc=$langs->trans("Description")." (offered line)";
diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index e1c4be97184..124447bb81c 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -1413,7 +1413,12 @@ abstract class CommonObject
     		dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR);
     		return -1;
     	}
-
+		if (! in_array($suffix,array('','_public','_private')))
+		{
+    		dol_syslog(get_class($this)."::upate_note Parameter suffix must be empty, '_private' or '_public'", LOG_ERR);
+			return -2;
+		}
+		
     	$sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
     	$sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL");
     	$sql.= " WHERE rowid =". $this->id;
diff --git a/test/phpunit/BuildDocTest.php b/test/phpunit/BuildDocTest.php
index 4ac21f0fec4..67cea036bae 100644
--- a/test/phpunit/BuildDocTest.php
+++ b/test/phpunit/BuildDocTest.php
@@ -221,7 +221,7 @@ class BuildDocTest extends PHPUnit_Framework_TestCase
     	$newlangs5=new Translate("",$conf);
     	$newlangs5->setDefaultLang('ru_RU');
     	$localobject->modelpdf='crabe';
-    	$result=facture_pdf_create($db, $localobject, $localobject->modelpdf, $newlangs);
+    	$result=facture_pdf_create($db, $localobject, $localobject->modelpdf, $newlangs5);
     	$this->assertLessThan($result, 0);
     	print __METHOD__." result=".$result."\n";
 
@@ -376,7 +376,7 @@ class BuildDocTest extends PHPUnit_Framework_TestCase
         $langs=$this->savlangs;
         $db=$this->savdb;
 
-        $conf->fichinter->dir_output.='/temp';
+        $conf->ficheinter->dir_output.='/temp';
         $localobject=new Fichinter($this->savdb);
         $localobject->initAsSpecimen();
 
diff --git a/test/phpunit/ContactTest.php b/test/phpunit/ContactTest.php
index bac26a28485..844b36b311a 100755
--- a/test/phpunit/ContactTest.php
+++ b/test/phpunit/ContactTest.php
@@ -210,9 +210,9 @@ class ContactTest extends PHPUnit_Framework_TestCase
     	print __METHOD__." id=".$localobject->id." result=".$result."\n";
     	$this->assertLessThan($result, 0, 'Contact::update error');
 		
-    	$result=$localobject->update_note_private($localobject->note_private);
+    	$result=$localobject->update_note($localobject->note_private,'_private');
     	print __METHOD__." id=".$localobject->id." result=".$result."\n";
-    	$this->assertLessThan($result, 0, 'Contact::update_note_private error');
+    	$this->assertLessThan($result, 0, 'Contact::update_note error');
 		
     	$result=$localobject->update_note_public($localobject->note_public);
 		print __METHOD__." id=".$localobject->id." result=".$result."\n";
@@ -223,8 +223,8 @@ class ContactTest extends PHPUnit_Framework_TestCase
         print __METHOD__." id=".$localobject->id." result=".$result."\n";
     	$this->assertLessThan($result, 0, 'Contact::fetch error');
 
-    	print __METHOD__." old=".$localobject->note." new=".$newobject->note."\n";
-    	$this->assertEquals($localobject->note, $newobject->note);
+    	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";
diff --git a/test/phpunit/FilesLibTest.php b/test/phpunit/FilesLibTest.php
index f87494c924d..858e096aa36 100644
--- a/test/phpunit/FilesLibTest.php
+++ b/test/phpunit/FilesLibTest.php
@@ -312,35 +312,35 @@ class FilesLibTest extends PHPUnit_Framework_TestCase
 
         $result=dol_copy($file, '/adir/that/does/not/exists/file.csv');
         print __METHOD__." result=".$result."\n";
-        $this->assertLessThan(0,$result);    // We should have error
+        $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);    // Should be 1
+        $this->assertGreaterThanOrEqual(1,$result, 'copy into a dir that exists');    // 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);    // Should be 0
+        $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);    // Should be 1
+        $this->assertGreaterThanOrEqual(1,$result,'copy destination already eists, overwrite');    // Should be 1
 
         // Again to test with overwriting=1
         $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);
+        $this->assertTrue($result,'copy destination does not exists');
 
         $result=dol_delete_file($conf->admin->dir_temp.'/file2.csv');
         print __METHOD__." result=".$result."\n";
-        $this->assertTrue($result);
+        $this->assertTrue($result,'delete file');
 
-        // Again to test no erreor when deleteing a non existing file
+        // Again to test no error when deleteing a non existing file
         $result=dol_delete_file($conf->admin->dir_temp.'/file2.csv');
         print __METHOD__." result=".$result."\n";
-        $this->assertTrue($result);
+        $this->assertTrue($result,'delete file that does not exists');
     }
 
     /**
diff --git a/test/phpunit/HolidayTest.php b/test/phpunit/HolidayTest.php
index f0bb254ce25..42800adc2a2 100644
--- a/test/phpunit/HolidayTest.php
+++ b/test/phpunit/HolidayTest.php
@@ -204,9 +204,9 @@ class HolidayTest extends PHPUnit_Framework_TestCase
     	print __METHOD__." id=".$localobject->id." result=".$result."\n";
     	$this->assertLessThan($result, 0, 'Holiday::update error');
 		
-    	$result=$localobject->update_note_private($localobject->note_private);
+    	$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');
+    	$this->assertLessThan($result, 0, 'Holiday::update_note error');
 		
     	$result=$localobject->update_note_public($localobject->note_public);
     	print __METHOD__." id=".$localobject->id." result=".$result."\n";
diff --git a/test/phpunit/PdfDocTest.php b/test/phpunit/PdfDocTest.php
index dd08b18ca07..c119f1a4ec6 100755
--- a/test/phpunit/PdfDocTest.php
+++ b/test/phpunit/PdfDocTest.php
@@ -132,6 +132,7 @@ class PdfDocTest extends PHPUnit_Framework_TestCase
 		$localobject=new Facture($this->savdb);
 		$localobject->initAsSpecimen();
 		$localobject->lines=array();
+		$localobject->lines[0]=new FactureLigne($this->savdb);
 		$localobject->lines[0]->fk_product=1;
 		$localobject->lines[0]->label='Label 1';
 		$localobject->lines[0]->desc="This is a description with a é accent\n(Country of origin: France)";
diff --git a/test/phpunit/SocieteTest.php b/test/phpunit/SocieteTest.php
index 619bf98dbe7..487f25c8ec9 100755
--- a/test/phpunit/SocieteTest.php
+++ b/test/phpunit/SocieteTest.php
@@ -210,7 +210,7 @@ class SocieteTest extends PHPUnit_Framework_TestCase
     	print __METHOD__." id=".$localobject->id." result=".$result."\n";
     	$this->assertLessThan($result, 0);
 		
-    	$result=$localobject->update_note_private($localobject->note_private);
+    	$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');
 		
@@ -223,7 +223,7 @@ class SocieteTest extends PHPUnit_Framework_TestCase
         print __METHOD__." id=".$localobject->id." result=".$result."\n";
     	$this->assertLessThan($result, 0);
 
-    	$this->assertEquals($localobject->note, $newobject->note);
+    	$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);
-- 
GitLab