From e7c405425cf216fbb6fc85da24dad577a4762bf6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 19 Dec 2023 14:03:17 +0100 Subject: [PATCH] Debug v19 --- htdocs/core/lib/functions.lib.php | 8 ++++---- htdocs/master.inc.php | 1 + test/phpunit/FunctionsLibTest.php | 15 ++++++++++----- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index f270ca3743a..e3f3e0c87a2 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1220,10 +1220,10 @@ function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0) foreach ($conf->file->dol_document_root as $key => $dirroot) { // ex: array(["main"]=>"/home/main/htdocs", ["alt0"]=>"/home/dirmod/htdocs", ...) if ($key == 'main') { if ($type == 3) { - global $dolibarr_main_url_root; + /*global $dolibarr_main_url_root;*/ // Define $urlwithroot - $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($conf->file->dol_main_url_root)); $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current @@ -1244,10 +1244,10 @@ function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0) $res = (preg_match('/^http/i', $conf->file->dol_url_root[$key]) ? '' : DOL_MAIN_URL_ROOT).$conf->file->dol_url_root[$key].'/'.$path; } if ($type == 3) { - global $dolibarr_main_url_root; + /*global $dolibarr_main_url_root;*/ // Define $urlwithroot - $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($conf->file->dol_main_url_root)); $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index a2e5d7fd27b..9a07285c7f1 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -82,6 +82,7 @@ $conf->file->main_authentication = empty($dolibarr_main_authentication) ? 'dolib $conf->file->main_force_https = empty($dolibarr_main_force_https) ? '' : $dolibarr_main_force_https; // Force https $conf->file->strict_mode = empty($dolibarr_strict_mode) ? '' : $dolibarr_strict_mode; // Force php strict mode (for debug) $conf->file->instance_unique_id = empty($dolibarr_main_instance_unique_id) ? (empty($dolibarr_main_cookie_cryptkey) ? '' : $dolibarr_main_cookie_cryptkey) : $dolibarr_main_instance_unique_id; // Unique id of instance +$conf->file->dol_main_url_root = $dolibarr_main_url_root; $conf->file->dol_document_root = array('main' => (string) DOL_DOCUMENT_ROOT); // Define array of document root directories ('/home/htdocs') $conf->file->dol_url_root = array('main' => (string) DOL_URL_ROOT); // Define array of url root path ('' or '/dolibarr') if (!empty($dolibarr_main_document_root_alt)) { diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 596dee81378..6c8c7490764 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -25,7 +25,7 @@ * \remarks To run this script as CLI: phpunit filename.php */ -global $conf,$user,$langs,$db; +global $conf,$user,$langs,$db,$mysoc; //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'; @@ -199,6 +199,11 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase $sql = forgeSQLFromUniversalSearchCriteria($filter); $this->assertEquals(" AND ((t.ref LIKE 'SO-%') or (t.date_creation < '20160101') or (t.date_creation < 0) or (t.nature IS NULL))", $sql); + $filter = 't.fk_soc IN (SELECT rowid FROM llx_societe WHERE fournisseur = 1)'; + $sql = forgeSQLFromUniversalSearchCriteria($filter); + $this->assertEquals(" xxx", $sql); + + return true; } @@ -388,11 +393,11 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase */ $result=dol_buildpath('/google/oauth2callback.php', 2); - print __METHOD__." result=".$result."\n"; + print __METHOD__." dol_buildpath result=".$result."\n"; $this->assertStringStartsWith('http', $result); $result=dol_buildpath('/google/oauth2callback.php', 3); - print __METHOD__." result=".$result."\n"; + print __METHOD__." dol_buildpath result=".$result."\n"; $this->assertStringStartsWith('http', $result); } @@ -1634,13 +1639,13 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase $langs->load("main"); // Try simple replacement - $substit = array("__AAA__"=>'Not used', "__BBB__"=>'Not used', "__CCC__"=>"C replaced", "DDD"=>"D replaced"); + $substit = array("__AAA__"=>'Not used', "__BBB__"=>'Not used', "__CCC__"=>"C instead", "DDD"=>"D instead"); $substit += getCommonSubstitutionArray($langs); $chaine = 'This is a string with theme constant __[MAIN_THEME]__ and __(DIRECTION)__ and __CCC__ and DDD and __MYCOMPANY_NAME__ and __YEAR__'; $newstring = make_substitutions($chaine, $substit); print __METHOD__." ".$newstring."\n"; - $this->assertEquals($newstring, 'This is a string with theme constant eldy and ltr and C replaced and D replaced and '.$mysoc->name.' and '.dol_print_date(dol_now(), '%Y', 'gmt')); + $this->assertEquals($newstring, 'This is a string with theme constant eldy and ltr and C instead and D instead and '.$mysoc->name.' and '.dol_print_date(dol_now(), '%Y', 'gmt')); // Try mix HTML not HTML, no change on initial text $substit = array("__NOHTML__"=>'No html', "__HTML__"=>'HTML');