From bb35c5f3477a97b937cf083fa1b66e315ae53507 Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Sat, 29 Aug 2020 11:48:11 -0400 Subject: [PATCH] Clean money for non-deductible amount tests --- api/v3/Contribution.php | 2 +- tests/phpunit/api/v3/ContributionTest.php | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/api/v3/Contribution.php b/api/v3/Contribution.php index 7a5e94dcb5..6303617982 100644 --- a/api/v3/Contribution.php +++ b/api/v3/Contribution.php @@ -32,7 +32,7 @@ function civicrm_api3_contribution_create($params) { // The BAO should not clean money - it should be done in the form layer & api wrapper // (although arguably the api should expect pre-cleaned it seems to do some cleaning.) if (empty($params['skipCleanMoney'])) { - foreach (['total_amount', 'net_amount', 'fee_amount'] as $field) { + foreach (['total_amount', 'net_amount', 'fee_amount', 'non_deductible_amount'] as $field) { if (isset($params[$field])) { $params[$field] = CRM_Utils_Rule::cleanMoney($params[$field]); } diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index bf24317b88..0e088557b0 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -4948,4 +4948,26 @@ class api_v3_ContributionTest extends CiviUnitTestCase { $this->assertEquals('Completed', $contribution['contribution_status']); } + /** + * Test the "clean money" functionality. + */ + public function testCleanMoney() { + $params = [ + 'contact_id' => $this->_individualId, + 'financial_type_id' => 1, + 'total_amount' => '$100', + 'fee_amount' => '$20', + 'net_amount' => '$80', + 'non_deductible_amount' => '$80', + 'sequential' => 1, + ]; + $id = $this->callAPISuccess('Contribution', 'create', $params)['id']; + // Reading the return values of the API isn't reliable here; get the data from the db. + $contribution = $this->callAPISuccess('Contribution', 'getsingle', ['id' => $id]); + $this->assertEquals('100.00', $contribution['total_amount']); + $this->assertEquals('20.00', $contribution['fee_amount']); + $this->assertEquals('80.00', $contribution['net_amount']); + $this->assertEquals('80.00', $contribution['non_deductible_amount']); + } + } -- 2.25.1