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

dev/core#2747 Reconcile remaining fields between scheduled reminders and legacy tokens #21046

Merged
merged 2 commits into from
Aug 12, 2021
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
8 changes: 7 additions & 1 deletion CRM/Contribute/DAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Contribute/Contribution.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:9e26b2d7dbaf18117d12aae5bb1b0378)
* (GenCodeChecksum:b14fa847767daf3723033f41dbca9612)
*/

/**
Expand Down Expand Up @@ -872,6 +872,12 @@ public static function &fields() {
'type' => 'EntityRef',
'label' => ts("Campaign"),
],
'pseudoconstant' => [
'table' => 'civicrm_campaign',
'keyColumn' => 'id',
'labelColumn' => 'title',
'prefetch' => 'FALSE',
],
'add' => '3.4',
],
'creditnote_id' => [
Expand Down
9 changes: 8 additions & 1 deletion CRM/Contribute/Tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function getApiEntityName(): string {
* @return array
*/
protected function getExposedFields(): array {
return [
$fields = [
'contribution_page_id',
'source',
'id',
Expand All @@ -75,7 +75,14 @@ protected function getExposedFields(): array {
'contribution_status_id',
'financial_type_id',
'payment_instrument_id',
'cancel_reason',
'amount_level',
'check_number',
];
if (CRM_Campaign_BAO_Campaign::isCampaignEnable()) {
$fields[] = 'campaign_id';
}
return $fields;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions CRM/Core/CodeGen/Specification.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,9 @@ public function getField(&$fieldXML, &$fields) {
'callback',
// Path to options edit form
'optionEditPath',
// Should options for this field be prefetched (for presenting on forms).
// The default is TRUE, but adding FALSE helps when there could be many options
'prefetch',
];
foreach ($validOptions as $pseudoOption) {
if (!empty($fieldXML->pseudoconstant->$pseudoOption)) {
Expand Down
9 changes: 1 addition & 8 deletions CRM/Core/SelectValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -568,14 +568,7 @@ public static function contributionTokens(): array {
foreach ($processor->getAllTokens() as $token => $title) {
$tokens['{contribution.' . $token . '}'] = $title;
}
return array_merge($tokens, [
'{contribution.cancel_reason}' => ts('Contribution Cancel Reason'),
'{contribution.amount_level}' => ts('Amount Level'),
'{contribution.check_number}' => ts('Check Number'),
'{contribution.campaign}' => ts('Contribution Campaign'),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note I manually tested that this token still works in the original legacy flow - although it is no longer advertised and it never worked in the scheduled reminders flow. This change just stops it from being advertised

// @todo - we shouldn't need to include custom fields here -
// remove, with test.
Copy link
Contributor Author

@eileenmcnaughton eileenmcnaughton Aug 6, 2021

Choose a reason for hiding this comment

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

The removed lines are from the function that determins the tokens that show up here.

Per the comments I thought the custom field line was also redundant & UI testing should it to be true - I wound up UI testing rather than unit
testing that custom fields are still advertised
as the test uses rollback & adding custom fields would break that.

image

image

], CRM_Utils_Token::getCustomFieldTokens('Contribution', TRUE));
return $tokens;
}

/**
Expand Down
31 changes: 30 additions & 1 deletion tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
+--------------------------------------------------------------------+
*/

use Civi\Api4\Contribution;

/**
* Class CRM_Contribute_ActionMapping_ByTypeTest
* @group ActionSchedule
Expand Down Expand Up @@ -151,6 +153,8 @@ public function createTestCases() {
* Create a contribution record for Alice with type "Member Dues".
*/
public function addAliceDues(): void {
$this->enableCiviCampaign();
$campaignID = $this->campaignCreate();
$this->ids['Contribution']['alice'] = $this->callAPISuccess('Contribution', 'create', [
'contact_id' => $this->contacts['alice']['id'],
'receive_date' => date('Ymd', strtotime($this->targetDate)),
Expand All @@ -164,6 +168,7 @@ public function addAliceDues(): void {
// Having a cancel date is a bit artificial here but we can test it....
'cancel_date' => '2021-08-09',
'contribution_status_id' => 1,
'campaign_id' => $campaignID,
'soft_credit' => [
'1' => [
'contact_id' => $this->contacts['carol']['id'],
Expand Down Expand Up @@ -281,7 +286,10 @@ public function testTokenRendering(): void {
non_deductible_amount = {contribution.non_deductible_amount}
total_amount = {contribution.total_amount}
net_amount = {contribution.net_amount}
fee_amount = {contribution.fee_amount}';
fee_amount = {contribution.fee_amount}
campaign_id = {contribution.campaign_id}
campaign name = {contribution.campaign_id:name}
campaign label = {contribution.campaign_id:label}';

$this->schedule->save();
$this->callAPISuccess('job', 'send_reminder', []);
Expand All @@ -305,6 +313,9 @@ public function testTokenRendering(): void {
'total_amount = € 100.00',
'net_amount = € 95.00',
'fee_amount = € 5.00',
'campaign_id = 1',
'campaign name = big_campaign',
'campaign label = Campaign',
];
$this->mut->checkMailLog($expected);

Expand Down Expand Up @@ -337,6 +348,9 @@ public function testTokenRendering(): void {
'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']);
Expand All @@ -354,6 +368,21 @@ public function testTokenRendering(): void {
'contribution_status_id:label',
];
$processor = new CRM_Contribute_Tokens();
$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) {
$allFields[$field['name']] = $field['title'];
}
// $this->assertEquals($realLegacyTokens, $allFields);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is commented out because it is not true yet & I want to discuss whether it should be TRUE

$this->assertEquals($legacyTokens, $processor->tokenNames);
foreach ($tokens as $token) {
$this->assertEquals(CRM_Core_SelectValues::contributionTokens()['{contribution.' . $token . '}'], $processor->tokenNames[$token]);
}
Expand Down
6 changes: 6 additions & 0 deletions xml/schema/Contribute/Contribution.xml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,12 @@
<import>true</import>
<comment>The campaign for which this contribution has been triggered.</comment>
<add>3.4</add>
<pseudoconstant>
<table>civicrm_campaign</table>
<keyColumn>id</keyColumn>
<labelColumn>title</labelColumn>
<prefetch>FALSE</prefetch>
</pseudoconstant>
<html>
<type>EntityRef</type>
<label>Campaign</label>
Expand Down