Skip to content

Commit

Permalink
Smarty modifier - stop using isset to check taxTerm
Browse files Browse the repository at this point in the history
I'm thinking this should fail on some notices on CI - so will follow with the fix
  • Loading branch information
eileenmcnaughton committed Dec 31, 2021
1 parent 29cc02c commit 42b37f8
Show file tree
Hide file tree
Showing 17 changed files with 65 additions and 63 deletions.
4 changes: 3 additions & 1 deletion CRM/Utils/String.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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)}
Expand All @@ -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}
Expand All @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<th style="text-align:left;font-weight:bold;width:100%"><font size="1">{ts}Description{/ts}</font></th>
<th style="text-align:right;font-weight:bold;white-space: nowrap"><font size="1">{ts}Quantity{/ts}</font></th>
<th style="text-align:right;font-weight:bold;white-space: nowrap"><font size="1">{ts}Unit Price{/ts}</font></th>
<th style="text-align:right;font-weight:bold;white-space: nowrap"><font size="1">{if isset($taxTerm)}{$taxTerm}{/if}</font></th>
<th style="text-align:right;font-weight:bold;white-space: nowrap"><font size="1">{$taxTerm}</font></th>
<th style="text-align:right;font-weight:bold;white-space: nowrap"><font size="1">{ts 1=$currency}Amount %1{/ts}</font></th>
</tr>
{foreach from=$lineItem item=value key=priceset name=taxpricevalue}
Expand All @@ -99,7 +99,7 @@
{if $value.tax_amount != ''}
<td style="text-align:right;"><font size="1">{if isset($value.tax_rate)}{$value.tax_rate}%{/if}</font></td>
{else}
<td style="text-align:right;"><font size="1">{if isset($taxTerm)}{ts 1=$taxTerm}-{/ts}{/if}</font></td>
<td style="text-align:right;"><font size="1">{if $taxTerm}{ts 1=$taxTerm}-{/ts}{/if}</font></td>
{/if}
<td style="text-align:right;"><font size="1">{$value.subTotal|crmMoney:$currency}</font></td>
</tr>
Expand All @@ -114,10 +114,10 @@
<tr>
<td colspan="3"></td>
{if $priceset}
<td style="text-align:right;white-space: nowrap"><font size="1">{if isset($taxTerm)}{ts 1=$taxTerm 2=$priceset}TOTAL %1 %2%{/ts}{/if}</font></td>
<td style="text-align:right;white-space: nowrap"><font size="1">{if $taxTerm}{ts 1=$taxTerm 2=$priceset}TOTAL %1 %2%{/ts}{/if}</font></td>
<td style="text-align:right"><font size="1" align="right">{$value|crmMoney:$currency}</font> </td>
{elseif $priceset == 0}
<td style="text-align:right;white-space: nowrap"><font size="1">{if isset($taxTerm)}{ts 1=$taxTerm}TOTAL %1{/ts}{/if}</font></td>
<td style="text-align:right;white-space: nowrap"><font size="1">{if $taxTerm}{ts 1=$taxTerm}TOTAL %1{/ts}{/if}</font></td>
<td style="text-align:right"><font size="1" align="right">{$value|crmMoney:$currency}</font> </td>
{/if}
</tr>
Expand Down Expand Up @@ -302,7 +302,7 @@
<th style="padding-right:28px;text-align:left;font-weight:bold;width:200px;"><font size="1">{ts}Description{/ts}</font></th>
<th style="padding-left:28px;text-align:right;font-weight:bold;"><font size="1">{ts}Quantity{/ts}</font></th>
<th style="padding-left:28px;text-align:right;font-weight:bold;"><font size="1">{ts}Unit Price{/ts}</font></th>
<th style="padding-left:28px;text-align:right;font-weight:bold;"><font size="1">{if isset($taxTerm)}{$taxTerm}{/if}</font></th>
<th style="padding-left:28px;text-align:right;font-weight:bold;"><font size="1">{$taxTerm}</font></th>
<th style="padding-left:28px;text-align:right;font-weight:bold;"><font size="1">{ts 1=$currency}Amount %1{/ts}</font></th>
</tr>
{foreach from=$lineItem item=value key=priceset name=pricevalue}
Expand All @@ -329,7 +329,7 @@
{if $value.tax_amount != ''}
<td style="padding-left:28px;text-align:right;"><font size="1">{if isset($value.tax_rate)}{$value.tax_rate}%{/if}</font></td>
{else}
<td style="padding-left:28px;text-align:right"><font size="1">{if isset($taxTerm)}{ts 1=$taxTerm}No %1{/ts}{/if}</font></td>
<td style="padding-left:28px;text-align:right"><font size="1">{if $taxTerm}{ts 1=$taxTerm}No %1{/ts}{/if}</font></td>
{/if}
<td style="padding-left:28px;text-align:right;"><font size="1">{$value.subTotal|crmMoney:$currency}</font></td>
</tr>
Expand All @@ -345,10 +345,10 @@
<tr>
<td colspan="3"></td>
{if $priceset}
<td style="padding-left:28px;text-align:right;"><font size="1">{if isset($taxTerm)}{ts 1=$taxTerm 2=$priceset}TOTAL %1 %2%{/ts}{/if}</font></td>
<td style="padding-left:28px;text-align:right;"><font size="1">{if $taxTerm}{ts 1=$taxTerm 2=$priceset}TOTAL %1 %2%{/ts}{/if}</font></td>
<td style="padding-left:28px;text-align:right;"><font size="1" align="right">{$value|crmMoney:$currency}</font> </td>
{elseif $priceset == 0}
<td style="padding-left:28px;text-align:right;"><font size="1">{if isset($taxTerm)}{ts 1=$taxTerm}TOTAL NO %1{/ts}{/if}</font></td>
<td style="padding-left:28px;text-align:right;"><font size="1">{if $taxTerm}{ts 1=$taxTerm}TOTAL NO %1{/ts}{/if}</font></td>
<td style="padding-left:28px;text-align:right;"><font size="1" align="right">{$value|crmMoney:$currency}</font> </td>
{/if}
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@
{foreach from=$dataArray item=value key=priceset}
<tr>
{if $priceset || $priceset == 0 || $value != ''}
<td>&nbsp;{if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$taxTerm} {$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{else}
<td>&nbsp;{ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if}</td>
<td>&nbsp;{ts}No{/ts} {$taxTerm}</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{/if}
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@
{foreach from=$dataArray item=value key=priceset}
<tr>
{if $priceset || $priceset == 0}
<td>&nbsp;{if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$taxTerm} {$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{else}
<td>&nbsp;{ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if}</td>
<td>&nbsp;{ts}No{/ts} {$taxTerm}</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{/if}
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{if $is_pay_later}

===========================================================
{if isset($pay_later_receipt)}{$pay_later_receipt}{/if}
{$pay_later_receipt}
===========================================================
{/if}

Expand Down Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@
{foreach from=$dataArray item=value key=priceset}
<tr>
{if $priceset || $priceset == 0}
<td>&nbsp;{if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$taxTerm} {$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{else}
<td>&nbsp;{ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if}</td>
<td>&nbsp;{ts}No{/ts} {$taxTerm}</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{/if}
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions xml/templates/message_templates/event_online_receipt_html.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@
{foreach from=$dataArray item=value key=priceset}
<tr>
{if $priceset || $priceset == 0}
<td>&nbsp;{if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$taxTerm} {$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{else}
<td>&nbsp;{ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if}</td>
<td>&nbsp;{ts}No{/ts} {$taxTerm}</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{/if}
</tr>
Expand Down
4 changes: 2 additions & 2 deletions xml/templates/message_templates/event_online_receipt_text.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@
{foreach from=$dataArray item=value key=priceset}
<tr>
{if $priceset}
<td>&nbsp;{if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$taxTerm} {$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{elseif $priceset == 0}
<td>&nbsp;{ts}No{/ts} {if isset($taxTerm)}{$taxTerm}{/if}</td>
<td>&nbsp;{ts}No{/ts} {$taxTerm}</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{/if}
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,10 @@
{foreach from=$dataArray item=value key=priceset}
<tr>
{if $priceset || $priceset == 0}
<td>&nbsp;{if isset($taxTerm)}{$taxTerm}{/if} {$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$taxTerm} {$priceset|string_format:"%.2f"}%</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{else}
<td>&nbsp;{ts}NO{/ts} {if isset($taxTerm)}{$taxTerm}{/if}</td>
<td>&nbsp;{ts}NO{/ts} {$taxTerm}</td>
<td>&nbsp;{$value|crmMoney:$currency}</td>
{/if}
</tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 42b37f8

Please sign in to comment.