From b4bb60fc32391a20570f22ce53e801c67ec1a8b1 Mon Sep 17 00:00:00 2001 From: Octo Hapiness Date: Tue, 19 Dec 2017 05:46:00 +0100 Subject: [PATCH] CRM-20866: Soft credit appearance inconsistent in contribution search --- CRM/Contribute/BAO/Query.php | 7 ++- CRM/Contribute/Selector/Search.php | 2 +- .../CRM/Contribute/Selector/SearchTest.php | 57 +++++++++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 tests/phpunit/CRM/Contribute/Selector/SearchTest.php diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 23c32b4fcdf5..f3e9fabf7e9a 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -730,8 +730,11 @@ public static function softCreditReturnProperties($isExportMode = FALSE) { * * The default return properties array returns far too many fields for 'everyday use. Every field you add to this array * kills a small kitten so add carefully. + * + * @param array $queryParams + * @return array */ - public static function selectorReturnProperties() { + public static function selectorReturnProperties($queryParams) { $properties = array( 'contact_type' => 1, 'contact_sub_type' => 1, @@ -758,7 +761,7 @@ public static function selectorReturnProperties() { 'cancel_date' => 1, 'contribution_recur_id' => 1, ); - if (self::isSoftCreditOptionEnabled()) { + if (self::isSoftCreditOptionEnabled($queryParams)) { $properties = array_merge($properties, self::softCreditReturnProperties()); } diff --git a/CRM/Contribute/Selector/Search.php b/CRM/Contribute/Selector/Search.php index d05e92ce084a..069dd8a1a583 100644 --- a/CRM/Contribute/Selector/Search.php +++ b/CRM/Contribute/Selector/Search.php @@ -179,7 +179,7 @@ public function __construct( // type of selector $this->_action = $action; - $returnProperties = CRM_Contribute_BAO_Query::selectorReturnProperties(); + $returnProperties = CRM_Contribute_BAO_Query::selectorReturnProperties($this->_queryParams); $this->_includeSoftCredits = CRM_Contribute_BAO_Query::isSoftCreditOptionEnabled($this->_queryParams); $this->_query = new CRM_Contact_BAO_Query( $this->_queryParams, diff --git a/tests/phpunit/CRM/Contribute/Selector/SearchTest.php b/tests/phpunit/CRM/Contribute/Selector/SearchTest.php new file mode 100644 index 000000000000..108941ec21d3 --- /dev/null +++ b/tests/phpunit/CRM/Contribute/Selector/SearchTest.php @@ -0,0 +1,57 @@ +getQuery()->query(); + self::assertContains('civicrm_contribution_soft.amount', $select); + } + + /** + * CRM-20866 - Soft credit appearance inconsistent in contribution search + */ + public function testSoftCreditFieldNotSelected() { + $queryParams = array(array('contribution_or_softcredits', '=', 'only_contribs', 0, 0)); + $searchSelector = new CRM_Contribute_Selector_Search($queryParams, CRM_Core_Action::VIEW); + + list($select, $from, $where, $having) = $searchSelector->getQuery()->query(); + self::assertNotContains('civicrm_contribution_soft.amount', $select); + } + +}