Merge pull request #2546 from brylie/master
[civicrm-core.git] / tests / phpunit / api / v3 / CustomSearchTest.php
1 <?php
2
3 require_once 'CiviTest/CiviUnitTestCase.php';
4
5 class api_v3_CustomSearchTest extends CiviUnitTestCase {
6 protected $_apiversion;
7
8 function setUp() {
9 $this->_apiversion = 3;
10 parent::setUp();
11 }
12
13 function tearDown() {}
14
15 public function testCustomSearch() {
16 $result = $this->callAPISuccess('CustomSearch', 'create', array(
17 'label' => 'Invalid, overwritten',
18 'description' => 'Longish description of the example search form',
19 'class_name' => 'CRM_Contact_Form_Search_Custom_Examplez',
20 ));
21 $this->assertAPISuccess($result);
22 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
23 $entityId = $result['id'];
24 $this->assertTrue(is_numeric($entityId), 'In line ' . __LINE__);
25 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
26 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
27 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
28 AND option_group_id = 25');
29 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
30 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
31
32 // deactivate
33 $result = $this->callAPISuccess('CustomSearch', 'create', array(
34 'id' => $entityId,
35 'is_active' => 0,
36 ));
37
38 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
39 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
40 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
41 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
42 AND option_group_id = 25');
43 $this->assertDBQuery(0, 'SELECT is_active FROM civicrm_option_value
44 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
45
46 // activate
47 $result = $this->callAPISuccess('CustomSearch', 'create', array(
48 'id' => $entityId,
49 'is_active' => 1,
50 ));
51
52 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
53 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
54 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
55 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
56 AND option_group_id = 25');
57 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
58 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
59
60 $result = $this->callAPISuccess('CustomSearch', 'delete', array(
61 'id' => $entityId,
62 ));
63 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__);
64 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value
65 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
66 OR label = "CRM_Contact_Form_Search_Custom_Examplez"
67 ');
68 }
69 }