Merge pull request #11461 from mattwire/tax_calcs_on_edit_contribution
[civicrm-core.git] / tests / phpunit / CRM / Mailing / BAO / QueryTest.php
1 <?php
2
3 /**
4 * Include dataProvider for tests
5 * @group headless
6 */
7 class CRM_Mailing_BAO_QueryTest extends CiviUnitTestCase {
8
9 /**
10 * @return CRM_Mailing_BAO_QueryTestDataProvider
11 */
12 public function dataProvider() {
13 return new CRM_Mailing_BAO_QueryTestDataProvider();
14 }
15
16 public function setUp() {
17 parent::setUp();
18 }
19
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',
30 'civicrm_mailing',
31 'civicrm_mailing_recipients',
32 'civicrm_email',
33 'civicrm_contact',
34 );
35 $this->quickCleanup($tablesToTruncate);
36 }
37
38 /**
39 * Test CRM_Contact_BAO_Query::searchQuery()
40 * @dataProvider dataProvider
41 * @param $fv
42 * @param $count
43 * @param $ids
44 * @param $full
45 */
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'
51 )
52 );
53
54 $params = CRM_Contact_BAO_Query::convertFormValues($fv);
55 $obj = new CRM_Contact_BAO_Query($params);
56
57 // let's set useGroupBy=true, to prevent duplicate records
58 $obj->_useGroupBy = TRUE;
59
60 $dao = $obj->searchQuery();
61
62 $contacts = array();
63 while ($dao->fetch()) {
64 $contacts[] = $dao->contact_id;
65 }
66
67 sort($contacts, SORT_NUMERIC);
68
69 $this->assertEquals($ids, $contacts);
70 }
71
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
92 }