Commit | Line | Data |
---|---|---|
6a488035 TO |
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_Contact_BAO_QueryTest extends CiviUnitTestCase { | |
9 | function get_info() { | |
10 | return array( | |
11 | 'name' => 'Contact BAO Query', | |
12 | 'description' => 'Test all Contact_BAO_Query methods.', | |
13 | 'group' => 'CiviCRM BAO Query Tests', | |
14 | ); | |
15 | } | |
16 | ||
17 | public function dataProvider() { | |
18 | return new CRM_Contact_BAO_QueryTestDataProvider; | |
19 | } | |
20 | ||
21 | function setUp() { | |
22 | parent::setUp(); | |
23 | } | |
24 | ||
25 | function tearDown() { | |
26 | $tablesToTruncate = array( | |
27 | 'civicrm_group_contact', | |
28 | 'civicrm_group', | |
29 | 'civicrm_saved_search', | |
30 | 'civicrm_entity_tag', | |
31 | 'civicrm_tag', | |
32 | 'civicrm_contact', | |
33 | ); | |
34 | $this->quickCleanup($tablesToTruncate); | |
35 | } | |
36 | ||
37 | /** | |
38 | * Test CRM_Contact_BAO_Query::searchQuery() | |
39 | * @dataProvider dataProvider | |
40 | */ | |
41 | function testSearch($fv, $count, $ids, $full) { | |
42 | $op = new PHPUnit_Extensions_Database_Operation_Insert(); | |
43 | $op->execute($this->_dbconn, | |
44 | new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet( | |
45 | dirname(__FILE__) . '/queryDataset.xml' | |
46 | ) | |
47 | ); | |
48 | ||
49 | $params = CRM_Contact_BAO_Query::convertFormValues($fv); | |
50 | $obj = new CRM_Contact_BAO_Query($params); | |
51 | $dao = $obj->searchQuery(); | |
52 | ||
53 | $contacts = array(); | |
54 | while ($dao->fetch()) { | |
55 | $contacts[] = $dao->contact_id; | |
56 | } | |
57 | ||
58 | sort($contacts, SORT_NUMERIC); | |
59 | ||
60 | $this->assertEquals($ids, $contacts, 'In line ' . __LINE__); | |
61 | } | |
62 | } | |
63 |