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

Switch pledge_acknowledgement to parse through the processor only #21789

Closed
wants to merge 2 commits into from
Closed
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
31 changes: 1 addition & 30 deletions CRM/Pledge/BAO/Pledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,34 +569,6 @@ public static function sendAcknowledgment(&$form, $params) {
$form->assign('payments', $payments);
}

// handle domain token values
$domain = CRM_Core_BAO_Domain::getDomain();
$tokens = [
'domain' => ['name', 'phone', 'address', 'email'],
'contact' => CRM_Core_SelectValues::contactTokens(),
];
$domainValues = [];
foreach ($tokens['domain'] as $token) {
$domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
}
$form->assign('domain', $domainValues);

// handle contact token values.
$ids = [$params['contact_id']];
$fields = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields()),
['display_name', 'checksum', 'contact_id']
);
foreach ($fields as $key => $val) {
$returnProperties[$val] = TRUE;
}
[$details] = CRM_Utils_Token::getTokenDetails($ids,
$returnProperties,
TRUE, TRUE, NULL,
$tokens,
get_class($form)
);
$form->assign('contact', $details[$params['contact_id']]);

// handle custom data.
if (!empty($params['hidden_custom'])) {
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', NULL, $params['id']);
Expand Down Expand Up @@ -641,8 +613,7 @@ public static function sendAcknowledgment(&$form, $params) {
}
else {
// set the domain values.
$userName = $domainValues['name'] ?? NULL;
$userEmail = $domainValues['email'] ?? NULL;
[$userName, $userEmail] = CRM_Core_BAO_Domain::getNameAndEmail();
}

if (!isset($receiptFrom)) {
Expand Down
9 changes: 9 additions & 0 deletions CRM/Upgrade/Incremental/MessageTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@ protected function getTemplateUpdates() {
['name' => 'case_activity', 'type' => 'subject'],
],
],
[
'version' => '5.44.alpha1',
'upgrade_descriptor' => ts('Use domain tokens instead of smarty values'),
'label' => ts('Pledge acknowledgement'),
'templates' => [
['name' => 'pledge_acknowledge', 'type' => 'text'],
['name' => 'pledge_acknowledge', 'type' => 'html'],
],
],
];
}

Expand Down
4 changes: 4 additions & 0 deletions CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,10 @@ public static function getTokenDeprecations(): array {
'$last_name' => 'contact.last_name',
'$displayName' => 'contact.display_name',
],
'pledge_acknowledgement' => [
'$domain' => 'no longer available / relevant',
'$contact' => 'no longer available / relevant',
],
],
];
}
Expand Down
8,072 changes: 4,036 additions & 4,036 deletions sql/civicrm_generated.mysql

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions tests/phpunit/CRM/Pledge/Form/PledgeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

use Civi\Api4\Email;

/**
* CRM_Pledge_Form_PledgeTest
*
* @group headless
*/
class CRM_Pledge_Form_PledgeTest extends CiviUnitTestCase {

/**
* Test the post process function.
*
* @throws \API_Exception
* @throws \CRM_Core_Exception
*/
public function testPostProcess(): void {
$mut = new CiviMailUtils($this);
$loggedInUser = $this->createLoggedInUser();
$this->addLocationBlockToDomain();
$this->swapMessageTemplateForInput('pledge_acknowledge', '{domain.name} {contact.first_name}');

$form = $this->getFormObject('CRM_Pledge_Form_Pledge', [
'amount' => 10,
'installments' => 1,
'contact_id' => $this->individualCreate(),
'is_acknowledge' => 1,
'start_date' => '2021-01-04',
'create_date' => '2021-01-04',
'from_email_address' => Email::get()
->addWhere('contact_id', '=', $loggedInUser)
->addSelect('id')->execute()->first()['id'],
]);
$form->buildForm();
$form->postProcess();
$mut->checkAllMailLog([
'Default Domain Name Anthony',
123,
'[email protected]',
'<p>Dear Anthony,</p>',
]);
$mut->clearMessages();
$this->revertTemplateToReservedTemplate('pledge_acknowledge');
}

}
30 changes: 24 additions & 6 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
* <http://www.gnu.org/licenses/>.
*/

