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