Fix substitution of mix html/nohtml
Fix send email reminder for past due date of invoices More PHPUnit test
This commit is contained in:
parent
ce869003cf
commit
526235d020
@ -4912,8 +4912,9 @@ class Facture extends CommonInvoice
|
||||
$nbMailSend = 0;
|
||||
$errorsMsg = array();
|
||||
|
||||
$langs->load("bills");
|
||||
|
||||
if (empty($conf->facture->enabled)) { // Should not happen. If module disabled, cron job should not be visible.
|
||||
$langs->load("bills");
|
||||
$this->output .= $langs->trans('ModuleNotEnabled', $langs->transnoentitiesnoconv("Facture"));
|
||||
return 0;
|
||||
}
|
||||
@ -4930,6 +4931,8 @@ class Facture extends CommonInvoice
|
||||
$formmail = new FormMail($this->db);
|
||||
|
||||
$now = dol_now();
|
||||
$tmpidate = dol_get_first_hour(dol_time_plus_duree($now, $nbdays, 'd'), 'gmt');
|
||||
|
||||
$tmpinvoice = new Facture($this->db);
|
||||
|
||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||
@ -4942,16 +4945,18 @@ class Facture extends CommonInvoice
|
||||
$sql .= ", ".MAIN_DB_PREFIX."c_paiement as cp";
|
||||
}
|
||||
$sql .= " WHERE f.paye = 0";
|
||||
$sql .= " AND f.date_lim_reglement = '".$this->db->idate(dol_get_first_hour(dol_time_plus_duree($now, -1 * $nbdays, 'd'), 'gmt'), 'gmt')."'";
|
||||
$sql .= " AND f.date_lim_reglement = '".$this->db->idate($tmpidate, 'gmt')."'";
|
||||
$sql .= " AND f.entity IN (".getEntity('facture').")";
|
||||
if (!empty($paymentmode) && $paymentmode != 'all') {
|
||||
$sql .= " AND f.fk_mode_reglement = cp.id AND cp.code = '".$this->db->escape($paymentmode)."'";
|
||||
}
|
||||
// TODO Add filter to check there is no payment started
|
||||
$sql .= $this->db->order("date_lim_reglement", "ASC");
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
$tmpidate=$this->db->idate(dol_get_first_hour(dol_time_plus_duree($now, -1 * $nbdays, 'd'), 'gmt'), 'gmt');
|
||||
$this->output .= 'Search unpaid invoices with due date = '.$tmpidate.'<br>';
|
||||
|
||||
$stmpidate = dol_print_date($tmpidate, 'day', 'gmt');
|
||||
$this->output .= $langs->trans("SearchUnpaidInvoicesWithDueDate", $stmpidate).'<br>';
|
||||
|
||||
if ($resql) {
|
||||
while ($obj = $this->db->fetch_object($resql)) {
|
||||
@ -4964,6 +4969,7 @@ class Facture extends CommonInvoice
|
||||
$outputlangs = new Translate('', $conf);
|
||||
if ($tmpinvoice->thirdparty->default_lang) {
|
||||
$outputlangs->setDefaultLang($tmpinvoice->thirdparty->default_lang);
|
||||
$outputlangs->loadLangs(array("main", "bills"));
|
||||
} else {
|
||||
$outputlangs = $langs;
|
||||
}
|
||||
@ -4971,8 +4977,8 @@ class Facture extends CommonInvoice
|
||||
// Select email template
|
||||
$arraymessage = $formmail->getEMailTemplate($this->db, 'facture_send', $user, $outputlangs, (is_numeric($template) ? $template : 0), 1, (is_numeric($template) ? '' : $template));
|
||||
if (is_numeric($arraymessage) && $arraymessage <= 0) {
|
||||
$langs->load("bills");
|
||||
$this->output .= $langs->trans('FailedToFindEmailTemplate', $template);
|
||||
$langs->load("errors");
|
||||
$this->output .= $langs->trans('ErrorFailedToFindEmailTemplate', $template);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -4980,15 +4986,17 @@ class Facture extends CommonInvoice
|
||||
$errormesg = '';
|
||||
|
||||
// Make substitution in email content
|
||||
$substitutionarray = getCommonSubstitutionArray($langs, 0, '', $this);
|
||||
$substitutionarray = getCommonSubstitutionArray($outputlangs, 0, '', $tmpinvoice);
|
||||
|
||||
complete_substitutions_array($substitutionarray, $langs, $this);
|
||||
complete_substitutions_array($substitutionarray, $outputlangs, $tmpinvoice);
|
||||
|
||||
// Content
|
||||
$sendContent = make_substitutions($langs->trans($arraymessage->content), $substitutionarray);
|
||||
$content = $outputlangs->transnoentitiesnoconv($arraymessage->content);
|
||||
|
||||
$sendContent = make_substitutions($content, $substitutionarray, $outputlangs, 1);
|
||||
|
||||
//Topic
|
||||
$sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : html_entity_decode($langs->trans('EventReminder'));
|
||||
$sendTopic = (!empty($arraymessage->topic)) ? $arraymessage->topic : $outputlangs->transnoentitiesnoconv('InformationMessage');
|
||||
|
||||
// Recipient
|
||||
$res = $tmpinvoice->fetch_thirdparty();
|
||||
|
||||
@ -2369,42 +2369,23 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs =
|
||||
*/
|
||||
function dol_getdate($timestamp, $fast = false, $forcetimezone = '')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if (empty($conf->global->MAIN_USE_OLD_FUNCTIONS_FOR_GETDATE)) {
|
||||
//$datetimeobj = new DateTime('@'.$timestamp);
|
||||
$datetimeobj = new DateTime();
|
||||
$datetimeobj->setTimestamp($timestamp); // Use local PHP server timezone
|
||||
if ($forcetimezone) {
|
||||
$datetimeobj->setTimezone(new DateTimeZone($forcetimezone == 'gmt' ? 'UTC' : $forcetimezone)); // (add timezone relative to the date entered)
|
||||
}
|
||||
$arrayinfo = array(
|
||||
'year'=>((int) date_format($datetimeobj, 'Y')),
|
||||
'mon'=>((int) date_format($datetimeobj, 'm')),
|
||||
'mday'=>((int) date_format($datetimeobj, 'd')),
|
||||
'wday'=>((int) date_format($datetimeobj, 'w')),
|
||||
'yday'=>((int) date_format($datetimeobj, 'z')),
|
||||
'hours'=>((int) date_format($datetimeobj, 'H')),
|
||||
'minutes'=>((int) date_format($datetimeobj, 'i')),
|
||||
'seconds'=>((int) date_format($datetimeobj, 's')),
|
||||
'0'=>$timestamp
|
||||
);
|
||||
} else {
|
||||
// PHP getdate is restricted to the years 1901-2038 on Unix and 1970-2038 on Windows
|
||||
$usealternatemethod = false;
|
||||
if ($timestamp <= 0) {
|
||||
$usealternatemethod = true; // <= 1970
|
||||
}
|
||||
if ($timestamp >= 2145913200) {
|
||||
$usealternatemethod = true; // >= 2038
|
||||
}
|
||||
|
||||
if ($usealternatemethod) {
|
||||
$arrayinfo = adodb_getdate($timestamp, $fast);
|
||||
} else {
|
||||
$arrayinfo = getdate($timestamp);
|
||||
}
|
||||
//$datetimeobj = new DateTime('@'.$timestamp);
|
||||
$datetimeobj = new DateTime();
|
||||
$datetimeobj->setTimestamp($timestamp); // Use local PHP server timezone
|
||||
if ($forcetimezone) {
|
||||
$datetimeobj->setTimezone(new DateTimeZone($forcetimezone == 'gmt' ? 'UTC' : $forcetimezone)); // (add timezone relative to the date entered)
|
||||
}
|
||||
$arrayinfo = array(
|
||||
'year'=>((int) date_format($datetimeobj, 'Y')),
|
||||
'mon'=>((int) date_format($datetimeobj, 'm')),
|
||||
'mday'=>((int) date_format($datetimeobj, 'd')),
|
||||
'wday'=>((int) date_format($datetimeobj, 'w')),
|
||||
'yday'=>((int) date_format($datetimeobj, 'z')),
|
||||
'hours'=>((int) date_format($datetimeobj, 'H')),
|
||||
'minutes'=>((int) date_format($datetimeobj, 'i')),
|
||||
'seconds'=>((int) date_format($datetimeobj, 's')),
|
||||
'0'=>$timestamp
|
||||
);
|
||||
|
||||
return $arrayinfo;
|
||||
}
|
||||
@ -6664,6 +6645,8 @@ function dol_textishtml($msg, $option = 0)
|
||||
return true;
|
||||
} elseif (preg_match('/<\/textarea/i', $msg)) {
|
||||
return true;
|
||||
} elseif (preg_match('/<(b|em|i|u)>/i', $msg)) {
|
||||
return true;
|
||||
} elseif (preg_match('/<br/i', $msg)) {
|
||||
return true;
|
||||
}
|
||||
@ -6681,9 +6664,7 @@ function dol_textishtml($msg, $option = 0)
|
||||
return true;
|
||||
} elseif (preg_match('/<(br|div|font|li|p|span|strong|table)>/i', $msg)) {
|
||||
return true;
|
||||
} elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*>/i', $msg)) {
|
||||
return true;
|
||||
} elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*\/>/i', $msg)) {
|
||||
} elseif (preg_match('/<(br|div|font|li|p|span|strong|table)\s+[^<>\/]*\/?>/i', $msg)) {
|
||||
return true;
|
||||
} elseif (preg_match('/<img\s+[^<>]*src[^<>]*>/i', $msg)) {
|
||||
return true; // must accept <img src="http://example.com/aaa.png" />
|
||||
@ -7220,13 +7201,15 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null,
|
||||
* complete_substitutions_array($substitutionarray, $langs, $thirdparty);
|
||||
* $mesg = make_substitutions($mesg, $substitutionarray, $langs);
|
||||
*
|
||||
* @param string $text Source string in which we must do substitution
|
||||
* @param array $substitutionarray Array with key->val to substitute. Example: array('__MYKEY__' => 'MyVal', ...)
|
||||
* @param Translate $outputlangs Output language
|
||||
* @return string Output string after substitutions
|
||||
* @param string $text Source string in which we must do substitution
|
||||
* @param array $substitutionarray Array with key->val to substitute. Example: array('__MYKEY__' => 'MyVal', ...)
|
||||
* @param Translate $outputlangs Output language
|
||||
* @param int $converttextinhtmlifnecessary 0=Convert only value into HTML if text is already in HTML
|
||||
* 1=Will also convert initial $text into HTML if we try to insert one value that is HTML
|
||||
* @return string Output string after substitutions
|
||||
* @see complete_substitutions_array(), getCommonSubstitutionArray()
|
||||
*/
|
||||
function make_substitutions($text, $substitutionarray, $outputlangs = null)
|
||||
function make_substitutions($text, $substitutionarray, $outputlangs = null, $converttextinhtmlifnecessary = 0)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
@ -7238,22 +7221,41 @@ function make_substitutions($text, $substitutionarray, $outputlangs = null)
|
||||
$outputlangs = $langs;
|
||||
}
|
||||
|
||||
// Is initial text HTML or simple text ?
|
||||
$msgishtml = 0;
|
||||
if (dol_textishtml($text, 1)) {
|
||||
$msgishtml = 1;
|
||||
}
|
||||
|
||||
// Make substitution for language keys: __(AnyTranslationKey)__ or __(AnyTranslationKey|langfile)__
|
||||
if (is_object($outputlangs)) {
|
||||
$reg = array();
|
||||
while (preg_match('/__\(([^\)]+)\)__/', $text, $reg)) {
|
||||
$msgishtml = 0;
|
||||
if (dol_textishtml($text, 1)) {
|
||||
$msgishtml = 1;
|
||||
}
|
||||
|
||||
// If key is __(TranslationKey|langfile)__, then force load of langfile.lang
|
||||
$tmp = explode('|', $reg[1]);
|
||||
if (!empty($tmp[1])) {
|
||||
$outputlangs->load($tmp[1]);
|
||||
}
|
||||
|
||||
$text = preg_replace('/__\('.preg_quote($reg[1], '/').'\)__/', $msgishtml ?dol_htmlentitiesbr($outputlangs->transnoentitiesnoconv($reg[1])) : $outputlangs->transnoentitiesnoconv($reg[1]), $text);
|
||||
$value = $outputlangs->transnoentitiesnoconv($reg[1]);
|
||||
|
||||
if (empty($converttextinhtmlifnecessary)) {
|
||||
// convert $newval into HTML is necessary
|
||||
$text = preg_replace('/__\('.preg_quote($reg[1], '/').'\)__/', $msgishtml ? dol_htmlentitiesbr($value) : $value, $text);
|
||||
} else {
|
||||
if (! $msgishtml) {
|
||||
$valueishtml = dol_textishtml($value, 1);
|
||||
|
||||
if ($valueishtml) {
|
||||
$text = dol_htmlentitiesbr($text);
|
||||
$msgishtml = 1;
|
||||
}
|
||||
} else {
|
||||
$value = dol_nl2br("$value");
|
||||
}
|
||||
|
||||
$text = preg_replace('/__\('.preg_quote($reg[1], '/').'\)__/', $value, $text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -7261,18 +7263,30 @@ function make_substitutions($text, $substitutionarray, $outputlangs = null)
|
||||
// Must be after the substitution of translation, so if the text of translation contains a string __[xxx]__, it is also converted.
|
||||
$reg = array();
|
||||
while (preg_match('/__\[([^\]]+)\]__/', $text, $reg)) {
|
||||
$msgishtml = 0;
|
||||
if (dol_textishtml($text, 1)) {
|
||||
$msgishtml = 1;
|
||||
}
|
||||
|
||||
$keyfound = $reg[1];
|
||||
if (isASecretKey($keyfound)) {
|
||||
$newval = '*****forbidden*****';
|
||||
$value = '*****forbidden*****';
|
||||
} else {
|
||||
$newval = empty($conf->global->$keyfound) ? '' : $conf->global->$keyfound;
|
||||
$value = empty($conf->global->$keyfound) ? '' : $conf->global->$keyfound;
|
||||
}
|
||||
|
||||
if (empty($converttextinhtmlifnecessary)) {
|
||||
// convert $newval into HTML is necessary
|
||||
$text = preg_replace('/__\['.preg_quote($keyfound, '/').'\]__/', $msgishtml ? dol_htmlentitiesbr($value) : $value, $text);
|
||||
} else {
|
||||
if (! $msgishtml) {
|
||||
$valueishtml = dol_textishtml($value, 1);
|
||||
|
||||
if ($valueishtml) {
|
||||
$text = dol_htmlentitiesbr($text);
|
||||
$msgishtml = 1;
|
||||
}
|
||||
} else {
|
||||
$value = dol_nl2br("$value");
|
||||
}
|
||||
|
||||
$text = preg_replace('/__\['.preg_quote($keyfound, '/').'\]__/', $value, $text);
|
||||
}
|
||||
$text = preg_replace('/__\['.preg_quote($keyfound, '/').'\]__/', $msgishtml ?dol_htmlentitiesbr($newval) : $newval, $text);
|
||||
}
|
||||
|
||||
// Make substitition for array $substitutionarray
|
||||
@ -7285,7 +7299,22 @@ function make_substitutions($text, $substitutionarray, $outputlangs = null)
|
||||
$value = ''; // Protection
|
||||
}
|
||||
|
||||
$text = str_replace("$key", "$value", $text); // We must keep the " to work when value is 123.5 for example
|
||||
if (empty($converttextinhtmlifnecessary)) {
|
||||
$text = str_replace("$key", "$value", $text); // We must keep the " to work when value is 123.5 for example
|
||||
} else {
|
||||
if (! $msgishtml) {
|
||||
$valueishtml = dol_textishtml($value, 1);
|
||||
|
||||
if ($valueishtml) {
|
||||
$text = dol_htmlentitiesbr($text);
|
||||
$msgishtml = 1;
|
||||
}
|
||||
} else {
|
||||
$value = dol_nl2br("$value");
|
||||
}
|
||||
|
||||
$text = str_replace("$key", "$value", $text); // We must keep the " to work when value is 123.5 for example
|
||||
}
|
||||
}
|
||||
|
||||
return $text;
|
||||
@ -7309,18 +7338,7 @@ function complete_substitutions_array(&$substitutionarray, $outputlangs, $object
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||
|
||||
// Add a substitution key for each extrafields, using key __EXTRA_XXX__
|
||||
// TODO Remove this. Already available into the getCommonSubstitutionArray used to build the substitution array.
|
||||
/*if (is_object($object) && is_array($object->array_options))
|
||||
{
|
||||
foreach($object->array_options as $key => $val)
|
||||
{
|
||||
$keyshort=preg_replace('/^(options|extra)_/','',$key);
|
||||
$substitutionarray['__EXTRAFIELD_'.$keyshort.'__']=$val;
|
||||
// For backward compatibiliy
|
||||
$substitutionarray['%EXTRA_'.$keyshort.'%']=$val;
|
||||
}
|
||||
}*/
|
||||
// Note: substitution key for each extrafields, using key __EXTRA_XXX__ is already available into the getCommonSubstitutionArray used to build the substitution array.
|
||||
|
||||
// Check if there is external substitution to do, requested by plugins
|
||||
$dirsubstitutions = array_merge(array(), (array) $conf->modules_parts['substitutions']);
|
||||
|
||||
@ -121,7 +121,7 @@ class modFacture extends DolibarrModules
|
||||
$datestart = dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
|
||||
$this->cronjobs = array(
|
||||
0=>array('label'=>'RecurringInvoices', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture-rec.class.php', 'objectname'=>'FactureRec', 'method'=>'createRecurringInvoices', 'parameters'=>'', 'comment'=>'Generate recurring invoices', 'frequency'=>1, 'unitfrequency'=>3600 * 24, 'priority'=>50, 'status'=>1, 'test'=>'$conf->facture->enabled', 'datestart'=>$datestart),
|
||||
1=>array('label'=>'SendEmailsRemindersOnInvoiceDueDate', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture.class.php', 'objectname'=>'Facture', 'method'=>'sendEmailsRemindersOnInvoiceDueDate', 'parameters'=>"10,all,EmailTemplateCode", 'comment'=>'Send an emails when the unpaid invoices reach a due date + n days. First param is the offset n of days, second parameter is "all" or a payment mode code, last paramater is the code of email template to use (an email template with EmailTemplateCode must exists. the version in the language of the thirdparty will be used in priority).', 'frequency'=>1, 'unitfrequency'=>3600 * 24, 'priority'=>50, 'status'=>0, 'test'=>'$conf->facture->enabled', 'datestart'=>$datestart),
|
||||
1=>array('label'=>'SendEmailsRemindersOnInvoiceDueDate', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture.class.php', 'objectname'=>'Facture', 'method'=>'sendEmailsRemindersOnInvoiceDueDate', 'parameters'=>"10,all,EmailTemplateCode", 'comment'=>'Send an emails when the unpaid invoices reach a due date + n days = today. First param is the offset n of days, second parameter is "all" or a payment mode code, last paramater is the code of email template to use (an email template with EmailTemplateCode must exists. the version in the language of the thirdparty will be used in priority).', 'frequency'=>1, 'unitfrequency'=>3600 * 24, 'priority'=>50, 'status'=>0, 'test'=>'$conf->facture->enabled', 'datestart'=>$datestart),
|
||||
);
|
||||
|
||||
// Permissions
|
||||
|
||||
@ -589,3 +589,4 @@ FacParentLine=Invoice Line Parent
|
||||
SituationTotalRayToRest=Remainder to pay without taxe
|
||||
PDFSituationTitle=Situation n° %d
|
||||
SituationTotalProgress=Total progress %d %%
|
||||
SearchUnpaidInvoicesWithDueDate=Search unpaid invoices with a due date = %s
|
||||
@ -262,6 +262,7 @@ ErrorDateIsInFuture=Error, the date can't be in the future
|
||||
ErrorAnAmountWithoutTaxIsRequired=Error, amount is mandatory
|
||||
ErrorAPercentIsRequired=Error, please fill in the percentage correctly
|
||||
ErrorYouMustFirstSetupYourChartOfAccount=You must first setup your chart of account
|
||||
ErrorFailedToFindEmailTemplate=Failed to find template with code name %s
|
||||
|
||||
# Warnings
|
||||
WarningParamUploadMaxFileSizeHigherThanPostMaxSize=Your PHP parameter upload_max_filesize (%s) is higher than PHP parameter post_max_size (%s). This is not a consistent setup.
|
||||
|
||||
@ -4421,7 +4421,12 @@ div.backgreypublicpayment { background-color: #f0f0f0; padding: 20px; border-bot
|
||||
opacity: 0.3;
|
||||
}
|
||||
#dolpaymenttable { min-width: 320px; font-size: 16px; } /* Width must have min to make stripe input area visible. Lower than 320 makes input area crazy for credit card that need zip code */
|
||||
#tablepublicpayment { border: 1px solid #CCCCCC !important; width: 100%; padding: 20px; }
|
||||
#tablepublicpayment {
|
||||
border: 1px solid #CCCCCC !important;
|
||||
width: 100%;
|
||||
padding: 20px;
|
||||
margin-bottom: 25px;
|
||||
}
|
||||
#tablepublicpayment .CTableRow1 { background-color: #F0F0F0 !important; }
|
||||
#tablepublicpayment tr.liste_total { border-bottom: 1px solid #CCCCCC !important; }
|
||||
#tablepublicpayment tr.liste_total td { border-top: none; }
|
||||
|
||||
@ -61,6 +61,11 @@ if (! defined("NOLOGIN")) {
|
||||
define("NOLOGIN", '1'); // If this page is public (can be called outside logged session)
|
||||
}
|
||||
|
||||
print "\n".$langs->trans("CurrentTimeZone").' : '.getServerTimeZoneString();
|
||||
print "\n".$langs->trans("CurrentHour").' : '.dol_print_date(dol_now('gmt'), 'dayhour', 'tzserver');
|
||||
print "\n";
|
||||
|
||||
|
||||
/**
|
||||
* Class for PHPUnit tests
|
||||
*
|
||||
@ -1376,16 +1381,16 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
|
||||
|
||||
$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']);
|
||||
$tmp=dol_getdate(24*60*60+1, false, 'UTC'); // 2/1/1970 and 1 second = friday
|
||||
$this->assertEquals(5, $tmp['wday'], 'Bad value of day in week');
|
||||
|
||||
$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(1, false, 'UTC'); // 1/1/1970 and 1 second = thirday
|
||||
$this->assertEquals(4, $tmp['wday'], 'Bad value of day in week');
|
||||
|
||||
$tmp=dol_getdate(24*60*60+1); // 2/1/1970 and 1 second = friday
|
||||
$this->assertEquals(5, $tmp['wday']);
|
||||
$tmp=dol_getdate(24*60*60+1, false, 'UTC'); // 2/1/1970 and 1 second = friday
|
||||
$this->assertEquals(5, $tmp['wday'], 'Bad value of day in week');
|
||||
|
||||
$tmp=dol_getdate(1, false, "Europe/Paris"); // 1/1/1970 and 1 second = thirday
|
||||
$this->assertEquals(1970, $tmp['year']);
|
||||
@ -1417,38 +1422,36 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
|
||||
$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
|
||||
$tmp=dol_getdate(1, false, 'UTC'); // 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(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
|
||||
$tmp=dol_getdate(15638401, false, 'UTC'); // 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(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
|
||||
$tmp=dol_getdate(1593561601, false, 'UTC'); // 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(2, $tmp['hours']); // There is a daylight, so we are GMT+2
|
||||
$this->assertEquals(0, $tmp['minutes']);
|
||||
$this->assertEquals(1, $tmp['seconds']);
|
||||
|
||||
@ -1463,13 +1466,33 @@ class FunctionsLibTest extends PHPUnit\Framework\TestCase
|
||||
*/
|
||||
public function testMakeSubstitutions()
|
||||
{
|
||||
global $conf, $langs;
|
||||
global $conf, $langs, $mysoc;
|
||||
$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__';
|
||||
// Try simple replacement
|
||||
$substit = array("__AAA__"=>'Not used', "__BBB__"=>'Not used', "__CCC__"=>"C replaced", "DDD"=>"D replaced");
|
||||
$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);
|
||||
$this->assertEquals($newstring, 'This is a string with eldy and ltr and __C replaced__');
|
||||
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'));
|
||||
|
||||
// Try mix HTML not HTML, no change on initial text
|
||||
$substit = array("__NOHTML__"=>'No html', "__HTML__"=>'<b>HTML</b>');
|
||||
|
||||
$chaine = "This is a text with\nNew line\nThen\n__NOHTML__\nThen\n__HTML__";
|
||||
$newstring = make_substitutions($chaine, $substit, $langs);
|
||||
print __METHOD__." ".$newstring."\n";
|
||||
$this->assertEquals($newstring, "This is a text with\nNew line\nThen\nNo html\nThen\n<b>HTML</b>", 'Test on make_substitutions with conversion of inserted values only');
|
||||
|
||||
// Try mix HTML not HTML, accept to change initial text
|
||||
$substit = array("__NOHTML__"=>'No html', "__HTML__"=>'<b>HTML</b>');
|
||||
|
||||
$chaine = "This is a text with\nNew line\nThen\n__NOHTML__\nThen\n__HTML__";
|
||||
$newstring = make_substitutions($chaine, $substit, $langs, 1);
|
||||
print __METHOD__." ".$newstring."\n";
|
||||
$this->assertEquals($newstring, "This is a text with<br>\nNew line<br>\nThen<br>\nNo html<br>\nThen<br>\n<b>HTML</b>", 'Test on make_substitutions with full conversion of text accepted');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user