From e58a3abb59dd041dd274e5f68657bb6d09cbc0f0 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 5 Jul 2016 19:50:33 +1200 Subject: [PATCH] CRM-19045 contribution.api total_amount cannot be returned using operators --- CRM/Contact/BAO/Query.php | 2 +- tests/phpunit/api/v3/ContributionTest.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 498c2dcfe7..8eb6257ddf 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -2258,7 +2258,7 @@ class CRM_Contact_BAO_Query { $fieldName = "LOWER(contact_a.{$fieldName})"; } else { - if ($op != 'IN' && !is_numeric($value)) { + if ($op != 'IN' && !is_numeric($value) && !is_array($value)) { $fieldName = "LOWER({$field['where']})"; } else { diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index 07a06a2c8b..b2fd05a1bc 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -540,6 +540,22 @@ class api_v3_ContributionTest extends CiviUnitTestCase { // 2); } + /** + * Test retrieval by total_amount works. + * + * @throws Exception + */ + public function testGetContributionByTotalAmount() { + $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('total_amount' => '5'))); + $this->callAPISuccess('Contribution', 'create', array_merge($this->_params, array('total_amount' => '10'))); + $this->callAPISuccessGetCount('Contribution', array('total_amount' => 10), 1); + $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => 6)), 1); + $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => 0)), 2); + $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('>' => -5)), 2); + $this->callAPISuccessGetCount('Contribution', array('total_amount' => array('<' => 0)), 0); + $this->callAPISuccessGetCount('Contribution', array(), 2); + } + /** * Create test with unique field name on source. */ -- 2.25.1