Skip to content

Commit

Permalink
Merge pull request #12809 from eileenmcnaughton/report_test
Browse files Browse the repository at this point in the history
Report Template test for SelectWhere - add test
  • Loading branch information
eileenmcnaughton authored Sep 13, 2018
2 parents 8f7f840 + 880f81a commit 7b43caf
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions tests/phpunit/api/v3/ReportTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,77 @@ public function testReportTemplate() {
');
}

/**
* Test api to get rows from reports.
*
* @dataProvider getReportTemplatesSupportingSelectWhere
*
* @param $reportID
*
* @throws \PHPUnit_Framework_IncompleteTestError
*/
public function testReportTemplateSelectWhere($reportID) {
$this->hookClass->setHook('civicrm_selectWhereClause', array($this, 'hookSelectWhere'));
$result = $this->callAPISuccess('report_template', 'getrows', [
'report_id' => $reportID,
'options' => ['metadata' => ['sql']],
]);
$found = FALSE;
foreach ($result['metadata']['sql'] as $sql) {
if (strstr($sql, " = 'Organization' ")) {
$found = TRUE;
}
}
$this->assertTrue($found, $reportID);
}

/**
* Get templates suitable for SelectWhere test.
*
* @return array
*/
public function getReportTemplatesSupportingSelectWhere() {
$allTemplates = $this->getReportTemplates();
// Exclude all that do not work as of test being written. I have not dug into why not.
$currentlyExcluded = [
'contribute/repeat',
'contact/detail',
'member/summary',
'event/summary',
'case/summary',
'case/timespent',
'case/demographics',
'contact/log',
'contribute/bookkeeping',
'grant/detail',
'event/incomesummary',
'case/detail',
'Mailing/bounce',
'Mailing/summary',
'grant/statistics',
'logging/contact/detail',
'logging/contact/summary',
];
foreach ($allTemplates as $index => $template) {
$reportID = $template[0];
if (in_array($reportID, $currentlyExcluded) || stristr($reportID, 'has existing issues')) {
unset($allTemplates[$index]);
}
}
return $allTemplates;
}

/**
* @param \CRM_Core_DAO $entity
* @param array $clauses
*/
public function hookSelectWhere($entity, &$clauses) {
// Restrict access to cases by type
if ($entity == 'Contact') {
$clauses['contact_type'][] = " = 'Organization' ";
}
}

/**
* Test getrows on contact summary report.
*/
Expand Down

0 comments on commit 7b43caf

Please sign in to comment.