Skip to content

Commit

Permalink
Merge pull request #10603 from JMAConsulting/CRM-20640
Browse files Browse the repository at this point in the history
CRM-20640: Added unit test for the fix
  • Loading branch information
eileenmcnaughton authored Jul 4, 2017
2 parents 1f356cc + 27367f5 commit aad414c
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion tests/phpunit/api/v3/ReportTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,28 @@ public function testContributionSummaryWithTwoGroups() {
$this->assertEquals(4, $rows['values'][0]['civicrm_contribution_total_amount_count']);
}

/**
* CRM-20640: Test the group filter works on the contribution summary when a single contact in 2 groups.
*/
public function testContributionSummaryWithSingleContactsInTwoGroups() {
list($groupID1, $individualID) = $this->setUpPopulatedGroup(TRUE);
// create second group and add the individual to it.
$groupID2 = $this->groupCreate(array('name' => uniqid(), 'title' => uniqid()));
$this->callAPISuccess('GroupContact', 'create', array(
'group_id' => $groupID2,
'contact_id' => $individualID,
'status' => 'Added',
));

$rows = $this->callAPISuccess('report_template', 'getrows', array(
'report_id' => 'contribute/summary',
'gid_value' => array($groupID1, $groupID2),
'gid_op' => 'in',
'options' => array('metadata' => array('sql')),
));
$this->assertEquals(1, $rows['count']);
}

/**
* Test the group filter works on the contribution summary when 2 groups are involved.
*/
Expand Down Expand Up @@ -463,9 +485,11 @@ public function setUpPopulatedSmartGroup() {
* This gives us a range of scenarios for testing contacts are included only once
* whenever they are hard-added or in the criteria.
*
* @param bool $returnAddedContact
*
* @return int
*/
public function setUpPopulatedGroup() {
public function setUpPopulatedGroup($returnAddedContact = FALSE) {
$individual1ID = $this->individualCreate();
$individualID = $this->individualCreate();
$individualIDRemoved = $this->individualCreate();
Expand All @@ -487,6 +511,11 @@ public function setUpPopulatedGroup() {

// Refresh the cache for test purposes. It would be better to alter to alter the GroupContact add function to add contacts to the cache.
CRM_Contact_BAO_GroupContactCache::remove($groupID, FALSE);

if ($returnAddedContact) {
return array($groupID, $individualID);
}

return $groupID;
}

Expand Down

0 comments on commit aad414c

Please sign in to comment.