.{$this->contributionJoinTableColumn}
LEFT JOIN $this->tempTableRepeat2 {$this->_aliases['civicrm_contribution']}2
ON {$this->groupByTableAlias}.$fromCol = {$this->_aliases['civicrm_contribution']}2.{$this->contributionJoinTableColumn}";
+
+ //Join temp table if report is filtered by group. This is specific to 'notin' operator and covered in unit test(ref dev/core#212)
+ if (!empty($this->_params['gid_op']) && $this->_params['gid_op'] == 'notin') {
+ $this->joinGroupTempTable('civicrm_contact', 'id', $this->_aliases['civicrm_contact']);
+ }
}
/**
public function postProcess() {
$this->beginPostProcess();
+ $this->buildGroupTempTable();
$this->select();
$this->from();
$this->where();
$this->assertEquals(2, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE));
- $this->assertContains('DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci
+ $expected = 'DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci
SELECT SQL_CALC_FOUND_ROWS contact_civireport.id as cid FROM civicrm_contact contact_civireport INNER JOIN civicrm_contribution contribution_civireport USE index (received_date) ON contribution_civireport.contact_id = contact_civireport.id
AND contribution_civireport.is_test = 0
AND contribution_civireport.receive_date BETWEEN \'20140701000000\' AND \'20150630235959\'
-
+
LEFT JOIN civicrm_contribution cont_exclude ON cont_exclude.contact_id = contact_civireport.id
AND cont_exclude.receive_date BETWEEN \'2015-7-1\' AND \'20160630235959\' WHERE cont_exclude.id IS NULL AND 1 AND ( contribution_civireport.contribution_status_id IN (1) )
- GROUP BY contact_civireport.id', $rows['metadata']['sql'][0]);
+ GROUP BY contact_civireport.id';
+ $this->assertContains(preg_replace('/\s+/', ' ', $expected), preg_replace('/\s+/', ' ', $rows['metadata']['sql'][0]));
}
/**
}
}
+ /**
+ * Test the group filter works on the various reports.
+ *
+ * @dataProvider getMembershipAndContributionReportTemplatesForGroupTests
+ *
+ * @param string $template
+ * Report template unique identifier.
+ */
+ public function testReportsWithNoTInSmartGroupFilter($template) {
+ $groupID = $this->setUpPopulatedGroup();
+ $rows = $this->callAPISuccess('report_template', 'getrows', array(
+ 'report_id' => $template,
+ 'gid_value' => array($groupID),
+ 'gid_op' => 'notin',
+ 'options' => array('metadata' => array('sql')),
+ ));
+ $this->assertNumberOfContactsInResult(2, $rows, $template);
+ }
+
}