From 927898c59a56afcd73d9842e1628946c5d91e960 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 5 Sep 2018 17:38:23 +1200 Subject: [PATCH] Fix metadata on cancel_reason so it is an exportable field This means it is available for searching --- CRM/Contribute/BAO/Query.php | 7 ++++--- CRM/Contribute/DAO/Contribution.php | 4 ++-- CRM/Contribute/Form/Search.php | 8 ++++++++ templates/CRM/Contribute/Form/Search/Common.tpl | 4 ++-- tests/phpunit/CRM/Contribute/Form/SearchTest.php | 4 ++-- tests/phpunit/CRM/Export/BAO/ExportTest.php | 2 +- tests/phpunit/api/v3/ContributionTest.php | 15 +++++++++++++++ xml/schema/Contribute/Contribution.xml | 3 +++ 8 files changed, 37 insertions(+), 10 deletions(-) diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index abf05f7e71..7d23de39b0 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -506,7 +506,9 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query { return; } $whereTable = $fields[$fldName]; - $value = trim($value); + if (!is_array($value)) { + $value = trim($value); + } $dataType = "String"; if (!empty($whereTable['type'])) { @@ -929,8 +931,7 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query { $form->add('text', 'contribution_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8)); $form->addRule('contribution_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money'); - // Adding Cancelled Contribution fields -- CRM-21343 - $form->add('text', 'contribution_cancel_reason', ts('Cancellation / Refund Reason'), array('size' => 40)); + $form->addField('cancel_reason'); CRM_Core_Form_Date::buildDateRange($form, 'contribution_cancel_date', 1, '_low', '_high', ts('From:'), FALSE); $form->addElement('hidden', 'contribution_cancel_date_range_error'); diff --git a/CRM/Contribute/DAO/Contribution.php b/CRM/Contribute/DAO/Contribution.php index faa6a8c9db..299ef839a4 100644 --- a/CRM/Contribute/DAO/Contribution.php +++ b/CRM/Contribute/DAO/Contribution.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Contribute/Contribution.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:45a20d00d01766a61687cbac5cef1482) + * (GenCodeChecksum:eec525df6c3c6151861750217f3ebe5d) */ /** @@ -584,7 +584,7 @@ class CRM_Contribute_DAO_Contribution extends CRM_Core_DAO { 'cancel_reason' => [ 'name' => 'cancel_reason', 'type' => CRM_Utils_Type::T_TEXT, - 'title' => ts('Cancel Reason'), + 'title' => ts('Cancellation / Refund Reason'), 'import' => TRUE, 'where' => 'civicrm_contribution.cancel_reason', 'headerPattern' => '/(cancel.?)?reason/i', diff --git a/CRM/Contribute/Form/Search.php b/CRM/Contribute/Form/Search.php index 035b9523e8..c31c0733f0 100644 --- a/CRM/Contribute/Form/Search.php +++ b/CRM/Contribute/Form/Search.php @@ -62,6 +62,14 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search { */ protected $_prefix = "contribute_"; + + /** + * Explicitly declare the entity api name. + */ + public function getDefaultEntity() { + return 'Contribution'; + } + /** * Processing needed for buildForm and later. */ diff --git a/templates/CRM/Contribute/Form/Search/Common.tpl b/templates/CRM/Contribute/Form/Search/Common.tpl index 4412dac0a4..add2f85563 100644 --- a/templates/CRM/Contribute/Form/Search/Common.tpl +++ b/templates/CRM/Contribute/Form/Search/Common.tpl @@ -158,8 +158,8 @@ {include file="CRM/Contribute/Form/PCP.js.tpl"} - {$form.contribution_cancel_reason.label}
- {$form.contribution_cancel_reason.html} + {$form.cancel_reason.label}
+ {$form.cancel_reason.html} diff --git a/tests/phpunit/CRM/Contribute/Form/SearchTest.php b/tests/phpunit/CRM/Contribute/Form/SearchTest.php index a409cf53b3..311576a4ad 100644 --- a/tests/phpunit/CRM/Contribute/Form/SearchTest.php +++ b/tests/phpunit/CRM/Contribute/Form/SearchTest.php @@ -542,14 +542,14 @@ class CRM_Contribute_Form_SearchTest extends CiviUnitTestCase { 'form_value' => array('cancel_reason' => 'Invalid Credit Card Number'), 'expected_count' => 1, 'expected_contribution' => array($Contribution3['id']), - 'expected_qill' => "Cancel Reason Like '%Invalid Credit Card Number%'", + 'expected_qill' => "Cancellation / Refund Reason Like '%Invalid Credit Card Number%'", ), // Case 3: Search for Cancelled Date and Cancelled Reason array( 'form_value' => array('cancel_date' => date('Y-m-d'), 'cancel_reason' => 'Insufficient funds'), 'expected_count' => 1, 'expected_contribution' => array($Contribution1['id']), - 'expected_qill' => "Cancel Date Like '%" . date('Y-m-d') . "%'ANDCancel Reason Like '%Insufficient funds%'", + 'expected_qill' => "Cancel Date Like '%" . date('Y-m-d') . "%'ANDCancellation / Refund Reason Like '%Insufficient funds%'", ), ); diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index ff368a31d7..cbdd374827 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -2065,7 +2065,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { 95 => 'Invoice Reference', 96 => 'Invoice Number', 97 => 'Currency', - 98 => 'Cancel Reason', + 98 => 'Cancellation / Refund Reason', 99 => 'Receipt Date', 100 => 'Product Name', 101 => 'SKU', diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 3f7294e023..73540669e1 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -302,6 +302,21 @@ class api_v3_ContributionTest extends CiviUnitTestCase { } } + /** + * Test cancel reason works as a filter. + */ + public function testFilterCancelReason() { + $params = $this->_params; + $params['cancel_date'] = 'yesterday'; + $params['cancel_reason'] = 'You lose sucker'; + $this->callAPISuccess('Contribution', 'create', $params); + $params = $this->_params; + $params['cancel_date'] = 'yesterday'; + $params['cancel_reason'] = 'You are a winner'; + $this->callAPISuccess('Contribution', 'create', $params); + $this->callAPISuccessGetCount('Contribution', ['cancel_reason' => 'You are a winner'], 1); + } + /** * We need to ensure previous tested behaviour still works as part of the api contract. */ diff --git a/xml/schema/Contribute/Contribution.xml b/xml/schema/Contribute/Contribution.xml index edcb3befa4..5ea0ccc0fd 100644 --- a/xml/schema/Contribute/Contribution.xml +++ b/xml/schema/Contribute/Contribution.xml @@ -286,10 +286,13 @@ cancel_reason text + Cancellation / Refund Reason true + true /(cancel.?)?reason/i Text + 40 1.3 -- 2.25.1