From ead1a15e04a730ddd3634e75ea84c0d34974a9ac Mon Sep 17 00:00:00 2001 From: Monish Deb Date: Wed, 19 Dec 2018 20:11:58 +0530 Subject: [PATCH] Added test case --- CRM/Mailing/BAO/Mailing.php | 4 --- CRM/Report/Form/Mailing/Opened.php | 1 - tests/phpunit/api/v3/ReportTemplateTest.php | 29 +++++++++++++++++++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 03f6afb4d0..434355d1e5 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -2236,11 +2236,7 @@ ORDER BY civicrm_email.is_bulkmail DESC 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"; diff --git a/CRM/Report/Form/Mailing/Opened.php b/CRM/Report/Form/Mailing/Opened.php index 98ba274137..62a076dc34 100644 --- a/CRM/Report/Form/Mailing/Opened.php +++ b/CRM/Report/Form/Mailing/Opened.php @@ -299,7 +299,6 @@ class CRM_Report_Form_Mailing_Opened extends CRM_Report_Form { } } if (!empty($groupBys)) { - $this->_select = CRM_Contact_BAO_Query::appendAnyValueToSelect($this->_selectClauses, $groupBys); $this->_groupBy = "GROUP BY " . implode(', ', $groupBys); } } diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index 1f4ff7e1fc..c758370f08 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -192,7 +192,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { */ 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'); @@ -216,12 +216,37 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { */ 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']); } /** -- 2.25.1