Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | |
3 | /** | |
4 | * Include dataProvider for tests | |
acb109b7 | 5 | * @group headless |
6a488035 TO |
6 | */ |
7 | class CRM_Mailing_BAO_QueryTest extends CiviUnitTestCase { | |
6a488035 | 8 | |
e9479dcf EM |
9 | /** |
10 | * @return CRM_Mailing_BAO_QueryTestDataProvider | |
11 | */ | |
6a488035 | 12 | public function dataProvider() { |
608e6658 | 13 | return new CRM_Mailing_BAO_QueryTestDataProvider(); |
6a488035 TO |
14 | } |
15 | ||
00be9182 | 16 | public function setUp() { |
6a488035 TO |
17 | parent::setUp(); |
18 | } | |
19 | ||
00be9182 | 20 | public function tearDown() { |
6a488035 TO |
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', | |
30 | 'civicrm_mailing', | |
f60d2cb7 | 31 | 'civicrm_mailing_recipients', |
6a488035 TO |
32 | 'civicrm_email', |
33 | 'civicrm_contact', | |
34 | ); | |
35 | $this->quickCleanup($tablesToTruncate); | |
36 | } | |
37 | ||
38 | /** | |
39 | * Test CRM_Contact_BAO_Query::searchQuery() | |
6c6e6187 | 40 | * @dataProvider dataProvider |
1e1fdcf6 EM |
41 | * @param $fv |
42 | * @param $count | |
43 | * @param $ids | |
44 | * @param $full | |
6a488035 | 45 | */ |
00be9182 | 46 | public function testSearch($fv, $count, $ids, $full) { |
6a488035 TO |
47 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); |
48 | $op->execute($this->_dbconn, | |
bbfd46a5 | 49 | $this->createFlatXMLDataSet( |
6a488035 TO |
50 | dirname(__FILE__) . '/queryDataset.xml' |
51 | ) | |
52 | ); | |
53 | ||
54 | $params = CRM_Contact_BAO_Query::convertFormValues($fv); | |
92915c55 | 55 | $obj = new CRM_Contact_BAO_Query($params); |
77c09991 | 56 | |
57 | // let's set useGroupBy=true, to prevent duplicate records | |
58 | $obj->_useGroupBy = TRUE; | |
59 | ||
92915c55 | 60 | $dao = $obj->searchQuery(); |
6a488035 TO |
61 | |
62 | $contacts = array(); | |
63 | while ($dao->fetch()) { | |
64 | $contacts[] = $dao->contact_id; | |
65 | } | |
66 | ||
67 | sort($contacts, SORT_NUMERIC); | |
68 | ||
a15773db | 69 | $this->assertEquals($ids, $contacts); |
6a488035 | 70 | } |
96025800 | 71 | |
5b794985 | 72 | /** |
73 | * CRM-20412: Test accurate count for unique open details | |
74 | */ | |
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' | |
80 | ) | |
81 | ); | |
82 | ||
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); | |
87 | ||
88 | $this->assertEquals(4, $totalOpenedMailCount); | |
89 | $this->assertEquals(4, count($totalOpenedMail)); | |
90 | } | |
91 | ||
6a488035 | 92 | } |