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-19752 - Unit Test for issue CRM-19752 #9746

Merged
merged 1 commit into from
Feb 1, 2018
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
38 changes: 28 additions & 10 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -4895,17 +4895,10 @@ public function &summaryContribution($context = NULL) {
if ($context == 'search') {
$where .= " AND contact_a.is_deleted = 0 ";
}
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
if (!empty($financialTypes)) {
$where .= " AND civicrm_contribution.financial_type_id IN (" . implode(',', array_keys($financialTypes)) . ") AND li.id IS NULL";
$from .= " LEFT JOIN civicrm_line_item li
ON civicrm_contribution.id = li.contribution_id AND
li.entity_table = 'civicrm_contribution' AND li.financial_type_id NOT IN (" . implode(',', array_keys($financialTypes)) . ") ";
}
else {
$where .= " AND civicrm_contribution.financial_type_id IN (0)";
}

$query = $this->getSummaryQuery($where, $from);
$where = $query[0];
$from = $query[1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be .=

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope it doesnt'

// make sure contribution is completed - CRM-4989
$completedWhere = $where . " AND civicrm_contribution.contribution_status_id = 1 ";

Expand Down Expand Up @@ -5035,6 +5028,31 @@ public function &summaryContribution($context = NULL) {
return $summary;
}

/**
* Function for getting the SummaryQuery of the respective financial type
*
* @param $where
* @param $from
*
* @return array
*/
public function getSummaryQuery($where, $from) {
if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
$financialTypes = CRM_Contribute_PseudoConstant::financialType();
}
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
if (!empty($financialTypes)) {
$where .= " AND civicrm_contribution.financial_type_id IN (" . implode(',', array_keys($financialTypes)) . ") AND li.id IS NULL";
$from .= " LEFT JOIN civicrm_line_item li
ON civicrm_contribution.id = li.contribution_id AND
li.entity_table = 'civicrm_contribution' AND li.financial_type_id NOT IN (" . implode(',', array_keys($financialTypes)) . ") ";
}
else {
$where .= " AND civicrm_contribution.financial_type_id IN (0)";
}
return array($where, $from, $financialTypes);
}

/**
* Getter for the qill object.
*
Expand Down
23 changes: 23 additions & 0 deletions tests/phpunit/CRM/Contact/BAO/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,27 @@ public function testContactIDClause() {
$this->fail('Test failed for some reason which is not good');
}

public function testGetSummaryQueryWithFinancialACLDisabled() {
$where = NULL;
$from = NULL;
$CRM_Contact_BAO_Query = new CRM_Contact_BAO_Query();
$query = $CRM_Contact_BAO_Query->getSummaryQuery($where, $from);
$this->assertEquals(" AND civicrm_contribution.financial_type_id IN (" . implode(',', array_keys($query[2])) . ") AND li.id IS NULL", $query[0]);
}

public function testGetSummaryQueryWithFinancialACLEnabled() {
$where = NULL;
$from = NULL;
$cid = $this->createLoggedInUser();
CRM_Core_Config::singleton()->userPermissionClass->permissions = array('access CiviCRM', 'CiviCRM: view contributions of type Donation');
$CRM_Contact_BAO_Query = new CRM_Contact_BAO_Query();
$query = $CRM_Contact_BAO_Query->getSummaryQuery($where, $from);
$from = $query[1];
$financialTypes = $query[2];
$this->assertEquals(
" LEFT JOIN civicrm_line_item li
ON civicrm_contribution.id = li.contribution_id AND
li.entity_table = 'civicrm_contribution' AND li.financial_type_id NOT IN (" . implode(',', array_keys($financialTypes)) . ") ", $from);
}

}