diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index 3b636b1523a5..41022c7680c0 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -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. */ @@ -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(); @@ -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; }