Skip to content

Commit

Permalink
Added test case
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Dec 19, 2018
1 parent b736d2b commit ead1a15
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
4 changes: 0 additions & 4 deletions CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -2236,11 +2236,7 @@ public static function &report($id, $skipDetails = FALSE, $isSMS = FALSE) {
break;

case 'opened':
$url = "mailing/opened";
$searchFilter .= "&mailing_open_status=Y";
$reportFilter .= "&distinct=0"; // do not use group by clause in report, because same report used for total and unique open
break;

case 'opened_unique':
$url = "mailing/opened";
$searchFilter .= "&mailing_open_status=Y";
Expand Down
1 change: 0 additions & 1 deletion CRM/Report/Form/Mailing/Opened.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ public function groupBy() {
}
}
if (!empty($groupBys)) {
$this->_select = CRM_Contact_BAO_Query::appendAnyValueToSelect($this->_selectClauses, $groupBys);
$this->_groupBy = "GROUP BY " . implode(', ', $groupBys);
}
}
Expand Down
29 changes: 27 additions & 2 deletions tests/phpunit/api/v3/ReportTemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function hookSelectWhere($entity, &$clauses) {
*/
public function testReportTemplateGetRowsContactSummary() {
$description = "Retrieve rows from a report template (optionally providing the instance_id).";
$result = $this->callAPIAndDocument('report_template', 'getrows', array(
$result = $this->callApiSuccess('report_template', 'getrows', array(
'report_id' => 'contact/summary',
'options' => array('metadata' => array('labels', 'title')),
), __FUNCTION__, __FILE__, $description, 'Getrows');
Expand All @@ -216,12 +216,37 @@ public function testReportTemplateGetRowsContactSummary() {
*/
public function testReportTemplateGetRowsMailingUniqueOpened() {
$description = "Retrieve rows from a mailing opened report template.";
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
$this->createFlatXMLDataSet(
dirname(__FILE__) . '/../../CRM/Mailing/BAO/queryDataset.xml'
)
);

// Check total rows without distinct
global $_REQUEST;
$_REQUEST['distinct'] = 0;
$result = $this->callAPIAndDocument('report_template', 'getrows', array(
'report_id' => 'Mailing/opened',
'options' => array('metadata' => array('labels', 'title')),
), __FUNCTION__, __FILE__, $description, 'Getrows');
$this->assertEquals(14, $result['count']);

$this->assertEquals(4, $result['count']);
// Check total rows with distinct
$_REQUEST['distinct'] = 1;
$result = $this->callAPIAndDocument('report_template', 'getrows', array(
'report_id' => 'Mailing/opened',
'options' => array('metadata' => array('labels', 'title')),
), __FUNCTION__, __FILE__, $description, 'Getrows');
$this->assertEquals(5, $result['count']);

// Check total rows with distinct by passing NULL value to distinct parameter
$_REQUEST['distinct'] = NULL;
$result = $this->callAPIAndDocument('report_template', 'getrows', array(
'report_id' => 'Mailing/opened',
'options' => array('metadata' => array('labels', 'title')),
), __FUNCTION__, __FILE__, $description, 'Getrows');
$this->assertEquals(5, $result['count']);
}

/**
Expand Down

0 comments on commit ead1a15

Please sign in to comment.