CRM-19811 fix contribution search to not use LOWER() on default fields (e.g. creditno...
authoreileen <emcnaughton@wikimedia.org>
Fri, 30 Dec 2016 20:24:28 +0000 (09:24 +1300)
committereileen <emcnaughton@wikimedia.org>
Fri, 30 Dec 2016 21:27:01 +0000 (10:27 +1300)
Add unit test to demonstrate case sensitivity still respected

CRM/Contribute/BAO/Query.php
tests/phpunit/api/v3/ContributionTest.php

index 0702247218abf83934712a99d4788cd7b0dfbca6..9807acc2cffc222c1cbaa41fef19d45b7cd085c1 100644 (file)
@@ -611,10 +611,9 @@ class CRM_Contribute_BAO_Query extends CRM_Core_BAO_Query {
           $dataType = CRM_Utils_Type::typeToString($whereTable['type']);
         }
 
-        $wc = ($op != 'LIKE' && $dataType != 'Date') ? "LOWER($whereTable[where])" : "$whereTable[where]";
-        $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($wc, $op, $value, $dataType);
+        $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause($whereTable['where'], $op, $value, $dataType);
         $query->_qill[$grouping][] = "$whereTable[title] $op $quoteValue";
-        list($tableName, $fieldName) = explode('.', $whereTable['where'], 2);
+        list($tableName) = explode('.', $whereTable['where'], 2);
         $query->_tables[$tableName] = $query->_whereTables[$tableName] = 1;
         if ($tableName == 'civicrm_contribution_product') {
           $query->_tables['civicrm_product'] = $query->_whereTables['civicrm_product'] = 1;
index e3e6c0936aa3eaec21381ccc9d7053748af6dadb..eda27e457b54aaca7c53aef5cec004ddbdd62c46 100644 (file)
@@ -540,6 +540,16 @@ class api_v3_ContributionTest extends CiviUnitTestCase {
     // 2);
   }
 
+  /**
+   * Check the credit note retrieval is case insensitive.
+   */
+  public function testGetCreditNoteCaseInsensitive() {
+    $this->contributionCreate(array('contact_id' => $this->_individualId));
+    $this->contributionCreate(array('creditnote_id' => 'cN1234', 'contact_id' => $this->_individualId, 'invoice_id' => rand(), 'trxn_id' => rand()));
+    $contribution = $this->callAPISuccess('Contribution', 'getsingle', array('creditnote_id' => 'CN1234'));
+    $this->assertEquals($contribution['creditnote_id'], 'cN1234');
+  }
+
   /**
    * Test retrieval by total_amount works.
    *