From 45174d7edada53f24fa3989801fa9b3095d0b31f Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 6 Feb 2023 19:50:15 +1300 Subject: [PATCH] Fully deprecate legacy contributionTokens --- CRM/Core/SelectValues.php | 1 + .../Contribute/ActionMapping/ByTypeTest.php | 56 ++++++++++++------- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index e42cacaca4..9ebebe9e76 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -582,6 +582,7 @@ class CRM_Core_SelectValues { * @return array */ public static function contributionTokens(): array { + CRM_Core_Error::deprecatedFunctionWarning('use the token processor'); $tokenProcessor = new TokenProcessor(Civi::dispatcher(), ['schema' => ['contributionId']]); $allTokens = $tokenProcessor->listTokens(); foreach (array_keys($allTokens) as $token) { diff --git a/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php b/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php index f9d84519e8..e963b4ffea 100644 --- a/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php +++ b/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php @@ -366,20 +366,6 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends \Civi\ActionSchedule\Abstr } } - $tokens = [ - 'id', - 'payment_instrument_id:label', - 'financial_type_id:label', - 'contribution_status_id:label', - ]; - $legacyTokens = []; - $realLegacyTokens = []; - foreach (CRM_Core_SelectValues::contributionTokens() as $token => $label) { - $legacyTokens[substr($token, 14, -1)] = $label; - if (strpos($token, ':') === FALSE) { - $realLegacyTokens[substr($token, 14, -1)] = $label; - } - } $fields = (array) Contribution::getFields()->addSelect('name', 'title')->execute()->indexBy('name'); $allFields = []; foreach ($fields as $field) { @@ -389,7 +375,7 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends \Civi\ActionSchedule\Abstr } // contact ID is skipped. unset($allFields['contact_id']); - $this->assertEquals($allFields, $realLegacyTokens); + $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [ 'controller' => __CLASS__, 'smarty' => FALSE, @@ -403,10 +389,42 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends \Civi\ActionSchedule\Abstr } $comparison[substr($token, 14, -1)] = $label; } - $this->assertEquals($legacyTokens, $comparison); - foreach ($tokens as $token) { - $this->assertEquals(CRM_Core_SelectValues::contributionTokens()['{contribution.' . $token . '}'], $comparison[$token]); - } + $this->assertEquals( + [ + 'id' => 'Contribution ID', + 'financial_type_id:label' => 'Financial Type', + 'contribution_page_id:label' => 'Contribution Page', + 'payment_instrument_id:label' => 'Payment Method', + 'receive_date' => 'Date Received', + 'non_deductible_amount' => 'Non-deductible Amount', + 'total_amount' => 'Total Amount', + 'fee_amount' => 'Fee Amount', + 'net_amount' => 'Net Amount', + 'trxn_id' => 'Transaction ID', + 'invoice_id' => 'Invoice Reference', + 'invoice_number' => 'Invoice Number', + 'currency' => 'Currency', + 'cancel_date' => 'Cancelled / Refunded Date', + 'cancel_reason' => 'Cancellation / Refund Reason', + 'receipt_date' => 'Receipt Date', + 'thankyou_date' => 'Thank-you Date', + 'source' => 'Contribution Source', + 'amount_level' => 'Amount Label', + 'contribution_recur_id' => 'Recurring Contribution ID', + 'is_test:label' => 'Test', + 'is_pay_later:label' => 'Is Pay Later', + 'contribution_status_id:label' => 'Contribution Status', + 'address_id' => 'Address ID', + 'check_number' => 'Check Number', + 'campaign_id:label' => 'Campaign', + 'creditnote_id' => 'Credit Note ID', + 'tax_amount' => 'Tax Amount', + 'revenue_recognition_date' => 'Revenue Recognition Date', + 'is_template:label' => 'Is a Template Contribution', + 'paid_amount' => 'Amount Paid', + 'balance_amount' => 'Balance', + 'tax_exclusive_amount' => 'Tax Exclusive Amount', + ], $comparison); } /** -- 2.25.1