From 2b3e31ac1c66724ac4eb706a98fe7cdf1975e52c Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 31 Dec 2016 09:24:28 +1300 Subject: [PATCH] CRM-19811 fix contribution search to not use LOWER() on default fields (e.g. creditnote_id). Add unit test to demonstrate case sensitivity still respected --- CRM/Contribute/BAO/Query.php | 5 ++--- tests/phpunit/api/v3/ContributionTest.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 0702247218..9807acc2cf 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -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; diff --git a/tests/phpunit/api/v3/ContributionTest.php b/tests/phpunit/api/v3/ContributionTest.php index e3e6c0936a..eda27e457b 100644 --- a/tests/phpunit/api/v3/ContributionTest.php +++ b/tests/phpunit/api/v3/ContributionTest.php @@ -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. * -- 2.25.1