3 require_once 'CiviTest/CiviUnitTestCase.php';
6 * Class api_v3_CustomSearchTest
8 class api_v3_CustomSearchTest
extends CiviUnitTestCase
{
9 protected $_apiversion;
11 public function setUp() {
12 $this->_apiversion
= 3;
14 $this->useTransaction(TRUE);
17 public function testCustomSearch() {
18 $result = $this->callAPISuccess('CustomSearch', 'create', array(
19 'label' => 'Invalid, overwritten',
20 'description' => 'Longish description of the example search form',
21 'class_name' => 'CRM_Contact_Form_Search_Custom_Examplez',
23 $this->assertAPISuccess($result);
24 $this->assertEquals(1, $result['count']);
25 $entityId = $result['id'];
26 $this->assertTrue(is_numeric($entityId));
27 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
28 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
29 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
30 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
31 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
32 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
35 $result = $this->callAPISuccess('CustomSearch', 'create', array(
40 $this->assertEquals(1, $result['count']);
41 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
42 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
43 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
44 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
45 $this->assertDBQuery(0, 'SELECT is_active FROM civicrm_option_value
46 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
49 $result = $this->callAPISuccess('CustomSearch', 'create', array(
54 $this->assertEquals(1, $result['count']);
55 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
56 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
57 AND label = "CRM_Contact_Form_Search_Custom_Examplez"
58 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "custom_search") ');
59 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
60 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"');
62 $result = $this->callAPISuccess('CustomSearch', 'delete', array(
65 $this->assertEquals(1, $result['count']);
66 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value
67 WHERE name = "CRM_Contact_Form_Search_Custom_Examplez"
68 OR label = "CRM_Contact_Form_Search_Custom_Examplez"