4 * Include dataProvider for tests
7 class CRM_Mailing_BAO_QueryTest
extends CiviUnitTestCase
{
10 * @return CRM_Mailing_BAO_QueryTestDataProvider
12 public function dataProvider() {
13 return new CRM_Mailing_BAO_QueryTestDataProvider();
16 public function setUp() {
20 public function tearDown() {
21 $tablesToTruncate = array(
22 'civicrm_mailing_event_bounce',
23 'civicrm_mailing_event_delivered',
24 'civicrm_mailing_event_opened',
25 'civicrm_mailing_event_reply',
26 'civicrm_mailing_event_trackable_url_open',
27 'civicrm_mailing_event_queue',
28 'civicrm_mailing_trackable_url',
29 'civicrm_mailing_job',
31 'civicrm_mailing_recipients',
35 $this->quickCleanup($tablesToTruncate);
39 * Test CRM_Contact_BAO_Query::searchQuery()
40 * @dataProvider dataProvider
46 public function testSearch($fv, $count, $ids, $full) {
47 $op = new PHPUnit_Extensions_Database_Operation_Insert();
48 $op->execute($this->_dbconn
,
49 $this->createFlatXMLDataSet(
50 dirname(__FILE__
) . '/queryDataset.xml'
54 $params = CRM_Contact_BAO_Query
::convertFormValues($fv);
55 $obj = new CRM_Contact_BAO_Query($params);
57 // let's set useGroupBy=true, to prevent duplicate records
58 $obj->_useGroupBy
= TRUE;
60 $dao = $obj->searchQuery();
63 while ($dao->fetch()) {
64 $contacts[] = $dao->contact_id
;
67 sort($contacts, SORT_NUMERIC
);
69 $this->assertEquals($ids, $contacts);
73 * CRM-20412: Test accurate count for unique open details
75 public function testOpenedMailingQuery() {
76 $op = new PHPUnit_Extensions_Database_Operation_Insert();
77 $op->execute($this->_dbconn
,
78 $this->createFlatXMLDataSet(
79 dirname(__FILE__
) . '/queryDataset.xml'
83 // ensure that total unique opened mail count is same while
84 // fetching rows and row count for mailing_id = 14
85 $totalOpenedMailCount = CRM_Mailing_Event_BAO_Opened
::getTotalCount(14, NULL, TRUE);
86 $totalOpenedMail = CRM_Mailing_Event_BAO_Opened
::getRows(14, NULL, TRUE);
88 $this->assertEquals(4, $totalOpenedMailCount);
89 $this->assertEquals(4, count($totalOpenedMail));