Commit 3ae1b2f4 authored by eileen's avatar eileen

CRM-17647 add tests & form cleaning of event thousand separators

style fix
parent cdd71d6b
......@@ -49,6 +49,15 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
*/
public $_totalAmount;
/**
* Monetary fields that may be submitted.
*
* These should get a standardised format in the beginPostProcess function.
*
* These fields are common to many forms. Some may override this.
*/
protected $submittableMoneyFields = ['total_amount', 'net_amount', 'non_deductible_amount', 'fee_amount', 'tax_amount', 'amount'];
/**
* Set variables up before form is built.
*/
......@@ -205,6 +214,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
$taxAmount = 0;
foreach ($this->_params as $k => $v) {
$this->cleanMoneyFields($v);
if ($v == 'skip') {
continue;
}
......@@ -398,6 +408,8 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
$now = date('YmdHis');
$this->_params = $this->get('params');
$this->cleanMoneyFields($this->_params);
if (!empty($this->_params[0]['contact_id'])) {
// unclear when this would be set & whether it could be checked in getContactID.
// perhaps it relates to when cid is in the url
......@@ -1039,6 +1051,7 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
}
$contribParams['skipLineItem'] = 1;
$contribParams['skipCleanMoney'] = 1;
// create contribution record
$contribution = CRM_Contribute_BAO_Contribution::add($contribParams);
// CRM-11124
......@@ -1296,7 +1309,8 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
$_REQUEST['id'] = $form->_eventId = $params['id'];
$form->controller = new CRM_Event_Controller_Registration();
$form->_params = $params['params'];
$form->_amount = $form->_totalAmount = CRM_Utils_Array::value('totalAmount', $params);
// This happens in buildQuickForm so emulate here.
$form->_amount = $form->_totalAmount = CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value('totalAmount', $params));
$form->set('params', $params['params']);
$form->_values['custom_pre_id'] = array();
$form->_values['custom_post_id'] = array();
......@@ -1332,4 +1346,19 @@ class CRM_Event_Form_Registration_Confirm extends CRM_Event_Form_Registration {
return array();
}
/**
* Clean money fields from the form.
*
* @param array $params
*/
protected function cleanMoneyFields(&$params) {
foreach ($this->submittableMoneyFields as $moneyField) {
foreach ($params as $index => $paramField) {
if (isset($paramField[$moneyField])) {
$params[$index][$moneyField] = CRM_Utils_Rule::cleanMoney($paramField[$moneyField]);
}
}
}
}
}
......@@ -351,7 +351,7 @@ class CRM_Batch_Form_EntryTest extends CiviUnitTestCase {
'field' => array(
1 => array(
'financial_type' => 1,
'total_amount' => $this->formatMoneyInput(1500.15),
'total_amount' => $this->formatMoneyInput(1500.15),
'receive_date' => '2013-07-24',
'receive_date_time' => NULL,
'payment_instrument' => 1,
......
......@@ -81,9 +81,14 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
/**
* Initial test of submit function for paid event.
*
* @param string $thousandSeparator
*
* @dataProvider getThousandSeparators
*
* @throws \Exception
*/
public function testPaidSubmit() {
public function testPaidSubmit($thousandSeparator) {
$this->setCurrencySeparators($thousandSeparator);
$paymentProcessorID = $this->processorCreate();
$params = array('is_monetary' => 1, 'financial_type_id' => 1);
$event = $this->eventCreate($params);
......@@ -93,7 +98,7 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
'contributeMode' => 'direct',
'registerByID' => $individualID,
'paymentProcessorObj' => CRM_Financial_BAO_PaymentProcessor::getPayment($paymentProcessorID),
'totalAmount' => 800,
'totalAmount' => $this->formatMoneyInput(8000.67),
'params' => array(
array(
'qfKey' => 'e6eb2903eae63d4c5c6cc70bfdda8741_2801',
......@@ -133,7 +138,7 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
'participant_role_id' => '1',
'currencyID' => 'USD',
'amount_level' => 'Tiny-tots (ages 5-8) - 1',
'amount' => '800.00',
'amount' => $this->formatMoneyInput(8000.67),
'tax_amount' => NULL,
'year' => '2019',
'month' => '1',
......@@ -147,6 +152,7 @@ class CRM_Event_Form_Registration_ConfirmTest extends CiviUnitTestCase {
));
$this->callAPISuccessGetCount('Participant', array(), 1);
$contribution = $this->callAPISuccessGetSingle('Contribution', array());
$this->assertEquals(8000.67, $contribution['total_amount']);
$lastFinancialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($contribution['id'], 'DESC');
$financialTrxn = $this->callAPISuccessGetSingle(
'FinancialTrxn',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment