From 0772222900ef5c690df8ffb0d396e4436fd94aac Mon Sep 17 00:00:00 2001 From: "Laurent Destailleur (aka Eldy)" Date: Thu, 6 Feb 2025 12:04:41 +0100 Subject: [PATCH] QUAL Add get_substitutionarray_each_var_object in phpunit --- htdocs/commande/class/commande.class.php | 2 +- htdocs/core/class/commonobject.class.php | 2 +- .../doc/doc_generic_order_odt.modules.php | 3 ++ test/phpunit/CommonClassTest.class.php | 3 ++ test/phpunit/ODFTest.php | 38 +++++++++++++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 28c11b0b566..c8c3c37ba53 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -4073,7 +4073,7 @@ class Commande extends CommonOrder */ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) { - global $conf, $langs; + global $langs; $langs->load("orders"); $outputlangs->load("products"); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index fb52b9b8fc9..3758c0c3d6c 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -5801,7 +5801,7 @@ abstract class CommonObject */ protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams = null) { - global $conf, $langs, $user, $hookmanager, $action; + global $conf, $langs, $hookmanager, $action; $srctemplatepath = ''; diff --git a/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php b/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php index 41ff51ed49d..5ee13332781 100644 --- a/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php +++ b/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php @@ -38,6 +38,9 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/doc.lib.php'; /** * Class to build documents using ODF templates generator + * + * This files is called by the "$obj = new $classname($this->db);" found into + * the commobject.class.php->commonGenerateDocument() called by $object->generateDocument() */ class doc_generic_order_odt extends ModelePDFCommandes { diff --git a/test/phpunit/CommonClassTest.class.php b/test/phpunit/CommonClassTest.class.php index 4f75b562dcd..7e71bfda436 100644 --- a/test/phpunit/CommonClassTest.class.php +++ b/test/phpunit/CommonClassTest.class.php @@ -37,6 +37,9 @@ global $conf,$user,$langs,$db; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; +// Delete the log file to avoid problem of writing permission on it +@unlink(DOL_DATA_ROOT.'/dolibarr.log'); + if (empty($user->id)) { print "Load permissions for admin user nb 1\n"; diff --git a/test/phpunit/ODFTest.php b/test/phpunit/ODFTest.php index 8700f0a52a6..441469edd48 100644 --- a/test/phpunit/ODFTest.php +++ b/test/phpunit/ODFTest.php @@ -28,6 +28,7 @@ global $conf,$user,$langs,$db; //define('TEST_DB_FORCE_TYPE','mysql'); // This is to force using mysql driver //require_once 'PHPUnit/Autoload.php'; require_once dirname(__FILE__).'/../../htdocs/master.inc.php'; +require_once dirname(__FILE__).'/../../htdocs/commande/class/commande.class.php'; require_once dirname(__FILE__).'/../../htdocs/includes/odtphp/odf.php'; require_once dirname(__FILE__).'/CommonClassTest.class.php'; @@ -50,6 +51,43 @@ $langs->load("main"); */ class ODFTest extends CommonClassTest { + /** + * test ODF convertVarToOdf + * + * @return int + */ + public function testGetSubstitutionarrayEachVarObject() + { + global $conf,$user,$langs,$db; + $conf = $this->savconf; + $user = $this->savuser; + $langs = $this->savlangs; + $db = $this->savdb; + + $localobject = new Commande($db); + $localobject->fetch(1); + + $localobject->lines[0]->date_start = dol_now(); + $localobject->lines[0]->date_end = dol_now() + 84600; + + $result = $localobject->generateDocument('generic_order_odt', $langs); + print __METHOD__." result=".$result."\n"; + + $this->assertEquals(1, $result); + + + $filefound = DOL_DOCUMENT_ROOT.'/core/modules/commande/doc/doc_generic_order_odt.modules.php'; + require_once $filefound; + + $objdoc = new doc_generic_order_odt($db); + + $result = $objdoc->get_substitutionarray_each_var_object($localobject, $langs); + + $this->assertEquals(1, $result['object_id']); + } + + + /** * test ODF convertVarToOdf *