diff --git a/CRM/Utils/String.php b/CRM/Utils/String.php index 3400263aa06b..1cb1e8cbc28d 100644 --- a/CRM/Utils/String.php +++ b/CRM/Utils/String.php @@ -1038,7 +1038,9 @@ public static function parseOneOffStringThroughSmarty($templateString) { $cachingValue = $smarty->caching; $smarty->caching = 0; $smarty->assign('smartySingleUseString', $templateString); - $templateString = $smarty->fetch('string:{eval var=$smartySingleUseString}'); + // Do not escape the smartySingleUseString as that is our smarty template + // and is likely to contain html. + $templateString = (string) $smarty->fetch('string:{eval var=$smartySingleUseString|smarty:nodefaults}'); $smarty->caching = $cachingValue; $smarty->assign('smartySingleUseString', NULL); return $templateString; diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index c67f327ce38e..bf0ca8949bb2 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -2733,7 +2733,7 @@ protected function swapMessageTemplateForInput(string $templateName, string $inp * @param string $templateName * @param string $type */ - protected function swapMessageTemplateForTestTemplate($templateName = 'contribution_online_receipt', $type = 'html') { + protected function swapMessageTemplateForTestTemplate($templateName = 'contribution_online_receipt', $type = 'html'): void { $testTemplate = file_get_contents(__DIR__ . '/../../templates/message_templates/' . $templateName . '_' . $type . '.tpl'); CRM_Core_DAO::executeQuery( "UPDATE civicrm_msg_template diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 0fc48fdca917..113083f59454 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -2082,7 +2082,7 @@ public function testCompleteTransaction() { /** * Test completing a transaction via the API with a non-USD transaction. */ - public function testCompleteTransactionEuro() { + public function testCompleteTransactionEuro(): void { $mut = new CiviMailUtils($this, TRUE); $this->swapMessageTemplateForTestTemplate(); $this->createLoggedInUser(); diff --git a/tests/templates/message_templates/contribution_online_receipt_html.tpl b/tests/templates/message_templates/contribution_online_receipt_html.tpl index 8f98967aec4d..eba77796a5d3 100644 --- a/tests/templates/message_templates/contribution_online_receipt_html.tpl +++ b/tests/templates/message_templates/contribution_online_receipt_html.tpl @@ -14,19 +14,19 @@ contactID:::{$contactID} contributionID:::{$contributionID} amount:::{$amount} - {if isset($amount_level)} + {if !empty($amount_level)} amount_level:::{$amount_level} {/if} - {if isset($pay_later_receipt)} + {if !empty($pay_later_receipt)} pay_later_receipt:::{$pay_later_receipt} {/if} - {if isset($headerstyle)} + {if !empty($headerstyle)} headerStyle:::{$headerStyle} {/if} - {if isset($valueStyle)} + {if !empty($valueStyle)} valueStyle:::{$valueStyle} {/if} - {if isset($labelStyle)} + {if !empty($labelStyle)} labelStyle:::{$labelStyle} {/if} priceSetID:::{$priceSetID} @@ -38,31 +38,31 @@ getTaxDetails:::{$getTaxDetails} totalTaxAmount:::{$totalTaxAmount} {/if} - {if isset($is_monetary)} + {if !empty($is_monetary)} is_monetary:::{$is_monetary} {/if} - {if isset($isShare)} + {if !empty($isShare)} isShare:::{$isShare} {/if} honor_block_is_active:::{$honor_block_is_active} {if $honor_block_is_active} soft_credit_type:::{$soft_credit_type} {/if} - {if isset($is_recur)} + {if !empty($is_recur)} is_recur:::{$is_recur} {/if} - {if isset($trxn_id)} + {if !empty($trxn_id)} trxn_id:::{$trxn_id} {/if} - {if isset($cancelSubscriptionUrl)} + {if !empty($cancelSubscriptionUrl)} cancelSubscriptionUrl:::{$cancelSubscriptionUrl} updateSubscriptionBillingUrl:::{$updateSubscriptionBillingUrl} updateSubscriptionUrl:::{$updateSubscriptionUrl} {/if} - {if isset($priceset)} + {if !empty($priceset)} priceset:::{$priceset} {/if} - {if isset($taxTerm)} + {if !empty($taxTerm)} taxTerm:::{$taxTerm} {/if} {if !empty($pcpBlock)} @@ -71,56 +71,56 @@ pcp_roll_nickname:::{$pcp_roll_nickname} pcp_personal_note:::{$pcp_personal_note} {/if} - {if isset($onBehalfProfile_grouptitle)} + {if !empty($onBehalfProfile_grouptitle)} onBehalfProfile_grouptitle:::{$onBehalfProfile_grouptitle} {/if} email:::{$email} - {if isset($contributionPageId)} + {if !empty($contributionPageId)} contributionPageId:::{$contributionPageId} title:::{$title} {/if} - {if isset($isBillingAddressRequiredForPayLater)} + {if !empty($isBillingAddressRequiredForPayLater)} isBillingAddressRequiredForPayLater:::{$isBillingAddressRequiredForPayLater} {/if} - {if isset($billingName)} + {if !empty($billingName)} billingName:::{$billingName} address:::{$address} {/if} - {if isset($credit_card_type)} + {if !empty($credit_card_type)} credit_card_type:::{$credit_card_type} credit_card_number:::{$credit_card_number} credit_card_exp_date:::{$credit_card_exp_date} {/if} - {if isset($selectPremium)} + {if !empty($selectPremium)} selectPremium:::{$selectPremium} product_name:::{$product_name} option:::{$option} sku:::{$sku} {/if} - {if isset($start_date)} + {if !empty($start_date)} start_date:::{$start_date} end_date:::{$end_date} {/if} - {if isset($is_deductible)} + {if !empty($is_deductible)} is_deductible:::{$is_deductible} {/if} - {if isset($contact_email)} + {if !empty($contact_email)} contact_email:::{$contact_email} {/if} - {if isset($contact_phone)} + {if !empty($contact_phone)} contact_phone:::{$contact_phone} {/if} - {if isset($price)} + {if !empty($price)} price:::{$price} {/if} - {if isset($customPre_grouptitle)} + {if !empty($customPre_grouptitle)} customPre_grouptitle:::{$customPre_grouptitle} {/if} - {if isset($customPost_grouptitle)} + {if !empty($customPost_grouptitle)} customPost_grouptitle:::{$customPost_grouptitle} {/if} contributionStatus:::{$contributionStatus} - {if isset($lineItem)} + {if !empty($lineItem)} {foreach from=$lineItem item=value key=priceset} {foreach from=$value item=line} line.html_type:::{$line.html_type} @@ -129,7 +129,7 @@ line.description:::{$line.description} line.qty:::{$line.qty} line.unit_price:::{$line.unit_price} - {if isset($line.tax_rate)} + {if !empty($line.tax_rate)} line.tax_rate:::{$line.tax_rate} line.tax_amount:::{$line.tax_amount} {/if} diff --git a/xml/templates/message_templates/contribution_invoice_receipt_html.tpl b/xml/templates/message_templates/contribution_invoice_receipt_html.tpl index 05ebb636b7a5..712a447a0326 100644 --- a/xml/templates/message_templates/contribution_invoice_receipt_html.tpl +++ b/xml/templates/message_templates/contribution_invoice_receipt_html.tpl @@ -75,7 +75,7 @@ {ts}Description{/ts} {ts}Quantity{/ts} {ts}Unit Price{/ts} - {if isset($taxTerm)}{$taxTerm}{/if} + {$taxTerm} {ts 1=$currency}Amount %1{/ts} {foreach from=$lineItem item=value key=priceset name=taxpricevalue} @@ -99,7 +99,7 @@ {if $value.tax_amount != ''} {if isset($value.tax_rate)}{$value.tax_rate}%{/if} {else} - {if isset($taxTerm)}{ts 1=$taxTerm}-{/ts}{/if} + {if $taxTerm}{ts 1=$taxTerm}-{/ts}{/if} {/if} {$value.subTotal|crmMoney:$currency} @@ -114,10 +114,10 @@ {if $priceset} - {if isset($taxTerm)}{ts 1=$taxTerm 2=$priceset}TOTAL %1 %2%{/ts}{/if} + {if $taxTerm}{ts 1=$taxTerm 2=$priceset}TOTAL %1 %2%{/ts}{/if} {$value|crmMoney:$currency} {elseif $priceset == 0} - {if isset($taxTerm)}{ts 1=$taxTerm}TOTAL %1{/ts}{/if} + {if $taxTerm}{ts 1=$taxTerm}TOTAL %1{/ts}{/if} {$value|crmMoney:$currency} {/if} @@ -302,7 +302,7 @@ {ts}Description{/ts} {ts}Quantity{/ts} {ts}Unit Price{/ts} - {if isset($taxTerm)}{$taxTerm}{/if} + {$taxTerm} {ts 1=$currency}Amount %1{/ts} {foreach from=$lineItem item=value key=priceset name=pricevalue} @@ -329,7 +329,7 @@ {if $value.tax_amount != ''} {if isset($value.tax_rate)}{$value.tax_rate}%{/if} {else} - {if isset($taxTerm)}{ts 1=$taxTerm}No %1{/ts}{/if} + {if $taxTerm}{ts 1=$taxTerm}No %1{/ts}{/if} {/if} {$value.subTotal|crmMoney:$currency} @@ -345,10 +345,10 @@ {if $priceset} - {if isset($taxTerm)}{ts 1=$taxTerm 2=$priceset}TOTAL %1 %2%{/ts}{/if} + {if $taxTerm}{ts 1=$taxTerm 2=$priceset}TOTAL %1 %2%{/ts}{/if} {$value|crmMoney:$currency} {elseif $priceset == 0} - {if isset($taxTerm)}{ts 1=$taxTerm}TOTAL NO %1{/ts}{/if} + {if $taxTerm}{ts 1=$taxTerm}TOTAL NO %1{/ts}{/if} {$value|crmMoney:$currency} {/if} diff --git a/xml/templates/message_templates/contribution_offline_receipt_html.tpl b/xml/templates/message_templates/contribution_offline_receipt_html.tpl index e74a4ab6228c..331e115591eb 100644 --- a/xml/templates/message_templates/contribution_offline_receipt_html.tpl +++ b/xml/templates/message_templates/contribution_offline_receipt_html.tpl @@ -121,10 +121,10 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset || $priceset == 0 || $value != ''} -  {if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}% +  {$taxTerm} {$priceset|string_format:"%.2f"}%  {$value|crmMoney:$currency} {else} -  {ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if} +  {ts}No{/ts} {$taxTerm}  {$value|crmMoney:$currency} {/if} diff --git a/xml/templates/message_templates/contribution_offline_receipt_text.tpl b/xml/templates/message_templates/contribution_offline_receipt_text.tpl index 8e8f878f9645..75091e234d95 100644 --- a/xml/templates/message_templates/contribution_offline_receipt_text.tpl +++ b/xml/templates/message_templates/contribution_offline_receipt_text.tpl @@ -37,9 +37,9 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset || $priceset == 0 || $value != ''} -{if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}% : {$value|crmMoney:$currency} +{$taxTerm} {$priceset|string_format:"%.2f"}% : {$value|crmMoney:$currency} {else} -{ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if} : {$value|crmMoney:$currency} +{ts}No{/ts} {$taxTerm} : {$value|crmMoney:$currency} {/if} {/foreach} {/if} diff --git a/xml/templates/message_templates/contribution_online_receipt_html.tpl b/xml/templates/message_templates/contribution_online_receipt_html.tpl index 363aef9fc919..a05185bd7cdc 100644 --- a/xml/templates/message_templates/contribution_online_receipt_html.tpl +++ b/xml/templates/message_templates/contribution_online_receipt_html.tpl @@ -109,10 +109,10 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset || $priceset == 0} -  {if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}% +  {$taxTerm} {$priceset|string_format:"%.2f"}%  {$value|crmMoney:$currency} {else} -  {ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if} +  {ts}No{/ts} {$taxTerm}  {$value|crmMoney:$currency} {/if} diff --git a/xml/templates/message_templates/contribution_online_receipt_text.tpl b/xml/templates/message_templates/contribution_online_receipt_text.tpl index 87d01e7120fb..5782ea423e15 100644 --- a/xml/templates/message_templates/contribution_online_receipt_text.tpl +++ b/xml/templates/message_templates/contribution_online_receipt_text.tpl @@ -5,7 +5,7 @@ {if $is_pay_later} =========================================================== -{if isset($pay_later_receipt)}{$pay_later_receipt}{/if} +{$pay_later_receipt} =========================================================== {/if} @@ -38,9 +38,9 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset || $priceset == 0} -{if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}%: {$value|crmMoney:$currency} +{$taxTerm} {$priceset|string_format:"%.2f"}%: {$value|crmMoney:$currency} {else} -{ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if}: {$value|crmMoney:$currency} +{ts}No{/ts} {$taxTerm}: {$value|crmMoney:$currency} {/if} {/foreach} {/if} diff --git a/xml/templates/message_templates/event_offline_receipt_html.tpl b/xml/templates/message_templates/event_offline_receipt_html.tpl index b3748bcab7fe..5068249e8090 100644 --- a/xml/templates/message_templates/event_offline_receipt_html.tpl +++ b/xml/templates/message_templates/event_offline_receipt_html.tpl @@ -226,10 +226,10 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset || $priceset == 0} -  {if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}% +  {$taxTerm} {$priceset|string_format:"%.2f"}%  {$value|crmMoney:$currency} {else} -  {ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if} +  {ts}No{/ts} {$taxTerm}  {$value|crmMoney:$currency} {/if} diff --git a/xml/templates/message_templates/event_offline_receipt_text.tpl b/xml/templates/message_templates/event_offline_receipt_text.tpl index c5c1741a81f9..4b7e95e9f873 100644 --- a/xml/templates/message_templates/event_offline_receipt_text.tpl +++ b/xml/templates/message_templates/event_offline_receipt_text.tpl @@ -125,9 +125,9 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset || $priceset == 0} -{if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}%: {$value|crmMoney:$currency} +{$taxTerm} {$priceset|string_format:"%.2f"}%: {$value|crmMoney:$currency} {else} -{ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if}: {$value|crmMoney:$currency} +{ts}No{/ts} {$taxTerm}: {$value|crmMoney:$currency} {/if} {/foreach} {/if} diff --git a/xml/templates/message_templates/event_online_receipt_html.tpl b/xml/templates/message_templates/event_online_receipt_html.tpl index 41e510a58b08..6787823789a7 100644 --- a/xml/templates/message_templates/event_online_receipt_html.tpl +++ b/xml/templates/message_templates/event_online_receipt_html.tpl @@ -269,10 +269,10 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset || $priceset == 0} -  {if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}% +  {$taxTerm} {$priceset|string_format:"%.2f"}%  {$value|crmMoney:$currency} {else} -  {ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if} +  {ts}No{/ts} {$taxTerm}  {$value|crmMoney:$currency} {/if} diff --git a/xml/templates/message_templates/event_online_receipt_text.tpl b/xml/templates/message_templates/event_online_receipt_text.tpl index e3dbd3835eb4..50512cdfa2de 100644 --- a/xml/templates/message_templates/event_online_receipt_text.tpl +++ b/xml/templates/message_templates/event_online_receipt_text.tpl @@ -145,9 +145,9 @@ You were registered by: {$payer.name} {foreach from=$dataArray item=value key=priceset} {if $priceset || $priceset == 0} -{if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}%: {$value|crmMoney:$currency} +{$taxTerm} {$priceset|string_format:"%.2f"}%: {$value|crmMoney:$currency} {else} -{ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if}: {$value|crmMoney:$currency} +{ts}No{/ts} {$taxTerm}: {$value|crmMoney:$currency} {/if} {/foreach} {/if} diff --git a/xml/templates/message_templates/membership_offline_receipt_html.tpl b/xml/templates/message_templates/membership_offline_receipt_html.tpl index 9012b9a46bbb..034a49975d9c 100644 --- a/xml/templates/message_templates/membership_offline_receipt_html.tpl +++ b/xml/templates/message_templates/membership_offline_receipt_html.tpl @@ -157,10 +157,10 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset} -  {if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}% +  {$taxTerm} {$priceset|string_format:"%.2f"}%  {$value|crmMoney:$currency} {elseif $priceset == 0} -  {ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if} +  {ts}No{/ts} {$taxTerm}  {$value|crmMoney:$currency} {/if} diff --git a/xml/templates/message_templates/membership_offline_receipt_text.tpl b/xml/templates/message_templates/membership_offline_receipt_text.tpl index 0817ad6bb4d7..715aff365471 100644 --- a/xml/templates/message_templates/membership_offline_receipt_text.tpl +++ b/xml/templates/message_templates/membership_offline_receipt_text.tpl @@ -52,9 +52,9 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset} -{if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"} %: {$value|crmMoney:$currency} +{$taxTerm} {$priceset|string_format:"%.2f"} %: {$value|crmMoney:$currency} {elseif $priceset == 0} -{ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if}: {$value|crmMoney:$currency} +{ts}No{/ts} {$taxTerm}: {$value|crmMoney:$currency} {/if} {/foreach} {/if} diff --git a/xml/templates/message_templates/membership_online_receipt_html.tpl b/xml/templates/message_templates/membership_online_receipt_html.tpl index 9e2ceb6268b6..35f4fbbb1164 100644 --- a/xml/templates/message_templates/membership_online_receipt_html.tpl +++ b/xml/templates/message_templates/membership_online_receipt_html.tpl @@ -217,10 +217,10 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset || $priceset == 0} -  {if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}% +  {$taxTerm} {$priceset|string_format:"%.2f"}%  {$value|crmMoney:$currency} {else} -  {ts}NO{/ts} {if isset($taxTerm)}{$taxTerm}{/if} +  {ts}NO{/ts} {$taxTerm}  {$value|crmMoney:$currency} {/if} diff --git a/xml/templates/message_templates/membership_online_receipt_text.tpl b/xml/templates/message_templates/membership_online_receipt_text.tpl index e85feaeec601..d1647bdbe20f 100644 --- a/xml/templates/message_templates/membership_online_receipt_text.tpl +++ b/xml/templates/message_templates/membership_online_receipt_text.tpl @@ -74,9 +74,9 @@ {foreach from=$dataArray item=value key=priceset} {if $priceset || $priceset == 0} -{if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}%: {$value|crmMoney:$currency} +{$taxTerm} {$priceset|string_format:"%.2f"}%: {$value|crmMoney:$currency} {else} -{ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if}: {$value|crmMoney:$currency} +{ts}No{/ts} {$taxTerm}: {$value|crmMoney:$currency} {/if} {/foreach} {/if}