Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smarty modifier - stop using isset to check taxTerm #22323

Merged
merged 2 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CRM/Core/DomainTokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function getDomainTokens(): array {
'id' => ts('Domain ID'),
'description' => ts('Domain Description'),
'now' => ts('Current time/date'),
'tax_term' => ts('Sales tax term (e.g VAT)'),
];
}

Expand Down Expand Up @@ -92,9 +93,9 @@ public static function getDomainTokenValues(?int $domainID = NULL, bool $html =
$domain->find(TRUE);
}
$tokens = [
'name' => $domain->name,
'name' => $domain->name ?? '',
'id' => $domain->id,
'description' => $domain->description,
'description' => $domain->description ?? '',
];
$loc = $domain->getLocationValues();
if ($html) {
Expand All @@ -107,6 +108,7 @@ public static function getDomainTokenValues(?int $domainID = NULL, bool $html =
$email = reset($loc['email']);
$tokens['phone'] = $phone['phone'] ?? '';
$tokens['email'] = $email['email'] ?? '';
$tokens['tax_term'] = (string) Civi::settings()->get('tax_term');
Civi::cache('metadata')->set($cacheKey, $tokens);
}
return Civi::cache('metadata')->get($cacheKey);
Expand Down
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
11 changes: 11 additions & 0 deletions Civi/WorkflowMessage/GenericWorkflowMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,15 @@ protected function validateExtra_contact(array &$errors) {
}
}

/**
* Define tokens to be exported as smarty values.
*
* @param array $export
*/
protected function exportExtraTokenContext(array &$export): void {
// Tax term is exposed at the generic level as so many templates use it
// (e.g. Membership, participant, pledge as well as contributions).
$export['smartyTokenAlias']['taxTerm'] = 'domain.tax_term';
}

}
9 changes: 4 additions & 5 deletions tests/phpunit/CRM/Core/BAO/MessageTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ class CRM_Core_BAO_MessageTemplateTest extends CiviUnitTestCase {

/**
* Post test cleanup.
*
* @throws \CRM_Core_Exception
*/
public function tearDown():void {
$this->quickCleanup(['civicrm_address', 'civicrm_phone', 'civicrm_im', 'civicrm_website', 'civicrm_openid', 'civicrm_email'], TRUE);
parent::tearDown();
Civi::cache('metadata')->clear();
}

public function testRenderTemplate() {
public function testRenderTemplate(): void {
$contactId = $this->individualCreate([
'first_name' => 'Abba',
'last_name' => 'Baab',
Expand Down Expand Up @@ -107,7 +106,7 @@ public function testSendTemplate_RenderMode_OpenTemplate(): void {
$this->assertStringContainsString('<p>Hello testSendTemplate_RenderMode_OpenTemplate Abba Baab!</p>', $messageHtml);
}

public function testSendTemplate_RenderMode_DefaultTpl() {
public function testSendTemplate_RenderMode_DefaultTpl(): void {
CRM_Core_Transaction::create(TRUE)->run(function(CRM_Core_Transaction $tx) {
$tx->rollback();

Expand Down Expand Up @@ -144,7 +143,7 @@ public function testSendTemplate_RenderMode_DefaultTpl() {
});
}

public function testSendTemplate_RenderMode_TokenContext() {
public function testSendTemplateRenderModeTokenContext(): void {
CRM_Core_Transaction::create(TRUE)->run(function(CRM_Core_Transaction $tx) {
$tx->rollback();

Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/CRM/Utils/TokenConsistencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ public function getDomainTokens(): array {
'{domain.id}' => ts('Domain ID'),
'{domain.description}' => ts('Domain Description'),
'{domain.now}' => 'Current time/date',
'{domain.tax_term}' => 'Sales tax term (e.g VAT)',
];
}

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
6 changes: 4 additions & 2 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2052,8 +2052,9 @@ public function testSearch() {
* Note that we are creating a logged in user because email goes out from
* that person
*/
public function testCompleteTransaction() {
public function testCompleteTransaction(): void {
$mut = new CiviMailUtils($this, TRUE);
Civi::settings()->set('tax_term', 'GST');
$this->swapMessageTemplateForTestTemplate();
$this->createLoggedInUser();
$params = array_merge($this->_params, ['contribution_status_id' => 2]);
Expand All @@ -2074,6 +2075,7 @@ public function testCompleteTransaction() {
"receipt_date:::\n",
'title:::Contribution',
'contributionStatus:::Completed',
'taxTerm:::GST',
]);
$mut->stop();
$this->revertTemplateToReservedTemplate();
Expand All @@ -2082,7 +2084,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,89 +38,85 @@
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)}
taxTerm:::{$taxTerm}
{/if}
{if !empty($pcpBlock)}
pcpBlock:::{$pcpBlock}
pcp_display_in_roll:::{$pcp_display_in_roll}
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)}
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 +125,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
Loading