Skip to content

Commit

Permalink
Always assign taxTerm to templates
Browse files Browse the repository at this point in the history
I do wonder about making this a domain token - I go back & forth a bit but as
a domain token it would be available in non-smarty contexts too & could be exported
  • Loading branch information
eileenmcnaughton committed Jan 2, 2022
1 parent 42b37f8 commit b8fe55c
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
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
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
4 changes: 3 additions & 1 deletion 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@
{if !empty($priceset)}
priceset:::{$priceset}
{/if}
{if !empty($taxTerm)}
taxTerm:::{$taxTerm}
{/if}
{if !empty($pcpBlock)}
pcpBlock:::{$pcpBlock}
pcp_display_in_roll:::{$pcp_display_in_roll}
Expand All @@ -82,10 +80,8 @@
{if !empty($isBillingAddressRequiredForPayLater)}
isBillingAddressRequiredForPayLater:::{$isBillingAddressRequiredForPayLater}
{/if}
{if !empty($billingName)}
billingName:::{$billingName}
address:::{$address}
{/if}
{if !empty($credit_card_type)}
credit_card_type:::{$credit_card_type}
credit_card_number:::{$credit_card_number}
Expand Down

0 comments on commit b8fe55c

Please sign in to comment.