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

Add noisy deprecation to deprecated contribution token functions #25050

Merged
merged 1 commit into from
Nov 25, 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
1 change: 1 addition & 0 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4606,6 +4606,7 @@ public static function replaceContributionTokens(
$messageToken,
$escapeSmarty
) {
CRM_Core_Error::deprecatedFunctionWarning('use the TokenProcessor');
if (empty($contributionIds)) {
return [];
}
Expand Down
3 changes: 3 additions & 0 deletions CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,7 @@ public static function getUserTokenReplacement($token, $escapeSmarty = FALSE) {
* in CRM_Contribute_Form_Task_PDFLetter.
*/
protected static function _buildContributionTokens() {
CRM_Core_Error::deprecatedFunctionWarning('use the token processor');
$key = 'contribution';

if (!isset(Civi::$statics[__CLASS__][__FUNCTION__][$key])) {
Expand Down Expand Up @@ -1569,6 +1570,7 @@ public static function getApiTokenReplacement($entity, $token, $entityArray) {
* @return mixed
*/
public static function replaceContributionTokens($str, &$contribution, $html = FALSE, $knownTokens = NULL, $escapeSmarty = FALSE) {
CRM_Core_Error::deprecatedFunctionWarning('use the token processor');
$key = 'contribution';
if (!$knownTokens || empty($knownTokens[$key])) {
//early return
Expand Down Expand Up @@ -1716,6 +1718,7 @@ public static function getMembershipTokenReplacement($entity, $token, $membershi
* @throws \CRM_Core_Exception
*/
public static function getContributionTokenReplacement($token, $contribution, $html = FALSE, $escapeSmarty = FALSE) {
CRM_Core_Error::deprecatedFunctionWarning('use the token processor');
self::_buildContributionTokens();

switch ($token) {
Expand Down
36 changes: 0 additions & 36 deletions tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,42 +366,6 @@ public function testTokenRendering(): void {
}
}

$messageToken = CRM_Utils_Token::getTokens($this->schedule->body_text);

$contributionDetails = CRM_Contribute_BAO_Contribution::replaceContributionTokens(
[$this->ids['Contribution']['alice']],
$this->schedule->body_text,
$messageToken,
$this->schedule->body_text,
$this->schedule->body_text,
$messageToken,
TRUE
);
$expected = [
'receive_date = February 1st, 2015',
'new style status = Completed',
'contribution status id = 1',
'id ' . $this->ids['Contribution']['alice'],
'contribution_id ' . $this->ids['Contribution']['alice'],
'financial type id = 1',
'financial type name = Donation',
'financial type label = Donation',
'payment instrument id = 4',
'payment instrument name = Check',
'payment instrument label = Check',
'legacy source SSF',
'source SSF',
'non_deductible_amount = € 10.00',
'total_amount = € 100.00',
'net_amount = € 95.00',
'fee_amount = € 5.00',
'campaign_id = 1',
'campaign name = big_campaign',
'campaign label = Campaign',
];
foreach ($expected as $string) {
$this->assertStringContainsString($string, $contributionDetails[$this->contacts['alice']['id']]['html']);
}
$tokens = [
'id',
'payment_instrument_id:label',
Expand Down
72 changes: 1 addition & 71 deletions tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1232,80 +1232,10 @@ public function testProcessOnBehalfOrganization() {
$this->assertEquals($params['onbehalf_dupe_alert'], 1);
}

/**
* Test for replaceContributionTokens.
*
* This function tests whether the contribution tokens are replaced with
* values from contribution.
*
* @throws \CRM_Core_Exception
*/
public function testReplaceContributionTokens(): void {
$customGroup = $this->customGroupCreate(['extends' => 'Contribution', 'title' => 'contribution stuff']);
$customField = $this->customFieldOptionValueCreate($customGroup, 'myCustomField');
$contactId1 = $this->individualCreate();
$params = [
'contact_id' => $contactId1,
'receive_date' => '20120511',
'total_amount' => 100.00,
'financial_type_id' => 1,
'trxn_id' => 12345,
'invoice_id' => 67890,
'source' => 'SSF',
'contribution_status_id' => 2,
"custom_{$customField['id']}" => 'value1',
'currency' => 'EUR',
];
$contribution1 = $this->contributionCreate($params);
$contactId2 = $this->individualCreate();
$params = [
'contact_id' => $contactId2,
'receive_date' => '20150511',
'total_amount' => 200.00,
'financial_type_id' => 1,
'trxn_id' => 6789,
'invoice_id' => 12345,
'source' => 'ABC',
'contribution_status_id' => 1,
"custom_{$customField['id']}" => 'value2',
];
$contribution2 = $this->contributionCreate($params);
$ids = [$contribution1, $contribution2];

$subject = 'This is a test for contribution ID: {contribution.contribution_id}';
$text = 'Contribution Amount: {contribution.total_amount}';
$html = "<p>Contribution Source: {contribution.contribution_source}</p></br>
<p>Contribution Invoice ID: {contribution.invoice_id}</p></br>
<p>Contribution Receive Date: {contribution.receive_date}</p></br>
<p>Contribution Custom Field: {contribution.custom_{$customField['id']}}</p></br>
{contribution.contribution_status_id:name}";

$subjectToken = CRM_Utils_Token::getTokens($subject);
$messageToken = CRM_Utils_Token::getTokens($text);
$messageToken = array_merge($messageToken, CRM_Utils_Token::getTokens($html));

$contributionDetails = CRM_Contribute_BAO_Contribution::replaceContributionTokens(
$ids,
$subject,
$subjectToken,
$text,
$html,
$messageToken,
TRUE
);

$this->assertEquals('Contribution Amount: € 100.00', $contributionDetails[$contactId1]['text'], 'The text does not match');
$this->assertEquals('<p>Contribution Source: ABC</p></br>
<p>Contribution Invoice ID: 12345</p></br>
<p>Contribution Receive Date: May 11th, 2015 12:00 AM</p></br>
<p>Contribution Custom Field: Label2</p></br>
Completed', $contributionDetails[$contactId2]['html'], 'The html does not match');
}

/**
* Test for contribution with deferred revenue.
*/
public function testContributionWithDeferredRevenue() {
public function testContributionWithDeferredRevenue(): void {
$contactId = $this->individualCreate();
Civi::settings()->set('deferred_revenue_enabled', TRUE);
$params = [
Expand Down