use Civi\Api4\Address;
use Civi\Api4\Contribution;
use Civi\Api4\CustomField;
use Civi\Api4\CustomGroup;
use Civi\Api4\FinancialType;
use Civi\Api4\LineItem;
use Civi\Api4\MembershipType;
use Civi\Api4\OptionGroup;
use Civi\Api4\Phone;
use Civi\Api4\RelationshipType;
use Civi\Payment\System;
use Civi\Api4\OptionValue;
Expand Down Expand Up @@ -731,7 +733,7 @@ public function membershipStatusCreate($name = 'test member status') {
*
* @throws \CRM_Core_Exception
*/
public function membershipStatusDelete(int $membershipStatusID) {
public function membershipStatusDelete(int $membershipStatusID): void {
$this->callAPISuccess('Membership', 'get', ['status_id' => $membershipStatusID, 'api.Membership.delete' => 1]);
$this->callAPISuccess('MembershipStatus', 'Delete', ['id' => $membershipStatusID]);
}
Expand Down Expand Up @@ -1010,10 +1012,8 @@ public function entityTagAdd($params) {
*
* @return int
* id of created pledge
*
* @throws \CRM_Core_Exception
*/
public function pledgeCreate($params) {
public function pledgeCreate($params): int {
$params = array_merge([
'pledge_create_date' => date('Ymd'),
'start_date' => date('Ymd'),
Expand Down Expand Up @@ -3612,8 +3612,8 @@ public function createCase($clientId, $loggedInUser = NULL, $extra = []) {
'status_id' => 1,
'case_type' => 'housing_support',
'subject' => 'Case Subject',
'start_date' => date("Y-m-d"),
'start_date_time' => date("YmdHis"),
'start_date' => date('Y-m-d'),
'start_date_time' => date('YmdHis'),
'medium_id' => 2,
'activity_details' => '',
], $extra);
Expand Down Expand Up @@ -3799,4 +3799,22 @@ protected function ensureMembershipPriceSetExists(): void {
");
}

/**
* Add an address block to the current domain.
*
* @noinspection PhpUnhandledExceptionInspection
*/
protected function addLocationBlockToDomain(): void {
$contactID = CRM_Core_BAO_Domain::getDomain()->contact_id;
Phone::create()
->setValues(['phone' => 123, 'contact_id' => $contactID])
->execute()
->first()['id'];
Address::create()->setValues([
'street_address' => '10 Downing Street',
'city' => 'London',
'contact_id' => $contactID,
])->execute()->first();
}

}
4 changes: 2 additions & 2 deletions xml/templates/message_templates/pledge_acknowledge_html.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<tr>
<td>
{assign var="greeting" value="{contact.email_greeting}"}{if $greeting}<p>{$greeting},</p>{/if}
{assign var="greeting" value="{contact.email_greeting_display}"}{if $greeting}<p>{$greeting},</p>{/if}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the original still works but since we are changing we should update

<p>{ts}Thank you for your generous pledge.{/ts}</p>
</td>
</tr>
Expand Down Expand Up @@ -80,7 +80,7 @@

<tr>
<td colspan="2" {$valueStyle}>
<p>{ts 1=$domain.phone 2=$domain.email}Please contact us at %1 or send email to %2 if you have questions
<p>{ts 1='{domain.phone}' 2='{domain.email}'}Please contact us at %1 or send email to %2 if you have questions
or need to modify your payment schedule.{/ts}</p>
</td>
</tr>
Expand Down
4 changes: 2 additions & 2 deletions xml/templates/message_templates/pledge_acknowledge_text.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{assign var="greeting" value="{contact.email_greeting}"}{if $greeting}<p>{$greeting},</p>{/if}
{assign var="greeting" value="{contact.email_greeting_display}"}{if $greeting}{$greeting},{/if}

{ts}Thank you for your generous pledge.{/ts}

Expand Down Expand Up @@ -30,7 +30,7 @@
{/if}


{ts 1=$domain.phone 2=$domain.email}Please contact us at %1 or send email to %2 if you have questions
{ts 1='{domain.phone}' 2='{domain.email}'}Please contact us at %1 or send email to %2 if you have questions
or need to modify your payment schedule.{/ts}

{if $customGroup}
Expand Down