Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20866: Soft credit appearance inconsistent in contribution search #11433

Merged
merged 1 commit into from
Dec 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CRM/Contribute/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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());
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
57 changes: 57 additions & 0 deletions tests/phpunit/CRM/Contribute/Selector/SearchTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
* Class CRM_Contribute_Selector_SearchTest
*
* @package CiviCRM
*/
class CRM_Contribute_Selector_SearchTest extends CiviUnitTestCase {

/**
* CRM-20866 - Soft credit appearance inconsistent in contribution search
*/
public function testSoftCreditFieldsSelected() {
$queryParams = array(array('contribution_or_softcredits', '=', 'both_related', 0, 0));
$searchSelector = new CRM_Contribute_Selector_Search($queryParams, CRM_Core_Action::VIEW);

list($select, $from, $where, $having) = $searchSelector->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);
}

}