CRM-19045 contribution.api total_amount cannot be returned using operators
authoreileen <emcnaughton@wikimedia.org>
Tue, 5 Jul 2016 07:50:33 +0000 (19:50 +1200)
committereileen <emcnaughton@wikimedia.org>
Tue, 5 Jul 2016 07:50:33 +0000 (19:50 +1200)
CRM/Contact/BAO/Query.php
tests/phpunit/api/v3/ContributionTest.php

index 498c2dcfe77282173d99444dce4a9fff4e2457a8..8eb6257ddfbfab4eeebfb1070ed0ac9b9d87fc8a 100644 (file)
@@ -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 {
index 07a06a2c8bae8f30099402a2278df63338f4ed59..b2fd05a1bcd418e65b26bb4f700e50fd3d239380 100644 (file)
@@ -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.
    */