commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-old / civicrm / tests / phpunit / CRM / Mailing / BAO / QueryTest.php
1 <?php
2 require_once 'CiviTest/CiviUnitTestCase.php';
3 require_once 'CiviTest/Contact.php';
4
5 /**
6 * Include dataProvider for tests
7 */
8 class CRM_Mailing_BAO_QueryTest extends CiviUnitTestCase {
9
10 /**
11 * @return CRM_Mailing_BAO_QueryTestDataProvider
12 */
13 public function dataProvider() {
14 return new CRM_Mailing_BAO_QueryTestDataProvider();
15 }
16
17 public function setUp() {
18 parent::setUp();
19 }
20
21 public function tearDown() {
22 $tablesToTruncate = array(
23 'civicrm_mailing_event_bounce',
24 'civicrm_mailing_event_delivered',
25 'civicrm_mailing_event_opened',
26 'civicrm_mailing_event_reply',
27 'civicrm_mailing_event_trackable_url_open',
28 'civicrm_mailing_event_queue',
29 'civicrm_mailing_trackable_url',
30 'civicrm_mailing_job',
31 'civicrm_mailing',
32 'civicrm_mailing_recipients',
33 'civicrm_email',
34 'civicrm_contact',
35 );
36 $this->quickCleanup($tablesToTruncate);
37 }
38
39 /**
40 * Test CRM_Contact_BAO_Query::searchQuery()
41 * @dataProvider dataProvider
42 * @param $fv
43 * @param $count
44 * @param $ids
45 * @param $full
46 */
47 public function testSearch($fv, $count, $ids, $full) {
48 $op = new PHPUnit_Extensions_Database_Operation_Insert();
49 $op->execute($this->_dbconn,
50 $this->createFlatXMLDataSet(
51 dirname(__FILE__) . '/queryDataset.xml'
52 )
53 );
54
55 $params = CRM_Contact_BAO_Query::convertFormValues($fv);
56 $obj = new CRM_Contact_BAO_Query($params);
57
58 // let's set useGroupBy=true, to prevent duplicate records
59 $obj->_useGroupBy = TRUE;
60
61 $dao = $obj->searchQuery();
62
63 $contacts = array();
64 while ($dao->fetch()) {
65 $contacts[] = $dao->contact_id;
66 }
67
68 sort($contacts, SORT_NUMERIC);
69
70 $this->assertEquals($ids, $contacts, 'In line ' . __LINE__);
71 }
72
73 }